netrc: refactor into smaller sub functions

Fixes #20950 - test 685 is extended for this
Closes #20932
This commit is contained in:
Daniel Stenberg 2026-03-09 08:38:14 +01:00
parent a46816b4cb
commit a327a5bded
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
4 changed files with 334 additions and 221 deletions

View file

@ -35,10 +35,18 @@ On Windows two filenames in the home directory are checked: *.netrc* and
*_netrc*, preferring the former. Older versions on Windows checked for
*_netrc* only.
A quick and simple example of how to setup a *.netrc* to allow curl to FTP to
the machine host.example.com with username 'myself' and password 'secret'
A quick and simple example of how to setup a *.netrc* to allow curl to access
the machine host.example.com with username `myself` and password `secret`
could look similar to:
machine host.example.com
login myself
password secret
curl also supports the `default` keyword. This is the same as machine name
except that default matches any name. There can be only one `default` token,
and it must be after all machine tokens.
When providing a username in the URL and a *.netrc* file, curl looks for the
password for that specific user for the given host if such an entry appears in
the file before a "generic" `machine` entry without `login` specified.

View file

@ -50,6 +50,11 @@ and similar things are not supported).
The netrc file provides credentials for a hostname independent of which
protocol and port number that are used.
When providing a username in the URL and a *.netrc* file, libcurl looks for
and uses the password for that specific user for the given host if such an
entry appears in the file before a "generic" `machine` entry without `login`
specified.
libcurl does not verify that the file has the correct properties set (as the
standard Unix ftp client does). It should only be readable by user.