145916cd2Sjpk /*
245916cd2Sjpk  * CDDL HEADER START
345916cd2Sjpk  *
445916cd2Sjpk  * The contents of this file are subject to the terms of the
545916cd2Sjpk  * Common Development and Distribution License (the "License").
645916cd2Sjpk  * You may not use this file except in compliance with the License.
745916cd2Sjpk  *
845916cd2Sjpk  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
945916cd2Sjpk  * or http://www.opensolaris.org/os/licensing.
1045916cd2Sjpk  * See the License for the specific language governing permissions
1145916cd2Sjpk  * and limitations under the License.
1245916cd2Sjpk  *
1345916cd2Sjpk  * When distributing Covered Code, include this CDDL HEADER in each
1445916cd2Sjpk  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1545916cd2Sjpk  * If applicable, add the following below this CDDL HEADER, with the
1645916cd2Sjpk  * fields enclosed by brackets "[]" replaced with your own identifying
1745916cd2Sjpk  * information: Portions Copyright [yyyy] [name of copyright owner]
1845916cd2Sjpk  *
1945916cd2Sjpk  * CDDL HEADER END
2045916cd2Sjpk  */
2145916cd2Sjpk /*
2245916cd2Sjpk  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
2345916cd2Sjpk  * Use is subject to license terms.
2445916cd2Sjpk  */
2545916cd2Sjpk 
2645916cd2Sjpk #include "files_common.h"
2745916cd2Sjpk #include <sys/tsol/tndb.h>
2845916cd2Sjpk #include <string.h>
2945916cd2Sjpk 
3045916cd2Sjpk /*
3145916cd2Sjpk  *	files/tsol_gettpent.c --
3245916cd2Sjpk  *           "files" backend for nsswitch "tnrhtp" database
3345916cd2Sjpk  */
3445916cd2Sjpk static int
check_name(nss_XbyY_args_t * args,const char * line,int linelen)35*cb5caa98Sdjl check_name(nss_XbyY_args_t *args, const char *line, int linelen)
3645916cd2Sjpk {
37*cb5caa98Sdjl 	const char	*limit, *linep, *keyp;
3845916cd2Sjpk 
39*cb5caa98Sdjl 	linep = line;
40*cb5caa98Sdjl 	limit = line + linelen;
41*cb5caa98Sdjl 	keyp = args->key.name;
42*cb5caa98Sdjl 
43*cb5caa98Sdjl 	/* compare template name, ':' is the seperator */
44*cb5caa98Sdjl 	while (*keyp && linep < limit && *linep != ':' && *keyp == *linep) {
45*cb5caa98Sdjl 		keyp++;
46*cb5caa98Sdjl 		linep++;
47*cb5caa98Sdjl 	}
48*cb5caa98Sdjl 	if (*keyp == '\0' && linep < limit && *linep == ':')
4945916cd2Sjpk 		return (1);
5045916cd2Sjpk 
5145916cd2Sjpk 	return (0);
5245916cd2Sjpk }
5345916cd2Sjpk 
5445916cd2Sjpk static nss_status_t
getbyname(be,a)5545916cd2Sjpk getbyname(be, a)
5645916cd2Sjpk 	files_backend_ptr_t	be;
5745916cd2Sjpk 	void			*a;
5845916cd2Sjpk {
5945916cd2Sjpk 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *)a;
6045916cd2Sjpk 
61*cb5caa98Sdjl 	if (argp->key.name == NULL)
62*cb5caa98Sdjl 		return (NSS_NOTFOUND);
63*cb5caa98Sdjl 
6445916cd2Sjpk 	return (_nss_files_XY_all(be, argp, 1, argp->key.name, check_name));
6545916cd2Sjpk }
6645916cd2Sjpk 
6745916cd2Sjpk static files_backend_op_t tsol_tp_ops[] = {
6845916cd2Sjpk 	_nss_files_destr,
6945916cd2Sjpk 	_nss_files_endent,
7045916cd2Sjpk 	_nss_files_setent,
7145916cd2Sjpk 	_nss_files_getent_netdb,
7245916cd2Sjpk 	getbyname
7345916cd2Sjpk };
7445916cd2Sjpk nss_backend_t *
75*cb5caa98Sdjl /* LINTED E_FUNC_ARG_UNUSED */
_nss_files_tnrhtp_constr(dummy1,dummy2,dummy3)7645916cd2Sjpk _nss_files_tnrhtp_constr(dummy1, dummy2, dummy3)
7745916cd2Sjpk 	const char	*dummy1, *dummy2, *dummy3;
7845916cd2Sjpk {
7945916cd2Sjpk 	return (_nss_files_constr(tsol_tp_ops,
8045916cd2Sjpk 				sizeof (tsol_tp_ops) / sizeof (tsol_tp_ops[0]),
8145916cd2Sjpk 				"/etc/security/tsol/tnrhtp",
8245916cd2Sjpk 				NSS_LINELEN_TSOL_TP,
8345916cd2Sjpk 				NULL));
8445916cd2Sjpk }
85