Unleashed v1.4
[unleashed.git] / usr / src / lib / libresolv2 / common / irs / getnetgrent.c
blob163c2bc43d7dd488f6e006ff9ee0cb22e09697f3
1 /*
2 * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1996-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 /* Imports */
20 #include "port_before.h"
22 #if !defined(__BIND_NOSTATIC)
24 #include <sys/types.h>
26 #include <netinet/in.h>
27 #include <arpa/nameser.h>
29 #include <errno.h>
30 #include <resolv.h>
31 #include <stdio.h>
33 #include <irs.h>
35 #include "port_after.h"
37 #include "irs_data.h"
39 /* Forward */
41 static struct net_data *init(void);
44 /* Public */
46 #ifndef SETNETGRENT_ARGS
47 #define SETNETGRENT_ARGS const char *netgroup
48 #endif
49 void
50 setnetgrent(SETNETGRENT_ARGS) {
51 struct net_data *net_data = init();
53 setnetgrent_p(netgroup, net_data);
56 void
57 endnetgrent(void) {
58 struct net_data *net_data = init();
60 endnetgrent_p(net_data);
63 #ifndef INNETGR_ARGS
64 #define INNETGR_ARGS const char *netgroup, const char *host, \
65 const char *user, const char *domain
66 #endif
67 int
68 innetgr(INNETGR_ARGS) {
69 struct net_data *net_data = init();
71 return (innetgr_p(netgroup, host, user, domain, net_data));
74 int
75 getnetgrent(NGR_R_CONST char **host, NGR_R_CONST char **user,
76 NGR_R_CONST char **domain)
78 struct net_data *net_data = init();
79 const char *ch, *cu, *cd;
80 int ret;
82 ret = getnetgrent_p(&ch, &cu, &cd, net_data);
83 if (ret != 1)
84 return (ret);
86 DE_CONST(ch, *host);
87 DE_CONST(cu, *user);
88 DE_CONST(cd, *domain);
89 return (ret);
92 /* Shared private. */
94 void
95 setnetgrent_p(const char *netgroup, struct net_data *net_data) {
96 struct irs_ng *ng;
98 if ((net_data != NULL) && ((ng = net_data->ng) != NULL))
99 (*ng->rewind)(ng, netgroup);
102 void
103 endnetgrent_p(struct net_data *net_data) {
104 struct irs_ng *ng;
106 if (!net_data)
107 return;
108 if ((ng = net_data->ng) != NULL)
109 (*ng->close)(ng);
110 net_data->ng = NULL;
114 innetgr_p(const char *netgroup, const char *host,
115 const char *user, const char *domain,
116 struct net_data *net_data) {
117 struct irs_ng *ng;
119 if (!net_data || !(ng = net_data->ng))
120 return (0);
121 return ((*ng->test)(ng, netgroup, host, user, domain));
125 getnetgrent_p(const char **host, const char **user, const char **domain,
126 struct net_data *net_data ) {
127 struct irs_ng *ng;
129 if (!net_data || !(ng = net_data->ng))
130 return (0);
131 return ((*ng->next)(ng, host, user, domain));
134 /* Private */
136 static struct net_data *
137 init(void) {
138 struct net_data *net_data;
140 if (!(net_data = net_data_init(NULL)))
141 goto error;
142 if (!net_data->ng) {
143 net_data->ng = (*net_data->irs->ng_map)(net_data->irs);
144 if (!net_data->ng) {
145 error:
146 errno = EIO;
147 return (NULL);
151 return (net_data);
154 #endif /*__BIND_NOSTATIC*/
156 /*! \file */