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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *	Copyright (c) 1988-1995 Sun Microsystems Inc
24  *	All Rights Reserved.
25  *
26  *	files/getrpcent.c -- "files" backend for nsswitch "rpc" database
27  */
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <rpc/rpcent.h>
32 #include "files_common.h"
33 #include <strings.h>
34 
35 static int
36 check_name(args)
37 	nss_XbyY_args_t		*args;
38 {
39 	struct rpcent		*rpc	= (struct rpcent *) args->returnval;
40 	const char		*name	= args->key.name;
41 	char			**aliasp;
42 
43 	if (strcmp(rpc->r_name, name) == 0) {
44 		return (1);
45 	}
46 	for (aliasp = rpc->r_aliases;  *aliasp != 0;  aliasp++) {
47 		if (strcmp(*aliasp, name) == 0) {
48 			return (1);
49 		}
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 	return (_nss_files_XY_all(be, argp, 1, argp->key.name, check_name));
62 }
63 
64 static int
65 check_rpcnum(argp)
66 	nss_XbyY_args_t		*argp;
67 {
68 	struct rpcent		*rpc = (struct rpcent *) argp->returnval;
69 
70 	return (rpc->r_number == argp->key.number);
71 }
72 
73 
74 static nss_status_t
75 getbynumber(be, a)
76 	files_backend_ptr_t	be;
77 	void			*a;
78 {
79 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *) a;
80 	char			numstr[12];
81 
82 	sprintf(numstr, "%d", argp->key.number);
83 	return (_nss_files_XY_all(be, argp, 1, numstr, check_rpcnum));
84 }
85 
86 static files_backend_op_t rpc_ops[] = {
87 	_nss_files_destr,
88 	_nss_files_endent,
89 	_nss_files_setent,
90 	_nss_files_getent_netdb,
91 	getbyname,
92 	getbynumber
93 };
94 
95 /*ARGSUSED*/
96 nss_backend_t *
97 _nss_files_rpc_constr(dummy1, dummy2, dummy3)
98 	const char	*dummy1, *dummy2, *dummy3;
99 {
100 	return (_nss_files_constr(rpc_ops,
101 				sizeof (rpc_ops) / sizeof (rpc_ops[0]),
102 				"/etc/rpc",
103 				NSS_LINELEN_RPC,
104 				NULL));
105 }
106