1*4904Srs200217 /* 2*4904Srs200217 * CDDL HEADER START 3*4904Srs200217 * 4*4904Srs200217 * The contents of this file are subject to the terms of the 5*4904Srs200217 * Common Development and Distribution License (the "License"). 6*4904Srs200217 * You may not use this file except in compliance with the License. 7*4904Srs200217 * 8*4904Srs200217 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*4904Srs200217 * or http://www.opensolaris.org/os/licensing. 10*4904Srs200217 * See the License for the specific language governing permissions 11*4904Srs200217 * and limitations under the License. 12*4904Srs200217 * 13*4904Srs200217 * When distributing Covered Code, include this CDDL HEADER in each 14*4904Srs200217 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*4904Srs200217 * If applicable, add the following below this CDDL HEADER, with the 16*4904Srs200217 * fields enclosed by brackets "[]" replaced with your own identifying 17*4904Srs200217 * information: Portions Copyright [yyyy] [name of copyright owner] 18*4904Srs200217 * 19*4904Srs200217 * CDDL HEADER END 20*4904Srs200217 */ 21*4904Srs200217 22*4904Srs200217 /* 23*4904Srs200217 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24*4904Srs200217 * Use is subject to license terms. 25*4904Srs200217 */ 26*4904Srs200217 27*4904Srs200217 #pragma ident "%Z%%M% %I% %E% SMI" 28*4904Srs200217 29*4904Srs200217 #include "mdns_common.h" 30*4904Srs200217 31*4904Srs200217 /* 32*4904Srs200217 * gethostby* functions for the hosts database. The hosts 33*4904Srs200217 * database stores IPv4 addresses only. 34*4904Srs200217 * mDNS query functions to perform the host lookup 35*4904Srs200217 * are in mdns/common/mdns_common.c file. 36*4904Srs200217 * _nss_mdns_hosts_constr is called to initialize 37*4904Srs200217 * the nsswitch backend data structures. 38*4904Srs200217 */ 39*4904Srs200217 40*4904Srs200217 static nss_status_t 41*4904Srs200217 getbyname(be, a) 42*4904Srs200217 mdns_backend_ptr_t be; 43*4904Srs200217 void *a; 44*4904Srs200217 { 45*4904Srs200217 struct mdns_querydata qdata; 46*4904Srs200217 char *hname; 47*4904Srs200217 48*4904Srs200217 (void) memset(&qdata, 0, sizeof (struct mdns_querydata)); 49*4904Srs200217 50*4904Srs200217 qdata.argp = (nss_XbyY_args_t *)a; 51*4904Srs200217 hname = (char *)qdata.argp->key.name; 52*4904Srs200217 53*4904Srs200217 _nss_mdns_updatecfg(be); 54*4904Srs200217 return (_nss_mdns_querybyname(be, hname, AF_INET, &qdata)); 55*4904Srs200217 } 56*4904Srs200217 57*4904Srs200217 /*ARGSUSED*/ 58*4904Srs200217 static nss_status_t 59*4904Srs200217 getbyaddr(be, a) 60*4904Srs200217 mdns_backend_ptr_t be; 61*4904Srs200217 void *a; 62*4904Srs200217 { 63*4904Srs200217 nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 64*4904Srs200217 struct in_addr addr; 65*4904Srs200217 struct mdns_querydata qdata; 66*4904Srs200217 char buffer[sizeof ("255.255.255.255.in-addr.arpa.")]; 67*4904Srs200217 uint8_t *p; 68*4904Srs200217 69*4904Srs200217 (void) memset(&qdata, 0, sizeof (struct mdns_querydata)); 70*4904Srs200217 qdata.argp = argp; 71*4904Srs200217 72*4904Srs200217 argp->h_errno = 0; 73*4904Srs200217 if ((argp->key.hostaddr.type != AF_INET) || 74*4904Srs200217 (argp->key.hostaddr.len != sizeof (addr))) 75*4904Srs200217 return (NSS_NOTFOUND); 76*4904Srs200217 77*4904Srs200217 (void) memcpy(&addr, argp->key.hostaddr.addr, sizeof (addr)); 78*4904Srs200217 79*4904Srs200217 if (inet_ntop(AF_INET, (void *) &addr.s_addr, 80*4904Srs200217 (void *)qdata.paddrbuf, 81*4904Srs200217 sizeof (qdata.paddrbuf)) == NULL) 82*4904Srs200217 return (NSS_NOTFOUND); 83*4904Srs200217 84*4904Srs200217 qdata.af = AF_INET; 85*4904Srs200217 p = (uint8_t *)&addr.s_addr; 86*4904Srs200217 (void) snprintf(buffer, sizeof (buffer), 87*4904Srs200217 "%u.%u.%u.%u.in-addr.arpa.", p[3], p[2], p[1], p[0]); 88*4904Srs200217 89*4904Srs200217 _nss_mdns_updatecfg(be); 90*4904Srs200217 return (_nss_mdns_querybyaddr(be, buffer, qdata.af, &qdata)); 91*4904Srs200217 } 92*4904Srs200217 93*4904Srs200217 /*ARGSUSED*/ 94*4904Srs200217 static nss_status_t 95*4904Srs200217 _nss_mdns_getent(be, args) 96*4904Srs200217 mdns_backend_ptr_t be; 97*4904Srs200217 void *args; 98*4904Srs200217 { 99*4904Srs200217 return (NSS_UNAVAIL); 100*4904Srs200217 } 101*4904Srs200217 102*4904Srs200217 /*ARGSUSED*/ 103*4904Srs200217 static nss_status_t 104*4904Srs200217 _nss_mdns_setent(be, dummy) 105*4904Srs200217 mdns_backend_ptr_t be; 106*4904Srs200217 void *dummy; 107*4904Srs200217 { 108*4904Srs200217 return (NSS_UNAVAIL); 109*4904Srs200217 } 110*4904Srs200217 111*4904Srs200217 /*ARGSUSED*/ 112*4904Srs200217 static nss_status_t 113*4904Srs200217 _nss_mdns_endent(be, dummy) 114*4904Srs200217 mdns_backend_ptr_t be; 115*4904Srs200217 void *dummy; 116*4904Srs200217 { 117*4904Srs200217 return (NSS_UNAVAIL); 118*4904Srs200217 } 119*4904Srs200217 120*4904Srs200217 /*ARGSUSED*/ 121*4904Srs200217 static nss_status_t 122*4904Srs200217 _nss_mdns_hosts_destr(be, dummy) 123*4904Srs200217 mdns_backend_ptr_t be; 124*4904Srs200217 void *dummy; 125*4904Srs200217 { 126*4904Srs200217 _nss_mdns_destr(be); 127*4904Srs200217 return (NSS_SUCCESS); 128*4904Srs200217 } 129*4904Srs200217 130*4904Srs200217 static mdns_backend_op_t host_ops[] = { 131*4904Srs200217 _nss_mdns_hosts_destr, 132*4904Srs200217 _nss_mdns_endent, 133*4904Srs200217 _nss_mdns_setent, 134*4904Srs200217 _nss_mdns_getent, 135*4904Srs200217 getbyname, 136*4904Srs200217 getbyaddr, 137*4904Srs200217 }; 138*4904Srs200217 139*4904Srs200217 /*ARGSUSED*/ 140*4904Srs200217 nss_backend_t * 141*4904Srs200217 _nss_mdns_hosts_constr(dummy1, dummy2, dummy3) 142*4904Srs200217 const char *dummy1, *dummy2, *dummy3; 143*4904Srs200217 { 144*4904Srs200217 return (_nss_mdns_constr(host_ops, 145*4904Srs200217 sizeof (host_ops) / sizeof (host_ops[0]))); 146*4904Srs200217 } 147*4904Srs200217 148*4904Srs200217 /*ARGSUSED*/ 149*4904Srs200217 nss_status_t 150*4904Srs200217 _nss_get_mdns_hosts_name(mdns_backend_ptr_t *be, void **bufp, size_t *sizep) 151*4904Srs200217 { 152*4904Srs200217 return (_nss_mdns_gethost_withttl(*bufp, *sizep, 0)); 153*4904Srs200217 } 154