xref: /illumos-gate/usr/src/lib/nsswitch/files/common/tsol_gettpent.c (revision 581cede61ac9c14d8d4ea452562a567189eead78)
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 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include "files_common.h"
29 #include <sys/tsol/tndb.h>
30 #include <string.h>
31 
32 /*
33  *	files/tsol_gettpent.c --
34  *           "files" backend for nsswitch "tnrhtp" database
35  */
36 static int
37 check_name(nss_XbyY_args_t *args, const char *line, int linelen)
38 {
39 	const char	*limit, *linep, *keyp;
40 
41 	linep = line;
42 	limit = line + linelen;
43 	keyp = args->key.name;
44 
45 	/* compare template name, ':' is the seperator */
46 	while (*keyp && linep < limit && *linep != ':' && *keyp == *linep) {
47 		keyp++;
48 		linep++;
49 	}
50 	if (*keyp == '\0' && linep < limit && *linep == ':')
51 		return (1);
52 
53 	return (0);
54 }
55 
56 static nss_status_t
57 getbyname(be, a)
58 	files_backend_ptr_t	be;
59 	void			*a;
60 {
61 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *)a;
62 
63 	if (argp->key.name == NULL)
64 		return (NSS_NOTFOUND);
65 
66 	return (_nss_files_XY_all(be, argp, 1, argp->key.name, check_name));
67 }
68 
69 static files_backend_op_t tsol_tp_ops[] = {
70 	_nss_files_destr,
71 	_nss_files_endent,
72 	_nss_files_setent,
73 	_nss_files_getent_netdb,
74 	getbyname
75 };
76 nss_backend_t *
77 /* LINTED E_FUNC_ARG_UNUSED */
78 _nss_files_tnrhtp_constr(dummy1, dummy2, dummy3)
79 	const char	*dummy1, *dummy2, *dummy3;
80 {
81 	return (_nss_files_constr(tsol_tp_ops,
82 				sizeof (tsol_tp_ops) / sizeof (tsol_tp_ops[0]),
83 				"/etc/security/tsol/tnrhtp",
84 				NSS_LINELEN_TSOL_TP,
85 				NULL));
86 }
87