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