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 * 25*2830Sdjl * files/getnetent.c -- "files" backend for nsswitch "networks" database 260Sstevel@tonic-gate */ 270Sstevel@tonic-gate 280Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 290Sstevel@tonic-gate 300Sstevel@tonic-gate 31*2830Sdjl #include <sys/types.h> 32*2830Sdjl #include <sys/socket.h> 33*2830Sdjl #include <netinet/in.h> 34*2830Sdjl #include <arpa/inet.h> 350Sstevel@tonic-gate #include <netdb.h> 360Sstevel@tonic-gate #include "files_common.h" 370Sstevel@tonic-gate #include <strings.h> 38*2830Sdjl #include <ctype.h> 390Sstevel@tonic-gate 400Sstevel@tonic-gate static nss_status_t 410Sstevel@tonic-gate getbyname(be, a) 420Sstevel@tonic-gate files_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 47*2830Sdjl return (_nss_files_XY_all(be, argp, 1, argp->key.name, 48*2830Sdjl _nss_files_check_name_aliases)); 490Sstevel@tonic-gate } 500Sstevel@tonic-gate 510Sstevel@tonic-gate static int 52*2830Sdjl check_addr(nss_XbyY_args_t *argp, const char *line, int linelen) 530Sstevel@tonic-gate { 54*2830Sdjl 55*2830Sdjl const char *limit, *linep, *addrstart; 56*2830Sdjl int addrlen; 57*2830Sdjl char addrbuf[NSS_LINELEN_NETWORKS]; 58*2830Sdjl in_addr_t linenet; 59*2830Sdjl 60*2830Sdjl linep = line; 61*2830Sdjl limit = line + linelen; 620Sstevel@tonic-gate 63*2830Sdjl /* skip network name */ 64*2830Sdjl while (linep < limit && !isspace(*linep)) 65*2830Sdjl linep++; 66*2830Sdjl /* skip the delimiting spaces */ 67*2830Sdjl while (linep < limit && isspace(*linep)) 68*2830Sdjl linep++; 69*2830Sdjl if (linep == limit) 70*2830Sdjl return (0); 71*2830Sdjl 72*2830Sdjl addrstart = linep; 73*2830Sdjl while (linep < limit && !isspace(*linep)) 74*2830Sdjl linep++; 75*2830Sdjl addrlen = linep - addrstart; 76*2830Sdjl if (addrlen < sizeof (addrbuf)) { 77*2830Sdjl (void) memcpy(addrbuf, addrstart, addrlen); 78*2830Sdjl addrbuf[addrlen] = '\0'; 79*2830Sdjl if ((linenet = inet_network(addrbuf)) == 80*2830Sdjl (in_addr_t)0xffffffffU) 81*2830Sdjl return (0); 82*2830Sdjl return (AF_INET == argp->key.netaddr.type && 83*2830Sdjl linenet == argp->key.netaddr.net); 84*2830Sdjl } 85*2830Sdjl return (0); 860Sstevel@tonic-gate } 870Sstevel@tonic-gate 880Sstevel@tonic-gate static nss_status_t 890Sstevel@tonic-gate getbyaddr(be, a) 900Sstevel@tonic-gate files_backend_ptr_t be; 910Sstevel@tonic-gate void *a; 920Sstevel@tonic-gate { 93*2830Sdjl nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 940Sstevel@tonic-gate 950Sstevel@tonic-gate return (_nss_files_XY_all(be, argp, 1, 0, check_addr)); 960Sstevel@tonic-gate } 970Sstevel@tonic-gate 980Sstevel@tonic-gate static files_backend_op_t net_ops[] = { 990Sstevel@tonic-gate _nss_files_destr, 1000Sstevel@tonic-gate _nss_files_endent, 1010Sstevel@tonic-gate _nss_files_setent, 1020Sstevel@tonic-gate _nss_files_getent_netdb, 1030Sstevel@tonic-gate getbyname, 1040Sstevel@tonic-gate getbyaddr 1050Sstevel@tonic-gate }; 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate /*ARGSUSED*/ 1080Sstevel@tonic-gate nss_backend_t * 1090Sstevel@tonic-gate _nss_files_networks_constr(dummy1, dummy2, dummy3) 1100Sstevel@tonic-gate const char *dummy1, *dummy2, *dummy3; 1110Sstevel@tonic-gate { 1120Sstevel@tonic-gate return (_nss_files_constr(net_ops, 1130Sstevel@tonic-gate sizeof (net_ops) / sizeof (net_ops[0]), 1140Sstevel@tonic-gate _PATH_NETWORKS, 1150Sstevel@tonic-gate NSS_LINELEN_NETWORKS, 1160Sstevel@tonic-gate NULL)); 1170Sstevel@tonic-gate } 118