2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (c) 1998-1999 by Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #if defined(LIBC_SCCS) && !defined(lint)
19 static const char rcsid[] = "$Id: getnetgrent_r.c,v 1.11.558.2 2008/02/28 05:46:12 marka Exp $";
20 #endif /* LIBC_SCCS and not lint */
22 #include <port_before.h>
23 #if !defined(_REENTRANT) || !defined(DO_PTHREADS)
24 static int getnetgrent_r_not_required = 0;
29 #include <sys/types.h>
30 #include <netinet/in.h>
33 #include <port_after.h>
37 #define NGR_R_PRIVATE 0
41 copy_protoent(NGR_R_CONST char **, NGR_R_CONST char **, NGR_R_CONST char **,
42 const char *, const char *, const char *, NGR_R_COPY_ARGS);
45 innetgr_r(const char *netgroup, const char *host, const char *user,
47 char *ng, *ho, *us, *dom;
49 DE_CONST(netgroup, ng);
52 DE_CONST(domain, dom);
54 return (innetgr(ng, ho, us, dom));
58 * These assume a single context is in operation per thread.
59 * If this is not the case we will need to call irs directly
60 * rather than through the base functions.
64 getnetgrent_r(NGR_R_CONST char **machinep, NGR_R_CONST char **userp,
65 NGR_R_CONST char **domainp, NGR_R_ARGS)
67 NGR_R_CONST char *mp, *up, *dp;
68 int res = getnetgrent(&mp, &up, &dp);
73 return (copy_protoent(machinep, userp, domainp,
74 mp, up, dp, NGR_R_COPY));
77 #if NGR_R_PRIVATE == 2
85 setnetgrent_r(NGR_R_SET_CONST char *netgroup, NGR_R_SET_ARGS)
87 setnetgrent_r(NGR_R_SET_CONST char *netgroup)
90 #if NGR_R_PRIVATE == 2
94 #if defined(NGR_R_SET_ARGS) && NGR_R_PRIVATE == 0
99 DE_CONST(netgroup, tmp);
102 #if NGR_R_PRIVATE == 1
104 #elif NGR_R_PRIVATE == 2
105 *buf = p = malloc(sizeof(struct private));
107 #ifdef NGR_R_SET_RESULT
114 #ifdef NGR_R_SET_RESULT
115 return (NGR_R_SET_RESULT);
120 #ifdef NGR_R_END_ARGS
121 endnetgrent_r(NGR_R_END_ARGS)
126 #if NGR_R_PRIVATE == 2
127 struct private *p = buf;
129 #if defined(NGR_R_SET_ARGS) && NGR_R_PRIVATE == 0
135 #if NGR_R_PRIVATE == 1
139 #elif NGR_R_PRIVATE == 2
144 NGR_R_END_RESULT(NGR_R_OK);
150 copy_protoent(NGR_R_CONST char **machinep, NGR_R_CONST char **userp,
151 NGR_R_CONST char **domainp, const char *mp, const char *up,
152 const char *dp, NGR_R_COPY_ARGS)
154 #if NGR_R_PRIVATE == 2
155 struct private *p = buf;
161 /* Find out the amount of space required to store the answer. */
163 if (mp != NULL) len += strlen(mp) + 1;
164 if (up != NULL) len += strlen(up) + 1;
165 if (dp != NULL) len += strlen(dp) + 1;
167 #if NGR_R_PRIVATE == 1
174 #elif NGR_R_PRIVATE == 2
177 p->buf = malloc(len);
182 if (len > (int)buflen) {
215 #else /* NGR_R_RETURN */
216 static int getnetgrent_r_unknown_system = 0;
217 #endif /* NGR_R_RETURN */
218 #endif /* !defined(_REENTRANT) || !defined(DO_PTHREADS) */