mirror of
https://github.com/curl/curl.git
synced 2026-08-01 07:58:10 +03:00
netrc: use the NETRC environment variable (first) if set
Add test 755 to verify. Proposed-by: Berthin Torres Callañaupa URL: https://curl.se/mail/lib-2025-06/0015.html Closes #17712
This commit is contained in:
parent
cb9b1a4c4e
commit
cb2a48bf5b
6 changed files with 111 additions and 39 deletions
68
lib/netrc.c
68
lib/netrc.c
|
|
@ -396,47 +396,51 @@ NETRCcode Curl_parsenetrc(struct store_netrc *store, const char *host,
|
|||
char *filealloc = NULL;
|
||||
|
||||
if(!netrcfile) {
|
||||
char *home = NULL;
|
||||
char *homea = NULL;
|
||||
#if defined(HAVE_GETPWUID_R) && defined(HAVE_GETEUID)
|
||||
char pwbuf[1024];
|
||||
#endif
|
||||
char *home = NULL;
|
||||
char *homea = curl_getenv("HOME"); /* portable environment reader */
|
||||
if(homea) {
|
||||
home = homea;
|
||||
#if defined(HAVE_GETPWUID_R) && defined(HAVE_GETEUID)
|
||||
}
|
||||
else {
|
||||
struct passwd pw, *pw_res;
|
||||
if(!getpwuid_r(geteuid(), &pw, pwbuf, sizeof(pwbuf), &pw_res)
|
||||
&& pw_res) {
|
||||
home = pw.pw_dir;
|
||||
}
|
||||
#elif defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
|
||||
}
|
||||
else {
|
||||
struct passwd *pw;
|
||||
pw = getpwuid(geteuid());
|
||||
if(pw) {
|
||||
home = pw->pw_dir;
|
||||
}
|
||||
#elif defined(_WIN32)
|
||||
}
|
||||
else {
|
||||
homea = curl_getenv("USERPROFILE");
|
||||
filealloc = curl_getenv("NETRC");
|
||||
if(!filealloc) {
|
||||
homea = curl_getenv("HOME"); /* portable environment reader */
|
||||
if(homea) {
|
||||
home = homea;
|
||||
#if defined(HAVE_GETPWUID_R) && defined(HAVE_GETEUID)
|
||||
}
|
||||
else {
|
||||
struct passwd pw, *pw_res;
|
||||
if(!getpwuid_r(geteuid(), &pw, pwbuf, sizeof(pwbuf), &pw_res)
|
||||
&& pw_res) {
|
||||
home = pw.pw_dir;
|
||||
}
|
||||
#elif defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
|
||||
}
|
||||
else {
|
||||
struct passwd *pw;
|
||||
pw = getpwuid(geteuid());
|
||||
if(pw) {
|
||||
home = pw->pw_dir;
|
||||
}
|
||||
#elif defined(_WIN32)
|
||||
}
|
||||
else {
|
||||
homea = curl_getenv("USERPROFILE");
|
||||
if(homea) {
|
||||
home = homea;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if(!home)
|
||||
return NETRC_FILE_MISSING; /* no home directory found (or possibly out
|
||||
of memory) */
|
||||
if(!home)
|
||||
return NETRC_FILE_MISSING; /* no home directory found (or possibly out
|
||||
of memory) */
|
||||
|
||||
filealloc = aprintf("%s%s.netrc", home, DIR_CHAR);
|
||||
if(!filealloc) {
|
||||
free(homea);
|
||||
return NETRC_OUT_OF_MEMORY;
|
||||
filealloc = aprintf("%s%s.netrc", home, DIR_CHAR);
|
||||
if(!filealloc) {
|
||||
free(homea);
|
||||
return NETRC_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
retcode = parsenetrc(store, host, loginp, passwordp, filealloc);
|
||||
free(filealloc);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue