17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5cb5caa98Sdjl  * Common Development and Distribution License (the "License").
6cb5caa98Sdjl  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2187a231a8Sjbeck 
227c478bd9Sstevel@tonic-gate /*
23*7257d1b4Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24cb5caa98Sdjl  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * gethostent.c
317c478bd9Sstevel@tonic-gate  *
327c478bd9Sstevel@tonic-gate  * In order to avoid duplicating libresolv code here, and since libresolv.so.2
337c478bd9Sstevel@tonic-gate  * provides res_-equivalents of the getXbyY and {set,get}Xent, lets call
347c478bd9Sstevel@tonic-gate  * re_gethostbyaddr() and so on from this file. Among other things, this
357c478bd9Sstevel@tonic-gate  * should help us avoid problems like the one described in bug 1264386,
367c478bd9Sstevel@tonic-gate  * where the internal getanswer() acquired new functionality in BIND 4.9.3,
377c478bd9Sstevel@tonic-gate  * but the local copy of getanswer() in this file wasn't updated, so that new
387c478bd9Sstevel@tonic-gate  * functionality wasn't available to the name service switch.
397c478bd9Sstevel@tonic-gate  */
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #define	gethostbyaddr	res_gethostbyaddr
427c478bd9Sstevel@tonic-gate #define	gethostbyname	res_gethostbyname
437c478bd9Sstevel@tonic-gate #define	gethostbyname2	res_gethostbyname2
447c478bd9Sstevel@tonic-gate #define	sethostent	res_sethostent
457c478bd9Sstevel@tonic-gate #define	endhostent	res_endhostent
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #include "dns_common.h"
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate extern char *inet_ntoa(struct in_addr in);
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate struct hostent *_gethostbyname(int *h_errnop, const char *name);
527c478bd9Sstevel@tonic-gate static struct hostent *_gethostbyaddr(int *h_errnop, const char *addr,
537c478bd9Sstevel@tonic-gate     int len, int type);
547c478bd9Sstevel@tonic-gate struct hostent *_nss_dns_gethostbyname2(int *h_errnop, const char *name);
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #pragma weak	res_gethostbyname
577c478bd9Sstevel@tonic-gate #pragma weak	res_gethostbyname2
587c478bd9Sstevel@tonic-gate #pragma weak	res_gethostbyaddr
597c478bd9Sstevel@tonic-gate #pragma weak	res_sethostent
607c478bd9Sstevel@tonic-gate #pragma weak	res_endhostent
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate nss_backend_t *_nss_dns_constr(dns_backend_op_t ops[], int n_ops);
637c478bd9Sstevel@tonic-gate nss_status_t __nss_dns_getbyaddr(dns_backend_ptr_t, void *);
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate typedef union {
667c478bd9Sstevel@tonic-gate 	long al;
677c478bd9Sstevel@tonic-gate 	char ac;
687c478bd9Sstevel@tonic-gate } align;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate  * Internet Name Domain Server (DNS) only implementation.
727c478bd9Sstevel@tonic-gate  */
737c478bd9Sstevel@tonic-gate static struct hostent *
747c478bd9Sstevel@tonic-gate _gethostbyaddr(int *h_errnop, const char *addr, int len, int type)
757c478bd9Sstevel@tonic-gate {
767c478bd9Sstevel@tonic-gate 	struct hostent	*hp;
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 	hp = gethostbyaddr(addr, len, type);
797c478bd9Sstevel@tonic-gate 	*h_errnop = *get_h_errno();
807c478bd9Sstevel@tonic-gate 	return (hp);
817c478bd9Sstevel@tonic-gate }
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate struct hostent *
847c478bd9Sstevel@tonic-gate _nss_dns_gethostbyname2(int *h_errnop, const char *name)
857c478bd9Sstevel@tonic-gate {
867c478bd9Sstevel@tonic-gate 	struct hostent *hp;
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	hp = gethostbyname2(name, AF_INET6);
897c478bd9Sstevel@tonic-gate 	*h_errnop = *get_h_errno();
907c478bd9Sstevel@tonic-gate 	return (hp);
917c478bd9Sstevel@tonic-gate }
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate struct hostent *
947c478bd9Sstevel@tonic-gate _gethostbyname(int *h_errnop, const char *name)
957c478bd9Sstevel@tonic-gate {
967c478bd9Sstevel@tonic-gate 	struct hostent *hp;
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate 	hp = gethostbyname(name);
997c478bd9Sstevel@tonic-gate 	*h_errnop = *get_h_errno();
1007c478bd9Sstevel@tonic-gate 	return (hp);
1017c478bd9Sstevel@tonic-gate }
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate static void
1047c478bd9Sstevel@tonic-gate _sethostent(errp, stayopen)
1057c478bd9Sstevel@tonic-gate 	nss_status_t	*errp;
1067c478bd9Sstevel@tonic-gate 	int		stayopen;
1077c478bd9Sstevel@tonic-gate {
1087c478bd9Sstevel@tonic-gate 	int	ret;
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	ret = sethostent(stayopen);
1117c478bd9Sstevel@tonic-gate 	if (ret == 0)
1127c478bd9Sstevel@tonic-gate 		*errp = NSS_SUCCESS;
1137c478bd9Sstevel@tonic-gate 	else
1147c478bd9Sstevel@tonic-gate 		*errp = NSS_UNAVAIL;
1157c478bd9Sstevel@tonic-gate }
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate static void
1187c478bd9Sstevel@tonic-gate _endhostent(errp)
1197c478bd9Sstevel@tonic-gate 	nss_status_t	*errp;
1207c478bd9Sstevel@tonic-gate {
1217c478bd9Sstevel@tonic-gate 	int	ret;
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 	ret = endhostent();
1247c478bd9Sstevel@tonic-gate 	if (ret == 0)
1257c478bd9Sstevel@tonic-gate 		*errp = NSS_SUCCESS;
1267c478bd9Sstevel@tonic-gate 	else
1277c478bd9Sstevel@tonic-gate 		*errp = NSS_UNAVAIL;
1287c478bd9Sstevel@tonic-gate }
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1327c478bd9Sstevel@tonic-gate static nss_status_t
1337c478bd9Sstevel@tonic-gate getbyname(be, a)
1347c478bd9Sstevel@tonic-gate 	dns_backend_ptr_t	be;
1357c478bd9Sstevel@tonic-gate 	void			*a;
1367c478bd9Sstevel@tonic-gate {
1377c478bd9Sstevel@tonic-gate 	struct hostent	*he;
1387c478bd9Sstevel@tonic-gate 	nss_XbyY_args_t	*argp = (nss_XbyY_args_t *)a;
1397c478bd9Sstevel@tonic-gate 	int		ret, mt_disabled;
1407c478bd9Sstevel@tonic-gate 	int		old_retry;
1417c478bd9Sstevel@tonic-gate 	sigset_t	oldmask;
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 	switch_resolver_setup(&mt_disabled, &oldmask, &old_retry);
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 	he = _gethostbyname(&argp->h_errno, argp->key.name);
1467c478bd9Sstevel@tonic-gate 	if (he != NULL) {
147cb5caa98Sdjl 		if (argp->buf.result == NULL) {
148cb5caa98Sdjl 			/*
149cb5caa98Sdjl 			 * if asked to return data in string,
150cb5caa98Sdjl 			 * convert the hostent structure into
151cb5caa98Sdjl 			 * string data
152cb5caa98Sdjl 			 */
153cb5caa98Sdjl 			ret = ent2str(he, a, AF_INET);
154cb5caa98Sdjl 			if (ret == NSS_STR_PARSE_SUCCESS)
155cb5caa98Sdjl 				argp->returnval = argp->buf.buffer;
1567c478bd9Sstevel@tonic-gate 		} else {
157cb5caa98Sdjl 			ret = ent2result(he, a, AF_INET);
158cb5caa98Sdjl 			if (ret == NSS_STR_PARSE_SUCCESS)
159cb5caa98Sdjl 				argp->returnval = argp->buf.result;
160cb5caa98Sdjl 		}
161cb5caa98Sdjl 
162cb5caa98Sdjl 		if (ret != NSS_STR_PARSE_SUCCESS) {
1637c478bd9Sstevel@tonic-gate 			argp->h_errno = HOST_NOT_FOUND;
1647c478bd9Sstevel@tonic-gate 			if (ret == NSS_STR_PARSE_ERANGE) {
1657c478bd9Sstevel@tonic-gate 				argp->erange = 1;
1667c478bd9Sstevel@tonic-gate 			}
1677c478bd9Sstevel@tonic-gate 		}
1687c478bd9Sstevel@tonic-gate 	}
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	switch_resolver_reset(mt_disabled, oldmask, old_retry);
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 	return (_herrno2nss(argp->h_errno));
1737c478bd9Sstevel@tonic-gate }
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1787c478bd9Sstevel@tonic-gate static nss_status_t
1797c478bd9Sstevel@tonic-gate getbyaddr(be, a)
1807c478bd9Sstevel@tonic-gate 	dns_backend_ptr_t	be;
1817c478bd9Sstevel@tonic-gate 	void			*a;
1827c478bd9Sstevel@tonic-gate {
1837c478bd9Sstevel@tonic-gate 	return (__nss_dns_getbyaddr(be, a));
1847c478bd9Sstevel@tonic-gate }
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate /*
1887c478bd9Sstevel@tonic-gate  * Exposing a DNS backend specific interface so that it doesn't conflict
1897c478bd9Sstevel@tonic-gate  * with other getbyaddr() routines from other switch backends.
1907c478bd9Sstevel@tonic-gate  */
191cb5caa98Sdjl /*ARGSUSED*/
1927c478bd9Sstevel@tonic-gate nss_status_t
1937c478bd9Sstevel@tonic-gate __nss_dns_getbyaddr(be, a)
1947c478bd9Sstevel@tonic-gate 	dns_backend_ptr_t	be;
1957c478bd9Sstevel@tonic-gate 	void			*a;
1967c478bd9Sstevel@tonic-gate {
19787a231a8Sjbeck 	struct hostent	*he;
1987c478bd9Sstevel@tonic-gate 	nss_XbyY_args_t	*argp = (nss_XbyY_args_t *)a;
19987a231a8Sjbeck 	int		ret, mt_disabled;
2007c478bd9Sstevel@tonic-gate 	struct in_addr	unmapv4;
2017c478bd9Sstevel@tonic-gate 	sigset_t	oldmask;
2027c478bd9Sstevel@tonic-gate 	int		af, addrlen;
2037c478bd9Sstevel@tonic-gate 	void		*addrp;
2047c478bd9Sstevel@tonic-gate 	int		old_retry;
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	switch_resolver_setup(&mt_disabled, &oldmask, &old_retry);
2077c478bd9Sstevel@tonic-gate 
208cb5caa98Sdjl 	/* LINTED: E_BAD_PTR_CAST_ALIGN */
2097c478bd9Sstevel@tonic-gate 	if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)argp->key.hostaddr.addr)) {
2107c478bd9Sstevel@tonic-gate 		addrp = &unmapv4;
2117c478bd9Sstevel@tonic-gate 		addrlen = sizeof (unmapv4);
2127c478bd9Sstevel@tonic-gate 		af = AF_INET;
213cb5caa98Sdjl 		(void) memcpy(addrp, &argp->key.hostaddr.addr[12], addrlen);
2147c478bd9Sstevel@tonic-gate 	} else {
2157c478bd9Sstevel@tonic-gate 		addrp = (void *)argp->key.hostaddr.addr;
2167c478bd9Sstevel@tonic-gate 		addrlen = argp->key.hostaddr.len;
2177c478bd9Sstevel@tonic-gate 		af = argp->key.hostaddr.type;
2187c478bd9Sstevel@tonic-gate 	}
2197c478bd9Sstevel@tonic-gate 	he = _gethostbyaddr(&argp->h_errno, addrp, addrlen, af);
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 	if (he != NULL) {
22287a231a8Sjbeck 		/*
22387a231a8Sjbeck 		 * if asked to return data in string, convert
22487a231a8Sjbeck 		 * the hostent structure into string data
22587a231a8Sjbeck 		 */
22687a231a8Sjbeck 		if (argp->buf.result == NULL)
22787a231a8Sjbeck 			ret = ent2str(he, a, argp->key.hostaddr.type);
22887a231a8Sjbeck 		else
22987a231a8Sjbeck 			ret = ent2result(he, a, argp->key.hostaddr.type);
230cb5caa98Sdjl 
2317c478bd9Sstevel@tonic-gate 		if (ret == NSS_STR_PARSE_SUCCESS) {
23287a231a8Sjbeck 			if (argp->buf.result == NULL)
23387a231a8Sjbeck 				argp->returnval = argp->buf.buffer;
2347c478bd9Sstevel@tonic-gate 			else
23587a231a8Sjbeck 				argp->returnval = argp->buf.result;
2367c478bd9Sstevel@tonic-gate 		} else {
2377c478bd9Sstevel@tonic-gate 			argp->h_errno = HOST_NOT_FOUND;
23887a231a8Sjbeck 			if (ret == NSS_STR_PARSE_ERANGE)
2397c478bd9Sstevel@tonic-gate 				argp->erange = 1;
2407c478bd9Sstevel@tonic-gate 		}
2417c478bd9Sstevel@tonic-gate 	}
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 	switch_resolver_reset(mt_disabled, oldmask, old_retry);
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 	return (_herrno2nss(argp->h_errno));
2467c478bd9Sstevel@tonic-gate }
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2507c478bd9Sstevel@tonic-gate static nss_status_t
2517c478bd9Sstevel@tonic-gate _nss_dns_getent(be, args)
2527c478bd9Sstevel@tonic-gate 	dns_backend_ptr_t	be;
2537c478bd9Sstevel@tonic-gate 	void			*args;
2547c478bd9Sstevel@tonic-gate {
2557c478bd9Sstevel@tonic-gate 	return (NSS_UNAVAIL);
2567c478bd9Sstevel@tonic-gate }
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2607c478bd9Sstevel@tonic-gate static nss_status_t
2617c478bd9Sstevel@tonic-gate _nss_dns_setent(be, dummy)
2627c478bd9Sstevel@tonic-gate 	dns_backend_ptr_t	be;
2637c478bd9Sstevel@tonic-gate 	void			*dummy;
2647c478bd9Sstevel@tonic-gate {
2657c478bd9Sstevel@tonic-gate 	nss_status_t	errp;
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 	sigset_t	oldmask, newmask;
2687c478bd9Sstevel@tonic-gate 	int		mt_disabled = 1;
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate 	/*
2717c478bd9Sstevel@tonic-gate 	 * Try to enable MT; if not, we have to single-thread libresolv
2727c478bd9Sstevel@tonic-gate 	 * access
2737c478bd9Sstevel@tonic-gate 	 */
2747c478bd9Sstevel@tonic-gate 	if (enable_mt == 0 || (mt_disabled = (*enable_mt)()) != 0) {
2757c478bd9Sstevel@tonic-gate 		(void) sigfillset(&newmask);
276*7257d1b4Sraf 		(void) thr_sigsetmask(SIG_SETMASK, &newmask, &oldmask);
277*7257d1b4Sraf 		(void) mutex_lock(&one_lane);
2787c478bd9Sstevel@tonic-gate 	}
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 	_sethostent(&errp, 1);
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 	if (mt_disabled) {
283*7257d1b4Sraf 		(void) mutex_unlock(&one_lane);
284*7257d1b4Sraf 		(void) thr_sigsetmask(SIG_SETMASK, &oldmask, NULL);
2857c478bd9Sstevel@tonic-gate 	} else {
2867c478bd9Sstevel@tonic-gate 		(void) (*disable_mt)();
2877c478bd9Sstevel@tonic-gate 	}
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate 	return (errp);
2907c478bd9Sstevel@tonic-gate }
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2947c478bd9Sstevel@tonic-gate static nss_status_t
2957c478bd9Sstevel@tonic-gate _nss_dns_endent(be, dummy)
2967c478bd9Sstevel@tonic-gate 	dns_backend_ptr_t	be;
2977c478bd9Sstevel@tonic-gate 	void			*dummy;
2987c478bd9Sstevel@tonic-gate {
2997c478bd9Sstevel@tonic-gate 	nss_status_t	errp;
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 	sigset_t	oldmask, newmask;
3027c478bd9Sstevel@tonic-gate 	int		mt_disabled = 1;
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 	/*
3057c478bd9Sstevel@tonic-gate 	 * Try to enable MT; if not, we have to single-thread libresolv
3067c478bd9Sstevel@tonic-gate 	 * access
3077c478bd9Sstevel@tonic-gate 	 */
3087c478bd9Sstevel@tonic-gate 	if (enable_mt == 0 || (mt_disabled = (*enable_mt)()) != 0) {
3097c478bd9Sstevel@tonic-gate 		(void) sigfillset(&newmask);
310*7257d1b4Sraf 		(void) thr_sigsetmask(SIG_SETMASK, &newmask, &oldmask);
311*7257d1b4Sraf 		(void) mutex_lock(&one_lane);
3127c478bd9Sstevel@tonic-gate 	}
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate 	_endhostent(&errp);
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 	if (mt_disabled) {
317*7257d1b4Sraf 		(void) mutex_unlock(&one_lane);
318*7257d1b4Sraf 		(void) thr_sigsetmask(SIG_SETMASK, &oldmask, NULL);
3197c478bd9Sstevel@tonic-gate 	} else {
3207c478bd9Sstevel@tonic-gate 		(void) (*disable_mt)();
3217c478bd9Sstevel@tonic-gate 	}
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate 	return (errp);
3247c478bd9Sstevel@tonic-gate }
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3287c478bd9Sstevel@tonic-gate static nss_status_t
3297c478bd9Sstevel@tonic-gate _nss_dns_destr(be, dummy)
3307c478bd9Sstevel@tonic-gate 	dns_backend_ptr_t	be;
3317c478bd9Sstevel@tonic-gate 	void			*dummy;
3327c478bd9Sstevel@tonic-gate {
3337c478bd9Sstevel@tonic-gate 	nss_status_t	errp;
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 	if (be != 0) {
3367c478bd9Sstevel@tonic-gate 		/* === Should change to invoke ops[ENDENT] ? */
3377c478bd9Sstevel@tonic-gate 		sigset_t	oldmask, newmask;
3387c478bd9Sstevel@tonic-gate 		int		mt_disabled = 1;
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate 		if (enable_mt == 0 || (mt_disabled = (*enable_mt)()) != 0) {
3417c478bd9Sstevel@tonic-gate 			(void) sigfillset(&newmask);
342*7257d1b4Sraf 			(void) thr_sigsetmask(SIG_SETMASK, &newmask, &oldmask);
343*7257d1b4Sraf 			(void) mutex_lock(&one_lane);
3447c478bd9Sstevel@tonic-gate 		}
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate 		_endhostent(&errp);
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate 		if (mt_disabled) {
349*7257d1b4Sraf 			(void) mutex_unlock(&one_lane);
350*7257d1b4Sraf 			(void) thr_sigsetmask(SIG_SETMASK, &oldmask, NULL);
3517c478bd9Sstevel@tonic-gate 		} else {
3527c478bd9Sstevel@tonic-gate 			(void) (*disable_mt)();
3537c478bd9Sstevel@tonic-gate 		}
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate 		free(be);
3567c478bd9Sstevel@tonic-gate 	}
3577c478bd9Sstevel@tonic-gate 	return (NSS_SUCCESS);   /* In case anyone is dumb enough to check */
3587c478bd9Sstevel@tonic-gate }
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate static dns_backend_op_t host_ops[] = {
3627c478bd9Sstevel@tonic-gate 	_nss_dns_destr,
3637c478bd9Sstevel@tonic-gate 	_nss_dns_endent,
3647c478bd9Sstevel@tonic-gate 	_nss_dns_setent,
3657c478bd9Sstevel@tonic-gate 	_nss_dns_getent,
3667c478bd9Sstevel@tonic-gate 	getbyname,
3677c478bd9Sstevel@tonic-gate 	getbyaddr,
3687c478bd9Sstevel@tonic-gate };
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3717c478bd9Sstevel@tonic-gate nss_backend_t *
3727c478bd9Sstevel@tonic-gate _nss_dns_hosts_constr(dummy1, dummy2, dummy3)
3737c478bd9Sstevel@tonic-gate 	const char	*dummy1, *dummy2, *dummy3;
3747c478bd9Sstevel@tonic-gate {
3757c478bd9Sstevel@tonic-gate 	return (_nss_dns_constr(host_ops,
3767c478bd9Sstevel@tonic-gate 		sizeof (host_ops) / sizeof (host_ops[0])));
3777c478bd9Sstevel@tonic-gate }
378cb5caa98Sdjl 
379cb5caa98Sdjl /*
380cb5caa98Sdjl  * optional NSS2 packed backend gethostsbyname with ttl
381cb5caa98Sdjl  * entry point.
382cb5caa98Sdjl  *
383cb5caa98Sdjl  * Returns:
384cb5caa98Sdjl  *	NSS_SUCCESS - successful
385cb5caa98Sdjl  *	NSS_NOTFOUND - successful but nothing found
386cb5caa98Sdjl  *	NSS_ERROR - fallback to NSS backend lookup mode
387cb5caa98Sdjl  * If successful, buffer will be filled with valid data
388cb5caa98Sdjl  *
389cb5caa98Sdjl  */
390cb5caa98Sdjl 
391cb5caa98Sdjl /*ARGSUSED*/
392cb5caa98Sdjl nss_status_t
393cb5caa98Sdjl _nss_get_dns_hosts_name(dns_backend_ptr_t *be, void **bufp, size_t *sizep)
394cb5caa98Sdjl {
395cb5caa98Sdjl 	return (_nss_dns_gethost_withttl(*bufp, *sizep, 0));
396cb5caa98Sdjl }
397