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 52571Sjacobs * Common Development and Distribution License (the "License"). 62571Sjacobs * 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 /* 220Sstevel@tonic-gate * files/printers_getbyname.c -- "files" backend for 230Sstevel@tonic-gate * nsswitch "printers" database. 240Sstevel@tonic-gate * 252571Sjacobs * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 260Sstevel@tonic-gate * Use is subject to license terms. 270Sstevel@tonic-gate */ 280Sstevel@tonic-gate 290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate static const char *printers = "/etc/printers.conf"; 320Sstevel@tonic-gate 330Sstevel@tonic-gate #pragma weak _nss_files__printers_constr = _nss_files_printers_constr 340Sstevel@tonic-gate 350Sstevel@tonic-gate #include "files_common.h" 360Sstevel@tonic-gate #include <stdlib.h> 370Sstevel@tonic-gate #include <strings.h> 380Sstevel@tonic-gate 39*2830Sdjl static int 40*2830Sdjl check_name(nss_XbyY_args_t *argp, const char *line, int linelen) 41*2830Sdjl { 420Sstevel@tonic-gate 43*2830Sdjl const char *limit, *linep; 44*2830Sdjl const char *keyp = argp->key.name; 45*2830Sdjl int klen = strlen(keyp); 46*2830Sdjl 47*2830Sdjl linep = line; 48*2830Sdjl limit = line + linelen; 490Sstevel@tonic-gate 50*2830Sdjl /* 51*2830Sdjl * find the name in the namelist a|b|c...: 52*2830Sdjl */ 53*2830Sdjl while (linep+klen < limit && *linep != '|' && *linep != ':') { 54*2830Sdjl if ((strncmp(linep, keyp, klen) == 0) && 55*2830Sdjl ((*(linep + klen) == '|') || (*(linep + klen) == ':'))) { 56*2830Sdjl return (1); 57*2830Sdjl } else { 58*2830Sdjl while (linep < limit && *linep != '|' && *linep != ':') 59*2830Sdjl linep++; 60*2830Sdjl if (linep >= limit || *linep == ':') 61*2830Sdjl return (0); 62*2830Sdjl if (*linep == '|') 63*2830Sdjl linep++; 64*2830Sdjl } 65*2830Sdjl } 66*2830Sdjl return (0); 670Sstevel@tonic-gate } 680Sstevel@tonic-gate 690Sstevel@tonic-gate static nss_status_t 700Sstevel@tonic-gate getbyname(be, a) 710Sstevel@tonic-gate files_backend_ptr_t be; 720Sstevel@tonic-gate void *a; 730Sstevel@tonic-gate { 740Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; 750Sstevel@tonic-gate 76*2830Sdjl return (_nss_files_XY_all(be, argp, 1, argp->key.name, 77*2830Sdjl check_name)); 780Sstevel@tonic-gate } 790Sstevel@tonic-gate 800Sstevel@tonic-gate static files_backend_op_t printers_ops[] = { 810Sstevel@tonic-gate _nss_files_destr, 820Sstevel@tonic-gate _nss_files_endent, 830Sstevel@tonic-gate _nss_files_setent, 84*2830Sdjl _nss_files_getent_rigid, 850Sstevel@tonic-gate getbyname 860Sstevel@tonic-gate }; 870Sstevel@tonic-gate 88*2830Sdjl /*ARGSUSED*/ 890Sstevel@tonic-gate nss_backend_t * 900Sstevel@tonic-gate _nss_files_printers_constr(dummy1, dummy2, dummy3) 910Sstevel@tonic-gate const char *dummy1, *dummy2, *dummy3; 920Sstevel@tonic-gate { 930Sstevel@tonic-gate return (_nss_files_constr(printers_ops, 94*2830Sdjl sizeof (printers_ops) / sizeof (printers_ops[0]), 95*2830Sdjl printers, 96*2830Sdjl NSS_LINELEN_PRINTERS, 97*2830Sdjl NULL)); 980Sstevel@tonic-gate } 99