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 /*
287c478bd9Sstevel@tonic-gate  * gethostent.c
297c478bd9Sstevel@tonic-gate  *
307c478bd9Sstevel@tonic-gate  * In order to avoid duplicating libresolv code here, and since libresolv.so.2
317c478bd9Sstevel@tonic-gate  * provides res_-equivalents of the getXbyY and {set,get}Xent, lets call
327c478bd9Sstevel@tonic-gate  * re_gethostbyaddr() and so on from this file. Among other things, this
337c478bd9Sstevel@tonic-gate  * should help us avoid problems like the one described in bug 1264386,
347c478bd9Sstevel@tonic-gate  * where the internal getanswer() acquired new functionality in BIND 4.9.3,
357c478bd9Sstevel@tonic-gate  * but the local copy of getanswer() in this file wasn't updated, so that new
367c478bd9Sstevel@tonic-gate  * functionality wasn't available to the name service switch.
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #define	gethostbyaddr	res_gethostbyaddr
407c478bd9Sstevel@tonic-gate #define	gethostbyname	res_gethostbyname
417c478bd9Sstevel@tonic-gate #define	gethostbyname2	res_gethostbyname2
427c478bd9Sstevel@tonic-gate #define	sethostent	res_sethostent
437c478bd9Sstevel@tonic-gate #define	endhostent	res_endhostent
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #include "dns_common.h"
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate extern char *inet_ntoa(struct in_addr in);
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate struct hostent *_gethostbyname(int *h_errnop, const char *name);
507c478bd9Sstevel@tonic-gate static struct hostent *_gethostbyaddr(int *h_errnop, const char *addr,
517c478bd9Sstevel@tonic-gate     int len, int type);
527c478bd9Sstevel@tonic-gate struct hostent *_nss_dns_gethostbyname2(int *h_errnop, const char *name);
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate #pragma weak	res_gethostbyname
557c478bd9Sstevel@tonic-gate #pragma weak	res_gethostbyname2
567c478bd9Sstevel@tonic-gate #pragma weak	res_gethostbyaddr
577c478bd9Sstevel@tonic-gate #pragma weak	res_sethostent
587c478bd9Sstevel@tonic-gate #pragma weak	res_endhostent
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate nss_backend_t *_nss_dns_constr(dns_backend_op_t ops[], int n_ops);
617c478bd9Sstevel@tonic-gate nss_status_t __nss_dns_getbyaddr(dns_backend_ptr_t, void *);
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate typedef union {
647c478bd9Sstevel@tonic-gate 	long al;
657c478bd9Sstevel@tonic-gate 	char ac;
667c478bd9Sstevel@tonic-gate } align;
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * Internet Name Domain Server (DNS) only implementation.
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate static struct hostent *
_gethostbyaddr(int * h_errnop,const char * addr,int len,int type)727c478bd9Sstevel@tonic-gate _gethostbyaddr(int *h_errnop, const char *addr, int len, int type)
737c478bd9Sstevel@tonic-gate {
747c478bd9Sstevel@tonic-gate 	struct hostent	*hp;
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 	hp = gethostbyaddr(addr, len, type);
777c478bd9Sstevel@tonic-gate 	*h_errnop = *get_h_errno();
787c478bd9Sstevel@tonic-gate 	return (hp);
797c478bd9Sstevel@tonic-gate }
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate struct hostent *
_nss_dns_gethostbyname2(int * h_errnop,const char * name)827c478bd9Sstevel@tonic-gate _nss_dns_gethostbyname2(int *h_errnop, const char *name)
837c478bd9Sstevel@tonic-gate {
847c478bd9Sstevel@tonic-gate 	struct hostent *hp;
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate 	hp = gethostbyname2(name, AF_INET6);
877c478bd9Sstevel@tonic-gate 	*h_errnop = *get_h_errno();
887c478bd9Sstevel@tonic-gate 	return (hp);
897c478bd9Sstevel@tonic-gate }
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate struct hostent *
_gethostbyname(int * h_errnop,const char * name)927c478bd9Sstevel@tonic-gate _gethostbyname(int *h_errnop, const char *name)
937c478bd9Sstevel@tonic-gate {
947c478bd9Sstevel@tonic-gate 	struct hostent *hp;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 	hp = gethostbyname(name);
977c478bd9Sstevel@tonic-gate 	*h_errnop = *get_h_errno();
987c478bd9Sstevel@tonic-gate 	return (hp);
997c478bd9Sstevel@tonic-gate }
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate static void
_sethostent(errp,stayopen)1027c478bd9Sstevel@tonic-gate _sethostent(errp, stayopen)
1037c478bd9Sstevel@tonic-gate 	nss_status_t	*errp;
1047c478bd9Sstevel@tonic-gate 	int		stayopen;
1057c478bd9Sstevel@tonic-gate {
1067c478bd9Sstevel@tonic-gate 	int	ret;
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 	ret = sethostent(stayopen);
1097c478bd9Sstevel@tonic-gate 	if (ret == 0)
1107c478bd9Sstevel@tonic-gate 		*errp = NSS_SUCCESS;
1117c478bd9Sstevel@tonic-gate 	else
1127c478bd9Sstevel@tonic-gate 		*errp = NSS_UNAVAIL;
1137c478bd9Sstevel@tonic-gate }
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate static void
_endhostent(errp)1167c478bd9Sstevel@tonic-gate _endhostent(errp)
1177c478bd9Sstevel@tonic-gate 	nss_status_t	*errp;
1187c478bd9Sstevel@tonic-gate {
1197c478bd9Sstevel@tonic-gate 	int	ret;
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 	ret = endhostent();
1227c478bd9Sstevel@tonic-gate 	if (ret == 0)
1237c478bd9Sstevel@tonic-gate 		*errp = NSS_SUCCESS;
1247c478bd9Sstevel@tonic-gate 	else
1257c478bd9Sstevel@tonic-gate 		*errp = NSS_UNAVAIL;
1267c478bd9Sstevel@tonic-gate }
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1307c478bd9Sstevel@tonic-gate static nss_status_t
getbyname(be,a)1317c478bd9Sstevel@tonic-gate getbyname(be, a)
1327c478bd9Sstevel@tonic-gate 	dns_backend_ptr_t	be;
1337c478bd9Sstevel@tonic-gate 	void			*a;
1347c478bd9Sstevel@tonic-gate {
1357c478bd9Sstevel@tonic-gate 	struct hostent	*he;
1367c478bd9Sstevel@tonic-gate 	nss_XbyY_args_t	*argp = (nss_XbyY_args_t *)a;
1377c478bd9Sstevel@tonic-gate 	int		ret, mt_disabled;
1387c478bd9Sstevel@tonic-gate 	int		old_retry;
1397c478bd9Sstevel@tonic-gate 	sigset_t	oldmask;
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate 	switch_resolver_setup(&mt_disabled, &oldmask, &old_retry);
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 	he = _gethostbyname(&argp->h_errno, argp->key.name);
1447c478bd9Sstevel@tonic-gate 	if (he != NULL) {
145cb5caa98Sdjl 		if (argp->buf.result == NULL) {
146cb5caa98Sdjl 			/*
147cb5caa98Sdjl 			 * if asked to return data in string,
148cb5caa98Sdjl 			 * convert the hostent structure into
149cb5caa98Sdjl 			 * string data
150cb5caa98Sdjl 			 */
151cb5caa98Sdjl 			ret = ent2str(he, a, AF_INET);
152cb5caa98Sdjl 			if (ret == NSS_STR_PARSE_SUCCESS)
153cb5caa98Sdjl 				argp->returnval = argp->buf.buffer;
1547c478bd9Sstevel@tonic-gate 		} else {
155cb5caa98Sdjl 			ret = ent2result(he, a, AF_INET);
156cb5caa98Sdjl 			if (ret == NSS_STR_PARSE_SUCCESS)
157cb5caa98Sdjl 				argp->returnval = argp->buf.result;
158cb5caa98Sdjl 		}
159cb5caa98Sdjl 
160cb5caa98Sdjl 		if (ret != NSS_STR_PARSE_SUCCESS) {
1617c478bd9Sstevel@tonic-gate 			argp->h_errno = HOST_NOT_FOUND;
1627c478bd9Sstevel@tonic-gate 			if (ret == NSS_STR_PARSE_ERANGE) {
1637c478bd9Sstevel@tonic-gate 				argp->erange = 1;
1647c478bd9Sstevel@tonic-gate 			}
1657c478bd9Sstevel@tonic-gate 		}
1667c478bd9Sstevel@tonic-gate 	}
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 	switch_resolver_reset(mt_disabled, oldmask, old_retry);
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	return (_herrno2nss(argp->h_errno));
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1767c478bd9Sstevel@tonic-gate static nss_status_t
getbyaddr(be,a)1777c478bd9Sstevel@tonic-gate getbyaddr(be, a)
1787c478bd9Sstevel@tonic-gate 	dns_backend_ptr_t	be;
1797c478bd9Sstevel@tonic-gate 	void			*a;
1807c478bd9Sstevel@tonic-gate {
1817c478bd9Sstevel@tonic-gate 	return (__nss_dns_getbyaddr(be, a));
1827c478bd9Sstevel@tonic-gate }
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate /*
1867c478bd9Sstevel@tonic-gate  * Exposing a DNS backend specific interface so that it doesn't conflict
1877c478bd9Sstevel@tonic-gate  * with other getbyaddr() routines from other switch backends.
1887c478bd9Sstevel@tonic-gate  */
189cb5caa98Sdjl /*ARGSUSED*/
1907c478bd9Sstevel@tonic-gate nss_status_t
__nss_dns_getbyaddr(be,a)1917c478bd9Sstevel@tonic-gate __nss_dns_getbyaddr(be, a)
1927c478bd9Sstevel@tonic-gate 	dns_backend_ptr_t	be;
1937c478bd9Sstevel@tonic-gate 	void			*a;
1947c478bd9Sstevel@tonic-gate {
19587a231a8Sjbeck 	struct hostent	*he;
1967c478bd9Sstevel@tonic-gate 	nss_XbyY_args_t	*argp = (nss_XbyY_args_t *)a;
19787a231a8Sjbeck 	int		ret, mt_disabled;
1987c478bd9Sstevel@tonic-gate 	struct in_addr	unmapv4;
1997c478bd9Sstevel@tonic-gate 	sigset_t	oldmask;
2007c478bd9Sstevel@tonic-gate 	int		af, addrlen;
2017c478bd9Sstevel@tonic-gate 	void		*addrp;
2027c478bd9Sstevel@tonic-gate 	int		old_retry;
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate 	switch_resolver_setup(&mt_disabled, &oldmask, &old_retry);
2057c478bd9Sstevel@tonic-gate 
206cb5caa98Sdjl 	/* LINTED: E_BAD_PTR_CAST_ALIGN */
2077c478bd9Sstevel@tonic-gate 	if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)argp->key.hostaddr.addr)) {
2087c478bd9Sstevel@tonic-gate 		addrp = &unmapv4;
2097c478bd9Sstevel@tonic-gate 		addrlen = sizeof (unmapv4);
2107c478bd9Sstevel@tonic-gate 		af = AF_INET;
211cb5caa98Sdjl 		(void) memcpy(addrp, &argp->key.hostaddr.addr[12], addrlen);
2127c478bd9Sstevel@tonic-gate 	} else {
2137c478bd9Sstevel@tonic-gate 		addrp = (void *)argp->key.hostaddr.addr;
2147c478bd9Sstevel@tonic-gate 		addrlen = argp->key.hostaddr.len;
2157c478bd9Sstevel@tonic-gate 		af = argp->key.hostaddr.type;
2167c478bd9Sstevel@tonic-gate 	}
2177c478bd9Sstevel@tonic-gate 	he = _gethostbyaddr(&argp->h_errno, addrp, addrlen, af);
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 	if (he != NULL) {
22087a231a8Sjbeck 		/*
22187a231a8Sjbeck 		 * if asked to return data in string, convert
22287a231a8Sjbeck 		 * the hostent structure into string data
22387a231a8Sjbeck 		 */
22487a231a8Sjbeck 		if (argp->buf.result == NULL)
22587a231a8Sjbeck 			ret = ent2str(he, a, argp->key.hostaddr.type);
22687a231a8Sjbeck 		else
22787a231a8Sjbeck 			ret = ent2result(he, a, argp->key.hostaddr.type);
228cb5caa98Sdjl 
2297c478bd9Sstevel@tonic-gate 		if (ret == NSS_STR_PARSE_SUCCESS) {
23087a231a8Sjbeck 			if (argp->buf.result == NULL)
23187a231a8Sjbeck 				argp->returnval = argp->buf.buffer;
2327c478bd9Sstevel@tonic-gate 			else
23387a231a8Sjbeck 				argp->returnval = argp->buf.result;
2347c478bd9Sstevel@tonic-gate 		} else {
2357c478bd9Sstevel@tonic-gate 			argp->h_errno = HOST_NOT_FOUND;
23687a231a8Sjbeck 			if (ret == NSS_STR_PARSE_ERANGE)
2377c478bd9Sstevel@tonic-gate 				argp->erange = 1;
2387c478bd9Sstevel@tonic-gate 		}
2397c478bd9Sstevel@tonic-gate 	}
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate 	switch_resolver_reset(mt_disabled, oldmask, old_retry);
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 	return (_herrno2nss(argp->h_errno));
2447c478bd9Sstevel@tonic-gate }
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2487c478bd9Sstevel@tonic-gate static nss_status_t
_nss_dns_getent(be,args)2497c478bd9Sstevel@tonic-gate _nss_dns_getent(be, args)
2507c478bd9Sstevel@tonic-gate 	dns_backend_ptr_t	be;
2517c478bd9Sstevel@tonic-gate 	void			*args;
2527c478bd9Sstevel@tonic-gate {
2537c478bd9Sstevel@tonic-gate 	return (NSS_UNAVAIL);
2547c478bd9Sstevel@tonic-gate }
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2587c478bd9Sstevel@tonic-gate static nss_status_t
_nss_dns_setent(be,dummy)2597c478bd9Sstevel@tonic-gate _nss_dns_setent(be, dummy)
2607c478bd9Sstevel@tonic-gate 	dns_backend_ptr_t	be;
2617c478bd9Sstevel@tonic-gate 	void			*dummy;
2627c478bd9Sstevel@tonic-gate {
2637c478bd9Sstevel@tonic-gate 	nss_status_t	errp;
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate 	sigset_t	oldmask, newmask;
2667c478bd9Sstevel@tonic-gate 	int		mt_disabled = 1;
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate 	/*
2697c478bd9Sstevel@tonic-gate 	 * Try to enable MT; if not, we have to single-thread libresolv
2707c478bd9Sstevel@tonic-gate 	 * access
2717c478bd9Sstevel@tonic-gate 	 */
2727c478bd9Sstevel@tonic-gate 	if (enable_mt == 0 || (mt_disabled = (*enable_mt)()) != 0) {
2737c478bd9Sstevel@tonic-gate 		(void) sigfillset(&newmask);
274*7257d1b4Sraf 		(void) thr_sigsetmask(SIG_SETMASK, &newmask, &oldmask);
275*7257d1b4Sraf 		(void) mutex_lock(&one_lane);
2767c478bd9Sstevel@tonic-gate 	}
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	_sethostent(&errp, 1);
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 	if (mt_disabled) {
281*7257d1b4Sraf 		(void) mutex_unlock(&one_lane);
282*7257d1b4Sraf 		(void) thr_sigsetmask(SIG_SETMASK, &oldmask, NULL);
2837c478bd9Sstevel@tonic-gate 	} else {
2847c478bd9Sstevel@tonic-gate 		(void) (*disable_mt)();
2857c478bd9Sstevel@tonic-gate 	}
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate 	return (errp);
2887c478bd9Sstevel@tonic-gate }
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2927c478bd9Sstevel@tonic-gate static nss_status_t
_nss_dns_endent(be,dummy)2937c478bd9Sstevel@tonic-gate _nss_dns_endent(be, dummy)
2947c478bd9Sstevel@tonic-gate 	dns_backend_ptr_t	be;
2957c478bd9Sstevel@tonic-gate 	void			*dummy;
2967c478bd9Sstevel@tonic-gate {
2977c478bd9Sstevel@tonic-gate 	nss_status_t	errp;
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate 	sigset_t	oldmask, newmask;
3007c478bd9Sstevel@tonic-gate 	int		mt_disabled = 1;
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate 	/*
3037c478bd9Sstevel@tonic-gate 	 * Try to enable MT; if not, we have to single-thread libresolv
3047c478bd9Sstevel@tonic-gate 	 * access
3057c478bd9Sstevel@tonic-gate 	 */
3067c478bd9Sstevel@tonic-gate 	if (enable_mt == 0 || (mt_disabled = (*enable_mt)()) != 0) {
3077c478bd9Sstevel@tonic-gate 		(void) sigfillset(&newmask);
308*7257d1b4Sraf 		(void) thr_sigsetmask(SIG_SETMASK, &newmask, &oldmask);
309*7257d1b4Sraf 		(void) mutex_lock(&one_lane);
3107c478bd9Sstevel@tonic-gate 	}
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 	_endhostent(&errp);
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate 	if (mt_disabled) {
315*7257d1b4Sraf 		(void) mutex_unlock(&one_lane);
316*7257d1b4Sraf 		(void) thr_sigsetmask(SIG_SETMASK, &oldmask, NULL);
3177c478bd9Sstevel@tonic-gate 	} else {
3187c478bd9Sstevel@tonic-gate 		(void) (*disable_mt)();
3197c478bd9Sstevel@tonic-gate 	}
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate 	return (errp);
3227c478bd9Sstevel@tonic-gate }
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3267c478bd9Sstevel@tonic-gate static nss_status_t
_nss_dns_destr(be,dummy)3277c478bd9Sstevel@tonic-gate _nss_dns_destr(be, dummy)
3287c478bd9Sstevel@tonic-gate 	dns_backend_ptr_t	be;
3297c478bd9Sstevel@tonic-gate 	void			*dummy;
3307c478bd9Sstevel@tonic-gate {
3317c478bd9Sstevel@tonic-gate 	nss_status_t	errp;
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate 	if (be != 0) {
3347c478bd9Sstevel@tonic-gate 		/* === Should change to invoke ops[ENDENT] ? */
3357c478bd9Sstevel@tonic-gate 		sigset_t	oldmask, newmask;
3367c478bd9Sstevel@tonic-gate 		int		mt_disabled = 1;
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 		if (enable_mt == 0 || (mt_disabled = (*enable_mt)()) != 0) {
3397c478bd9Sstevel@tonic-gate 			(void) sigfillset(&newmask);
340*7257d1b4Sraf 			(void) thr_sigsetmask(SIG_SETMASK, &newmask, &oldmask);
341*7257d1b4Sraf 			(void) mutex_lock(&one_lane);
3427c478bd9Sstevel@tonic-gate 		}
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate 		_endhostent(&errp);
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate 		if (mt_disabled) {
347*7257d1b4Sraf 			(void) mutex_unlock(&one_lane);
348*7257d1b4Sraf 			(void) thr_sigsetmask(SIG_SETMASK, &oldmask, NULL);
3497c478bd9Sstevel@tonic-gate 		} else {
3507c478bd9Sstevel@tonic-gate 			(void) (*disable_mt)();
3517c478bd9Sstevel@tonic-gate 		}
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate 		free(be);
3547c478bd9Sstevel@tonic-gate 	}
3557c478bd9Sstevel@tonic-gate 	return (NSS_SUCCESS);   /* In case anyone is dumb enough to check */
3567c478bd9Sstevel@tonic-gate }
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate static dns_backend_op_t host_ops[] = {
3607c478bd9Sstevel@tonic-gate 	_nss_dns_destr,
3617c478bd9Sstevel@tonic-gate 	_nss_dns_endent,
3627c478bd9Sstevel@tonic-gate 	_nss_dns_setent,
3637c478bd9Sstevel@tonic-gate 	_nss_dns_getent,
3647c478bd9Sstevel@tonic-gate 	getbyname,
3657c478bd9Sstevel@tonic-gate 	getbyaddr,
3667c478bd9Sstevel@tonic-gate };
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3697c478bd9Sstevel@tonic-gate nss_backend_t *
_nss_dns_hosts_constr(dummy1,dummy2,dummy3)3707c478bd9Sstevel@tonic-gate _nss_dns_hosts_constr(dummy1, dummy2, dummy3)
3717c478bd9Sstevel@tonic-gate 	const char	*dummy1, *dummy2, *dummy3;
3727c478bd9Sstevel@tonic-gate {
3737c478bd9Sstevel@tonic-gate 	return (_nss_dns_constr(host_ops,
3747c478bd9Sstevel@tonic-gate 		sizeof (host_ops) / sizeof (host_ops[0])));
3757c478bd9Sstevel@tonic-gate }
376cb5caa98Sdjl 
377cb5caa98Sdjl /*
378cb5caa98Sdjl  * optional NSS2 packed backend gethostsbyname with ttl
379cb5caa98Sdjl  * entry point.
380cb5caa98Sdjl  *
381cb5caa98Sdjl  * Returns:
382cb5caa98Sdjl  *	NSS_SUCCESS - successful
383cb5caa98Sdjl  *	NSS_NOTFOUND - successful but nothing found
384cb5caa98Sdjl  *	NSS_ERROR - fallback to NSS backend lookup mode
385cb5caa98Sdjl  * If successful, buffer will be filled with valid data
386cb5caa98Sdjl  *
387cb5caa98Sdjl  */
388cb5caa98Sdjl 
389cb5caa98Sdjl /*ARGSUSED*/
390cb5caa98Sdjl nss_status_t
_nss_get_dns_hosts_name(dns_backend_ptr_t * be,void ** bufp,size_t * sizep)391cb5caa98Sdjl _nss_get_dns_hosts_name(dns_backend_ptr_t *be, void **bufp, size_t *sizep)
392cb5caa98Sdjl {
393cb5caa98Sdjl 	return (_nss_dns_gethost_withttl(*bufp, *sizep, 0));
394cb5caa98Sdjl }
395