10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*2830Sdjl * Common Development and Distribution License (the "License").
6*2830Sdjl * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*2830Sdjl * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23*2830Sdjl * Use is subject to license terms.
240Sstevel@tonic-gate *
250Sstevel@tonic-gate * nis/gethostent.c -- "nis" backend for nsswitch "hosts" database
260Sstevel@tonic-gate */
270Sstevel@tonic-gate
280Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
290Sstevel@tonic-gate
300Sstevel@tonic-gate #include <ctype.h>
310Sstevel@tonic-gate #include <netdb.h>
320Sstevel@tonic-gate #include <stdio.h>
330Sstevel@tonic-gate #include <string.h>
340Sstevel@tonic-gate #include <netinet/in.h>
350Sstevel@tonic-gate #include <arpa/inet.h>
360Sstevel@tonic-gate #include <sys/socket.h>
370Sstevel@tonic-gate #include "nis_common.h"
380Sstevel@tonic-gate #include <stdlib.h>
390Sstevel@tonic-gate
400Sstevel@tonic-gate static nss_status_t
getbyname(be,a)410Sstevel@tonic-gate getbyname(be, a)
420Sstevel@tonic-gate nis_backend_ptr_t be;
430Sstevel@tonic-gate void *a;
440Sstevel@tonic-gate {
45*2830Sdjl nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
460Sstevel@tonic-gate nss_status_t res;
470Sstevel@tonic-gate
480Sstevel@tonic-gate const char *s;
490Sstevel@tonic-gate char c;
500Sstevel@tonic-gate
510Sstevel@tonic-gate for (s = argp->key.name; (c = *s) != '\0'; s++) {
520Sstevel@tonic-gate if (isupper(c)) {
530Sstevel@tonic-gate char *copy;
540Sstevel@tonic-gate char *mung;
550Sstevel@tonic-gate
560Sstevel@tonic-gate if ((copy = strdup(argp->key.name)) == 0) {
570Sstevel@tonic-gate return (NSS_UNAVAIL);
580Sstevel@tonic-gate }
590Sstevel@tonic-gate for (mung = copy + (s - argp->key.name);
600Sstevel@tonic-gate (c = *mung) != '\0'; mung++) {
610Sstevel@tonic-gate if (isupper(c)) {
620Sstevel@tonic-gate *mung = _tolower(c);
630Sstevel@tonic-gate }
640Sstevel@tonic-gate }
650Sstevel@tonic-gate res = _nss_nis_lookup(be, argp, 1, "hosts.byname",
660Sstevel@tonic-gate copy, 0);
670Sstevel@tonic-gate free(copy);
680Sstevel@tonic-gate argp->h_errno = __nss2herrno(res);
690Sstevel@tonic-gate return (res);
700Sstevel@tonic-gate }
710Sstevel@tonic-gate }
720Sstevel@tonic-gate res = _nss_nis_lookup(be, argp, 1,
730Sstevel@tonic-gate "hosts.byname", argp->key.name, 0);
740Sstevel@tonic-gate if (res != NSS_SUCCESS)
750Sstevel@tonic-gate argp->h_errno = __nss2herrno(res);
760Sstevel@tonic-gate return (res);
770Sstevel@tonic-gate }
780Sstevel@tonic-gate
790Sstevel@tonic-gate static nss_status_t
getbyaddr(be,a)800Sstevel@tonic-gate getbyaddr(be, a)
810Sstevel@tonic-gate nis_backend_ptr_t be;
820Sstevel@tonic-gate void *a;
830Sstevel@tonic-gate {
84*2830Sdjl nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
850Sstevel@tonic-gate struct in_addr addr;
860Sstevel@tonic-gate char buf[18];
870Sstevel@tonic-gate nss_status_t res;
880Sstevel@tonic-gate extern char *inet_ntoa_r(); /* not an advertised function from */
890Sstevel@tonic-gate /* libnsl (no man page), so no */
900Sstevel@tonic-gate /* prototype. */
910Sstevel@tonic-gate
920Sstevel@tonic-gate /* === Do we really want to be this pedantic? */
930Sstevel@tonic-gate if (argp->key.hostaddr.type != AF_INET ||
940Sstevel@tonic-gate argp->key.hostaddr.len != sizeof (addr)) {
950Sstevel@tonic-gate return (NSS_NOTFOUND);
960Sstevel@tonic-gate }
97*2830Sdjl (void) memcpy(&addr, argp->key.hostaddr.addr, sizeof (addr));
980Sstevel@tonic-gate res = _nss_nis_lookup(be, argp, 1, "hosts.byaddr",
990Sstevel@tonic-gate inet_ntoa_r(addr, buf), 0);
1000Sstevel@tonic-gate if (res != NSS_SUCCESS)
1010Sstevel@tonic-gate argp->h_errno = __nss2herrno(res);
1020Sstevel@tonic-gate return (res);
1030Sstevel@tonic-gate }
1040Sstevel@tonic-gate
1050Sstevel@tonic-gate
1060Sstevel@tonic-gate static nis_backend_op_t host_ops[] = {
1070Sstevel@tonic-gate _nss_nis_destr,
1080Sstevel@tonic-gate _nss_nis_endent,
1090Sstevel@tonic-gate _nss_nis_setent,
1100Sstevel@tonic-gate _nss_nis_getent_netdb,
1110Sstevel@tonic-gate getbyname,
1120Sstevel@tonic-gate getbyaddr
1130Sstevel@tonic-gate };
1140Sstevel@tonic-gate
1150Sstevel@tonic-gate /*ARGSUSED*/
1160Sstevel@tonic-gate nss_backend_t *
_nss_nis_hosts_constr(dummy1,dummy2,dummy3)1170Sstevel@tonic-gate _nss_nis_hosts_constr(dummy1, dummy2, dummy3)
1180Sstevel@tonic-gate const char *dummy1, *dummy2, *dummy3;
1190Sstevel@tonic-gate {
1200Sstevel@tonic-gate return (_nss_nis_constr(host_ops,
1210Sstevel@tonic-gate sizeof (host_ops) / sizeof (host_ops[0]),
1220Sstevel@tonic-gate "hosts.byaddr"));
1230Sstevel@tonic-gate }
124