xref: /titanic_52/usr/src/lib/nsswitch/files/common/tsol_gettpent.c (revision cb5caa98562cf06753163f558cbcfe30b8f4673a)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
2745916cd2Sjpk 
2845916cd2Sjpk #include "files_common.h"
2945916cd2Sjpk #include <sys/tsol/tndb.h>
3045916cd2Sjpk #include <string.h>
3145916cd2Sjpk 
3245916cd2Sjpk /*
3345916cd2Sjpk  *	files/tsol_gettpent.c --
3445916cd2Sjpk  *           "files" backend for nsswitch "tnrhtp" database
3545916cd2Sjpk  */
3645916cd2Sjpk static int
37*cb5caa98Sdjl check_name(nss_XbyY_args_t *args, const char *line, int linelen)
3845916cd2Sjpk {
39*cb5caa98Sdjl 	const char	*limit, *linep, *keyp;
4045916cd2Sjpk 
41*cb5caa98Sdjl 	linep = line;
42*cb5caa98Sdjl 	limit = line + linelen;
43*cb5caa98Sdjl 	keyp = args->key.name;
44*cb5caa98Sdjl 
45*cb5caa98Sdjl 	/* compare template name, ':' is the seperator */
46*cb5caa98Sdjl 	while (*keyp && linep < limit && *linep != ':' && *keyp == *linep) {
47*cb5caa98Sdjl 		keyp++;
48*cb5caa98Sdjl 		linep++;
49*cb5caa98Sdjl 	}
50*cb5caa98Sdjl 	if (*keyp == '\0' && linep < limit && *linep == ':')
5145916cd2Sjpk 		return (1);
5245916cd2Sjpk 
5345916cd2Sjpk 	return (0);
5445916cd2Sjpk }
5545916cd2Sjpk 
5645916cd2Sjpk static nss_status_t
5745916cd2Sjpk getbyname(be, a)
5845916cd2Sjpk 	files_backend_ptr_t	be;
5945916cd2Sjpk 	void			*a;
6045916cd2Sjpk {
6145916cd2Sjpk 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *)a;
6245916cd2Sjpk 
63*cb5caa98Sdjl 	if (argp->key.name == NULL)
64*cb5caa98Sdjl 		return (NSS_NOTFOUND);
65*cb5caa98Sdjl 
6645916cd2Sjpk 	return (_nss_files_XY_all(be, argp, 1, argp->key.name, check_name));
6745916cd2Sjpk }
6845916cd2Sjpk 
6945916cd2Sjpk static files_backend_op_t tsol_tp_ops[] = {
7045916cd2Sjpk 	_nss_files_destr,
7145916cd2Sjpk 	_nss_files_endent,
7245916cd2Sjpk 	_nss_files_setent,
7345916cd2Sjpk 	_nss_files_getent_netdb,
7445916cd2Sjpk 	getbyname
7545916cd2Sjpk };
7645916cd2Sjpk nss_backend_t *
77*cb5caa98Sdjl /* LINTED E_FUNC_ARG_UNUSED */
7845916cd2Sjpk _nss_files_tnrhtp_constr(dummy1, dummy2, dummy3)
7945916cd2Sjpk 	const char	*dummy1, *dummy2, *dummy3;
8045916cd2Sjpk {
8145916cd2Sjpk 	return (_nss_files_constr(tsol_tp_ops,
8245916cd2Sjpk 				sizeof (tsol_tp_ops) / sizeof (tsol_tp_ops[0]),
8345916cd2Sjpk 				"/etc/security/tsol/tnrhtp",
8445916cd2Sjpk 				NSS_LINELEN_TSOL_TP,
8545916cd2Sjpk 				NULL));
8645916cd2Sjpk }
87