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