Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

also check %USERPROFILE% variable to find .netrc file on Windows #8855

Closed
wants to merge 3 commits into from

Conversation

wolfv
Copy link
Contributor

@wolfv wolfv commented May 16, 2022

It seems that %HOME% isn't always set on Windows.
However, %USERPROFILE% seems to be a standard variable on Windows. So I just added another branch of the if condition to look in there for the .netrc file if %HOME% is not set.

Ref: mamba-org/mamba#870

@wolfv wolfv force-pushed the netrc_userprofile branch 2 times, most recently from de3fc35 to 5e2af16 Compare May 16, 2022 07:18
@bagder
Copy link
Member

bagder commented May 16, 2022

It is already done/attempted here:

{ "USERPROFILE", NULL, FALSE },

So why isn't that working already?

@bagder bagder added cmdline tool Windows Windows-specific labels May 16, 2022
@wolfv
Copy link
Contributor Author

wolfv commented May 16, 2022

correct me if I am wrong, but it doesn't look like the findfile function is used in the netrc code?

Should we change the code to something like:

int Curl_parsenetrc(const char *host,
                    char **loginp,
                    char **passwordp,
                    bool *login_changed,
                    bool *password_changed,
                    char *netrcfile)
{
  int retcode = 1;

  if(!netrcfile) {
    netrcfile = findfile("netrc", TRUE);

    if(!netrcfile)
      return retcode; /* no home directory found (or possibly out of
                         memory) */

    retcode = parsenetrc(host, loginp, passwordp, login_changed,
                         password_changed, netrcfile);
    free(netrcfile);
  }
  else
    retcode = parsenetrc(host, loginp, passwordp, login_changed,
                         password_changed, netrcfile);
  return retcode;
}

@bagder
Copy link
Member

bagder commented May 16, 2022

but it doesn't look like the findfile

blah, but of course... 😕

@wolfv
Copy link
Contributor Author

wolfv commented May 16, 2022

@bagder not sure I understand your preferred fix for this. I guess it wouldn't be fine to depend on tool_findfile.h since that's not part of libcurl, right? Would be nice to re-use the findfile functions logic though.

Please let me know what you think. Happy to attempt an implementation & fix.

Copy link
Member

@bagder bagder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs a documentation update!

lib/netrc.c Outdated
@@ -256,6 +256,13 @@ int Curl_parsenetrc(const char *host,
if(pw) {
home = pw->pw_dir;
}
#elif defined(CURL_WIN32)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this rather check for plain WIN32 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed that! thanks

@wolfv wolfv force-pushed the netrc_userprofile branch from 5e2af16 to 1fd8f01 Compare May 24, 2022 15:10
@bagder bagder closed this in 4d4eb8e Jun 2, 2022
@bagder
Copy link
Member

bagder commented Jun 2, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants