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, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * 24 * Copyright (c) 1988-1995 Sun Microsystems Inc 25 * All Rights Reserved. 26 * 27 * files/getnetent.c -- "files" backend for nsswitch "networks" database 28 */ 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 33 #include <netdb.h> 34 #include "files_common.h" 35 #include <strings.h> 36 37 static int 38 check_name(args) 39 nss_XbyY_args_t *args; 40 { 41 struct netent *net = (struct netent *)args->returnval; 42 const char *name = args->key.name; 43 char **aliasp; 44 45 if (strcmp(net->n_name, name) == 0) 46 return (1); 47 for (aliasp = net->n_aliases; *aliasp != 0; aliasp++) { 48 if (strcmp(*aliasp, name) == 0) 49 return (1); 50 } 51 return (0); 52 } 53 54 static nss_status_t 55 getbyname(be, a) 56 files_backend_ptr_t be; 57 void *a; 58 { 59 nss_XbyY_args_t *argp = (nss_XbyY_args_t *) a; 60 61 return (_nss_files_XY_all(be, argp, 1, argp->key.name, check_name)); 62 } 63 64 static int 65 check_addr(args) 66 nss_XbyY_args_t *args; 67 { 68 struct netent *net = (struct netent *)args->returnval; 69 70 return ((net->n_addrtype == args->key.netaddr.type) && 71 (net->n_net == args->key.netaddr.net)); 72 } 73 74 static nss_status_t 75 getbyaddr(be, a) 76 files_backend_ptr_t be; 77 void *a; 78 { 79 nss_XbyY_args_t *argp = (nss_XbyY_args_t *) a; 80 81 return (_nss_files_XY_all(be, argp, 1, 0, check_addr)); 82 } 83 84 static files_backend_op_t net_ops[] = { 85 _nss_files_destr, 86 _nss_files_endent, 87 _nss_files_setent, 88 _nss_files_getent_netdb, 89 getbyname, 90 getbyaddr 91 }; 92 93 /*ARGSUSED*/ 94 nss_backend_t * 95 _nss_files_networks_constr(dummy1, dummy2, dummy3) 96 const char *dummy1, *dummy2, *dummy3; 97 { 98 return (_nss_files_constr(net_ops, 99 sizeof (net_ops) / sizeof (net_ops[0]), 100 _PATH_NETWORKS, 101 NSS_LINELEN_NETWORKS, 102 NULL)); 103 } 104