4 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (c) 1996-1999 by Internet Software Consortium.
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #if !defined(LINT) && !defined(CODECENTER)
21 static const char rcsid
[] = "Id: getgrent.c,v 1.5 2005/04/27 04:56:24 sra Exp";
26 #include "port_before.h"
28 #if !defined(WANT_IRS_GR) || defined(__BIND_NOSTATIC)
29 static int __bind_irs_gr_unneeded
;
32 #include <sys/types.h>
34 #include <netinet/in.h>
35 #include <arpa/nameser.h>
46 #include "port_after.h"
52 static struct net_data
*init(void);
59 struct net_data
*net_data
= init();
61 return (getgrent_p(net_data
));
65 getgrnam(const char *name
) {
66 struct net_data
*net_data
= init();
68 return (getgrnam_p(name
, net_data
));
73 struct net_data
*net_data
= init();
75 return (getgrgid_p(gid
, net_data
));
79 setgroupent(int stayopen
) {
80 struct net_data
*net_data
= init();
82 return (setgroupent_p(stayopen
, net_data
));
88 struct net_data
*net_data
= init();
95 struct net_data
*net_data
= init();
97 return (setgrent_p(net_data
));
99 #endif /* SETGRENT_VOID */
103 struct net_data
*net_data
= init();
105 endgrent_p(net_data
);
109 getgrouplist(GETGROUPLIST_ARGS
) {
110 struct net_data
*net_data
= init();
112 return (getgrouplist_p(name
, basegid
, groups
, ngroups
, net_data
));
115 /* Shared private. */
118 getgrent_p(struct net_data
*net_data
) {
121 if (!net_data
|| !(gr
= net_data
->gr
))
123 net_data
->gr_last
= (*gr
->next
)(gr
);
124 return (net_data
->gr_last
);
128 getgrnam_p(const char *name
, struct net_data
*net_data
) {
131 if (!net_data
|| !(gr
= net_data
->gr
))
133 if (net_data
->gr_stayopen
&& net_data
->gr_last
&&
134 !strcmp(net_data
->gr_last
->gr_name
, name
))
135 return (net_data
->gr_last
);
136 net_data
->gr_last
= (*gr
->byname
)(gr
, name
);
137 if (!net_data
->gr_stayopen
)
139 return (net_data
->gr_last
);
143 getgrgid_p(gid_t gid
, struct net_data
*net_data
) {
146 if (!net_data
|| !(gr
= net_data
->gr
))
148 if (net_data
->gr_stayopen
&& net_data
->gr_last
&&
149 (gid_t
)net_data
->gr_last
->gr_gid
== gid
)
150 return (net_data
->gr_last
);
151 net_data
->gr_last
= (*gr
->bygid
)(gr
, gid
);
152 if (!net_data
->gr_stayopen
)
154 return (net_data
->gr_last
);
158 setgroupent_p(int stayopen
, struct net_data
*net_data
) {
161 if (!net_data
|| !(gr
= net_data
->gr
))
164 net_data
->gr_stayopen
= (stayopen
!= 0);
166 net_data_minimize(net_data
);
172 setgrent_p(struct net_data
*net_data
) {
173 (void)setgroupent_p(0, net_data
);
177 setgrent_p(struct net_data
*net_data
) {
178 return (setgroupent_p(0, net_data
));
180 #endif /* SETGRENT_VOID */
183 endgrent_p(struct net_data
*net_data
) {
186 if ((net_data
!= NULL
) && ((gr
= net_data
->gr
) != NULL
))
191 getgrouplist_p(const char *name
, gid_t basegid
, gid_t
*groups
, int *ngroups
,
192 struct net_data
*net_data
) {
195 if (!net_data
|| !(gr
= net_data
->gr
)) {
199 return ((*gr
->list
)(gr
, name
, basegid
, groups
, ngroups
));
204 static struct net_data
*
206 struct net_data
*net_data
;
208 if (!(net_data
= net_data_init(NULL
)))
211 net_data
->gr
= (*net_data
->irs
->gr_map
)(net_data
->irs
);
213 if (!net_data
->gr
|| !net_data
->res
) {
218 (*net_data
->gr
->res_set
)(net_data
->gr
, net_data
->res
,
225 #endif /* WANT_IRS_GR */