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 * files/printers_getbyname.c -- "files" backend for 23 * nsswitch "printers" database. 24 * 25 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 26 * Use is subject to license terms. 27 */ 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 static const char *printers = "/etc/printers.conf"; 32 33 #pragma weak _nss_files__printers_constr = _nss_files_printers_constr 34 35 #include "files_common.h" 36 #include <stdlib.h> 37 #include <strings.h> 38 39 static int 40 check_name(nss_XbyY_args_t *argp, const char *line, int linelen) 41 { 42 43 const char *limit, *linep; 44 const char *keyp = argp->key.name; 45 int klen = strlen(keyp); 46 47 linep = line; 48 limit = line + linelen; 49 50 /* 51 * find the name in the namelist a|b|c...: 52 */ 53 while (linep+klen < limit && *linep != '|' && *linep != ':') { 54 if ((strncmp(linep, keyp, klen) == 0) && 55 ((*(linep + klen) == '|') || (*(linep + klen) == ':'))) { 56 return (1); 57 } else { 58 while (linep < limit && *linep != '|' && *linep != ':') 59 linep++; 60 if (linep >= limit || *linep == ':') 61 return (0); 62 if (*linep == '|') 63 linep++; 64 } 65 } 66 return (0); 67 } 68 69 static nss_status_t 70 getbyname(be, a) 71 files_backend_ptr_t be; 72 void *a; 73 { 74 nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 75 76 return (_nss_files_XY_all(be, argp, 1, argp->key.name, 77 check_name)); 78 } 79 80 static files_backend_op_t printers_ops[] = { 81 _nss_files_destr, 82 _nss_files_endent, 83 _nss_files_setent, 84 _nss_files_getent_rigid, 85 getbyname 86 }; 87 88 /*ARGSUSED*/ 89 nss_backend_t * 90 _nss_files_printers_constr(dummy1, dummy2, dummy3) 91 const char *dummy1, *dummy2, *dummy3; 92 { 93 return (_nss_files_constr(printers_ops, 94 sizeof (printers_ops) / sizeof (printers_ops[0]), 95 printers, 96 NSS_LINELEN_PRINTERS, 97 NULL)); 98 } 99