1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 1991-2002 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  *
26*0Sstevel@tonic-gate  * lib/libnsl/nss/gethostent6.c
27*0Sstevel@tonic-gate  *
28*0Sstevel@tonic-gate  * This file defines and implements the re-entrant enumeration routines for
29*0Sstevel@tonic-gate  *   IPv6 hosts: sethostent6(), gethostent6(), and endhostent6().
30*0Sstevel@tonic-gate  *   They consult the switch policy directly and do not "share" their
31*0Sstevel@tonic-gate  *   enumeration state nor the stayopen flag with the implentation of the
32*0Sstevel@tonic-gate  *   more commonly used getipnodebyname()/getipnodebyaddr(). The latter
33*0Sstevel@tonic-gate  *   follows a tortuous route in order to be consistent with netdir_getbyYY()
34*0Sstevel@tonic-gate  *   (see getipnodebyname.c and netdir_inet.c).
35*0Sstevel@tonic-gate  */
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
38*0Sstevel@tonic-gate 
39*0Sstevel@tonic-gate #include <sys/socket.h>
40*0Sstevel@tonic-gate #include <sys/types.h>
41*0Sstevel@tonic-gate #include <nss_dbdefs.h>
42*0Sstevel@tonic-gate #include <rpc/trace.h>
43*0Sstevel@tonic-gate #include "nss.h"
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate static int ipnodes_stayopen;
46*0Sstevel@tonic-gate /*
47*0Sstevel@tonic-gate  * Unsynchronized, but it affects only
48*0Sstevel@tonic-gate  * efficiency, not correctness
49*0Sstevel@tonic-gate  */
50*0Sstevel@tonic-gate 
51*0Sstevel@tonic-gate static DEFINE_NSS_DB_ROOT(db_root);
52*0Sstevel@tonic-gate static DEFINE_NSS_GETENT(context);
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate /* IPv6 wrapper for __str2hostent() */
55*0Sstevel@tonic-gate int
56*0Sstevel@tonic-gate str2hostent6(const char *instr, int lenstr, void *ent, char *buffer, int buflen)
57*0Sstevel@tonic-gate {
58*0Sstevel@tonic-gate 	return (__str2hostent(AF_INET6, instr, lenstr, ent, buffer, buflen));
59*0Sstevel@tonic-gate }
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate void
62*0Sstevel@tonic-gate _nss_initf_ipnodes(nss_db_params_t *p)
63*0Sstevel@tonic-gate {
64*0Sstevel@tonic-gate 	trace1(TR__nss_initf_ipnodes, 0);
65*0Sstevel@tonic-gate 	p->name	= NSS_DBNAM_IPNODES;
66*0Sstevel@tonic-gate 	p->default_config = NSS_DEFCONF_IPNODES;
67*0Sstevel@tonic-gate 	trace1(TR__nss_initf_ipnodes, 1);
68*0Sstevel@tonic-gate }
69*0Sstevel@tonic-gate 
70*0Sstevel@tonic-gate int
71*0Sstevel@tonic-gate __sethostent6(int stay)
72*0Sstevel@tonic-gate {
73*0Sstevel@tonic-gate 	trace1(TR_sethostent6, 0);
74*0Sstevel@tonic-gate 	ipnodes_stayopen |= stay;
75*0Sstevel@tonic-gate 	nss_setent(&db_root, _nss_initf_ipnodes, &context);
76*0Sstevel@tonic-gate 	trace1(TR_sethostent6, 1);
77*0Sstevel@tonic-gate 	return (0);
78*0Sstevel@tonic-gate }
79*0Sstevel@tonic-gate 
80*0Sstevel@tonic-gate int
81*0Sstevel@tonic-gate __endhostent6(void)
82*0Sstevel@tonic-gate {
83*0Sstevel@tonic-gate 	trace1(TR_endhostent6, 0);
84*0Sstevel@tonic-gate 	ipnodes_stayopen = 0;
85*0Sstevel@tonic-gate 	nss_endent(&db_root, _nss_initf_ipnodes, &context);
86*0Sstevel@tonic-gate 	nss_delete(&db_root);
87*0Sstevel@tonic-gate 	trace1(TR_endhostent6, 1);
88*0Sstevel@tonic-gate 	return (0);
89*0Sstevel@tonic-gate }
90*0Sstevel@tonic-gate 
91*0Sstevel@tonic-gate struct hostent *
92*0Sstevel@tonic-gate __gethostent6(struct hostent *result, char *buffer, int buflen, int *h_errnop)
93*0Sstevel@tonic-gate {
94*0Sstevel@tonic-gate 	nss_XbyY_args_t arg;
95*0Sstevel@tonic-gate 	nss_status_t	res;
96*0Sstevel@tonic-gate 
97*0Sstevel@tonic-gate 	trace2(TR_gethostent6, 0, buflen);
98*0Sstevel@tonic-gate 	NSS_XbyY_INIT(&arg, result, buffer, buflen, str2hostent6);
99*0Sstevel@tonic-gate 	res = nss_getent(&db_root, _nss_initf_ipnodes,
100*0Sstevel@tonic-gate 	    &context, &arg);
101*0Sstevel@tonic-gate 	arg.status = res;
102*0Sstevel@tonic-gate 	*h_errnop = arg.h_errno;
103*0Sstevel@tonic-gate 	trace2(TR_gethostent6, 1, buflen);
104*0Sstevel@tonic-gate 	return ((struct hostent *)NSS_XbyY_FINI(&arg));
105*0Sstevel@tonic-gate }
106