]> granicus.if.org Git - curl/commitdiff
Dan Nelson added the CURLOPT_FTP_ALTERNATIVE_TO_USER libcurl option and curl
authorDaniel Stenberg <daniel@haxx.se>
Tue, 25 Jul 2006 22:45:21 +0000 (22:45 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 25 Jul 2006 22:45:21 +0000 (22:45 +0000)
tool option named --ftp-alternative-to-user. It provides a mean to send a
particular command if the normal USER/PASS approach fails.

CHANGES
RELEASE-NOTES
docs/curl.1
docs/libcurl/curl_easy_setopt.3
include/curl/curl.h
lib/ftp.c
lib/url.c
lib/urldata.h
src/main.c

diff --git a/CHANGES b/CHANGES
index d2c219bf4236dff05b56287e595d5c9809177082..29c2aa2639c9651e56c527f3a5719a621126b9b7 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,10 @@
                                   Changelog
 
 Daniel (26 July 2006)
+- Dan Nelson added the CURLOPT_FTP_ALTERNATIVE_TO_USER libcurl option and curl
+  tool option named --ftp-alternative-to-user. It provides a mean to send a
+  particular command if the normal USER/PASS approach fails.
+
 - Michael Jerris added magic that builds lib/curllib.vcproj automatically for
   newer MSVC.
 
index 1eef7be4f0cf0d572a5304c56bf7643d5acd252e..a29daea1ae35a39300a3b20406b5e9f4f78c0254 100644 (file)
@@ -2,8 +2,8 @@ Curl and libcurl 7.15.5
 
  Public curl release number:               95
  Releases counted from the very beginning: 122
- Available command line options:           112
- Available curl_easy_setopt() options:     132
+ Available command line options:           113
+ Available curl_easy_setopt() options:     133
  Number of public functions in libcurl:    49
  Amount of public web site mirrors:        33
  Number of known libcurl bindings:         32
@@ -11,6 +11,8 @@ Curl and libcurl 7.15.5
 
 This release includes the following changes:
 
+ o added CURLOPT_FTP_ALTERNATIVE_TO_USER and --ftp-alternative-to-user
+ o now includes a vcproj file for building libcurl
  o added curl_formget()
  o added CURLOPT_MAX_SEND_SPEED_LARGE and CURLOPT_MAX_RECV_SPEED_LARGE
  o configure --enable-hidden-symbols
@@ -41,6 +43,6 @@ advice from friends like these:
 
  Dan Fandrich, Peter Silva, Arve Knudsen, Michael Wallner, Toshiyuki Maezawa,
  Ingmar Runge, Ates Goral, David McCreedy, Jari Sundell, Georg Horn,
- Gisle Vanem, Yang Tse
+ Gisle Vanem, Yang Tse, Michael Jerris, Dan Nelson
 
         Thanks! (and sorry if I forgot to mention someone)
index d99fbceaa8217eb4221995bf33059f54135c7436..de72eb5b61d462d648a16353a7103a9855cc0776 100644 (file)
@@ -396,6 +396,11 @@ in 7.11.0)
 If this option is used several times, the following occurrences make no
 difference.
 
+.IP "--ftp-alternative-to-user <command>"
+(FTP) If authenticating with the USER and PASS commands fails, send this
+command.  When connecting to Tumbleweed's Secure Transport server over FTPS
+using a client certificate, using "SITE AUTH" will tell the server to retrieve
+the username from the certificate. (Added in 7.15.5)
 .IP "--ftp-skip-pasv-ip"
 (FTP) Tell curl to not use the IP address the server suggests in its response
 to curl's PASV command when curl connects the data connection. Instead curl
index c4b9695777bed05f2bdabf9f205739169141529f..6ac538a7a75a454f303574078f6d82435d14013d 100644 (file)
@@ -859,6 +859,12 @@ waiting for a response, this value overrides \fICURLOPT_TIMEOUT\fP. It is
 recommended that if used in conjunction with \fICURLOPT_TIMEOUT\fP, you set
 \fICURLOPT_FTP_RESPONSE_TIMEOUT\fP to a value smaller than
 \fICURLOPT_TIMEOUT\fP.  (Added in 7.10.8)
