2 * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1998, 1999, 2001, 2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or 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 WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 #include <port_before.h>
19 #if !defined(_REENTRANT) || !defined(DO_PTHREADS)
20 static int getnetgrent_r_not_required
= 0;
25 #include <sys/types.h>
26 #include <netinet/in.h>
29 #include <port_after.h>
33 #define NGR_R_PRIVATE 0
37 copy_protoent(NGR_R_CONST
char **, NGR_R_CONST
char **, NGR_R_CONST
char **,
38 const char *, const char *, const char *, NGR_R_COPY_ARGS
);
41 innetgr_r(const char *netgroup
, const char *host
, const char *user
,
43 char *ng
, *ho
, *us
, *dom
;
45 DE_CONST(netgroup
, ng
);
48 DE_CONST(domain
, dom
);
50 return (innetgr(ng
, ho
, us
, dom
));
54 * These assume a single context is in operation per thread.
55 * If this is not the case we will need to call irs directly
56 * rather than through the base functions.
60 getnetgrent_r(NGR_R_CONST
char **machinep
, NGR_R_CONST
char **userp
,
61 NGR_R_CONST
char **domainp
, NGR_R_ARGS
)
63 NGR_R_CONST
char *mp
, *up
, *dp
;
64 int res
= getnetgrent(&mp
, &up
, &dp
);
69 return (copy_protoent(machinep
, userp
, domainp
,
70 mp
, up
, dp
, NGR_R_COPY
));
73 #if NGR_R_PRIVATE == 2
81 setnetgrent_r(NGR_R_SET_CONST
char *netgroup
, NGR_R_SET_ARGS
)
83 setnetgrent_r(NGR_R_SET_CONST
char *netgroup
)
86 #if NGR_R_PRIVATE == 2
90 #if defined(NGR_R_SET_ARGS) && NGR_R_PRIVATE == 0
95 DE_CONST(netgroup
, tmp
);
98 #if NGR_R_PRIVATE == 1
100 #elif NGR_R_PRIVATE == 2
101 *buf
= p
= malloc(sizeof(struct private));
103 #ifdef NGR_R_SET_RESULT
110 #ifdef NGR_R_SET_RESULT
111 return (NGR_R_SET_RESULT
);
116 #ifdef NGR_R_END_ARGS
117 endnetgrent_r(NGR_R_END_ARGS
)
122 #if NGR_R_PRIVATE == 2
123 struct private *p
= buf
;
125 #if defined(NGR_R_SET_ARGS) && NGR_R_PRIVATE == 0
131 #if NGR_R_PRIVATE == 1
135 #elif NGR_R_PRIVATE == 2
140 NGR_R_END_RESULT(NGR_R_OK
);
146 copy_protoent(NGR_R_CONST
char **machinep
, NGR_R_CONST
char **userp
,
147 NGR_R_CONST
char **domainp
, const char *mp
, const char *up
,
148 const char *dp
, NGR_R_COPY_ARGS
)
150 #if NGR_R_PRIVATE == 2
151 struct private *p
= buf
;
157 /* Find out the amount of space required to store the answer. */
159 if (mp
!= NULL
) len
+= strlen(mp
) + 1;
160 if (up
!= NULL
) len
+= strlen(up
) + 1;
161 if (dp
!= NULL
) len
+= strlen(dp
) + 1;
163 #if NGR_R_PRIVATE == 1
170 #elif NGR_R_PRIVATE == 2
173 p
->buf
= malloc(len
);
178 if (len
> (int)buflen
) {
211 #else /* NGR_R_RETURN */
212 static int getnetgrent_r_unknown_system
= 0;
213 #endif /* NGR_R_RETURN */
214 #endif /* !defined(_REENTRANT) || !defined(DO_PTHREADS) */