Hi fellow hackers,

here are the changes for adding --netrc-file to curl and cleaning up
now that the feature freeze is over :)

All tests are happy on my machine.

Comments welcome!
Julien
From 3df25aa91b45eb2a80543c6325277090bac388e6 Mon Sep 17 00:00:00 2001
From: Julien Chaffraix <[email protected]>
Date: Sat, 12 Feb 2011 07:53:03 -0800
Subject: [PATCH 1/3] curl: Added --netrc-file.

This enables people to specify a path to the netrc file to use.
The new option override --netrc if both are present. However it
does follow --netrc-optional if specified.
---
 docs/curl.1 |   10 ++++++++++
 src/main.c  |   13 ++++++++++++-
 2 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/docs/curl.1 b/docs/curl.1
index f1fe1b9..7f9f41c 100644
--- a/docs/curl.1
+++ b/docs/curl.1
@@ -815,6 +815,16 @@ to FTP to the machine host.domain.com with user name \&'myself' and password
 .IP "--netrc-optional"
 Very similar to \fI--netrc\fP, but this option makes the .netrc usage
 \fBoptional\fP and not mandatory as the \fI--netrc\fP option does.
+
+.IP "--netrc-file"
+This option is similar to \fI--netrc\fP, except that you provide the path
+(absolute or relative) to the netrc file that Curl should use.
+You can only specify one netrc file per invocation. If several
+\fI--netrc-file\fP options are provided, only the \fBlast one\fP will be used.
+
+This option overrides any use of \fI--netrc\fP as they are mutually exclusive.
+It will also abide by --netrc-optional if specified.
+
 .IP "--negotiate"
 (HTTP) Enables GSS-Negotiate authentication. The GSS-Negotiate method was
 designed by Microsoft and is used in their web applications. It is primarily
diff --git a/src/main.c b/src/main.c
index 1c707f8..8a1fab8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -527,6 +527,7 @@ struct Configurable {
                               changed */
   bool netrc_opt;
   bool netrc;
+  char *netrc_file;
   bool noprogress;
   bool isatty;             /* updated internally only if the output is a tty */
   struct getout *url_list; /* point to the first node */
@@ -842,6 +843,7 @@ static void help(void)
     "    --negotiate     Use HTTP Negotiate Authentication (H)",
     " -n/--netrc         Must read .netrc for user name and password",
     "    --netrc-optional Use either .netrc or URL; overrides -n",
+    "    --netrc-file <file> Set up the netrc filename to use",
     " -N/--no-buffer     Disable buffering of the output stream",
     "    --no-keepalive  Disable keepalive use on the connection",
     "    --no-sessionid  Disable SSL session-ID reusing (SSL)",
@@ -1949,6 +1951,7 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
     {"M", "manual",      FALSE},
     {"n", "netrc",       FALSE},
     {"no", "netrc-optional", FALSE},
+    {"ne", "netrc-file", TRUE},
     {"N", "buffer",   FALSE}, /* listed as --no-buffer in the help */
     {"o", "output",      TRUE},
     {"O",  "remote-name", FALSE},
@@ -2915,6 +2918,9 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
         /* use .netrc or URL */
         config->netrc_opt = toggle;
         break;
+      case 'e': /* netrc-file */
+        GetStr(&config->netrc_file, nextarg);
+        break;
       default:
         /* pick info from .netrc, if this is used for http, curl will
            automatically enfore user+password with the request */
@@ -4047,6 +4053,8 @@ static void free_config_fields(struct Configurable *config)
     free(config->writeout);
   if(config->httppost)
     curl_formfree(config->httppost);
+  if(config->netrc_file)
+    free(config->netrc_file);
   if(config->cert)
     free(config->cert);
   if(config->cacert)
@@ -5183,11 +5191,14 @@ operate(struct Configurable *config, int argc, argv_item_t argv[])
 
         if(config->netrc_opt)
           my_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
-        else if(config->netrc)
+        else if(config->netrc || config->netrc_file)
           my_setopt(curl, CURLOPT_NETRC, CURL_NETRC_REQUIRED);
         else
           my_setopt(curl, CURLOPT_NETRC, CURL_NETRC_IGNORED);
 
+        if(config->netrc_file)
+          my_setopt(curl, CURLOPT_NETRC_FILE, config->netrc_file);
+
         my_setopt(curl, CURLOPT_FOLLOWLOCATION, config->followlocation);
         my_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, config->unrestricted_auth);
         my_setopt(curl, CURLOPT_TRANSFERTEXT, config->use_ascii);
-- 
1.7.1

From 654803416989d9c90ccbea57e3b80e8f003454a5 Mon Sep 17 00:00:00 2001
From: Julien Chaffraix <[email protected]>
Date: Sat, 12 Feb 2011 08:34:36 -0800
Subject: [PATCH 2/3] tests: Cleaned up netrc testing.

