2N/A/*
2N/A * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC")
2N/A * Copyright (C) 1996-1999, 2001, 2003 Internet Software Consortium.
2N/A *
2N/A * Permission to use, copy, modify, and/or distribute this software for any
2N/A * purpose with or without fee is hereby granted, provided that the above
2N/A * copyright notice and this permission notice appear in all copies.
2N/A *
2N/A * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
2N/A * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
2N/A * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
2N/A * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
2N/A * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
2N/A * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2N/A * PERFORMANCE OF THIS SOFTWARE.
2N/A */
2N/A
2N/A#if defined(LIBC_SCCS) && !defined(lint)
2N/Astatic const char rcsid[] = "$Id: getnetgrent.c,v 1.6 2008/11/14 02:36:51 marka Exp $";
2N/A#endif /* LIBC_SCCS and not lint */
2N/A
2N/A/* Imports */
2N/A
2N/A#include "port_before.h"
2N/A
2N/A#if !defined(__BIND_NOSTATIC)
2N/A
2N/A#include <sys/types.h>
2N/A
2N/A#include <netinet/in.h>
2N/A#include <arpa/nameser.h>
2N/A
2N/A#include <errno.h>
2N/A#include <resolv.h>
2N/A#include <stdio.h>
2N/A
2N/A#include <irs.h>
2N/A
2N/A#include "port_after.h"
2N/A
2N/A#include "irs_data.h"
2N/A
2N/A/* Forward */
2N/A
2N/Astatic struct net_data *init(void);
2N/A
2N/A
2N/A/* Public */
2N/A
2N/A#ifndef SETNETGRENT_ARGS
2N/A#define SETNETGRENT_ARGS const char *netgroup
2N/A#endif
2N/Avoid
2N/Asetnetgrent(SETNETGRENT_ARGS) {
2N/A struct net_data *net_data = init();
2N/A
2N/A setnetgrent_p(netgroup, net_data);
2N/A}
2N/A
2N/Avoid
2N/Aendnetgrent(void) {
2N/A struct net_data *net_data = init();
2N/A
2N/A endnetgrent_p(net_data);
2N/A}
2N/A
2N/A#ifndef INNETGR_ARGS
2N/A#define INNETGR_ARGS const char *netgroup, const char *host, \
2N/A const char *user, const char *domain
2N/A#endif
2N/Aint
2N/Ainnetgr(INNETGR_ARGS) {
2N/A struct net_data *net_data = init();
2N/A
2N/A return (innetgr_p(netgroup, host, user, domain, net_data));
2N/A}
2N/A
2N/Aint
2N/Agetnetgrent(NGR_R_CONST char **host, NGR_R_CONST char **user,
2N/A NGR_R_CONST char **domain)
2N/A{
2N/A struct net_data *net_data = init();
2N/A const char *ch, *cu, *cd;
2N/A int ret;
2N/A
2N/A ret = getnetgrent_p(&ch, &cu, &cd, net_data);
2N/A if (ret != 1)
2N/A return (ret);
2N/A
2N/A DE_CONST(ch, *host);
2N/A DE_CONST(cu, *user);
2N/A DE_CONST(cd, *domain);
2N/A return (ret);
2N/A}
2N/A
2N/A/* Shared private. */
2N/A
2N/Avoid
2N/Asetnetgrent_p(const char *netgroup, struct net_data *net_data) {
2N/A struct irs_ng *ng;
2N/A
2N/A if ((net_data != NULL) && ((ng = net_data->ng) != NULL))
2N/A (*ng->rewind)(ng, netgroup);
2N/A}
2N/A
2N/Avoid
2N/Aendnetgrent_p(struct net_data *net_data) {
2N/A struct irs_ng *ng;
2N/A
2N/A if (!net_data)
2N/A return;
2N/A if ((ng = net_data->ng) != NULL)
2N/A (*ng->close)(ng);
2N/A net_data->ng = NULL;
2N/A}
2N/A
2N/Aint
2N/Ainnetgr_p(const char *netgroup, const char *host,
2N/A const char *user, const char *domain,
2N/A struct net_data *net_data) {
2N/A struct irs_ng *ng;
2N/A
2N/A if (!net_data || !(ng = net_data->ng))
2N/A return (0);
2N/A return ((*ng->test)(ng, netgroup, host, user, domain));
2N/A}
2N/A
2N/Aint
2N/Agetnetgrent_p(const char **host, const char **user, const char **domain,
2N/A struct net_data *net_data ) {
2N/A struct irs_ng *ng;
2N/A
2N/A if (!net_data || !(ng = net_data->ng))
2N/A return (0);
2N/A return ((*ng->next)(ng, host, user, domain));
2N/A}
2N/A
2N/A/* Private */
2N/A
2N/Astatic struct net_data *
2N/Ainit(void) {
2N/A struct net_data *net_data;
2N/A
2N/A if (!(net_data = net_data_init(NULL)))
2N/A goto error;
2N/A if (!net_data->ng) {
2N/A net_data->ng = (*net_data->irs->ng_map)(net_data->irs);
2N/A if (!net_data->ng) {
2N/A error:
2N/A errno = EIO;
2N/A return (NULL);
2N/A }
2N/A }
2N/A
2N/A return (net_data);
2N/A}
2N/A
2N/A#endif /*__BIND_NOSTATIC*/
2N/A
2N/A/*! \file */