10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 22*132Srobinson 230Sstevel@tonic-gate /* 24*132Srobinson * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 250Sstevel@tonic-gate * Use is subject to license terms. 260Sstevel@tonic-gate * 270Sstevel@tonic-gate * lib/libnsl/nss/gethostent_r.c 280Sstevel@tonic-gate * 290Sstevel@tonic-gate * This file defines and implements the re-entrant enumeration routines for 300Sstevel@tonic-gate * hosts: sethostent(), gethostent_r(), and endhostent(). They consult 310Sstevel@tonic-gate * the switch policy directly and do not "share" their enumeration state 320Sstevel@tonic-gate * nor the stayopen flag with the implentation of the more commonly used 330Sstevel@tonic-gate * gethostbyname_r()/gethostbyaddr_r(). The latter follows a tortuous 340Sstevel@tonic-gate * route in order to be consistent with netdir_getbyYY() (see 350Sstevel@tonic-gate * gethostbyname_r.c and netdir_inet.c). 360Sstevel@tonic-gate */ 370Sstevel@tonic-gate 380Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 390Sstevel@tonic-gate 400Sstevel@tonic-gate #include <sys/socket.h> 410Sstevel@tonic-gate #include <sys/types.h> 420Sstevel@tonic-gate #include <nss_dbdefs.h> 430Sstevel@tonic-gate #include "nss.h" 440Sstevel@tonic-gate 450Sstevel@tonic-gate /* 460Sstevel@tonic-gate * str2hostent() is now a wrapper to __str2hostent(). 470Sstevel@tonic-gate * __str2hostent() now takes an extra argument to specify the 480Sstevel@tonic-gate * AF_INET type for address parsing. 490Sstevel@tonic-gate */ 500Sstevel@tonic-gate int 510Sstevel@tonic-gate str2hostent(const char *instr, int lenstr, void *ent, char *buffer, int buflen) 520Sstevel@tonic-gate { 530Sstevel@tonic-gate return (__str2hostent(AF_INET, instr, lenstr, ent, buffer, buflen)); 540Sstevel@tonic-gate } 550Sstevel@tonic-gate 560Sstevel@tonic-gate static int hosts_stayopen; 570Sstevel@tonic-gate /* 580Sstevel@tonic-gate * Unsynchronized, but it affects only 590Sstevel@tonic-gate * efficiency, not correctness 600Sstevel@tonic-gate */ 610Sstevel@tonic-gate 620Sstevel@tonic-gate static DEFINE_NSS_DB_ROOT(db_root); 630Sstevel@tonic-gate static DEFINE_NSS_GETENT(context); 640Sstevel@tonic-gate 650Sstevel@tonic-gate void 660Sstevel@tonic-gate _nss_initf_hosts(nss_db_params_t *p) 670Sstevel@tonic-gate { 680Sstevel@tonic-gate p->name = NSS_DBNAM_HOSTS; 690Sstevel@tonic-gate p->default_config = NSS_DEFCONF_HOSTS; 700Sstevel@tonic-gate } 710Sstevel@tonic-gate 720Sstevel@tonic-gate int 730Sstevel@tonic-gate sethostent(int stay) 740Sstevel@tonic-gate { 750Sstevel@tonic-gate hosts_stayopen |= stay; 760Sstevel@tonic-gate nss_setent(&db_root, _nss_initf_hosts, &context); 770Sstevel@tonic-gate return (0); 780Sstevel@tonic-gate } 790Sstevel@tonic-gate 800Sstevel@tonic-gate int 810Sstevel@tonic-gate endhostent(void) 820Sstevel@tonic-gate { 830Sstevel@tonic-gate hosts_stayopen = 0; 840Sstevel@tonic-gate nss_endent(&db_root, _nss_initf_hosts, &context); 850Sstevel@tonic-gate nss_delete(&db_root); 860Sstevel@tonic-gate return (0); 870Sstevel@tonic-gate } 880Sstevel@tonic-gate 890Sstevel@tonic-gate struct hostent * 900Sstevel@tonic-gate gethostent_r(struct hostent *result, char *buffer, int buflen, int *h_errnop) 910Sstevel@tonic-gate { 920Sstevel@tonic-gate nss_XbyY_args_t arg; 930Sstevel@tonic-gate nss_status_t res; 940Sstevel@tonic-gate 950Sstevel@tonic-gate NSS_XbyY_INIT(&arg, result, buffer, buflen, str2hostent); 960Sstevel@tonic-gate res = nss_getent(&db_root, _nss_initf_hosts, 970Sstevel@tonic-gate &context, &arg); 980Sstevel@tonic-gate arg.status = res; 990Sstevel@tonic-gate *h_errnop = arg.h_errno; 1000Sstevel@tonic-gate return ((struct hostent *)NSS_XbyY_FINI(&arg)); 1010Sstevel@tonic-gate } 102