1getnetgrent(3C) Standard C Library Functions getnetgrent(3C)
2
3
4
6 getnetgrent, getnetgrent_r, setnetgrent, endnetgrent, innetgr - get
7 network group entry
8
10 #include <netdb.h>
11
12 int getnetgrent(char **machinep, char **userp, char **domainp);
13
14
15 int getnetgrent_r(char **machinep, char **userp, char **domainp,
16 char *buffer, intbuflen);
17
18
19 int setnetgrent(const char *netgroup);
20
21
22 int endnetgrent(void);
23
24
25 int innetgr(const char *netgroup, const char *machine,
26 const char *user, const char *domain);
27
28
30 These functions are used to test membership in and enumerate members of
31 ``netgroup'' network groups defined in a system database. Netgroups
32 are sets of (machine,user,domain) triples (see netgroup(4)).
33
34
35 These functions consult the source specified for netgroup in the
36 /etc/nsswitch.conf file (see nsswitch.conf(4)).
37
38
39 The function innetgr() returns 1 if there is a netgroup netgroup that
40 contains the specified machine, user, domain triple as a member; other‐
41 wise it returns 0. Any of the supplied pointers machine, user, and
42 domain may be NULL, signifying a "wild card" that matches all values in
43 that position of the triple.
44
45
46 The innetgr() function is safe for use in single-threaded and multi‐
47 threaded applications.
48
49
50 The functions setnetgrent(), getnetgrent(), and endnetgrent() are used
51 to enumerate the members of a given network group.
52
53
54 The function setnetgrent() establishes the network group specified in
55 the parameter netgroup as the current group whose members are to be
56 enumerated.
57
58
59 Successive calls to the function getnetgrent() will enumerate the mem‐
60 bers of the group established by calling setnetgrent(); each call
61 returns 1 if it succeeds in obtaining another member of the network
62 group, or 0 if there are no further members of the group.
63
64
65 When calling either getnetgrent() or getnetgrent_r(), addresses of the
66 three character pointers are used as arguments, for example:
67
68 char *mp, *up, *dp;
69 getnetgrent(&mp, &up, &dp);
70
71
72
73 Upon successful return from getnetgrent(), the pointer mp points to a
74 string containing the name of the machine part of the member triple, up
75 points to a string containing the user name and dp points to a string
76 containing the domain name. If the pointer returned for mp, up, or dp
77 is NULL, it signifies that the element of the netgroup contains wild
78 card specifier in that position of the triple.
79
80
81 The pointers returned by getnetgrent() point into a buffer allocated by
82 setnetgrent() that is reused by each call. This space is released when
83 an endnetgrent() call is made, and should not be released by the call‐
84 er. This implementation is not safe for use in multi-threaded applica‐
85 tions.
86
87
88 The function getnetgrent_r() is similar to getnetgrent() function, but
89 it uses a buffer supplied by the caller for the space needed to store
90 the results. The parameter buffer should be a pointer to a buffer
91 allocated by the caller and the length of this buffer should be speci‐
92 fied by the parameter buflen. The buffer must be large enough to hold
93 the data associated with the triple. The getnetgrent_r() function is
94 safe for use both in single-threaded and multi-threaded applications.
95
96
97 The function endnetgrent() frees the space allocated by the previous
98 setnetgrent() call. The equivalent of an endnetgrent() implicitly per‐
99 formed whenever a setnetgrent() call is made to a new network group.
100
101
102 Note that while setnetgrent() and endnetgrent() are safe for use in
103 multi-threaded applications, the effect of each is process-wide. Call‐
104 ing setnetgrent() resets the enumeration position for all threads. If
105 multiple threads interleave calls to getnetgrent_r() each will enumer‐
106 ate a disjoint subset of the netgroup. Thus the effective use of these
107 functions in multi-threaded applications may require coordination by
108 the caller.
109
111 The function getnetgrent_r() will return 0 and set errno to ERANGE if
112 the length of the buffer supplied by caller is not large enough to
113 store the result. See Intro(2) for the proper usage and interpretation
114 of errno in multi-threaded applications.
115
116
117 The functions setnetgrent() and endnetgrent() return 0 upon success.
118
120 /etc/nsswitch.conf
121
122
124 See attributes(5) for descriptions of the following attributes:
125
126
127
128
129 ┌─────────────────────────────┬─────────────────────────────┐
130 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
131 ├─────────────────────────────┼─────────────────────────────┤
132 │MT-Level │See DESCRIPTION section. │
133 └─────────────────────────────┴─────────────────────────────┘
134
136 Intro(2), Intro(3), netgroup(4), nsswitch.conf(4), attributes(5)
137
139 The function getnetgrent_r() is included in this release on an uncom‐
140 mitted basis only, and is subject to change or removal in future minor
141 releases.
142
144 Only the Network Information Services, NIS and NIS+, are supported as
145 sources for the netgroup database.
146
147
148 When compiling multi-threaded applications, see Intro(3), Notes On
149 Multithread Applications, for information about the use of the _REEN‐
150 TRANT flag.
151
152
153
154SunOS 5.11 5 Apr 2004 getnetgrent(3C)