xref: /titanic_41/usr/src/lib/nsswitch/files/common/getspent.c (revision 35a5a3587fd94b666239c157d3722745250ccbd7)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 #include <shadow.h>
31 #include "files_common.h"
32 #include <strings.h>
33 
34 static int
35 check_spnamp(nss_XbyY_args_t *argp, const char *line, int linelen)
36 {
37 	const char *linep = line;
38 	const char *keyp = argp->key.name;
39 
40 	/* +/- entries valid for compat source only */
41 	if (linelen == 0 || *line == '+' || *line == '-')
42 		return (0);
43 	while (*keyp && linelen-- && *keyp == *linep) {
44 		keyp++;
45 		linep++;
46 	}
47 	return (linelen && *keyp == '\0' && *linep == ':');
48 }
49 
50 static nss_status_t
51 getbyname(be, a)
52 	files_backend_ptr_t	be;
53 	void			*a;
54 {
55 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *)a;
56 
57 	return (_nss_files_XY_all(be, argp, 0, argp->key.name, check_spnamp));
58 }
59 
60 static files_backend_op_t shadow_ops[] = {
61 	_nss_files_destr,
62 	_nss_files_endent,
63 	_nss_files_setent,
64 	_nss_files_getent_rigid,
65 	getbyname
66 };
67 
68 /*ARGSUSED*/
69 nss_backend_t *
70 _nss_files_shadow_constr(dummy1, dummy2, dummy3)
71 	const char	*dummy1, *dummy2, *dummy3;
72 {
73 	return (_nss_files_constr(shadow_ops,
74 				sizeof (shadow_ops) / sizeof (shadow_ops[0]),
75 				SHADOW,
76 				NSS_LINELEN_SHADOW,
77 				NULL));
78 }
79