3 ms·
Is there some specification that covers what it is supposed to mean if a host is listed more than once in .netrc? The man page for netrc on most Unix or Unix-l
by tzs 9y ago
Is there some specification that covers what it is supposed to mean if a host is listed more than once in .netrc?
The man page for netrc on most Unix or Unix-like systems that I checked includes this for how the "machine" token is handled:
> Identify a remote machine name. The auto-login process searches the .netrc file for a machine token that matches the remote machine specified on the ftp command line or as an open command argument. Once a match is made, the subsequent .netrc tokens are processed, stopping when the end of file is reached or another machine or a default token is encountered
That specifically talks about ftp's use of .netrc, and as described only the first entry for a host is ever processed.
I can think of two ways to take that, from the point of view of a programmer thinking of using .netrc for a program that is not ftp.
1. .netrc was designed for ftp. If I'm going to use another programs' file I should use it exactly like it is documented to use it...so I should only look at the first matching machine too.
2. .netrc was designed for ftp, but it is explicitly documented as only looking at the first matching machine. What that tells me is that I can go ahead and tell my users to use .netrc for my program too, and if they need different credentials for my service than they do for ftp on a given machine, go ahead and make a separate machine entry for my program. Just make sure it is not the FIRST machine entry for that machine. I can add some way for them to tell my program which entry to use when there are multiple machine entries that match. Either a command line argument, an environment variable, or since ftp is guaranteed to not process other than the first match I could even add a new token in .netrc that marks my entry.