summaryrefslogtreecommitdiff
path: root/contrib/bind/lib/irs/getnetgrent.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bind/lib/irs/getnetgrent.c')
-rw-r--r--contrib/bind/lib/irs/getnetgrent.c110
1 files changed, 79 insertions, 31 deletions
diff --git a/contrib/bind/lib/irs/getnetgrent.c b/contrib/bind/lib/irs/getnetgrent.c
index 0acb776fcd36..8c5f5f894a66 100644
--- a/contrib/bind/lib/irs/getnetgrent.c
+++ b/contrib/bind/lib/irs/getnetgrent.c
@@ -1,5 +1,5 @@
/*
- * Portions Copyright (c) 1996 by Internet Software Consortium.
+ * Copyright (c) 1996,1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -16,14 +16,22 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: getnetgrent.c,v 1.9 1997/12/04 04:57:53 halley Exp $";
+static const char rcsid[] = "$Id: getnetgrent.c,v 1.14 1999/10/07 20:44:03 vixie Exp $";
#endif /* LIBC_SCCS and not lint */
/* Imports */
#include "port_before.h"
+#if !defined(__BIND_NOSTATIC)
+
+#include <sys/types.h>
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+
#include <errno.h>
+#include <resolv.h>
#include <stdio.h>
#include <irs.h>
@@ -34,60 +42,100 @@ static const char rcsid[] = "$Id: getnetgrent.c,v 1.9 1997/12/04 04:57:53 halley
/* Forward */
-static struct irs_ng * init(void);
+static struct net_data *init(void);
+
/* Public */
void
setnetgrent(const char *netgroup) {
- struct irs_ng *ng = init();
-
- if (ng != NULL)
- (*ng->rewind)(ng, netgroup);
+ struct net_data *net_data = init();
+
+ setnetgrent_p(netgroup, net_data);
}
-void
+void
endnetgrent(void) {
- struct irs_ng *ng = init();
-
- if (ng)
- (*ng->close)(ng);
- net_data.ng = NULL;
+ struct net_data *net_data = init();
+
+ endnetgrent_p(net_data);
}
int
innetgr(const char *netgroup, const char *host,
const char *user, const char *domain) {
- struct irs_ng *ng = init();
-
- if (!ng)
+ struct net_data *net_data = init();
+
+ return (innetgr_p(netgroup, host, user, domain, net_data));
+}
+
+int
+getnetgrent(char **host, char **user, char **domain) {
+ struct net_data *net_data = init();
+
+ return (getnetgrent_p(host, user, domain, net_data));
+}
+
+/* Shared private. */
+
+void
+setnetgrent_p(const char *netgroup, struct net_data *net_data) {
+ struct irs_ng *ng;
+
+ if ((net_data != NULL) && ((ng = net_data->ng) != NULL))
+ (*ng->rewind)(ng, netgroup);
+}
+
+void
+endnetgrent_p(struct net_data *net_data) {
+ struct irs_ng *ng;
+
+ if (!net_data)
+ return;
+ if ((ng = net_data->ng) != NULL)
+ (*ng->close)(ng);
+ net_data->ng = NULL;
+}
+
+int
+innetgr_p(const char *netgroup, const char *host,
+ const char *user, const char *domain,
+ struct net_data *net_data) {
+ struct irs_ng *ng;
+
+ if (!net_data || !(ng = net_data->ng))
return (0);
return ((*ng->test)(ng, netgroup, host, user, domain));
}
int
-getnetgrent(char **host, char **user, char **domain) {
- struct irs_ng *ng = init();
- struct netgrp *ngent;
-
- if (!ng)
+getnetgrent_p(char **host, char **user, char **domain,
+ struct net_data *net_data ) {
+ struct irs_ng *ng;
+
+ if (!net_data || !(ng = net_data->ng))
return (0);
return ((*ng->next)(ng, host, user, domain));
}
/* Private */
-static struct irs_ng *
+static struct net_data *
init(void) {
-
- if (!net_data_init())
+ struct net_data *net_data;
+
+ if (!(net_data = net_data_init(NULL)))
goto error;
- if (!net_data.ng)
- net_data.ng = (*net_data.irs->ng_map)(net_data.irs);
- if (!net_data.ng) {
-error:
- errno = EIO;
- return (NULL);
+ if (!net_data->ng) {
+ net_data->ng = (*net_data->irs->ng_map)(net_data->irs);
+ if (!net_data->ng) {
+ error:
+ errno = EIO;
+ return (NULL);
+ }
}
- return (net_data.ng);
+
+ return (net_data);
}
+
+#endif /*__BIND_NOSTATIC*/