xref: /onnv-gate/usr/src/lib/nsswitch/files/common/getspent.c (revision 2830:5228d1267a01)
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/getspent.c -- "files" backend for nsswitch "shadow" database
260Sstevel@tonic-gate  */
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #include <shadow.h>
310Sstevel@tonic-gate #include "files_common.h"
320Sstevel@tonic-gate #include <strings.h>
330Sstevel@tonic-gate 
340Sstevel@tonic-gate static int
check_spnamp(nss_XbyY_args_t * argp,const char * line,int linelen)35*2830Sdjl check_spnamp(nss_XbyY_args_t *argp, const char *line, int linelen)
360Sstevel@tonic-gate {
37*2830Sdjl 	const char *linep = line;
38*2830Sdjl 	const char *keyp = argp->key.name;
390Sstevel@tonic-gate 
40*2830Sdjl 	/* +/- entries valid for compat source only */
41*2830Sdjl 	if (linelen == 0 || *line == '+' || *line == '-')
420Sstevel@tonic-gate 		return (0);
43*2830Sdjl 	while (*keyp && linelen-- && *keyp == *linep) {
44*2830Sdjl 		keyp++;
45*2830Sdjl 		linep++;
46*2830Sdjl 	}
47*2830Sdjl 	return (linelen && *keyp == '\0' && *linep == ':');
480Sstevel@tonic-gate }
490Sstevel@tonic-gate 
500Sstevel@tonic-gate static nss_status_t
getbyname(be,a)510Sstevel@tonic-gate getbyname(be, a)
520Sstevel@tonic-gate 	files_backend_ptr_t	be;
530Sstevel@tonic-gate 	void			*a;
540Sstevel@tonic-gate {
55*2830Sdjl 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *)a;
560Sstevel@tonic-gate 
570Sstevel@tonic-gate 	return (_nss_files_XY_all(be, argp, 0, argp->key.name, check_spnamp));
580Sstevel@tonic-gate }
590Sstevel@tonic-gate 
600Sstevel@tonic-gate static files_backend_op_t shadow_ops[] = {
610Sstevel@tonic-gate 	_nss_files_destr,
620Sstevel@tonic-gate 	_nss_files_endent,
630Sstevel@tonic-gate 	_nss_files_setent,
640Sstevel@tonic-gate 	_nss_files_getent_rigid,
650Sstevel@tonic-gate 	getbyname
660Sstevel@tonic-gate };
670Sstevel@tonic-gate 
680Sstevel@tonic-gate /*ARGSUSED*/
690Sstevel@tonic-gate nss_backend_t *
_nss_files_shadow_constr(dummy1,dummy2,dummy3)700Sstevel@tonic-gate _nss_files_shadow_constr(dummy1, dummy2, dummy3)
710Sstevel@tonic-gate 	const char	*dummy1, *dummy2, *dummy3;
720Sstevel@tonic-gate {
730Sstevel@tonic-gate 	return (_nss_files_constr(shadow_ops,
740Sstevel@tonic-gate 				sizeof (shadow_ops) / sizeof (shadow_ops[0]),
750Sstevel@tonic-gate 				SHADOW,
760Sstevel@tonic-gate 				NSS_LINELEN_SHADOW,
770Sstevel@tonic-gate 				NULL));
780Sstevel@tonic-gate }
79