GNURLOPT_NETRC(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

πŸ’… GNURLOPT_NETRC(3) β€” like, the curl_easy_setopt options era, bestie πŸŽ€

okay so this page lives in the curl_easy_setopt options corner of the gnurl universe, and it's literally about letting libcurl read your ~/.netrc. yes. that file. the vibe check of "do I trust my saved passwords or not". let's go ✨


🌸 NAME 🌸

CURLOPT_NETRC β€” the "please go look at my .netrc" request, fr fr πŸ’Œ


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <gnurl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_NETRC, long level);

✨ DESCRIPTION ✨

So this parameter is the preference dial πŸ”˜ β€” it controls the level of preference libcurl gives to user names and passwords from your ~/.netrc file, relative to the user names and passwords sitting right there in the URL you passed with CURLOPT_URL(3).

On Windows, libcurl will use the file as %HOME%/_netrc, but bestie you can also tell libcurl a different file name to use with CURLOPT_NETRC_FILE(3). convenient icon behavior πŸ’…

Also super important: libcurl uses a user name (and supplied or prompted password) that you give it with CURLOPT_USERPWD(3) or CURLOPT_USERNAME(3) in preference to any of the options controlled by this parameter. like, your explicit creds win. main character energy πŸ‘‘

Only machine name, user name and password are taken into account (init macros and similar things aren't supported). so don't come at it with the fancy stuff, it's not doing that πŸ™ˆ

And heads up β€” 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. like, actual security note, not just vibes: lock that file down. πŸ”’

level should be set to one of the values described below. πŸ‘‡

⭐ the level values ⭐

  • CURL_NETRC_OPTIONAL β€” using the ~/.netrc file is optional, and information in the URL is to be preferred. The file will be scanned for the host and user name (to find the password only) or for the host only, to find the first user name and password after that machine, which ever information is not specified. 🫢 Undefined values of the option will have this effect. so if you left it weird/unspecified, congrats, this is what you get πŸ’«
  • CURL_NETRC_IGNORED β€” the library will ignore the ~/.netrc file. completely. not even a glance πŸ’€ This is the default. remember this one, it matters.
  • CURL_NETRC_REQUIRED β€” the use of the ~/.netrc file is required, and information in the URL is to be ignored. The file will be scanned for the host and user name (to find the password only) or for the host only, to find the first user name and password after that machine, which ever information is not specified. it's giving "netrc or nothing" πŸ”₯

πŸŽ€ DEFAULT πŸŽ€

CURL_NETRC_IGNORED

yep, out of the box it just ignores the whole file. no cap.


🌈 PROTOCOLS 🌈

Most 🌍 (that's it, that's the whole section, slay)


🧚 EXAMPLE 🧚

CURL *curl = curl_easy_init();
if(curl) {
  CURLcode ret;
  curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/");
  curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
  ret = curl_easy_perform(curl);
}

see how it sets the URL first, then flips the netrc dial to CURL_NETRC_OPTIONAL, then performs? iconic sequence, don't rearrange it πŸ“


πŸ’œ AVAILABILITY πŸ’œ

Always ⭐ β€” literally always there for you, bestie.


πŸ‘‘ RETURN VALUE πŸ‘‘

Returns CURLE_OK πŸ’–


🫢 SEE ALSO 🫢


ok that's the whole page!! go forth and let your .netrc live its truth (or don't, CURL_NETRC_IGNORED is the default after all 😭) πŸ’…βœ¨

mwah πŸ’‹ β€” written against libcurl 7.37.0, dated 17 Jun 2014, and this lil page is GNURLOPT_NETRC(3) in the manual, don't forget it πŸŽ€

πŸ“¦ where this page comes from