| 1 |
'\" t |
| 2 |
.\" Copyright 2002, Walter Harms <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: GPL-1.0-or-later |
| 6 |
.\" |
| 7 |
.TH setnetgrent 3 2026-02-08 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
setnetgrent, endnetgrent, getnetgrent, getnetgrent_r, innetgr \- |
| 10 |
handle network group entries |
| 11 |
.SH LIBRARY |
| 12 |
Standard C library |
| 13 |
.RI ( libc ,\~ \-lc ) |
| 14 |
.SH SYNOPSIS |
| 15 |
.nf |
| 16 |
.B #include <netdb.h> |
| 17 |
.P |
| 18 |
.BI "int setnetgrent(const char *" netgroup ); |
| 19 |
.B "void endnetgrent(void);" |
| 20 |
.P |
| 21 |
.BI "int getnetgrent(char **restrict " host , |
| 22 |
.BI " char **restrict " user ", char **restrict " domain ); |
| 23 |
.BR "int getnetgrent_r(" "size_t size;" |
| 24 |
.BI " char **restrict " host , |
| 25 |
.BI " char **restrict " user ", char **restrict " domain , |
| 26 |
.BI " char " buf "[restrict " size "], size_t " size ); |
| 27 |
.P |
| 28 |
.BI "int innetgr(const char *" netgroup ", const char *" host , |
| 29 |
.BI " const char *" user ", const char *" domain ); |
| 30 |
.fi |
| 31 |
.P |
| 32 |
.RS -4 |
| 33 |
Feature Test Macro Requirements for glibc (see |
| 34 |
.BR feature_test_macros (7)): |
| 35 |
.RE |
| 36 |
.P |
| 37 |
.BR \%setnetgrent (), |
| 38 |
.BR \%endnetgrent (), |
| 39 |
.BR \%getnetgrent (), |
| 40 |
.BR \%getnetgrent_r (), |
| 41 |
.BR \%innetgr (): |
| 42 |
.nf |
| 43 |
Since glibc 2.19: |
| 44 |
_DEFAULT_SOURCE |
| 45 |
glibc 2.19 and earlier: |
| 46 |
_BSD_SOURCE || _SVID_SOURCE |
| 47 |
.fi |
| 48 |
.SH DESCRIPTION |
| 49 |
The |
| 50 |
.I netgroup |
| 51 |
is a SunOS invention. |
| 52 |
A netgroup database is a list of string triples |
| 53 |
.RI ( hostname ", " username ", " domainname ) |
| 54 |
or other netgroup names. |
| 55 |
Any of the elements in a triple can be empty, |
| 56 |
which means that anything matches. |
| 57 |
The functions described here allow access to the netgroup databases. |
| 58 |
The file |
| 59 |
.I /etc/nsswitch.conf |
| 60 |
defines what database is searched. |
| 61 |
.P |
| 62 |
The |
| 63 |
.BR setnetgrent () |
| 64 |
call defines the netgroup that will be searched by subsequent |
| 65 |
.BR getnetgrent () |
| 66 |
calls. |
| 67 |
The |
| 68 |
.BR getnetgrent () |
| 69 |
function retrieves the next netgroup entry, and returns pointers in |
| 70 |
.IR host , |
| 71 |
.IR user , |
| 72 |
.IR domain . |
| 73 |
A null pointer means that the corresponding entry matches any string. |
| 74 |
The pointers are valid only as long as there is no call to other |
| 75 |
netgroup-related functions. |
| 76 |
To avoid this problem you can use the GNU function |
| 77 |
.BR getnetgrent_r () |
| 78 |
that stores the strings in the supplied buffer. |
| 79 |
To free all allocated buffers use |
| 80 |
.BR endnetgrent (). |
| 81 |
.P |
| 82 |
In most cases you want to check only if the triplet |
| 83 |
.RI ( hostname ", " username ", " domainname ) |
| 84 |
is a member of a netgroup. |
| 85 |
The function |
| 86 |
.BR innetgr () |
| 87 |
can be used for this without calling the above three functions. |
| 88 |
Again, a null pointer is a wildcard and matches any string. |
| 89 |
The function is thread-safe. |
| 90 |
.SH RETURN VALUE |
| 91 |
These functions return 1 on success and 0 for failure. |
| 92 |
.SH FILES |
| 93 |
.I /etc/netgroup |
| 94 |
.br |
| 95 |
.I /etc/nsswitch.conf |
| 96 |
.SH ATTRIBUTES |
| 97 |
For an explanation of the terms used in this section, see |
| 98 |
.BR attributes (7). |
| 99 |
.TS |
| 100 |
allbox; |
| 101 |
lb lb lbx |
| 102 |
l l l. |
| 103 |
Interface Attribute Value |
| 104 |
T{ |
| 105 |
.na |
| 106 |
.nh |
| 107 |
.BR setnetgrent (), |
| 108 |
.BR getnetgrent_r (), |
| 109 |
.BR innetgr () |
| 110 |
T} Thread safety T{ |
| 111 |
.na |
| 112 |
.nh |
| 113 |
MT-Unsafe race:netgrent |
| 114 |
locale |
| 115 |
T} |
| 116 |
T{ |
| 117 |
.na |
| 118 |
.nh |
| 119 |
.BR endnetgrent () |
| 120 |
T} Thread safety T{ |
| 121 |
.na |
| 122 |
.nh |
| 123 |
MT-Unsafe race:netgrent |
| 124 |
T} |
| 125 |
T{ |
| 126 |
.na |
| 127 |
.nh |
| 128 |
.BR getnetgrent () |
| 129 |
T} Thread safety T{ |
| 130 |
.na |
| 131 |
.nh |
| 132 |
MT-Unsafe race:netgrent |
| 133 |
race:netgrentbuf locale |
| 134 |
T} |
| 135 |
.TE |
| 136 |
.P |
| 137 |
In the above table, |
| 138 |
.I netgrent |
| 139 |
in |
| 140 |
.I race:netgrent |
| 141 |
signifies that if any of the functions |
| 142 |
.BR setnetgrent (), |
| 143 |
.BR getnetgrent_r (), |
| 144 |
.BR innetgr (), |
| 145 |
.BR getnetgrent (), |
| 146 |
or |
| 147 |
.BR endnetgrent () |
| 148 |
are used in parallel in different threads of a program, |
| 149 |
then data races could occur. |
| 150 |
.SH VERSIONS |
| 151 |
In the BSD implementation, |
| 152 |
.BR setnetgrent () |
| 153 |
returns void. |
| 154 |
.SH STANDARDS |
| 155 |
None. |
| 156 |
.SH HISTORY |
| 157 |
.BR setnetgrent (), |
| 158 |
.BR endnetgrent (), |
| 159 |
.BR getnetgrent (), |
| 160 |
and |
| 161 |
.BR innetgr () |
| 162 |
are available on most UNIX systems. |
| 163 |
.BR getnetgrent_r () |
| 164 |
is not widely available on other systems. |
| 165 |
.\" getnetgrent_r() is on Solaris 8 and AIX 5.1, but not the BSDs. |
| 166 |
.SH SEE ALSO |
| 167 |
.BR sethostent (3), |
| 168 |
.BR setprotoent (3), |
| 169 |
.BR setservent (3) |