#if defined(LIBC_SCCS) && !defined(lint)
static const char rcsid[] = "$Id: getnetgrent_r.c,v 1.5.2.1.4.4 2005/09/03 12:47:38 marka Exp $";
#endif
#include <port_before.h>
#if !defined(_REENTRANT) || !defined(DO_PTHREADS)
static int getnetgrent_r_not_required = 0;
#else
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdlib.h>
#include <port_after.h>
#ifdef NGR_R_RETURN
static NGR_R_RETURN
copy_protoent(char **, char **, char **, const char *, const char *,
const char *, NGR_R_COPY_ARGS);
NGR_R_RETURN
innetgr_r(const char *netgroup, const char *host, const char *user,
const char *domain) {
char *ng, *ho, *us, *dom;
DE_CONST(netgroup, ng);
DE_CONST(host, ho);
DE_CONST(user, us);
DE_CONST(domain, dom);
return (innetgr(ng, ho, us, dom));
}
NGR_R_RETURN
getnetgrent_r(char **machinep, char **userp, char **domainp, NGR_R_ARGS) {
char *mp, *up, *dp;
int res = getnetgrent(&mp, &up, &dp);
if (res != 1)
return (res);
return (copy_protoent(machinep, userp, domainp,
mp, up, dp, NGR_R_COPY));
}
NGR_R_SET_RETURN
#ifdef NGR_R_ENT_ARGS
setnetgrent_r(const char *netgroup, NGR_R_ENT_ARGS)
#else
setnetgrent_r(const char *netgroup)
#endif
{
char *tmp;
#if defined(NGR_R_ENT_ARGS) && !defined(NGR_R_PRIVATE)
UNUSED(buf);
UNUSED(buflen);
#endif
DE_CONST(netgroup, tmp);
setnetgrent(tmp);
#ifdef NGR_R_PRIVATE
*buf = NULL;
#endif
#ifdef NGR_R_SET_RESULT
return (NGR_R_SET_RESULT);
#endif
}
NGR_R_END_RETURN
#ifdef NGR_R_ENT_ARGS
endnetgrent_r(NGR_R_ENT_ARGS)
#else
endnetgrent_r(void)
#endif
{
#if defined(NGR_R_ENT_ARGS) && !defined(NGR_R_PRIVATE)
UNUSED(buf);
UNUSED(buflen);
#endif
endnetgrent();
#ifdef NGR_R_PRIVATE
if (*buf != NULL)
free(*buf);
*buf = NULL;
#endif
NGR_R_END_RESULT(NGR_R_OK);
}
static int
copy_protoent(char **machinep, char **userp, char **domainp,
const char *mp, const char *up, const char *dp,
NGR_R_COPY_ARGS) {
char *cp;
int n;
int len;
len = 0;
if (mp != NULL) len += strlen(mp) + 1;
if (up != NULL) len += strlen(up) + 1;
if (dp != NULL) len += strlen(dp) + 1;
#ifdef NGR_R_PRIVATE
free(*buf);
*buf = malloc(len);
if (*buf == NULL)
return(NGR_R_BAD);
cp = *buf;
#else
if (len > (int)buflen) {
errno = ERANGE;
return (NGR_R_BAD);
}
cp = buf;
#endif
if (mp != NULL) {
n = strlen(mp) + 1;
strcpy(cp, mp);
*machinep = cp;
cp += n;
} else
*machinep = NULL;
if (up != NULL) {
n = strlen(up) + 1;
strcpy(cp, up);
*userp = cp;
cp += n;
} else
*userp = NULL;
if (dp != NULL) {
n = strlen(dp) + 1;
strcpy(cp, dp);
*domainp = cp;
cp += n;
} else
*domainp = NULL;
return (NGR_R_OK);
}
#else
static int getnetgrent_r_unknown_system = 0;
#endif
#endif