xref: /onnv-gate/usr/src/lib/libresolv2/common/irs/getnetgrent.c (revision 11038:74b12212b8a2)
10Sstevel@tonic-gate /*
2*11038SRao.Shoaib@Sun.COM  * Copyright (C) 2004, 2005, 2008  Internet Systems Consortium, Inc. ("ISC")
3*11038SRao.Shoaib@Sun.COM  * Copyright (C) 1996-1999, 2001, 2003  Internet Software Consortium.
40Sstevel@tonic-gate  *
5*11038SRao.Shoaib@Sun.COM  * Permission to use, copy, modify, and/or distribute this software for any
60Sstevel@tonic-gate  * purpose with or without fee is hereby granted, provided that the above
70Sstevel@tonic-gate  * copyright notice and this permission notice appear in all copies.
80Sstevel@tonic-gate  *
9*11038SRao.Shoaib@Sun.COM  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10*11038SRao.Shoaib@Sun.COM  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11*11038SRao.Shoaib@Sun.COM  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12*11038SRao.Shoaib@Sun.COM  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13*11038SRao.Shoaib@Sun.COM  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14*11038SRao.Shoaib@Sun.COM  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15*11038SRao.Shoaib@Sun.COM  * PERFORMANCE OF THIS SOFTWARE.
160Sstevel@tonic-gate  */
170Sstevel@tonic-gate 
180Sstevel@tonic-gate #if defined(LIBC_SCCS) && !defined(lint)
19*11038SRao.Shoaib@Sun.COM static const char rcsid[] = "$Id: getnetgrent.c,v 1.6 2008/11/14 02:36:51 marka Exp $";
200Sstevel@tonic-gate #endif /* LIBC_SCCS and not lint */
210Sstevel@tonic-gate 
220Sstevel@tonic-gate /* Imports */
230Sstevel@tonic-gate 
240Sstevel@tonic-gate #include "port_before.h"
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #if !defined(__BIND_NOSTATIC)
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <sys/types.h>
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #include <netinet/in.h>
310Sstevel@tonic-gate #include <arpa/nameser.h>
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #include <errno.h>
340Sstevel@tonic-gate #include <resolv.h>
350Sstevel@tonic-gate #include <stdio.h>
360Sstevel@tonic-gate 
370Sstevel@tonic-gate #include <irs.h>
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #include "port_after.h"
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #include "irs_data.h"
420Sstevel@tonic-gate 
430Sstevel@tonic-gate /* Forward */
440Sstevel@tonic-gate 
450Sstevel@tonic-gate static struct net_data *init(void);
460Sstevel@tonic-gate 
470Sstevel@tonic-gate 
480Sstevel@tonic-gate /* Public */
490Sstevel@tonic-gate 
500Sstevel@tonic-gate #ifndef SETNETGRENT_ARGS
510Sstevel@tonic-gate #define SETNETGRENT_ARGS const char *netgroup
520Sstevel@tonic-gate #endif
530Sstevel@tonic-gate void
setnetgrent(SETNETGRENT_ARGS)540Sstevel@tonic-gate setnetgrent(SETNETGRENT_ARGS) {
550Sstevel@tonic-gate 	struct net_data *net_data = init();
560Sstevel@tonic-gate 
570Sstevel@tonic-gate 	setnetgrent_p(netgroup, net_data);
580Sstevel@tonic-gate }
590Sstevel@tonic-gate 
600Sstevel@tonic-gate void
endnetgrent(void)610Sstevel@tonic-gate endnetgrent(void) {
620Sstevel@tonic-gate 	struct net_data *net_data = init();
630Sstevel@tonic-gate 
640Sstevel@tonic-gate 	endnetgrent_p(net_data);
650Sstevel@tonic-gate }
660Sstevel@tonic-gate 
670Sstevel@tonic-gate #ifndef INNETGR_ARGS
680Sstevel@tonic-gate #define INNETGR_ARGS const char *netgroup, const char *host, \
690Sstevel@tonic-gate 		     const char *user, const char *domain
700Sstevel@tonic-gate #endif
710Sstevel@tonic-gate int
innetgr(INNETGR_ARGS)720Sstevel@tonic-gate innetgr(INNETGR_ARGS) {
730Sstevel@tonic-gate 	struct net_data *net_data = init();
740Sstevel@tonic-gate 
750Sstevel@tonic-gate 	return (innetgr_p(netgroup, host, user, domain, net_data));
760Sstevel@tonic-gate }
770Sstevel@tonic-gate 
780Sstevel@tonic-gate int
getnetgrent(NGR_R_CONST char ** host,NGR_R_CONST char ** user,NGR_R_CONST char ** domain)79*11038SRao.Shoaib@Sun.COM getnetgrent(NGR_R_CONST char **host, NGR_R_CONST char **user,
80*11038SRao.Shoaib@Sun.COM 	    NGR_R_CONST char **domain)
81*11038SRao.Shoaib@Sun.COM {
820Sstevel@tonic-gate 	struct net_data *net_data = init();
830Sstevel@tonic-gate 	const char *ch, *cu, *cd;
840Sstevel@tonic-gate 	int ret;
850Sstevel@tonic-gate 
860Sstevel@tonic-gate 	ret = getnetgrent_p(&ch, &cu, &cd, net_data);
870Sstevel@tonic-gate 	if (ret != 1)
880Sstevel@tonic-gate 		return (ret);
890Sstevel@tonic-gate 
900Sstevel@tonic-gate 	DE_CONST(ch, *host);
910Sstevel@tonic-gate 	DE_CONST(cu, *user);
920Sstevel@tonic-gate 	DE_CONST(cd, *domain);
930Sstevel@tonic-gate 	return (ret);
940Sstevel@tonic-gate }
950Sstevel@tonic-gate 
960Sstevel@tonic-gate /* Shared private. */
970Sstevel@tonic-gate 
980Sstevel@tonic-gate void
setnetgrent_p(const char * netgroup,struct net_data * net_data)990Sstevel@tonic-gate setnetgrent_p(const char *netgroup, struct net_data *net_data) {
1000Sstevel@tonic-gate 	struct irs_ng *ng;
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate 	if ((net_data != NULL) && ((ng = net_data->ng) != NULL))
1030Sstevel@tonic-gate 		(*ng->rewind)(ng, netgroup);
1040Sstevel@tonic-gate }
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate void
endnetgrent_p(struct net_data * net_data)1070Sstevel@tonic-gate endnetgrent_p(struct net_data *net_data) {
1080Sstevel@tonic-gate 	struct irs_ng *ng;
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate 	if (!net_data)
1110Sstevel@tonic-gate 		return;
1120Sstevel@tonic-gate 	if ((ng = net_data->ng) != NULL)
1130Sstevel@tonic-gate 		(*ng->close)(ng);
1140Sstevel@tonic-gate 	net_data->ng = NULL;
1150Sstevel@tonic-gate }
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate int
innetgr_p(const char * netgroup,const char * host,const char * user,const char * domain,struct net_data * net_data)1180Sstevel@tonic-gate innetgr_p(const char *netgroup, const char *host,
1190Sstevel@tonic-gate 	  const char *user, const char *domain,
1200Sstevel@tonic-gate 	  struct net_data *net_data) {
1210Sstevel@tonic-gate 	struct irs_ng *ng;
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate 	if (!net_data || !(ng = net_data->ng))
1240Sstevel@tonic-gate 		return (0);
1250Sstevel@tonic-gate 	return ((*ng->test)(ng, netgroup, host, user, domain));
1260Sstevel@tonic-gate }
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate int
getnetgrent_p(const char ** host,const char ** user,const char ** domain,struct net_data * net_data)1290Sstevel@tonic-gate getnetgrent_p(const char **host, const char **user, const char **domain,
1300Sstevel@tonic-gate 	      struct net_data *net_data ) {
1310Sstevel@tonic-gate 	struct irs_ng *ng;
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 	if (!net_data || !(ng = net_data->ng))
1340Sstevel@tonic-gate 		return (0);
1350Sstevel@tonic-gate 	return ((*ng->next)(ng, host, user, domain));
1360Sstevel@tonic-gate }
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate /* Private */
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate static struct net_data *
init(void)1410Sstevel@tonic-gate init(void) {
1420Sstevel@tonic-gate 	struct net_data *net_data;
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate 	if (!(net_data = net_data_init(NULL)))
1450Sstevel@tonic-gate 		goto error;
1460Sstevel@tonic-gate 	if (!net_data->ng) {
1470Sstevel@tonic-gate 		net_data->ng = (*net_data->irs->ng_map)(net_data->irs);
1480Sstevel@tonic-gate 		if (!net_data->ng) {
1490Sstevel@tonic-gate   error:
1500Sstevel@tonic-gate 			errno = EIO;
1510Sstevel@tonic-gate 			return (NULL);
1520Sstevel@tonic-gate 		}
1530Sstevel@tonic-gate 	}
154*11038SRao.Shoaib@Sun.COM 
1550Sstevel@tonic-gate 	return (net_data);
1560Sstevel@tonic-gate }
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate #endif /*__BIND_NOSTATIC*/
159*11038SRao.Shoaib@Sun.COM 
160*11038SRao.Shoaib@Sun.COM /*! \file */
161