xref: /aosp_15_r20/external/curl/docs/libcurl/opts/CURLOPT_NETRC.md (revision 6236dae45794135f37c4eb022389c904c8b0090d)
1*6236dae4SAndroid Build Coastguard Worker---
2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al.
3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl
4*6236dae4SAndroid Build Coastguard WorkerTitle: CURLOPT_NETRC
5*6236dae4SAndroid Build Coastguard WorkerSection: 3
6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl
7*6236dae4SAndroid Build Coastguard WorkerSee-also:
8*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_NETRC_FILE (3)
9*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_USERNAME (3)
10*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_USERPWD (3)
11*6236dae4SAndroid Build Coastguard WorkerProtocol:
12*6236dae4SAndroid Build Coastguard Worker  - All
13*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.1
14*6236dae4SAndroid Build Coastguard Worker---
15*6236dae4SAndroid Build Coastguard Worker
16*6236dae4SAndroid Build Coastguard Worker# NAME
17*6236dae4SAndroid Build Coastguard Worker
18*6236dae4SAndroid Build Coastguard WorkerCURLOPT_NETRC - enable use of .netrc
19*6236dae4SAndroid Build Coastguard Worker
20*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS
21*6236dae4SAndroid Build Coastguard Worker
22*6236dae4SAndroid Build Coastguard Worker~~~c
23*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h>
24*6236dae4SAndroid Build Coastguard Worker
25*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_NETRC, long level);
26*6236dae4SAndroid Build Coastguard Worker~~~
27*6236dae4SAndroid Build Coastguard Worker
28*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION
29*6236dae4SAndroid Build Coastguard Worker
30*6236dae4SAndroid Build Coastguard WorkerThis parameter controls the preference *level* of libcurl between using
31*6236dae4SAndroid Build Coastguard Workerusernames and passwords from your *~/.netrc* file, relative to usernames and
32*6236dae4SAndroid Build Coastguard Workerpasswords in the URL supplied with CURLOPT_URL(3).
33*6236dae4SAndroid Build Coastguard Worker
34*6236dae4SAndroid Build Coastguard WorkerOn Windows, libcurl primarily checks for *.netrc* in *%HOME%*. If *%HOME%* is
35*6236dae4SAndroid Build Coastguard Workernot set on Windows, libcurl falls back to *%USERPROFILE%*. If the file does
36*6236dae4SAndroid Build Coastguard Workernot exist, it falls back to check if there is instead a file named *_netrc* -
37*6236dae4SAndroid Build Coastguard Workerusing an underscore instead of period.
38*6236dae4SAndroid Build Coastguard Worker
39*6236dae4SAndroid Build Coastguard WorkerYou can also tell libcurl a different filename to use with
40*6236dae4SAndroid Build Coastguard WorkerCURLOPT_NETRC_FILE(3).
41*6236dae4SAndroid Build Coastguard Worker
42*6236dae4SAndroid Build Coastguard Workerlibcurl uses a username (and supplied or prompted password) supplied with
43*6236dae4SAndroid Build Coastguard WorkerCURLOPT_USERPWD(3) or CURLOPT_USERNAME(3) in preference to any of
44*6236dae4SAndroid Build Coastguard Workerthe options controlled by this parameter.
45*6236dae4SAndroid Build Coastguard Worker
46*6236dae4SAndroid Build Coastguard WorkerOnly machine name, username and password are taken into account (init macros
47*6236dae4SAndroid Build Coastguard Workerand similar things are not supported).
48*6236dae4SAndroid Build Coastguard Worker
49*6236dae4SAndroid Build Coastguard Workerlibcurl does not verify that the file has the correct properties set (as the
50*6236dae4SAndroid Build Coastguard Workerstandard Unix ftp client does). It should only be readable by user.
51*6236dae4SAndroid Build Coastguard Worker
52*6236dae4SAndroid Build Coastguard Worker*level* is a long that should be set to one of the values described below.
53*6236dae4SAndroid Build Coastguard Worker
54*6236dae4SAndroid Build Coastguard Worker## CURL_NETRC_IGNORED (0)
55*6236dae4SAndroid Build Coastguard Worker
56*6236dae4SAndroid Build Coastguard Workerlibcurl ignores the *.netrc* file. This is the default.
57*6236dae4SAndroid Build Coastguard Worker
58*6236dae4SAndroid Build Coastguard Worker## CURL_NETRC_OPTIONAL (1)
59*6236dae4SAndroid Build Coastguard Worker
60*6236dae4SAndroid Build Coastguard WorkerThe use of the *.netrc* file is optional, and information in the URL is to
61*6236dae4SAndroid Build Coastguard Workerbe preferred. The file is scanned for the host and username (to find the
62*6236dae4SAndroid Build Coastguard Workerpassword only) or for the host only, to find the first username and password
63*6236dae4SAndroid Build Coastguard Workerafter that *machine*, which ever information is not specified.
64*6236dae4SAndroid Build Coastguard Worker
65*6236dae4SAndroid Build Coastguard Worker## CURL_NETRC_REQUIRED (2)
66*6236dae4SAndroid Build Coastguard Worker
67*6236dae4SAndroid Build Coastguard WorkerThe use of the *.netrc* file is required, and any credential information
68*6236dae4SAndroid Build Coastguard Workerpresent in the URL is ignored. The file is scanned for the host and username
69*6236dae4SAndroid Build Coastguard Worker(to find the password only) or for the host only, to find the first username
70*6236dae4SAndroid Build Coastguard Workerand password after that *machine*, which ever information is not
71*6236dae4SAndroid Build Coastguard Workerspecified.
72*6236dae4SAndroid Build Coastguard Worker
73*6236dae4SAndroid Build Coastguard Worker# FILE FORMAT
74*6236dae4SAndroid Build Coastguard Worker
75*6236dae4SAndroid Build Coastguard WorkerThe **.netrc** file format is simple: you specify lines with a machine name
76*6236dae4SAndroid Build Coastguard Workerand follow the login and password that are associated with that machine.
77*6236dae4SAndroid Build Coastguard Worker
78*6236dae4SAndroid Build Coastguard WorkerEach field is provided as a sequence of letters that ends with a space or
79*6236dae4SAndroid Build Coastguard Workernewline. Starting in 7.84.0, libcurl also supports quoted strings. They start
80*6236dae4SAndroid Build Coastguard Workerand end with double quotes and support the escaped special letters ", n,
81*6236dae4SAndroid Build Coastguard Workerr, and t. Quoted strings are the only way a space character can be used in
82*6236dae4SAndroid Build Coastguard Workera username or password.
83*6236dae4SAndroid Build Coastguard Worker
84*6236dae4SAndroid Build Coastguard Worker## machine \<name\>
85*6236dae4SAndroid Build Coastguard Worker
86*6236dae4SAndroid Build Coastguard WorkerProvides credentials for a host called **name**. libcurl searches the .netrc
87*6236dae4SAndroid Build Coastguard Workerfile for a machine token that matches the hostname specified in the URL. Once
88*6236dae4SAndroid Build Coastguard Workera match is made, the subsequent tokens are processed, stopping when the end of
89*6236dae4SAndroid Build Coastguard Workerfile is reached or another "machine" is encountered.
90*6236dae4SAndroid Build Coastguard Worker
91*6236dae4SAndroid Build Coastguard Worker## default
92*6236dae4SAndroid Build Coastguard Worker
93*6236dae4SAndroid Build Coastguard WorkerThis is the same as machine name except that default matches any name. There
94*6236dae4SAndroid Build Coastguard Workercan be only one default token, and it must be after all machine tokens. To
95*6236dae4SAndroid Build Coastguard Workerprovide a default anonymous login for hosts that are not otherwise matched,
96*6236dae4SAndroid Build Coastguard Workeradd a line similar to this in the end:
97*6236dae4SAndroid Build Coastguard Worker
98*6236dae4SAndroid Build Coastguard Worker    default login anonymous password user@domain
99*6236dae4SAndroid Build Coastguard Worker
100*6236dae4SAndroid Build Coastguard Worker## login \<name\>
101*6236dae4SAndroid Build Coastguard Worker
102*6236dae4SAndroid Build Coastguard WorkerThe username string for the remote machine.
103*6236dae4SAndroid Build Coastguard Worker
104*6236dae4SAndroid Build Coastguard Worker## password \<secret\>
105*6236dae4SAndroid Build Coastguard Worker
106*6236dae4SAndroid Build Coastguard WorkerSupply a password. If this token is present, curl supplies the specified
107*6236dae4SAndroid Build Coastguard Workerstring if the remote server requires a password as part of the login process.
108*6236dae4SAndroid Build Coastguard WorkerNote that if this token is present in the .netrc file you really should make
109*6236dae4SAndroid Build Coastguard Workersure the file is not readable by anyone besides the user.
110*6236dae4SAndroid Build Coastguard Worker
111*6236dae4SAndroid Build Coastguard Worker## macdef \<name\>
112*6236dae4SAndroid Build Coastguard Worker
113*6236dae4SAndroid Build Coastguard WorkerDefine a macro. This feature is not supported by libcurl. In order for the
114*6236dae4SAndroid Build Coastguard Workerrest of the .netrc to still work fine, libcurl properly skips every definition
115*6236dae4SAndroid Build Coastguard Workerdone with "macdef" that it finds.
116*6236dae4SAndroid Build Coastguard Worker
117*6236dae4SAndroid Build Coastguard Worker# DEFAULT
118*6236dae4SAndroid Build Coastguard Worker
119*6236dae4SAndroid Build Coastguard WorkerCURL_NETRC_IGNORED
120*6236dae4SAndroid Build Coastguard Worker
121*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS%
122*6236dae4SAndroid Build Coastguard Worker
123*6236dae4SAndroid Build Coastguard Worker# EXAMPLE
124*6236dae4SAndroid Build Coastguard Worker
125*6236dae4SAndroid Build Coastguard Worker~~~c
126*6236dae4SAndroid Build Coastguard Workerint main(void)
127*6236dae4SAndroid Build Coastguard Worker{
128*6236dae4SAndroid Build Coastguard Worker  CURL *curl = curl_easy_init();
129*6236dae4SAndroid Build Coastguard Worker  if(curl) {
130*6236dae4SAndroid Build Coastguard Worker    CURLcode ret;
131*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/");
132*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
133*6236dae4SAndroid Build Coastguard Worker    ret = curl_easy_perform(curl);
134*6236dae4SAndroid Build Coastguard Worker  }
135*6236dae4SAndroid Build Coastguard Worker}
136*6236dae4SAndroid Build Coastguard Worker~~~
137*6236dae4SAndroid Build Coastguard Worker
138*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY%
139*6236dae4SAndroid Build Coastguard Worker
140*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE
141*6236dae4SAndroid Build Coastguard Worker
142*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK
143