xref: /titanic_44/usr/src/lib/nsswitch/files/common/tsol_getrhent.c (revision 587032cf0967234b39ccb50adca936a367841063)
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 <string.h>
30 #include <libtsnet.h>
31 
32 /*
33  *	files/tsol_getrhent.c --
34  *           "files" backend for nsswitch "tnrhdb" database
35  */
36 static int
37 check_addr(nss_XbyY_args_t *args)
38 {
39 	tsol_rhstr_t *rhstrp = (tsol_rhstr_t *)args->returnval;
40 
41 	if ((args->key.hostaddr.type == rhstrp->family) &&
42 	    (strcmp(args->key.hostaddr.addr, rhstrp->address) == 0))
43 		return (1);
44 
45 	return (0);
46 }
47 
48 static nss_status_t
49 getbyaddr(files_backend_ptr_t be, void *a)
50 {
51 	nss_XbyY_args_t *argp = a;
52 
53 	return (_nss_files_XY_all(be, argp, 1,
54 		argp->key.hostaddr.addr, check_addr));
55 }
56 
57 static files_backend_op_t tsol_rh_ops[] = {
58 	_nss_files_destr,
59 	_nss_files_endent,
60 	_nss_files_setent,
61 	_nss_files_getent_netdb,
62 	getbyaddr
63 };
64 
65 /* ARGSUSED */
66 nss_backend_t *
67 _nss_files_tnrhdb_constr(const char *dummy1, const char *dummy2,
68     const char *dummy3)
69 {
70 	return (_nss_files_constr(tsol_rh_ops,
71 	    sizeof (tsol_rh_ops) / sizeof (tsol_rh_ops[0]), TNRHDB_PATH,
72 	    NSS_LINELEN_TSOL_RH, NULL));
73 }
74