Tom Norton
Tom Norton

Reputation: 771

Can _netrc handle passphrases with spaces?

The following configuration works:

machine code.mycompany.net
login supernerd
password HelloW0rld

The following configuration doesn't work:

machine code.mycompany.net
login supernerd
password Please excuse my dear aunt sally.

Upvotes: 11

Views: 3961

Answers (4)

VonC
VonC

Reputation: 1323483

From this bug report (now python/cpython issue 36615) or this page, spaces in password don't seem to be supported in a .netrc (or _netrc) file.
Or even if they are, not all the programs using that .netrc file will be able to interpret said space correctly.


As runrig mentions in the comments:

Quoting the field as in another answer here should work, but the python library doesn't like it.
But, e.g., command line ftp and the perl netrc library is fine with it.

So this should work when used when those commands:

password "Please excuse my dear aunt sally."

Upvotes: 5

ceving
ceving

Reputation: 23794

This is the tokenizer of the GNU Inetutils version 2.5:

token (void)
{
  char *cp;
  int c;
  struct toktab *t;

  if (feof (cfile) || ferror (cfile))
    return (0);
  while ((c = getc (cfile)) != EOF &&
         (c == '\n' || c == '\t' || c == ' ' || c == ','))
    continue;
  if (c == EOF)
    return (0);
  cp = tokval;
  if (c == '"')
    {
      while ((c = getc (cfile)) != EOF && c != '"')
        {
          if (c == '\\')
            c = getc (cfile);
          *cp++ = c;
        }
    }
  else
    {
      *cp++ = c;
      while ((c = getc (cfile)) != EOF
             && c != '\n' && c != '\t' && c != ' ' && c != ',')
        {
          if (c == '\\')
            c = getc (cfile);
          *cp++ = c;
        }
    }
  *cp = 0;
  if (tokval[0] == 0)
    return (0);
  for (t = toktab; t->tokstr; t++)
    if (!strcmp (t->tokstr, tokval))
      return (t->tval);
  return (ID);
}

As you can see: tokens may be surrounded by double quotes.

  if (c == '"')
    {
      while ((c = getc (cfile)) != EOF && c != '"')
        {
          if (c == '\\')
            c = getc (cfile);
          *cp++ = c;
        }
    }

Upvotes: 1

fbauzac
fbauzac

Reputation: 487

I have studied wget's netrc.c; I hope most netrc parsers work similarly:

Note that # after whitespace starts a comment until end of line.

A string can be put between double quotes (for example if the string starts with #, or contains a lot of whitespace that we don't want to backslash).

"#pass%"
"S3cret with spaces"

To make sure a character is understood as part of a string, prefix it with a backslash so that it is understood verbatim. This is supported with or without double quotes:

S3cret\ with\ spaces
\#not-a-comment
backslash:\\
"anything"
"double\"quote"

Upvotes: 0

Jim
Jim

Reputation: 41

Using ftp on IRIX 6.5 running on an SGI, I added quotes around my password and it works fine, e.g.:

password "Please excuse my dear aunt sally." 

Upvotes: 4

Related Questions