From 85553593eb17861afc091a8054e7fae2a357b380 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 28 May 2001 08:31:02 +0000 Subject: [PATCH] * geturl.cc (get_url_to_file): Add parameter `allow_ftp_auth'. * geturl.h: Change declaration of `get_url_to_file' accordingly. * netio.cc (NetIO::NetIO): Add parameter `allow_ftp_auth'. Set member `ftp_auth'. (NetIO::open): Add parameter `allow_ftp_auth'. Use it in calls to constructors of derived classes. (NetIO::get_ftp_auth): New method. * netio.h: Change class definition accordingly. * nio-ftp.cc (NetIO_FTP::NetIO_FTP): Add parameter `allow_ftp_auth'. Take global variables `net_ftp_user' and `net_ftp_passwd' into account. Add code for ftp authentication retry. * nio-ftp.h: Change class definition accordingly. * nio-http.cc (NetIO_HTTP::NetIO_HTTP): Add parameter `allow_ftp_auth'. Add code for ftp authentication retry in case of proxy connection. * nio-http.h: Change class definition accordingly. * res.rc: Add FTP authentication dialog. * resource.h: Add new constants used in res.rc. * state.h: Add variables `net_ftp_user' and `net_ftp_passwd'. --- ChangeLog | 21 +++++++++++++++++++++ geturl.cc | 7 ++++--- geturl.h | 5 +++-- netio.cc | 31 ++++++++++++++++++++++++++----- netio.h | 6 ++++-- nio-ftp.cc | 24 +++++++++++++++++++----- nio-ftp.h | 4 ++-- nio-http.cc | 21 ++++++++++++++++++--- nio-http.h | 4 ++-- res.rc | 23 +++++++++++++++++++++++ resource.h | 3 ++- state.h | 4 +++- 12 files changed, 127 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7fdfcc87..886a9f63 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +Tue Mar 6 19:14:00 2001 Corinna Vinschen + + * geturl.cc (get_url_to_file): Add parameter `allow_ftp_auth'. + * geturl.h: Change declaration of `get_url_to_file' accordingly. + * netio.cc (NetIO::NetIO): Add parameter `allow_ftp_auth'. + Set member `ftp_auth'. + (NetIO::open): Add parameter `allow_ftp_auth'. Use it in calls + to constructors of derived classes. + (NetIO::get_ftp_auth): New method. + * netio.h: Change class definition accordingly. + * nio-ftp.cc (NetIO_FTP::NetIO_FTP): Add parameter `allow_ftp_auth'. + Take global variables `net_ftp_user' and `net_ftp_passwd' into account. + Add code for ftp authentication retry. + * nio-ftp.h: Change class definition accordingly. + * nio-http.cc (NetIO_HTTP::NetIO_HTTP): Add parameter `allow_ftp_auth'. + Add code for ftp authentication retry in case of proxy connection. + * nio-http.h: Change class definition accordingly. + * res.rc: Add FTP authentication dialog. + * resource.h: Add new constants used in res.rc. + * state.h: Add variables `net_ftp_user' and `net_ftp_passwd'. + Sun May 27 17:12:23 2001 Christopher Faylor * res.rc (IDD_SPLASH): Add a copyright year. diff --git a/geturl.cc b/geturl.cc index 472b6bbc..03f63b26 100644 --- a/geturl.cc +++ b/geturl.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, Red Hat, Inc. + * Copyright (c) 2000, 2001, Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -246,7 +246,8 @@ get_url_to_string (char *_url) } int -get_url_to_file (char *_url, char *_filename, int expected_length) +get_url_to_file (char *_url, char *_filename, int expected_length, + BOOL allow_ftp_auth) { log (LOG_BABBLE, "get_url_to_file %s %s", _url, _filename); if (total_download_bytes > 0) @@ -258,7 +259,7 @@ get_url_to_file (char *_url, char *_filename, int expected_length) remove (_filename); /* but ignore errors */ - NetIO *n = NetIO::open (_url); + NetIO *n = NetIO::open (_url, allow_ftp_auth); if (!n || !n->ok ()) { delete n; diff --git a/geturl.h b/geturl.h index 357a8bb4..5256a607 100644 --- a/geturl.h +++ b/geturl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, Red Hat, Inc. + * Copyright (c) 2000, 2001, Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,5 +20,6 @@ extern int total_download_bytes; extern int total_download_bytes_sofar; char *get_url_to_string (char *_url); -int get_url_to_file (char *_url, char *_filename, int expected_size); +int get_url_to_file (char *_url, char *_filename, int expected_size, + BOOL allow_ftp_auth = FALSE); void dismiss_url_status_dialog (); diff --git a/netio.cc b/netio.cc index 23c66302..e76f0c95 100644 --- a/netio.cc +++ b/netio.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, Red Hat, Inc. + * Copyright (c) 2000, 2001, Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,9 +37,10 @@ static char *cvsid = "\n%%% $Id$\n"; #include "port.h" -NetIO::NetIO (char *Purl) +NetIO::NetIO (char *Purl, BOOL allow_ftp_auth) { set_url (Purl); + ftp_auth = allow_ftp_auth; } NetIO::~NetIO () @@ -108,7 +109,7 @@ NetIO::read (char *buf, int nbytes) } NetIO * -NetIO::open (char *url) +NetIO::open (char *url, BOOL allow_ftp_auth) { NetIO *rv = 0; enum {http, ftp, file} proto; @@ -124,7 +125,7 @@ NetIO::open (char *url) else if (net_method == IDC_NET_IE5) rv = new NetIO_IE5 (url); else if (net_method == IDC_NET_PROXY) - rv = new NetIO_HTTP (url); + rv = new NetIO_HTTP (url, allow_ftp_auth); else if (net_method == IDC_NET_DIRECT) { switch (proto) @@ -133,7 +134,7 @@ NetIO::open (char *url) rv = new NetIO_HTTP (url); break; case ftp: - rv = new NetIO_FTP (url); + rv = new NetIO_FTP (url, allow_ftp_auth); break; } } @@ -239,3 +240,23 @@ NetIO::get_proxy_auth () passwd = &net_proxy_passwd; return auth_common (hinstance, IDD_PROXY_AUTH); } + +int +NetIO::get_ftp_auth () +{ + if (net_ftp_user) + { + free (net_ftp_user); + net_ftp_user = NULL; + } + if (net_ftp_passwd) + { + free (net_ftp_passwd); + net_ftp_passwd = NULL; + } + if (!ftp_auth) + return IDCANCEL; + user = &net_ftp_user; + passwd = &net_ftp_passwd; + return auth_common (hinstance, IDD_FTP_AUTH); +} diff --git a/netio.h b/netio.h index b0a91ca0..9cd47e1a 100644 --- a/netio.h +++ b/netio.h @@ -18,8 +18,9 @@ class NetIO { protected: - NetIO (char *url); + NetIO (char *url, BOOL allow_ftp_auth = FALSE); void set_url (char *url); + BOOL ftp_auth; public: /* if nonzero, this is the estimated total file size */ @@ -36,7 +37,7 @@ public: the given URL. It uses the network setup state in state.h. If anything fails, either the return values is NULL or the returned object is !ok() */ - static NetIO * open (char *url); + static NetIO * open (char *url, BOOL allow_ftp_auth = FALSE); /* If !ok() that means the transfer isn't happening. */ virtual int ok (); @@ -50,4 +51,5 @@ public: state.h */ int get_auth (); int get_proxy_auth (); + int get_ftp_auth (); }; diff --git a/nio-ftp.cc b/nio-ftp.cc index c2429b0d..970f6a7f 100644 --- a/nio-ftp.cc +++ b/nio-ftp.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, Red Hat, Inc. + * Copyright (c) 2000, 2001, Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -48,8 +48,8 @@ ftp_line (SimpleSocket *s) return atoi (last_line ?: "0"); } -NetIO_FTP::NetIO_FTP (char *Purl) - : NetIO (Purl) +NetIO_FTP::NetIO_FTP (char *Purl, BOOL allow_ftp_auth) + : NetIO (Purl, allow_ftp_auth) { s = 0; int code; @@ -72,13 +72,27 @@ NetIO_FTP::NetIO_FTP (char *Purl) SimpleSocket *c = new SimpleSocket (host, port); int done = 0; code = ftp_line (c); - c->printf ("USER anonymous\r\n"); + +auth_retry: + if (net_ftp_user) + c->printf ("USER %s\r\n", net_ftp_user); + else + c->printf ("USER anonymous\r\n"); code = ftp_line (c); if (code == 331) { - c->printf ("PASS cygwin-setup@\r\n"); + if (net_ftp_passwd) + c->printf ("PASS %s\r\n", net_ftp_passwd); + else + c->printf ("PASS cygwin-setup@\r\n"); code = ftp_line (c); } + if (code == 530) /* Authentication failed, retry */ + { + get_ftp_auth (); + if (net_ftp_user && net_ftp_passwd) + goto auth_retry; + } if (code < 200 || code >= 300) { diff --git a/nio-ftp.h b/nio-ftp.h index 4548bcd3..d4567b1e 100644 --- a/nio-ftp.h +++ b/nio-ftp.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, Red Hat, Inc. + * Copyright (c) 2000, 2001, Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,7 +21,7 @@ class NetIO_FTP : public NetIO { SimpleSocket *s; public: - NetIO_FTP (char *url); + NetIO_FTP (char *url, BOOL allow_ftp_auth = FALSE); virtual ~NetIO_FTP (); /* If !ok() that means the transfer isn't happening. */ diff --git a/nio-http.cc b/nio-http.cc index 04b316ee..b4c8b008 100644 --- a/nio-http.cc +++ b/nio-http.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, Red Hat, Inc. + * Copyright (c) 2000, 2001, Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,6 +27,7 @@ static char *cvsid = "\n%%% $Id$\n"; #include "state.h" #include "simpsock.h" #include "msg.h" +#include "concat.h" #include "netio.h" #include "nio-http.h" @@ -83,8 +84,8 @@ base64_encode (char *username, char *password) return rv; } -NetIO_HTTP::NetIO_HTTP (char *Purl) - : NetIO (Purl) +NetIO_HTTP::NetIO_HTTP (char *Purl, BOOL allow_ftp_auth) + : NetIO (Purl, allow_ftp_auth) { retry_get: if (port == 0) @@ -147,6 +148,20 @@ NetIO_HTTP::NetIO_HTTP (char *Purl) delete s; goto retry_get; } + if (code == 500 /* ftp authentication through proxy required */ + && net_method == IDC_NET_PROXY + && !strncmp (url, "ftp://", 6)) + { + get_ftp_auth (); + if (net_ftp_user && net_ftp_passwd) + { + delete s; + url = concat ("ftp://", net_ftp_user, + ":", net_ftp_passwd, + "@", url + 6, 0); + goto retry_get; + } + } if (code >= 300) { delete s; diff --git a/nio-http.h b/nio-http.h index e6342995..5206c11e 100644 --- a/nio-http.h +++ b/nio-http.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, Red Hat, Inc. + * Copyright (c) 2000, 2001, Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,7 +21,7 @@ class NetIO_HTTP : public NetIO { SimpleSocket *s; public: - NetIO_HTTP (char *url); + NetIO_HTTP (char *url, BOOL allow_ftp_auth = FALSE); virtual ~NetIO_HTTP (); /* If !ok() that means the transfer isn't happening. */ diff --git a/res.rc b/res.rc index 0c611aec..a408ba20 100644 --- a/res.rc +++ b/res.rc @@ -267,6 +267,24 @@ BEGIN PUSHBUTTON "<-- &Back",IDC_BACK,55,75,45,15 END +IDD_FTP_AUTH DIALOGEX 0, 0, 215, 95 +STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Cygwin Setup" +FONT 8, "MS Sans Serif" +BEGIN + ICON IDI_CYGWIN,IDC_STATIC,5,5,20,20 + LTEXT "&User ID",IDC_STATIC,5,28,55,15,SS_CENTERIMAGE, + WS_EX_RIGHT + EDITTEXT IDC_NET_USER,65,28,145,12,ES_AUTOHSCROLL + LTEXT "&Password",IDC_STATIC,10,43,50,15,SS_CENTERIMAGE, + WS_EX_RIGHT + EDITTEXT IDC_NET_PASSWD,65,43,145,12,ES_PASSWORD | ES_AUTOHSCROLL + LTEXT "FTP Authorization Required",IDC_STATIC, + 65,10,145,10 + DEFPUSHBUTTON "&OK",IDOK,100,75,45,15,WS_DISABLED + PUSHBUTTON "Cancel",IDCANCEL,165,75,45,15 +END + #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// @@ -334,6 +352,11 @@ BEGIN BEGIN BOTTOMMARGIN, 49 END + + IDD_FTP_AUTH, DIALOG + BEGIN + BOTTOMMARGIN, 49 + END END #endif // APSTUDIO_INVOKED diff --git a/resource.h b/resource.h index 15191940..161a1621 100644 --- a/resource.h +++ b/resource.h @@ -52,6 +52,7 @@ #define IDB_CHECK_YES 123 #define IDB_CHECK_NO 124 #define IDB_CHECK_NA 125 +#define IDD_FTP_AUTH 126 #define IDC_SOURCE_DOWNLOAD 1000 #define IDC_SOURCE_NETINST 1001 #define IDC_SOURCE_CWD 1002 @@ -107,7 +108,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NO_MFC 1 #define _APS_3D_CONTROLS 1 -#define _APS_NEXT_RESOURCE_VALUE 126 +#define _APS_NEXT_RESOURCE_VALUE 127 #define _APS_NEXT_COMMAND_VALUE 40003 #define _APS_NEXT_CONTROL_VALUE 1051 #define _APS_NEXT_SYMED_VALUE 101 diff --git a/state.h b/state.h index 454f802b..eb695d2d 100644 --- a/state.h +++ b/state.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, Red Hat, Inc. + * Copyright (c) 2000, 2001, Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,6 +35,8 @@ extern char * net_user; extern char * net_passwd; extern char * net_proxy_user; extern char * net_proxy_passwd; +extern char * net_ftp_user; +extern char * net_ftp_passwd; extern char * mirror_site; extern char * other_url; -- 2.43.5