cURL / Mailing Lists / curl-users / Single Mail

curl-users

finding the netrc

From: Doug Porter <dsp_at_waterspout.com>
Date: Tue, 10 Feb 2004 09:29:53 -0500

According to the curl(1) man page the netrc file is found by
using the "HOME" environment variable. This is not quite true
though. On platforms that support getpwuid(3) and geteuid(2) the
home directory reported by the password database is used. The
"HOME" environment variable is only used if the getpwuid(3) does
not provide a home directory.

I would like to see the environment variable checked before the
password database. This allows the user to override what is
considered their home directory, and can be very handy. In my
specific case I'd like to use a temporary home directory so that
I can script curl with a dynamically created netrc.

The following is my patch against HEAD to change the preference:

Index: netrc.c
===================================================================
RCS file: /repository/curl/lib/netrc.c,v
retrieving revision 1.29
diff -a -u -r1.29 netrc.c
--- netrc.c 29 Jan 2004 13:56:45 -0000 1.29
+++ netrc.c 10 Feb 2004 13:55:08 -0000
@@ -111,25 +111,26 @@
   }
 #endif /* CURLDEBUG */
   if(!netrcfile) {
+ home = curl_getenv("HOME"); /* portable environment reader */
+ if(home) {
+ home_alloc = TRUE;
 #if defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
- struct passwd *pw;
- pw= getpwuid(geteuid());
- if (pw) {
+ } else {
+ struct passwd *pw;
+ pw= getpwuid(geteuid());
+ if (pw) {
 #ifdef VMS
- home = decc$translate_vms(pw->pw_dir);
+ home = decc$translate_vms(pw->pw_dir);
 #else
- home = pw->pw_dir;
+ home = pw->pw_dir;
 #endif
- }
+ }
 #endif
-
- if(!home) {
- home = curl_getenv("HOME"); /* portable environment reader */
- if(!home)
- return -1;
- home_alloc = TRUE;
     }
 
+ if(!home)
+ return -1;
+
     netrcfile = curl_maprintf("%s%s%s", home, DIR_CHAR, NETRC);
     if(!netrcfile) {
       if(home_alloc)

-- 
Doug Porter <dsp_at_waterspout.com>
Received on 2004-02-10