diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ftp.c | 16 | ||||
-rw-r--r-- | lib/url.c | 4 | ||||
-rw-r--r-- | lib/urldata.h | 4 |
3 files changed, 22 insertions, 2 deletions
@@ -699,6 +699,7 @@ static CURLcode ftp_state_user(struct connectdata *conn) NBFTPSENDF(conn, "USER %s", ftp->user?ftp->user:""); state(conn, FTP_USER); + conn->data->state.ftp_trying_alternative = FALSE; return CURLE_OK; } @@ -2302,8 +2303,19 @@ static CURLcode ftp_state_user_resp(struct connectdata *conn, 530 User ... access denied (the server denies to log the specified user) */ - failf(data, "Access denied: %03d", ftpcode); - result = CURLE_LOGIN_DENIED; + + if (conn->data->set.ftp_alternative_to_user && + !conn->data->state.ftp_trying_alternative) { + /* Ok, USER failed. Let's try the supplied command. */ + NBFTPSENDF(conn, "%s", conn->data->set.ftp_alternative_to_user); + conn->data->state.ftp_trying_alternative = TRUE; + state(conn, FTP_USER); + result = CURLE_OK; + } + else { + failf(data, "Access denied: %03d", ftpcode); + result = CURLE_LOGIN_DENIED; + } } return result; } @@ -1546,6 +1546,10 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option, data->set.connect_only = va_arg(param, long)?TRUE:FALSE; break; + case CURLOPT_FTP_ALTERNATIVE_TO_USER: + data->set.ftp_alternative_to_user = va_arg(param, char *); + break; + default: /* unknown tag and its companion, just ignore: */ result = CURLE_FAILED_INIT; /* correct this */ diff --git a/lib/urldata.h b/lib/urldata.h index 63ccfe70a..c804105b6 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -937,6 +937,9 @@ struct UrlState { /* a place to store the most recenlty set FTP entrypath */ char *most_recent_ftp_entrypath; + /* set after initial USER failure, to prevent an authentication loop */ + bool ftp_trying_alternative; + #ifndef WIN32 /* do FTP line-end conversions on most platforms */ #define CURL_DO_LINEEND_CONV @@ -1054,6 +1057,7 @@ struct UserDefined { bool cookiesession; /* new cookie session? */ bool crlf; /* convert crlf on ftp upload(?) */ char *ftp_account; /* ftp account data */ + char *ftp_alternative_to_user; /* command to send if USER/PASS fails */ struct curl_slist *quote; /* after connection is established */ struct curl_slist *postquote; /* after the transfer */ struct curl_slist *prequote; /* before the transfer, after type */ |