2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A/*
2N/A * This file defines and implements the re-entrant enumeration routines for
2N/A * hosts: sethostent(), gethostent_r(), and endhostent(). They consult
2N/A * the switch policy directly and do not "share" their enumeration state
2N/A * nor the stayopen flag with the implentation of the more commonly used
2N/A * gethostbyname_r()/gethostbyaddr_r(). The latter follows a tortuous
2N/A * route in order to be consistent with netdir_getbyYY() (see
2N/A * gethostbyname_r.c and netdir_inet.c).
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include "mt.h"
2N/A#include <sys/socket.h>
2N/A#include <sys/types.h>
2N/A#include <nss_dbdefs.h>
2N/A#include "nss.h"
2N/A
2N/A/*
2N/A * str2hostent() is now a wrapper to __str2hostent().
2N/A * __str2hostent() now takes an extra argument to specify the
2N/A * AF_INET type for address parsing.
2N/A */
2N/Aint
2N/Astr2hostent(const char *instr, int lenstr, void *ent, char *buffer, int buflen)
2N/A{
2N/A return (__str2hostent(AF_INET, instr, lenstr, ent, buffer, buflen));
2N/A}
2N/A
2N/Astatic int hosts_stayopen;
2N/A/*
2N/A * Unsynchronized, but it affects only
2N/A * efficiency, not correctness
2N/A */
2N/A
2N/Astatic DEFINE_NSS_DB_ROOT(db_root);
2N/Astatic DEFINE_NSS_GETENT(context);
2N/A
2N/Avoid
2N/A_nss_initf_hosts(nss_db_params_t *p)
2N/A{
2N/A p->name = NSS_DBNAM_HOSTS;
2N/A p->default_config = NSS_DEFCONF_HOSTS;
2N/A}
2N/A
2N/Aint
2N/Asethostent(int stay)
2N/A{
2N/A hosts_stayopen |= stay;
2N/A nss_setent(&db_root, _nss_initf_hosts, &context);
2N/A return (0);
2N/A}
2N/A
2N/Aint
2N/Aendhostent(void)
2N/A{
2N/A hosts_stayopen = 0;
2N/A nss_endent(&db_root, _nss_initf_hosts, &context);
2N/A nss_delete(&db_root);
2N/A return (0);
2N/A}
2N/A
2N/Astruct hostent *
2N/Agethostent_r(struct hostent *result, char *buffer, int buflen, int *h_errnop)
2N/A{
2N/A nss_XbyY_args_t arg;
2N/A nss_status_t res;
2N/A
2N/A NSS_XbyY_INIT(&arg, result, buffer, buflen, str2hostent);
2N/A res = nss_getent(&db_root, _nss_initf_hosts,
2N/A &context, &arg);
2N/A arg.status = res;
2N/A *h_errnop = arg.h_errno;
2N/A return ((struct hostent *)NSS_XbyY_FINI(&arg));
2N/A}