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  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  *
25  * files/getspent.c -- "files" backend for nsswitch "shadow" database
26  */
27 
28 #include <shadow.h>
29 #include "files_common.h"
30 #include <strings.h>
31 
32 static int
check_spnamp(nss_XbyY_args_t * argp,const char * line,int linelen)33 check_spnamp(nss_XbyY_args_t *argp, const char *line, int linelen)
34 {
35 	const char *linep = line;
36 	const char *keyp = argp->key.name;
37 
38 	/* +/- entries valid for compat source only */
39 	if (linelen == 0 || *line == '+' || *line == '-')
40 		return (0);
41 	while (*keyp && linelen-- && *keyp == *linep) {
42 		keyp++;
43 		linep++;
44 	}
45 	return (linelen && *keyp == '\0' && *linep == ':');
46 }
47 
48 static nss_status_t
getbyname(be,a)49 getbyname(be, a)
50 	files_backend_ptr_t	be;
51 	void			*a;
52 {
53 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *)a;
54 
55 	return (_nss_files_XY_all(be, argp, 0, argp->key.name, check_spnamp));
56 }
57 
58 static files_backend_op_t shadow_ops[] = {
59 	_nss_files_destr,
60 	_nss_files_endent,
61 	_nss_files_setent,
62 	_nss_files_getent_rigid,
63 	getbyname
64 };
65 
66 /*ARGSUSED*/
67 nss_backend_t *
_nss_files_shadow_constr(dummy1,dummy2,dummy3)68 _nss_files_shadow_constr(dummy1, dummy2, dummy3)
69 	const char	*dummy1, *dummy2, *dummy3;
70 {
71 	return (_nss_files_constr(shadow_ops,
72 				sizeof (shadow_ops) / sizeof (shadow_ops[0]),
73 				SHADOW,
74 				NSS_LINELEN_SHADOW,
75 				NULL));
76 }
77