4 * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1998, 1999, 2001, 2003 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or 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 WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 #if defined(LIBC_SCCS) && !defined(lint)
21 static const char rcsid
[] = "Id: getnetgrent_r.c,v 1.14 2008/11/14 02:36:51 marka Exp";
22 #endif /* LIBC_SCCS and not lint */
24 #include <port_before.h>
25 #if !defined(_REENTRANT) || !defined(DO_PTHREADS)
26 static int getnetgrent_r_not_required
= 0;
31 #include <sys/types.h>
32 #include <netinet/in.h>
35 #include <port_after.h>
39 #define NGR_R_PRIVATE 0
43 copy_protoent(NGR_R_CONST
char **, NGR_R_CONST
char **, NGR_R_CONST
char **,
44 const char *, const char *, const char *, NGR_R_COPY_ARGS
);
47 innetgr_r(const char *netgroup
, const char *host
, const char *user
,
49 char *ng
, *ho
, *us
, *dom
;
51 DE_CONST(netgroup
, ng
);
54 DE_CONST(domain
, dom
);
56 return (innetgr(ng
, ho
, us
, dom
));
60 * These assume a single context is in operation per thread.
61 * If this is not the case we will need to call irs directly
62 * rather than through the base functions.
66 getnetgrent_r(NGR_R_CONST
char **machinep
, NGR_R_CONST
char **userp
,
67 NGR_R_CONST
char **domainp
, NGR_R_ARGS
)
69 NGR_R_CONST
char *mp
, *up
, *dp
;
70 int res
= getnetgrent(&mp
, &up
, &dp
);
75 return (copy_protoent(machinep
, userp
, domainp
,
76 mp
, up
, dp
, NGR_R_COPY
));
79 #if NGR_R_PRIVATE == 2
87 setnetgrent_r(NGR_R_SET_CONST
char *netgroup
, NGR_R_SET_ARGS
)
89 setnetgrent_r(NGR_R_SET_CONST
char *netgroup
)
92 #if NGR_R_PRIVATE == 2
96 #if defined(NGR_R_SET_ARGS) && NGR_R_PRIVATE == 0
101 DE_CONST(netgroup
, tmp
);
104 #if NGR_R_PRIVATE == 1
106 #elif NGR_R_PRIVATE == 2
107 *buf
= p
= malloc(sizeof(struct private));
109 #ifdef NGR_R_SET_RESULT
116 #ifdef NGR_R_SET_RESULT
117 return (NGR_R_SET_RESULT
);
122 #ifdef NGR_R_END_ARGS
123 endnetgrent_r(NGR_R_END_ARGS
)
128 #if NGR_R_PRIVATE == 2
129 struct private *p
= buf
;
131 #if defined(NGR_R_SET_ARGS) && NGR_R_PRIVATE == 0
137 #if NGR_R_PRIVATE == 1
141 #elif NGR_R_PRIVATE == 2
146 NGR_R_END_RESULT(NGR_R_OK
);
152 copy_protoent(NGR_R_CONST
char **machinep
, NGR_R_CONST
char **userp
,
153 NGR_R_CONST
char **domainp
, const char *mp
, const char *up
,
154 const char *dp
, NGR_R_COPY_ARGS
)
156 #if NGR_R_PRIVATE == 2
157 struct private *p
= buf
;
163 /* Find out the amount of space required to store the answer. */
165 if (mp
!= NULL
) len
+= strlen(mp
) + 1;
166 if (up
!= NULL
) len
+= strlen(up
) + 1;
167 if (dp
!= NULL
) len
+= strlen(dp
) + 1;
169 #if NGR_R_PRIVATE == 1
176 #elif NGR_R_PRIVATE == 2
179 p
->buf
= malloc(len
);
184 if (len
> (int)buflen
) {
217 #else /* NGR_R_RETURN */
218 static int getnetgrent_r_unknown_system
= 0;
219 #endif /* NGR_R_RETURN */
220 #endif /* !defined(_REENTRANT) || !defined(DO_PTHREADS) */