btw for my MUA i have written a netrc parser that is (then,
loosely) based upon NetBSD's ftp parser.  The source can be shrunk
massively from the 16KB that is has (we offer interactive commands
to load, show, etc).  It was converted to use a dictionary, but
the thing as such is pretty straightforward and decade(s) (s with
NetBSD) old.  Documentation is quite well and covers variants as
i know them:

 The .netrc file
   User credentials for machine accounts (see URL syntax and credential
   lookup†) can be placed in the .netrc file, which will be loaded and
   cached when requested by netrc-lookup†.  The default location ˜/.netrc†
   may be overridden by the NETRC† environment variable.  As long as syntax
   constraints are honoured the file source may be replaced with the output
   of the shell command set in netrc-pipe†, to load an encrypted file, for
   example.  The cache can be managed with the command netrc†.

   The file consists of space, tabulator or newline separated tokens.  This
   parser implements a superset of the original BSD syntax, but users should
   nonetheless be aware of portability glitches, shall their .netrc be us‐
   able across multiple programs and platforms:

   •   BSD only supports double quotation marks, for example ‘password "pass
       with spaces"’.
   •   BSD (only?) supports escaping of single characters via a reverse
       solidus (a space could be escaped via ‘\ ’), in- as well as outside
       of a quoted string.  This method is assumed to be present, and will
       actively be used to quote double quotation marks ‘"’ and reverse
       solidus ‘\’ characters inside the login and password tokens, for ex‐
       ample for display purposes.
   •   BSD does not require a final quotation mark of the last user input
       token.
   •   The original BSD (Berknet) parser also supported a format which al‐
       lowed tokens to be separated with commas – whereas at least Hewlett-
       Packard still seems to support this syntax, this parser does not!
   •   As a non-portable extension some widely-used programs support shell-
       style comments: if an input line starts, after any amount of white‐
       space, with a number sign ‘#’, then the rest of the line is ignored.
   •   Whereas other programs may require that the .netrc file is accessible
       by only the user if it contains a password token for any other login
       than “anonymous”, this parser will always require these strict per‐
       missions.

   Of the following list of supported tokens this parser uses (and caches)
   machine, login and password.  An existing default entry will not be used.

   machine name
             The hostname of the entries’ machine, lowercase-normalized be‐
             fore use.  Any further file content, until either end-of-file
             or the occurrence of another machine or a default first-class
             token is bound (only related) to the machine name.

             As an extension that should not be the cause of any worries
             this parser supports a single wildcard prefix for name:

                   machine *.example.com login USER password PASS
                   machine pop3.example.com login USER password PASS
                   machine smtp.example.com login USER password PASS

             which would match ‘xy.example.com’ as well as
             ‘pop3.example.com’, but neither ‘example.com’ nor
             ‘local.smtp.example.com’.  In the example neither
             ‘pop3.example.com’ nor ‘smtp.example.com’ will be matched by
             the wildcard, since the exact matches take precedence (it is
             however faster to specify it the other way around).

   default   This is the same as machine except that it is a fallback entry
             that is used shall none of the specified machines match; only
             one default token may be specified, and it must be the last
             first-class token.

   login name
             The user name on the remote machine.

   password string
             The user’s password on the remote machine.

   account string
             Supply an additional account password.  This is merely for FTP
             purposes.

   macdef name
             Define a macro.  A macro is defined with the specified name; it
             is formed from all lines beginning with the next line and con‐
             tinuing until a blank line is (consecutive newline characters
             are) encountered.  (Note that macdef entries cannot be utilized
             by multiple machines, too, but must be defined following the
             machine they are intended to be used with.)  If a macro named
             init exists, it is automatically run as the last step of the
             login process.  This is merely for FTP purposes.

This is covered by tests.  Last Coverity errors fixed on
2020-01-04, no user bugs/wishes since 2016-05-10, when we added
comment support due to

      I'd assumed they are accepted netrc syntax since fetchmail,
      lftp, ftp, msmtp and other network applications I use haven't
      ever complained about them.

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)

Reply via email to