+.IP CURLOPT_FTP_ALTERNATIVE_TO_USER
+Pass a char * as parameter, pointing to a string which will be used to
+authenticate if the usual FTP "USER user" and "PASS password" negotiation
+fails. This is currently only known to be required when connecting to
+Tumbleweed's Secure Transport FTPS server using client certificates for
+authentication. (Added in 7.15.5)
 .IP CURLOPT_FTP_SKIP_PASV_IP
 Pass a long. If set to a non-zero value, it instructs libcurl to not use the
 IP address the server suggests in its 227-response to libcurl's PASV command
index b9b341deef7f013310a0ef48c97bddbc1ec866ac..db14fe1f594426addc2a23aadcbd3568bfe6936d 100644 (file)
@@ -61,14 +61,14 @@ extern "C" {
 
 #ifdef CURL_HIDDEN_SYMBOLS
 /*
- * This definition is used to make external definitions visibile in the 
+ * This definition is used to make external definitions visibile in the
  * shared library when symbols are hidden by default.  It makes no
  * difference when compiling applications whether this is set or not,
  * only when compiling the library.
  */
 #define CURL_EXTERN CURL_EXTERN_SYMBOL
 #else
-#define CURL_EXTERN 
+#define CURL_EXTERN
 #endif
 #endif
 
@@ -979,6 +979,9 @@ typedef enum {
   CINIT(MAX_SEND_SPEED_LARGE, OFF_T, 145),
   CINIT(MAX_RECV_SPEED_LARGE, OFF_T, 146),
 
+  /* Pointer to command string to send if USER/PASS fails. */
+  CINIT(FTP_ALTERNATIVE_TO_USER, OBJECTPOINT, 147),
+
   CURLOPT_LASTENTRY /* the last unused */
 } CURLoption;
 
index c270305043cd2b6935cada924793d997b956b96c..c17d9fbaa229e667b8db22027520b145501a1820 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -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;
 }
index 17e3a7f57c5e6c213b1403dc1e18fee21a2d5e0a..b25d02be85b14ec5b070f8c3a9a168f90ed3d278 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -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 */
index 63ccfe70aecfd19dd321b44df22a178149c438b0..c804105b6be844fe805118c2053dbe92f6769c68 100644 (file)
@@ -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 */
index 3e717a3d255fefb1b66c4ad82e0e4bf70fc22fae..af20a396c7318d38c3429eb8a3a94658014b665c 100644 (file)
@@ -353,6 +353,7 @@ struct Configurable {
   struct curl_slist *tp_postquote;
   struct curl_slist *tp_prequote;
   char *ftp_account; /* for ACCT */
+  char *ftp_alternative_to_user; /* send command if USER/PASS fails */
   int ftp_filemethod;
 
   bool ignorecl; /* --ignore-content-length */
@@ -1340,6 +1341,7 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
     {"$r", "ftp-method", TRUE},
     {"$s", "local-port", TRUE},
     {"$t", "socks4",     TRUE},
+    {"$u", "ftp-alternative-to-user", TRUE},
 
     {"0", "http1.0",     FALSE},
     {"1", "tlsv1",       FALSE},
@@ -1776,6 +1778,9 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
           }
         }
         break;
+      case 'u': /* --ftp-alternative-to-user */
+        GetStr(&config->ftp_alternative_to_user, nextarg);
+        break;
       }
       break;
     case '#': /* --progress-bar */
@@ -3998,6 +4003,9 @@ operate(struct Configurable *config, int argc, char *argv[])
           curl_easy_setopt(curl, CURLOPT_LOCALPORTRANGE, config->localportrange);
         }
 
+        /* curl x.xx.x */
+        curl_easy_setopt(curl, CURLOPT_FTP_ALTERNATIVE_TO_USER, config->ftp_alternative_to_user);
+
         retry_numretries = config->req_retry;
 
         retrystart = curlx_tvnow();