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 1993-2000, 2003 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate * 26*0Sstevel@tonic-gate * gethostent6.c 27*0Sstevel@tonic-gate */ 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate /* 32*0Sstevel@tonic-gate * This is the DNS backend for IPv6 addresses. 33*0Sstevel@tonic-gate * getbyname() is a local routine, but getbyaddr() actually shares the 34*0Sstevel@tonic-gate * same codes as the one in gethostent.c. 35*0Sstevel@tonic-gate */ 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate #define endhostent res_endhostent 38*0Sstevel@tonic-gate 39*0Sstevel@tonic-gate #include <malloc.h> 40*0Sstevel@tonic-gate #include <stddef.h> 41*0Sstevel@tonic-gate #include <string.h> 42*0Sstevel@tonic-gate #include "dns_common.h" 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate /* 45*0Sstevel@tonic-gate * If the DNS name service switch routines are used in a binary that depends 46*0Sstevel@tonic-gate * on an older libresolv (libresolv.so.1, say), then having nss_dns.so.1 or 47*0Sstevel@tonic-gate * libnss_dns.a depend on a newer libresolv (libresolv.so.2) will cause 48*0Sstevel@tonic-gate * relocation problems. In particular, copy relocation of the _res structure 49*0Sstevel@tonic-gate * (which changes in size from libresolv.so.1 to libresolv.so.2) could 50*0Sstevel@tonic-gate * cause corruption, and result in a number of strange problems, including 51*0Sstevel@tonic-gate * core dumps. Hence, we check if a libresolv is already loaded. 52*0Sstevel@tonic-gate */ 53*0Sstevel@tonic-gate 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate #pragma weak res_endhostent 56*0Sstevel@tonic-gate 57*0Sstevel@tonic-gate extern struct hostent *_gethostbyname(int *, const char *); 58*0Sstevel@tonic-gate extern struct hostent *_nss_dns_gethostbyname2(int *, const char *); 59*0Sstevel@tonic-gate 60*0Sstevel@tonic-gate typedef union { 61*0Sstevel@tonic-gate long al; 62*0Sstevel@tonic-gate char ac; 63*0Sstevel@tonic-gate } align; 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate static void 67*0Sstevel@tonic-gate _endhostent(errp) 68*0Sstevel@tonic-gate nss_status_t *errp; 69*0Sstevel@tonic-gate { 70*0Sstevel@tonic-gate int ret; 71*0Sstevel@tonic-gate 72*0Sstevel@tonic-gate ret = endhostent(); 73*0Sstevel@tonic-gate if (ret == 0) 74*0Sstevel@tonic-gate *errp = NSS_SUCCESS; 75*0Sstevel@tonic-gate else 76*0Sstevel@tonic-gate *errp = NSS_UNAVAIL; 77*0Sstevel@tonic-gate } 78*0Sstevel@tonic-gate 79*0Sstevel@tonic-gate 80*0Sstevel@tonic-gate #ifdef RNDUP 81*0Sstevel@tonic-gate #undef RNDUP 82*0Sstevel@tonic-gate #endif 83*0Sstevel@tonic-gate #define RNDUP(x) ((1 + (((x)-1)/sizeof (void *))) * sizeof (void *)) 84*0Sstevel@tonic-gate 85*0Sstevel@tonic-gate #ifdef PTROFF 86*0Sstevel@tonic-gate #undef PTROFF 87*0Sstevel@tonic-gate #endif 88*0Sstevel@tonic-gate #define PTROFF(p, o) (((o) == 0) ? 0 : (void *)((char *)(p) + (o))) 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate 91*0Sstevel@tonic-gate /* 92*0Sstevel@tonic-gate * Make a copy of h->h_name. 93*0Sstevel@tonic-gate */ 94*0Sstevel@tonic-gate static char * 95*0Sstevel@tonic-gate cloneName(struct hostent *h, int *outerr) { 96*0Sstevel@tonic-gate 97*0Sstevel@tonic-gate char *name; 98*0Sstevel@tonic-gate int len; 99*0Sstevel@tonic-gate int error, *errp; 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gate if (outerr) 102*0Sstevel@tonic-gate errp = outerr; 103*0Sstevel@tonic-gate else 104*0Sstevel@tonic-gate errp = &error; 105*0Sstevel@tonic-gate 106*0Sstevel@tonic-gate if (h == 0 || h->h_name == 0) { 107*0Sstevel@tonic-gate *errp = 0; 108*0Sstevel@tonic-gate return (0); 109*0Sstevel@tonic-gate } 110*0Sstevel@tonic-gate 111*0Sstevel@tonic-gate len = strlen(h->h_name); 112*0Sstevel@tonic-gate 113*0Sstevel@tonic-gate if ((name = malloc(len+1)) == 0) { 114*0Sstevel@tonic-gate *errp = 1; 115*0Sstevel@tonic-gate return (0); 116*0Sstevel@tonic-gate } 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate memcpy(name, h->h_name, len+1); 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate *errp = 0; 121*0Sstevel@tonic-gate return (name); 122*0Sstevel@tonic-gate } 123*0Sstevel@tonic-gate 124*0Sstevel@tonic-gate 125*0Sstevel@tonic-gate /* 126*0Sstevel@tonic-gate * Copy the h->h_addr_list[] array to a new array, and append the 127*0Sstevel@tonic-gate * moreAddrs[] list. If h->h_addr_list[] contains IPv4 addresses, 128*0Sstevel@tonic-gate * convert them to v4 mapped IPv6 addresses. 129*0Sstevel@tonic-gate * 130*0Sstevel@tonic-gate * Note: The pointers to the addresses in the moreAddrs[] array are copied, 131*0Sstevel@tonic-gate * but not the IP addresses themselves. 132*0Sstevel@tonic-gate */ 133*0Sstevel@tonic-gate struct in6_addr ** 134*0Sstevel@tonic-gate cloneAddrList(struct hostent *h, struct in6_addr **moreAddrs, int *outerr) { 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate struct in6_addr **addrArray, *addrList; 137*0Sstevel@tonic-gate int domap, addrlen, i, j, addrCount, moreAddrCount = 0; 138*0Sstevel@tonic-gate 139*0Sstevel@tonic-gate int error, *errp; 140*0Sstevel@tonic-gate 141*0Sstevel@tonic-gate if (outerr) 142*0Sstevel@tonic-gate errp = outerr; 143*0Sstevel@tonic-gate else 144*0Sstevel@tonic-gate errp = &error; 145*0Sstevel@tonic-gate 146*0Sstevel@tonic-gate if (h == 0 || h->h_addr_list == 0) { 147*0Sstevel@tonic-gate *errp = 0; 148*0Sstevel@tonic-gate return (0); 149*0Sstevel@tonic-gate } 150*0Sstevel@tonic-gate 151*0Sstevel@tonic-gate /* Should we map v4 to IPv6 ? */ 152*0Sstevel@tonic-gate domap = (h->h_length == sizeof (struct in_addr)) && 153*0Sstevel@tonic-gate (h->h_addrtype == AF_INET); 154*0Sstevel@tonic-gate 155*0Sstevel@tonic-gate /* If mapping, make sure we allocate enough memory for addresses */ 156*0Sstevel@tonic-gate addrlen = h->h_length; 157*0Sstevel@tonic-gate if (domap && addrlen < sizeof (struct in6_addr)) 158*0Sstevel@tonic-gate addrlen = sizeof (struct in6_addr); 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate for (addrCount = 0; h->h_addr_list[addrCount]; addrCount++); 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate if (moreAddrs != 0) { 163*0Sstevel@tonic-gate for (moreAddrCount = 0; moreAddrs[moreAddrCount]; 164*0Sstevel@tonic-gate moreAddrCount++); 165*0Sstevel@tonic-gate } 166*0Sstevel@tonic-gate 167*0Sstevel@tonic-gate if ((addrArray = malloc((addrCount+moreAddrCount+1)*sizeof (addrList) + 168*0Sstevel@tonic-gate addrCount*addrlen)) == 0) { 169*0Sstevel@tonic-gate *errp = 1; 170*0Sstevel@tonic-gate return (0); 171*0Sstevel@tonic-gate } 172*0Sstevel@tonic-gate 173*0Sstevel@tonic-gate addrList = PTROFF(addrArray, (addrCount+moreAddrCount+1) * 174*0Sstevel@tonic-gate sizeof (addrList)); 175*0Sstevel@tonic-gate 176*0Sstevel@tonic-gate for (i = 0; i < addrCount; i++) { 177*0Sstevel@tonic-gate addrArray[i] = addrList; 178*0Sstevel@tonic-gate if (domap) { 179*0Sstevel@tonic-gate IN6_INADDR_TO_V4MAPPED( 180*0Sstevel@tonic-gate (struct in_addr *)h->h_addr_list[i], addrArray[i]); 181*0Sstevel@tonic-gate } else { 182*0Sstevel@tonic-gate memcpy(addrArray[i], h->h_addr_list[i], addrlen); 183*0Sstevel@tonic-gate } 184*0Sstevel@tonic-gate addrList = PTROFF(addrList, addrlen); 185*0Sstevel@tonic-gate } 186*0Sstevel@tonic-gate 187*0Sstevel@tonic-gate for (j = 0; j < moreAddrCount; j++, i++) { 188*0Sstevel@tonic-gate addrArray[i] = moreAddrs[j]; 189*0Sstevel@tonic-gate } 190*0Sstevel@tonic-gate 191*0Sstevel@tonic-gate /* Last pointer should be NULL */ 192*0Sstevel@tonic-gate addrArray[i] = 0; 193*0Sstevel@tonic-gate 194*0Sstevel@tonic-gate *errp = 0; 195*0Sstevel@tonic-gate return (addrArray); 196*0Sstevel@tonic-gate } 197*0Sstevel@tonic-gate 198*0Sstevel@tonic-gate 199*0Sstevel@tonic-gate /* 200*0Sstevel@tonic-gate * Create a new alias array that is is a copy of h->h_aliases[] plus 201*0Sstevel@tonic-gate * the aliases in mergeAliases[] which aren't duplicates of any alias 202*0Sstevel@tonic-gate * in h->h_aliases[]. 203*0Sstevel@tonic-gate * 204*0Sstevel@tonic-gate * Note 1: Only the string pointers (NOT the strings) in the mergeAliases[] 205*0Sstevel@tonic-gate * array are copied. 206*0Sstevel@tonic-gate * 207*0Sstevel@tonic-gate * Note 2: The duplicate aliases in mergeAliases[] are replaced by NULL 208*0Sstevel@tonic-gate * pointers. 209*0Sstevel@tonic-gate */ 210*0Sstevel@tonic-gate static char ** 211*0Sstevel@tonic-gate cloneAliasList(struct hostent *h, char **mergeAliases, int *outerr) { 212*0Sstevel@tonic-gate 213*0Sstevel@tonic-gate char **aliasArray, *aliasList; 214*0Sstevel@tonic-gate int i, j, k, aliasCount, mergeAliasCount = 0, realMac = 0; 215*0Sstevel@tonic-gate int stringSize = 0; 216*0Sstevel@tonic-gate int error, *errp; 217*0Sstevel@tonic-gate 218*0Sstevel@tonic-gate if (outerr) 219*0Sstevel@tonic-gate errp = outerr; 220*0Sstevel@tonic-gate else 221*0Sstevel@tonic-gate errp = &error; 222*0Sstevel@tonic-gate 223*0Sstevel@tonic-gate 224*0Sstevel@tonic-gate if (h == 0 || h->h_aliases == 0) { 225*0Sstevel@tonic-gate *errp = 0; 226*0Sstevel@tonic-gate return (0); 227*0Sstevel@tonic-gate } 228*0Sstevel@tonic-gate 229*0Sstevel@tonic-gate for (aliasCount = 0; h->h_aliases[aliasCount]; aliasCount++) { 230*0Sstevel@tonic-gate stringSize += RNDUP(strlen(h->h_aliases[aliasCount])+1); 231*0Sstevel@tonic-gate } 232*0Sstevel@tonic-gate 233*0Sstevel@tonic-gate if (mergeAliases != 0) { 234*0Sstevel@tonic-gate for (; mergeAliases[mergeAliasCount]; mergeAliasCount++) { 235*0Sstevel@tonic-gate int countThis = 1; 236*0Sstevel@tonic-gate /* Skip duplicates */ 237*0Sstevel@tonic-gate for (j = 0; j < aliasCount; j++) { 238*0Sstevel@tonic-gate if (strcmp(mergeAliases[mergeAliasCount], 239*0Sstevel@tonic-gate h->h_aliases[j]) == 0) { 240*0Sstevel@tonic-gate countThis = 0; 241*0Sstevel@tonic-gate break; 242*0Sstevel@tonic-gate } 243*0Sstevel@tonic-gate } 244*0Sstevel@tonic-gate if (countThis) 245*0Sstevel@tonic-gate realMac++; 246*0Sstevel@tonic-gate else 247*0Sstevel@tonic-gate mergeAliases[mergeAliasCount] = 0; 248*0Sstevel@tonic-gate } 249*0Sstevel@tonic-gate } 250*0Sstevel@tonic-gate 251*0Sstevel@tonic-gate if ((aliasArray = malloc((aliasCount+realMac+1)*sizeof (char **)+ 252*0Sstevel@tonic-gate stringSize)) == 0) { 253*0Sstevel@tonic-gate *errp = 1; 254*0Sstevel@tonic-gate return (0); 255*0Sstevel@tonic-gate } 256*0Sstevel@tonic-gate 257*0Sstevel@tonic-gate aliasList = PTROFF(aliasArray, 258*0Sstevel@tonic-gate (aliasCount+realMac+1)*sizeof (char **)); 259*0Sstevel@tonic-gate for (i = 0; i < aliasCount; i++) { 260*0Sstevel@tonic-gate int len = strlen(h->h_aliases[i]); 261*0Sstevel@tonic-gate aliasArray[i] = aliasList; 262*0Sstevel@tonic-gate memcpy(aliasArray[i], h->h_aliases[i], len+1); 263*0Sstevel@tonic-gate aliasList = PTROFF(aliasList, RNDUP(len+1)); 264*0Sstevel@tonic-gate } 265*0Sstevel@tonic-gate 266*0Sstevel@tonic-gate for (j = 0; j < mergeAliasCount; j++) { 267*0Sstevel@tonic-gate if (mergeAliases[j] != 0) { 268*0Sstevel@tonic-gate aliasArray[i++] = mergeAliases[j]; 269*0Sstevel@tonic-gate } 270*0Sstevel@tonic-gate } 271*0Sstevel@tonic-gate 272*0Sstevel@tonic-gate aliasArray[i] = 0; 273*0Sstevel@tonic-gate 274*0Sstevel@tonic-gate *errp = 0; 275*0Sstevel@tonic-gate return (aliasArray); 276*0Sstevel@tonic-gate } 277*0Sstevel@tonic-gate 278*0Sstevel@tonic-gate 279*0Sstevel@tonic-gate static nss_status_t 280*0Sstevel@tonic-gate getbyname(be, a) 281*0Sstevel@tonic-gate dns_backend_ptr_t be; 282*0Sstevel@tonic-gate void *a; 283*0Sstevel@tonic-gate { 284*0Sstevel@tonic-gate struct hostent *he = NULL; 285*0Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 286*0Sstevel@tonic-gate int ret, mt_disabled; 287*0Sstevel@tonic-gate sigset_t oldmask; 288*0Sstevel@tonic-gate int converr = 0, gotv6 = 0; 289*0Sstevel@tonic-gate struct hostent v6he; 290*0Sstevel@tonic-gate char *v6Name = 0; 291*0Sstevel@tonic-gate struct in6_addr **v6Addrs = 0, **mergeAddrs = 0; 292*0Sstevel@tonic-gate char **v6Aliases = 0, **mergeAliases = 0; 293*0Sstevel@tonic-gate int v6_h_errno; 294*0Sstevel@tonic-gate int old_retry; 295*0Sstevel@tonic-gate int af = argp->key.ipnode.af_family; 296*0Sstevel@tonic-gate int flags = argp->key.ipnode.flags; 297*0Sstevel@tonic-gate 298*0Sstevel@tonic-gate switch_resolver_setup(&mt_disabled, &oldmask, &old_retry); 299*0Sstevel@tonic-gate 300*0Sstevel@tonic-gate /* Now get the AAAA records */ 301*0Sstevel@tonic-gate if (af == AF_INET6) 302*0Sstevel@tonic-gate he = _nss_dns_gethostbyname2(&argp->h_errno, 303*0Sstevel@tonic-gate argp->key.ipnode.name); 304*0Sstevel@tonic-gate if (he != NULL) { 305*0Sstevel@tonic-gate /* 306*0Sstevel@tonic-gate * pointer in "he" is part of a static pthread key in libresolv 307*0Sstevel@tonic-gate * It should be treated as read only. 308*0Sstevel@tonic-gate * So clone a copy first. 309*0Sstevel@tonic-gate */ 310*0Sstevel@tonic-gate v6Name = cloneName(he, &converr); 311*0Sstevel@tonic-gate if (converr) { 312*0Sstevel@tonic-gate argp->h_errno = HOST_NOT_FOUND; 313*0Sstevel@tonic-gate argp->erange = 1; 314*0Sstevel@tonic-gate switch_resolver_reset(mt_disabled, oldmask, old_retry); 315*0Sstevel@tonic-gate return (_herrno2nss(argp->h_errno)); 316*0Sstevel@tonic-gate } 317*0Sstevel@tonic-gate v6Addrs = cloneAddrList(he, 0, &converr); 318*0Sstevel@tonic-gate if (converr) { 319*0Sstevel@tonic-gate if (v6Name != 0) 320*0Sstevel@tonic-gate free(v6Name); 321*0Sstevel@tonic-gate argp->h_errno = HOST_NOT_FOUND; 322*0Sstevel@tonic-gate argp->erange = 1; 323*0Sstevel@tonic-gate switch_resolver_reset(mt_disabled, oldmask, old_retry); 324*0Sstevel@tonic-gate return (_herrno2nss(argp->h_errno)); 325*0Sstevel@tonic-gate } 326*0Sstevel@tonic-gate v6Aliases = cloneAliasList(he, 0, &converr); 327*0Sstevel@tonic-gate if (converr) { 328*0Sstevel@tonic-gate if (v6Name != 0) 329*0Sstevel@tonic-gate free(v6Name); 330*0Sstevel@tonic-gate if (v6Addrs != 0) 331*0Sstevel@tonic-gate free(v6Addrs); 332*0Sstevel@tonic-gate argp->h_errno = HOST_NOT_FOUND; 333*0Sstevel@tonic-gate argp->erange = 1; 334*0Sstevel@tonic-gate switch_resolver_reset(mt_disabled, oldmask, old_retry); 335*0Sstevel@tonic-gate return (_herrno2nss(argp->h_errno)); 336*0Sstevel@tonic-gate } 337*0Sstevel@tonic-gate v6_h_errno = argp->h_errno; 338*0Sstevel@tonic-gate gotv6 = 1; 339*0Sstevel@tonic-gate } 340*0Sstevel@tonic-gate 341*0Sstevel@tonic-gate /* 342*0Sstevel@tonic-gate * The conditions to search "A" records: 343*0Sstevel@tonic-gate * 1. af is AF_INET 344*0Sstevel@tonic-gate * 2. if af is AF_INET6 345*0Sstevel@tonic-gate * then flags are either 346*0Sstevel@tonic-gate * 1) (AI_ALL | AI_V4MAPPED) or 347*0Sstevel@tonic-gate * 2) AI_V4MAPPED and he == NULL 348*0Sstevel@tonic-gate * (No V6 addresses found or no search for V6 at all) 349*0Sstevel@tonic-gate */ 350*0Sstevel@tonic-gate 351*0Sstevel@tonic-gate /* Get the A records, and store the information */ 352*0Sstevel@tonic-gate if ((af == AF_INET) || 353*0Sstevel@tonic-gate ((af == AF_INET6) && 354*0Sstevel@tonic-gate ((flags & (AI_ALL | AI_V4MAPPED)) || 355*0Sstevel@tonic-gate ((flags & AI_V4MAPPED) && he == NULL)))) 356*0Sstevel@tonic-gate he = _gethostbyname(&argp->h_errno, argp->key.ipnode.name); 357*0Sstevel@tonic-gate else 358*0Sstevel@tonic-gate he = NULL; 359*0Sstevel@tonic-gate 360*0Sstevel@tonic-gate /* Merge the results */ 361*0Sstevel@tonic-gate if (he != NULL) { 362*0Sstevel@tonic-gate mergeAddrs = cloneAddrList(he, v6Addrs, &converr); 363*0Sstevel@tonic-gate if (converr) { 364*0Sstevel@tonic-gate if (v6Name != 0) 365*0Sstevel@tonic-gate free(v6Name); 366*0Sstevel@tonic-gate if (v6Addrs != 0) 367*0Sstevel@tonic-gate free(v6Addrs); 368*0Sstevel@tonic-gate if (v6Aliases != 0) 369*0Sstevel@tonic-gate free(v6Aliases); 370*0Sstevel@tonic-gate argp->h_errno = HOST_NOT_FOUND; 371*0Sstevel@tonic-gate argp->erange = 1; 372*0Sstevel@tonic-gate switch_resolver_reset(mt_disabled, oldmask, 373*0Sstevel@tonic-gate old_retry); 374*0Sstevel@tonic-gate return (_herrno2nss(argp->h_errno)); 375*0Sstevel@tonic-gate } 376*0Sstevel@tonic-gate he->h_addr_list = (char **)mergeAddrs; 377*0Sstevel@tonic-gate 378*0Sstevel@tonic-gate mergeAliases = cloneAliasList(he, v6Aliases, &converr); 379*0Sstevel@tonic-gate if (converr) { 380*0Sstevel@tonic-gate if (v6Name != 0) 381*0Sstevel@tonic-gate free(v6Name); 382*0Sstevel@tonic-gate if (v6Addrs != 0) 383*0Sstevel@tonic-gate free(v6Addrs); 384*0Sstevel@tonic-gate if (v6Aliases != 0) 385*0Sstevel@tonic-gate free(v6Aliases); 386*0Sstevel@tonic-gate if (mergeAddrs != 0) 387*0Sstevel@tonic-gate free(mergeAddrs); 388*0Sstevel@tonic-gate argp->h_errno = HOST_NOT_FOUND; 389*0Sstevel@tonic-gate argp->erange = 1; 390*0Sstevel@tonic-gate switch_resolver_reset(mt_disabled, oldmask, 391*0Sstevel@tonic-gate old_retry); 392*0Sstevel@tonic-gate return (_herrno2nss(argp->h_errno)); 393*0Sstevel@tonic-gate } 394*0Sstevel@tonic-gate he->h_aliases = mergeAliases; 395*0Sstevel@tonic-gate 396*0Sstevel@tonic-gate /* reset h_length, h_addrtype */ 397*0Sstevel@tonic-gate he->h_length = sizeof (struct in6_addr); 398*0Sstevel@tonic-gate he->h_addrtype = AF_INET6; 399*0Sstevel@tonic-gate 400*0Sstevel@tonic-gate } else if (gotv6) { 401*0Sstevel@tonic-gate v6he.h_name = v6Name; 402*0Sstevel@tonic-gate v6he.h_length = sizeof (struct in6_addr); 403*0Sstevel@tonic-gate v6he.h_addrtype = AF_INET6; 404*0Sstevel@tonic-gate v6he.h_addr_list = (char **)v6Addrs; 405*0Sstevel@tonic-gate v6he.h_aliases = v6Aliases; 406*0Sstevel@tonic-gate he = &v6he; 407*0Sstevel@tonic-gate argp->h_errno = v6_h_errno; 408*0Sstevel@tonic-gate } 409*0Sstevel@tonic-gate 410*0Sstevel@tonic-gate if (he != 0) { 411*0Sstevel@tonic-gate ret = ent2result(he, a, AF_INET6); 412*0Sstevel@tonic-gate if (ret == NSS_STR_PARSE_SUCCESS) { 413*0Sstevel@tonic-gate argp->returnval = argp->buf.result; 414*0Sstevel@tonic-gate } else { 415*0Sstevel@tonic-gate argp->h_errno = HOST_NOT_FOUND; 416*0Sstevel@tonic-gate if (ret == NSS_STR_PARSE_ERANGE) { 417*0Sstevel@tonic-gate argp->erange = 1; 418*0Sstevel@tonic-gate } 419*0Sstevel@tonic-gate } 420*0Sstevel@tonic-gate } 421*0Sstevel@tonic-gate 422*0Sstevel@tonic-gate if (v6Name != 0) 423*0Sstevel@tonic-gate free(v6Name); 424*0Sstevel@tonic-gate if (v6Addrs != 0) 425*0Sstevel@tonic-gate free(v6Addrs); 426*0Sstevel@tonic-gate if (v6Aliases != 0) 427*0Sstevel@tonic-gate free(v6Aliases); 428*0Sstevel@tonic-gate if (mergeAddrs != 0) 429*0Sstevel@tonic-gate free(mergeAddrs); 430*0Sstevel@tonic-gate if (mergeAliases != 0) 431*0Sstevel@tonic-gate free(mergeAliases); 432*0Sstevel@tonic-gate 433*0Sstevel@tonic-gate switch_resolver_reset(mt_disabled, oldmask, old_retry); 434*0Sstevel@tonic-gate 435*0Sstevel@tonic-gate return (_herrno2nss(argp->h_errno)); 436*0Sstevel@tonic-gate } 437*0Sstevel@tonic-gate 438*0Sstevel@tonic-gate 439*0Sstevel@tonic-gate extern nss_status_t __nss_dns_getbyaddr(dns_backend_ptr_t, void *); 440*0Sstevel@tonic-gate 441*0Sstevel@tonic-gate static nss_status_t 442*0Sstevel@tonic-gate getbyaddr(be, a) 443*0Sstevel@tonic-gate dns_backend_ptr_t be; 444*0Sstevel@tonic-gate void *a; 445*0Sstevel@tonic-gate { 446*0Sstevel@tonic-gate /* uses the same getbyaddr from IPv4 */ 447*0Sstevel@tonic-gate return (__nss_dns_getbyaddr(be, a)); 448*0Sstevel@tonic-gate } 449*0Sstevel@tonic-gate 450*0Sstevel@tonic-gate 451*0Sstevel@tonic-gate /*ARGSUSED*/ 452*0Sstevel@tonic-gate static nss_status_t 453*0Sstevel@tonic-gate _nss_dns_getent(be, args) 454*0Sstevel@tonic-gate dns_backend_ptr_t be; 455*0Sstevel@tonic-gate void *args; 456*0Sstevel@tonic-gate { 457*0Sstevel@tonic-gate return (NSS_UNAVAIL); 458*0Sstevel@tonic-gate } 459*0Sstevel@tonic-gate 460*0Sstevel@tonic-gate 461*0Sstevel@tonic-gate /*ARGSUSED*/ 462*0Sstevel@tonic-gate static nss_status_t 463*0Sstevel@tonic-gate _nss_dns_setent(be, dummy) 464*0Sstevel@tonic-gate dns_backend_ptr_t be; 465*0Sstevel@tonic-gate void *dummy; 466*0Sstevel@tonic-gate { 467*0Sstevel@tonic-gate /* XXXX not implemented at this point */ 468*0Sstevel@tonic-gate return (NSS_UNAVAIL); 469*0Sstevel@tonic-gate } 470*0Sstevel@tonic-gate 471*0Sstevel@tonic-gate 472*0Sstevel@tonic-gate /*ARGSUSED*/ 473*0Sstevel@tonic-gate static nss_status_t 474*0Sstevel@tonic-gate _nss_dns_endent(be, dummy) 475*0Sstevel@tonic-gate dns_backend_ptr_t be; 476*0Sstevel@tonic-gate void *dummy; 477*0Sstevel@tonic-gate { 478*0Sstevel@tonic-gate /* XXXX not implemented at this point */ 479*0Sstevel@tonic-gate return (NSS_UNAVAIL); 480*0Sstevel@tonic-gate } 481*0Sstevel@tonic-gate 482*0Sstevel@tonic-gate 483*0Sstevel@tonic-gate /*ARGSUSED*/ 484*0Sstevel@tonic-gate static nss_status_t 485*0Sstevel@tonic-gate _nss_dns_destr(be, dummy) 486*0Sstevel@tonic-gate dns_backend_ptr_t be; 487*0Sstevel@tonic-gate void *dummy; 488*0Sstevel@tonic-gate { 489*0Sstevel@tonic-gate nss_status_t errp; 490*0Sstevel@tonic-gate 491*0Sstevel@tonic-gate if (be != 0) { 492*0Sstevel@tonic-gate /* === Should change to invoke ops[ENDENT] ? */ 493*0Sstevel@tonic-gate sigset_t oldmask, newmask; 494*0Sstevel@tonic-gate int mt_disabled = 1; 495*0Sstevel@tonic-gate 496*0Sstevel@tonic-gate if (enable_mt == 0 || (mt_disabled = (*enable_mt)()) != 0) { 497*0Sstevel@tonic-gate (void) sigfillset(&newmask); 498*0Sstevel@tonic-gate _thr_sigsetmask(SIG_SETMASK, &newmask, &oldmask); 499*0Sstevel@tonic-gate _mutex_lock(&one_lane); 500*0Sstevel@tonic-gate } 501*0Sstevel@tonic-gate 502*0Sstevel@tonic-gate _endhostent(&errp); 503*0Sstevel@tonic-gate 504*0Sstevel@tonic-gate if (mt_disabled) { 505*0Sstevel@tonic-gate _mutex_unlock(&one_lane); 506*0Sstevel@tonic-gate _thr_sigsetmask(SIG_SETMASK, &oldmask, NULL); 507*0Sstevel@tonic-gate } else { 508*0Sstevel@tonic-gate (void) (*disable_mt)(); 509*0Sstevel@tonic-gate } 510*0Sstevel@tonic-gate 511*0Sstevel@tonic-gate free(be); 512*0Sstevel@tonic-gate } 513*0Sstevel@tonic-gate return (NSS_SUCCESS); /* In case anyone is dumb enough to check */ 514*0Sstevel@tonic-gate } 515*0Sstevel@tonic-gate 516*0Sstevel@tonic-gate 517*0Sstevel@tonic-gate 518*0Sstevel@tonic-gate static dns_backend_op_t ipnodes_ops[] = { 519*0Sstevel@tonic-gate _nss_dns_destr, 520*0Sstevel@tonic-gate _nss_dns_endent, 521*0Sstevel@tonic-gate _nss_dns_setent, 522*0Sstevel@tonic-gate _nss_dns_getent, 523*0Sstevel@tonic-gate getbyname, 524*0Sstevel@tonic-gate getbyaddr, 525*0Sstevel@tonic-gate }; 526*0Sstevel@tonic-gate 527*0Sstevel@tonic-gate /*ARGSUSED*/ 528*0Sstevel@tonic-gate nss_backend_t * 529*0Sstevel@tonic-gate _nss_dns_ipnodes_constr(dummy1, dummy2, dummy3) 530*0Sstevel@tonic-gate const char *dummy1, *dummy2, *dummy3; 531*0Sstevel@tonic-gate { 532*0Sstevel@tonic-gate return (_nss_dns_constr(ipnodes_ops, 533*0Sstevel@tonic-gate sizeof (ipnodes_ops) / sizeof (ipnodes_ops[0]))); 534*0Sstevel@tonic-gate } 535