Removed the "netrc_debug" keyword replaced with --netrc-file additions.
Removed the debug code from Curl_parsenetrc as it is superseeded by
--netrc-file.
---
 lib/netrc.c        |   15 ---------------
 tests/data/test130 |    5 +----
 tests/data/test131 |    5 +----
 tests/data/test132 |    5 +----
 tests/data/test133 |    5 +----
 tests/data/test134 |    5 +----
 tests/data/test257 |    5 +----
 tests/runtests.pl  |   14 ++------------
 8 files changed, 8 insertions(+), 51 deletions(-)

diff --git a/lib/netrc.c b/lib/netrc.c
index b069c8c..6b616c6 100644
--- a/lib/netrc.c
+++ b/lib/netrc.c
@@ -80,21 +80,6 @@ int Curl_parsenetrc(const char *host,
 
 #define NETRC DOT_CHAR "netrc"
 
-#ifdef DEBUGBUILD
-  {
-    /* This is a hack to allow testing.
-     * If compiled with --enable-debug and CURL_DEBUG_NETRC is defined,
-     * then it's the path to a substitute .netrc for testing purposes *only* */
-
-    char *override = curl_getenv("CURL_DEBUG_NETRC");
-
-    if(override) {
-      fprintf(stderr, "NETRC: overridden " NETRC " file: %s\n", override);
-      netrcfile = override;
-      netrc_alloc = TRUE;
-    }
-  }
-#endif /* DEBUGBUILD */
   if(!netrcfile) {
     home = curl_getenv("HOME"); /* portable environment reader */
     if(home) {
diff --git a/tests/data/test130 b/tests/data/test130
index 43ab24c..fbcf525 100644
--- a/tests/data/test130
+++ b/tests/data/test130
@@ -30,9 +30,6 @@ dr-xr-xr-x   5 0        1            512 Oct  1  1997 usr
 #
 # Client-side
 <client>
-<features>
-netrc_debug
-</features>
 <server>
 ftp
 </server>
@@ -40,7 +37,7 @@ ftp
 FTP (optional .netrc; no user/pass) dir list PASV
  </name>
  <command>
---netrc-optional ftp://%HOSTIP:%FTPPORT/
+--netrc-optional --netrc-file log/netrc ftp://%HOSTIP:%FTPPORT/
 </command>
 <file name="log/netrc" >
 # the following two lines were created while testing curl
diff --git a/tests/data/test131 b/tests/data/test131
index 4e9ba6d..ad7f9e2 100644
--- a/tests/data/test131
+++ b/tests/data/test131
@@ -31,9 +31,6 @@ dr-xr-xr-x   5 0        1            512 Oct  1  1997 usr
 #
 # Client-side
 <client>
-<features>
-netrc_debug
-</features>
 <server>
 ftp
 </server>
@@ -41,7 +38,7 @@ ftp
 FTP (optional .netrc; user/no pass) dir list PASV
  </name>
  <command>
---netrc-optional ftp://user2@%HOSTIP:%FTPPORT/
+--netrc-optional --netrc-file log/netrc ftp://user2@%HOSTIP:%FTPPORT/
 </command>
 <file name="log/netrc" >
 # the following two lines were created while testing curl
diff --git a/tests/data/test132 b/tests/data/test132
index 2ff39fb..8d9e3ed 100644
--- a/tests/data/test132
+++ b/tests/data/test132
@@ -30,9 +30,6 @@ dr-xr-xr-x   5 0        1            512 Oct  1  1997 usr
 #
 # Client-side
 <client>
-<features>
-netrc_debug
-</features>
 <server>
 ftp
 </server>
@@ -40,7 +37,7 @@ ftp
 FTP (optional .netrc; user/passwd supplied) dir list PASV
  </name>
  <command>
---netrc-optional ftp://mary:mark@%HOSTIP:%FTPPORT/
+--netrc-optional --netrc-file log/netrc ftp://mary:mark@%HOSTIP:%FTPPORT/
 </command>
 <file name="log/netrc" >
 # the following two lines were created while testing curl
diff --git a/tests/data/test133 b/tests/data/test133
index 2e6b2c3..a15cfc3 100644
--- a/tests/data/test133
+++ b/tests/data/test133
@@ -30,9 +30,6 @@ dr-xr-xr-x   5 0        1            512 Oct  1  1997 usr
 #
 # Client-side
 <client>
-<features>
-netrc_debug
-</features>
 <server>
 ftp
 </server>
@@ -40,7 +37,7 @@ ftp
 FTP (compulsory .netrc; ignored user/passwd) dir list PASV
  </name>
  <command>
--n ftp://mary:mark@%HOSTIP:%FTPPORT/
+-n --netrc-file log/netrc ftp://mary:mark@%HOSTIP:%FTPPORT/
 </command>
 <file name="log/netrc" >
 # the following two lines were created while testing curl
diff --git a/tests/data/test134 b/tests/data/test134
index 8ff9c19..8303584 100644
--- a/tests/data/test134
+++ b/tests/data/test134
@@ -30,9 +30,6 @@ dr-xr-xr-x   5 0        1            512 Oct  1  1997 usr
 #
 # Client-side
 <client>
-<features>
-netrc_debug
-</features>
 <server>
 ftp
 </server>
@@ -40,7 +37,7 @@ ftp
 FTP (optional .netrc; programmatic user/passwd) dir list PASV
  </name>
  <command>
---netrc-optional -u romulus:rhemus ftp://mary:mark@%HOSTIP:%FTPPORT/
+--netrc-optional --netrc-file log/netrc -u romulus:rhemus ftp://mary:mark@%HOSTIP:%FTPPORT/
 </command>
 <file name="log/netrc" >
 # the following two lines were created while testing curl
diff --git a/tests/data/test257 b/tests/data/test257
index c211c2f..cc3b7f0 100644
--- a/tests/data/test257
+++ b/tests/data/test257
@@ -64,9 +64,6 @@ If this is received, the location following worked
 
 # Client-side
 <client>
-<features>
-netrc_debug
-</features>
 <server>
 http
 </server>
@@ -74,7 +71,7 @@ http
 HTTP Location: following with --netrc-optional
  </name>
  <command>
-http://supersite.com/want/257 -L -x http://%HOSTIP:%HTTPPORT --netrc-optional
+http://supersite.com/want/257 -L -x http://%HOSTIP:%HTTPPORT --netrc-optional --netrc-file log/netrc
 </command>
 
 # netrc auth for two out of three sites:
diff --git a/tests/runtests.pl b/tests/runtests.pl
index e372415..d931b15 100755
--- a/tests/runtests.pl
+++ b/tests/runtests.pl
@@ -2146,8 +2146,6 @@ sub checksystem {
             if($feat =~ /debug/i) {
                 # curl was built with --enable-debug
                 $debug_build = 1;
-                # set the NETRC debug env
-                $ENV{'CURL_DEBUG_NETRC'} = "$LOGDIR/netrc";
             }
             if($feat =~ /SSL/i) {
                 # ssl enabled
@@ -2476,20 +2474,12 @@ sub singletest {
                 next;
             }
         }
-	elsif($f eq "axTLS") {
-	    if($has_axtls) {
-		next;
-	    }
-	}
-        elsif($f eq "netrc_debug") {
-            if($debug_build) {
+        elsif($f eq "axTLS") {
+            if($has_axtls) {
                 next;
             }
         }
         elsif($f eq "unittest") {
-            # Unit tests should set the netrc filename directly, thus unset the
-            # environment variable.
-            delete($ENV{'CURL_DEBUG_NETRC'}) if $ENV{'CURL_DEBUG_NETRC'};
             if($debug_build) {
                 next;
             }
-- 
1.7.1

From a8276b5e13ed6c7794056ec0990f8ec0dcb71f6a Mon Sep 17 00:00:00 2001
From: Julien Chaffraix <[email protected]>
Date: Sat, 12 Feb 2011 08:45:05 -0800
Subject: [PATCH 3/3] netrc: Removed _NETRC_DEBUG code.

This is not needed anymore as we have unit testing running on it.
---
 lib/netrc.c |    9 ---------
 1 files changed, 0 insertions(+), 9 deletions(-)

diff --git a/lib/netrc.c b/lib/netrc.c
index 6b616c6..efb4076 100644
--- a/lib/netrc.c
+++ b/lib/netrc.c
@@ -142,9 +142,6 @@ int Curl_parsenetrc(const char *host,
           if(Curl_raw_equal(host, tok)) {
             /* and yes, this is our host! */
             state=HOSTVALID;
-#ifdef _NETRC_DEBUG
-            fprintf(stderr, "HOST: %s\n", tok);
-#endif
             retcode=0; /* we did find our host */
           }
           else
@@ -159,18 +156,12 @@ int Curl_parsenetrc(const char *host,
             }
             else {
               strncpy(login, tok, LOGINSIZE-1);
-#ifdef _NETRC_DEBUG
-              fprintf(stderr, "LOGIN: %s\n", login);
-#endif
             }
             state_login=0;
           }
           else if(state_password) {
             if(state_our_login || !specific_login) {
               strncpy(password, tok, PASSWORDSIZE-1);
-#ifdef _NETRC_DEBUG
-              fprintf(stderr, "PASSWORD: %s\n", password);
-#endif
             }
             state_password=0;
           }
-- 
1.7.1

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to