17c478bd9Sstevel@tonic-gate /*
2*9525b14bSRao Shoaib * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC")
3*9525b14bSRao Shoaib * Copyright (C) 1996-1999, 2001, 2003 Internet Software Consortium.
47c478bd9Sstevel@tonic-gate *
5*9525b14bSRao Shoaib * Permission to use, copy, modify, and/or distribute this software for any
67c478bd9Sstevel@tonic-gate * purpose with or without fee is hereby granted, provided that the above
77c478bd9Sstevel@tonic-gate * copyright notice and this permission notice appear in all copies.
87c478bd9Sstevel@tonic-gate *
9*9525b14bSRao Shoaib * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10*9525b14bSRao Shoaib * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11*9525b14bSRao Shoaib * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12*9525b14bSRao Shoaib * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13*9525b14bSRao Shoaib * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14*9525b14bSRao Shoaib * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15*9525b14bSRao Shoaib * PERFORMANCE OF THIS SOFTWARE.
167c478bd9Sstevel@tonic-gate */
177c478bd9Sstevel@tonic-gate
187c478bd9Sstevel@tonic-gate #if defined(LIBC_SCCS) && !defined(lint)
19*9525b14bSRao Shoaib static const char rcsid[] = "$Id: getnetgrent.c,v 1.6 2008/11/14 02:36:51 marka Exp $";
207c478bd9Sstevel@tonic-gate #endif /* LIBC_SCCS and not lint */
217c478bd9Sstevel@tonic-gate
227c478bd9Sstevel@tonic-gate /* Imports */
237c478bd9Sstevel@tonic-gate
247c478bd9Sstevel@tonic-gate #include "port_before.h"
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #if !defined(__BIND_NOSTATIC)
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate #include <sys/types.h>
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate #include <netinet/in.h>
317c478bd9Sstevel@tonic-gate #include <arpa/nameser.h>
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate #include <errno.h>
347c478bd9Sstevel@tonic-gate #include <resolv.h>
357c478bd9Sstevel@tonic-gate #include <stdio.h>
367c478bd9Sstevel@tonic-gate
377c478bd9Sstevel@tonic-gate #include <irs.h>
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate #include "port_after.h"
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate #include "irs_data.h"
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gate /* Forward */
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate static struct net_data *init(void);
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate /* Public */
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate #ifndef SETNETGRENT_ARGS
517c478bd9Sstevel@tonic-gate #define SETNETGRENT_ARGS const char *netgroup
527c478bd9Sstevel@tonic-gate #endif
537c478bd9Sstevel@tonic-gate void
setnetgrent(SETNETGRENT_ARGS)547c478bd9Sstevel@tonic-gate setnetgrent(SETNETGRENT_ARGS) {
557c478bd9Sstevel@tonic-gate struct net_data *net_data = init();
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate setnetgrent_p(netgroup, net_data);
587c478bd9Sstevel@tonic-gate }
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate void
endnetgrent(void)617c478bd9Sstevel@tonic-gate endnetgrent(void) {
627c478bd9Sstevel@tonic-gate struct net_data *net_data = init();
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate endnetgrent_p(net_data);
657c478bd9Sstevel@tonic-gate }
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate #ifndef INNETGR_ARGS
687c478bd9Sstevel@tonic-gate #define INNETGR_ARGS const char *netgroup, const char *host, \
697c478bd9Sstevel@tonic-gate const char *user, const char *domain
707c478bd9Sstevel@tonic-gate #endif
717c478bd9Sstevel@tonic-gate int
innetgr(INNETGR_ARGS)727c478bd9Sstevel@tonic-gate innetgr(INNETGR_ARGS) {
737c478bd9Sstevel@tonic-gate struct net_data *net_data = init();
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate return (innetgr_p(netgroup, host, user, domain, net_data));
767c478bd9Sstevel@tonic-gate }
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate int
getnetgrent(NGR_R_CONST char ** host,NGR_R_CONST char ** user,NGR_R_CONST char ** domain)79*9525b14bSRao Shoaib getnetgrent(NGR_R_CONST char **host, NGR_R_CONST char **user,
80*9525b14bSRao Shoaib NGR_R_CONST char **domain)
81*9525b14bSRao Shoaib {
827c478bd9Sstevel@tonic-gate struct net_data *net_data = init();
837c478bd9Sstevel@tonic-gate const char *ch, *cu, *cd;
847c478bd9Sstevel@tonic-gate int ret;
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate ret = getnetgrent_p(&ch, &cu, &cd, net_data);
877c478bd9Sstevel@tonic-gate if (ret != 1)
887c478bd9Sstevel@tonic-gate return (ret);
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate DE_CONST(ch, *host);
917c478bd9Sstevel@tonic-gate DE_CONST(cu, *user);
927c478bd9Sstevel@tonic-gate DE_CONST(cd, *domain);
937c478bd9Sstevel@tonic-gate return (ret);
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate /* Shared private. */
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate void
setnetgrent_p(const char * netgroup,struct net_data * net_data)997c478bd9Sstevel@tonic-gate setnetgrent_p(const char *netgroup, struct net_data *net_data) {
1007c478bd9Sstevel@tonic-gate struct irs_ng *ng;
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate if ((net_data != NULL) && ((ng = net_data->ng) != NULL))
1037c478bd9Sstevel@tonic-gate (*ng->rewind)(ng, netgroup);
1047c478bd9Sstevel@tonic-gate }
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate void
endnetgrent_p(struct net_data * net_data)1077c478bd9Sstevel@tonic-gate endnetgrent_p(struct net_data *net_data) {
1087c478bd9Sstevel@tonic-gate struct irs_ng *ng;
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate if (!net_data)
1117c478bd9Sstevel@tonic-gate return;
1127c478bd9Sstevel@tonic-gate if ((ng = net_data->ng) != NULL)
1137c478bd9Sstevel@tonic-gate (*ng->close)(ng);
1147c478bd9Sstevel@tonic-gate net_data->ng = NULL;
1157c478bd9Sstevel@tonic-gate }
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate int
innetgr_p(const char * netgroup,const char * host,const char * user,const char * domain,struct net_data * net_data)1187c478bd9Sstevel@tonic-gate innetgr_p(const char *netgroup, const char *host,
1197c478bd9Sstevel@tonic-gate const char *user, const char *domain,
1207c478bd9Sstevel@tonic-gate struct net_data *net_data) {
1217c478bd9Sstevel@tonic-gate struct irs_ng *ng;
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate if (!net_data || !(ng = net_data->ng))
1247c478bd9Sstevel@tonic-gate return (0);
1257c478bd9Sstevel@tonic-gate return ((*ng->test)(ng, netgroup, host, user, domain));
1267c478bd9Sstevel@tonic-gate }
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate int
getnetgrent_p(const char ** host,const char ** user,const char ** domain,struct net_data * net_data)1297c478bd9Sstevel@tonic-gate getnetgrent_p(const char **host, const char **user, const char **domain,
1307c478bd9Sstevel@tonic-gate struct net_data *net_data ) {
1317c478bd9Sstevel@tonic-gate struct irs_ng *ng;
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate if (!net_data || !(ng = net_data->ng))
1347c478bd9Sstevel@tonic-gate return (0);
1357c478bd9Sstevel@tonic-gate return ((*ng->next)(ng, host, user, domain));
1367c478bd9Sstevel@tonic-gate }
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate /* Private */
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate static struct net_data *
init(void)1417c478bd9Sstevel@tonic-gate init(void) {
1427c478bd9Sstevel@tonic-gate struct net_data *net_data;
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate if (!(net_data = net_data_init(NULL)))
1457c478bd9Sstevel@tonic-gate goto error;
1467c478bd9Sstevel@tonic-gate if (!net_data->ng) {
1477c478bd9Sstevel@tonic-gate net_data->ng = (*net_data->irs->ng_map)(net_data->irs);
1487c478bd9Sstevel@tonic-gate if (!net_data->ng) {
1497c478bd9Sstevel@tonic-gate error:
1507c478bd9Sstevel@tonic-gate errno = EIO;
1517c478bd9Sstevel@tonic-gate return (NULL);
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate }
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate return (net_data);
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate
1587c478bd9Sstevel@tonic-gate #endif /*__BIND_NOSTATIC*/
159*9525b14bSRao Shoaib
160*9525b14bSRao Shoaib /*! \file */
161