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  * files/getrpcent.c -- "files" backend for nsswitch "rpc" database
26  */
27 
28 #include <rpc/rpcent.h>
29 #include "files_common.h"
30 #include <strings.h>
31 #include <ctype.h>
32 #include <stdlib.h>
33 
34 static nss_status_t
getbyname(be,a)35 getbyname(be, a)
36 	files_backend_ptr_t	be;
37 	void			*a;
38 {
39 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *)a;
40 
41 	return (_nss_files_XY_all(be, argp, 1, argp->key.name,
42 			_nss_files_check_name_aliases));
43 }
44 
45 static int
check_rpcnum(nss_XbyY_args_t * argp,const char * line,int linelen)46 check_rpcnum(nss_XbyY_args_t *argp, const char *line, int linelen)
47 {
48 	int		r_number;
49 	const char	*limit, *linep;
50 
51 	linep = line;
52 	limit = line + linelen;
53 
54 	/* skip name */
55 	while (linep < limit && !isspace(*linep))
56 		linep++;
57 	/* skip the delimiting spaces */
58 	while (linep < limit && isspace(*linep))
59 		linep++;
60 	if (linep == limit)
61 		return (0);
62 	r_number = (int)strtol(linep, NULL, 10);
63 	return (r_number == argp->key.number);
64 }
65 
66 
67 static nss_status_t
getbynumber(be,a)68 getbynumber(be, a)
69 	files_backend_ptr_t	be;
70 	void			*a;
71 {
72 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *)a;
73 	char			numstr[12];
74 
75 	(void) snprintf(numstr, 12, "%d", argp->key.number);
76 	return (_nss_files_XY_all(be, argp, 1, numstr, check_rpcnum));
77 }
78 
79 static files_backend_op_t rpc_ops[] = {
80 	_nss_files_destr,
81 	_nss_files_endent,
82 	_nss_files_setent,
83 	_nss_files_getent_netdb,
84 	getbyname,
85 	getbynumber
86 };
87 
88 /*ARGSUSED*/
89 nss_backend_t *
_nss_files_rpc_constr(dummy1,dummy2,dummy3)90 _nss_files_rpc_constr(dummy1, dummy2, dummy3)
91 	const char	*dummy1, *dummy2, *dummy3;
92 {
93 	return (_nss_files_constr(rpc_ops,
94 				sizeof (rpc_ops) / sizeof (rpc_ops[0]),
95 				"/etc/rpc",
96 				NSS_LINELEN_RPC,
97 				NULL));
98 }
99