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/getprotoent.c -- "files" backend for nsswitch "protocols" database 260Sstevel@tonic-gate */ 270Sstevel@tonic-gate 280Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 290Sstevel@tonic-gate 300Sstevel@tonic-gate #include <netdb.h> 310Sstevel@tonic-gate #include "files_common.h" 320Sstevel@tonic-gate #include <strings.h> 33*2830Sdjl #include <ctype.h> 34*2830Sdjl #include <stdlib.h> 350Sstevel@tonic-gate 360Sstevel@tonic-gate static nss_status_t 370Sstevel@tonic-gate getbyname(be, a) 380Sstevel@tonic-gate files_backend_ptr_t be; 390Sstevel@tonic-gate void *a; 400Sstevel@tonic-gate { 41*2830Sdjl nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 420Sstevel@tonic-gate 43*2830Sdjl return (_nss_files_XY_all(be, argp, 1, argp->key.name, 44*2830Sdjl _nss_files_check_name_aliases)); 450Sstevel@tonic-gate } 460Sstevel@tonic-gate 470Sstevel@tonic-gate static int 48*2830Sdjl check_addr(nss_XbyY_args_t *argp, const char *line, int linelen) 490Sstevel@tonic-gate { 50*2830Sdjl int proto; 51*2830Sdjl const char *limit, *linep; 52*2830Sdjl 53*2830Sdjl linep = line; 54*2830Sdjl limit = line + linelen; 550Sstevel@tonic-gate 56*2830Sdjl /* skip name */ 57*2830Sdjl while (linep < limit && !isspace(*linep)) 58*2830Sdjl linep++; 59*2830Sdjl /* skip the delimiting spaces */ 60*2830Sdjl while (linep < limit && isspace(*linep)) 61*2830Sdjl linep++; 62*2830Sdjl if (linep == limit) 63*2830Sdjl return (0); 64*2830Sdjl proto = (int)strtol(linep, NULL, 10); 65*2830Sdjl return (proto == argp->key.number); 660Sstevel@tonic-gate } 670Sstevel@tonic-gate 680Sstevel@tonic-gate static nss_status_t 690Sstevel@tonic-gate getbynumber(be, a) 700Sstevel@tonic-gate files_backend_ptr_t be; 710Sstevel@tonic-gate void *a; 720Sstevel@tonic-gate { 73*2830Sdjl nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 740Sstevel@tonic-gate char numstr[12]; 750Sstevel@tonic-gate 76*2830Sdjl (void) snprintf(numstr, 12, "%d", argp->key.number); 770Sstevel@tonic-gate return (_nss_files_XY_all(be, argp, 1, 0, check_addr)); 780Sstevel@tonic-gate } 790Sstevel@tonic-gate 800Sstevel@tonic-gate static files_backend_op_t proto_ops[] = { 810Sstevel@tonic-gate _nss_files_destr, 820Sstevel@tonic-gate _nss_files_endent, 830Sstevel@tonic-gate _nss_files_setent, 840Sstevel@tonic-gate _nss_files_getent_netdb, 850Sstevel@tonic-gate getbyname, 860Sstevel@tonic-gate getbynumber 870Sstevel@tonic-gate }; 880Sstevel@tonic-gate 890Sstevel@tonic-gate /*ARGSUSED*/ 900Sstevel@tonic-gate nss_backend_t * 910Sstevel@tonic-gate _nss_files_protocols_constr(dummy1, dummy2, dummy3) 920Sstevel@tonic-gate const char *dummy1, *dummy2, *dummy3; 930Sstevel@tonic-gate { 940Sstevel@tonic-gate return (_nss_files_constr(proto_ops, 950Sstevel@tonic-gate sizeof (proto_ops) / sizeof (proto_ops[0]), 960Sstevel@tonic-gate _PATH_PROTOCOLS, 970Sstevel@tonic-gate NSS_LINELEN_PROTOCOLS, 980Sstevel@tonic-gate NULL)); 990Sstevel@tonic-gate } 100