setnetgrent(3)

๐Ÿ’– setnetgrent(3) โ€” Library Functions Manual ๐Ÿ’–

okay bestie, sit down, we're learning netgroups today and honestly? it's giving vintage. this whole page is about setnetgrent, endnetgrent, getnetgrent, getnetgrent_r, and innetgr โ€” the girlies that handle network group entries. and yes, it lives in the Standard C library (libc, -lc). ๐ŸŽ€


โœจ SYNOPSIS โœจ

#include <netdb.h>

int setnetgrent(const char *netgroup);
void endnetgrent(void);

int getnetgrent(char **restrict host,
            char **restrict user, char **restrict domain);
int getnetgrent_r(size_t size;
            char **restrict host,
            char **restrict user,
            char **restrict domain,
            char buf[restrict size], size_t size);

int innetgr(const char *netgroup, const char *host,
            const char *user, const char *domain);

๐Ÿฆ‹ Feature Test Macro Requirements for glibc ๐Ÿฆ‹

(peep feature_test_macros(7) if you're nosy, and you should be)

setnetgrent(), endnetgrent(), getnetgrent(), getnetgrent_r(), innetgr():

  • Since glibc 2.19:
    • _DEFAULT_SOURCE
  • glibc 2.19 and earlier:
    • _BSD_SOURCE || _SVID_SOURCE

๐ŸŒธ DESCRIPTION ๐ŸŒธ

The netgroup is a SunOS invention. no cap, that's literally where it came from. A netgroup database is a list of string triples โ€” that's (hostname, username, domainname) โ€” or other netgroup names. Any of the elements in a triple can be empty, and empty means โœจanything matchesโœจ. The functions described here allow access to the netgroup databases. And the file /etc/nsswitch.conf is the one that defines what database is searched. ๐Ÿ‘‘

The setnetgrent() call defines the netgroup that will be searched by subsequent getnetgrent() calls. The getnetgrent() function retrieves the next netgroup entry, and returns pointers in host, user, domain. A null pointer means that the corresponding entry matches any string โ€” wildcard behavior, we love her ๐Ÿ’…. The pointers are valid only as long as there is no call to other netgroup-related functions. To avoid this problem you can use the GNU function getnetgrent_r() that stores the strings in the supplied buffer. To free all allocated buffers use endnetgrent(). ๐Ÿงน

In most cases you want to check only if the triplet (hostname, username, domainname) is a member of a netgroup. The function innetgr() can be used for this without calling the above three functions โ€” shortcut queen ๐Ÿซถ. Again, a null pointer is a wildcard and matches any string. The function is thread-safe. ๐Ÿ”ฅ


๐Ÿ’œ RETURN VALUE ๐Ÿ’œ

These functions return 1 on success and 0 for failure. that's it, that's the whole vibe. โœจ


๐Ÿ“ FILES ๐Ÿ“

  • /etc/netgroup
  • /etc/nsswitch.conf

๐ŸŒˆ ATTRIBUTES ๐ŸŒˆ

For an explanation of the terms used in this section, see attributes(7).

  • setnetgrent(), getnetgrent_r(), innetgr() โ€” Thread safety: MT-Unsafe race:netgrent locale
  • endnetgrent() โ€” Thread safety: MT-Unsafe race:netgrent
  • getnetgrent() โ€” Thread safety: MT-Unsafe race:netgrent race:netgrentbuf locale

In the above table, netgrent in race:netgrent signifies that if any of the functions setnetgrent(), getnetgrent_r(), innetgr(), getnetgrent(), or endnetgrent() are used in parallel in different threads of a program, then data races could occur.

๐Ÿ˜ญ bestie PLEASE heed this one. parallel calls in different threads โ†’ data races. it's giving chaos and we do not want that energy in your program.

โญ VERSIONS โญ

In the BSD implementation, setnetgrent() returns void. (different flavor, different rules, iykyk)


๐ŸŽ€ STANDARDS ๐ŸŽ€

None. literally none. it's giving "we made this up and it stuck". ๐Ÿ’€


๐Ÿ‘‘ HISTORY ๐Ÿ‘‘

setnetgrent(), endnetgrent(), getnetgrent(), and innetgr() are available on most UNIX systems. getnetgrent_r() is not widely available on other systems โ€” she's the rare one, the main character of portability. ๐Ÿฆ‹


๐Ÿ”ฅ SEE ALSO ๐Ÿ”ฅ


and that's the whole page, bestie!! you ate this. this was Linux man-pages 6.20, dated 2026-02-08 โ€” so when you're citing your sources, that's the icon right there. mwah ๐Ÿ’–โœจ๐ŸŽ€

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: GPL-1.0-or-later
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms