xref: /onnv-gate/usr/src/lib/nsswitch/files/common/getrpcent.c (revision 2830:5228d1267a01)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*2830Sdjl  * Common Development and Distribution License (the "License").
6*2830Sdjl  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*2830Sdjl  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23*2830Sdjl  * Use is subject to license terms.
240Sstevel@tonic-gate  *
25*2830Sdjl  * files/getrpcent.c -- "files" backend for nsswitch "rpc" database
260Sstevel@tonic-gate  */
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #include <rpc/rpcent.h>
310Sstevel@tonic-gate #include "files_common.h"
320Sstevel@tonic-gate #include <strings.h>
33*2830Sdjl #include <ctype.h>
34*2830Sdjl #include <stdlib.h>
350Sstevel@tonic-gate 
360Sstevel@tonic-gate static nss_status_t
getbyname(be,a)370Sstevel@tonic-gate getbyname(be, a)
380Sstevel@tonic-gate 	files_backend_ptr_t	be;
390Sstevel@tonic-gate 	void			*a;
400Sstevel@tonic-gate {
41*2830Sdjl 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *)a;
420Sstevel@tonic-gate 
43*2830Sdjl 	return (_nss_files_XY_all(be, argp, 1, argp->key.name,
44*2830Sdjl 			_nss_files_check_name_aliases));
450Sstevel@tonic-gate }
460Sstevel@tonic-gate 
470Sstevel@tonic-gate static int
check_rpcnum(nss_XbyY_args_t * argp,const char * line,int linelen)48*2830Sdjl check_rpcnum(nss_XbyY_args_t *argp, const char *line, int linelen)
490Sstevel@tonic-gate {
50*2830Sdjl 	int		r_number;
51*2830Sdjl 	const char	*limit, *linep;
52*2830Sdjl 
53*2830Sdjl 	linep = line;
54*2830Sdjl 	limit = line + linelen;
550Sstevel@tonic-gate 
56*2830Sdjl 	/* skip name */
57*2830Sdjl 	while (linep < limit && !isspace(*linep))
58*2830Sdjl 		linep++;
59*2830Sdjl 	/* skip the delimiting spaces */
60*2830Sdjl 	while (linep < limit && isspace(*linep))
61*2830Sdjl 		linep++;
62*2830Sdjl 	if (linep == limit)
63*2830Sdjl 		return (0);
64*2830Sdjl 	r_number = (int)strtol(linep, NULL, 10);
65*2830Sdjl 	return (r_number == argp->key.number);
660Sstevel@tonic-gate }
670Sstevel@tonic-gate 
680Sstevel@tonic-gate 
690Sstevel@tonic-gate static nss_status_t
getbynumber(be,a)700Sstevel@tonic-gate getbynumber(be, a)
710Sstevel@tonic-gate 	files_backend_ptr_t	be;
720Sstevel@tonic-gate 	void			*a;
730Sstevel@tonic-gate {
74*2830Sdjl 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *)a;
750Sstevel@tonic-gate 	char			numstr[12];
760Sstevel@tonic-gate 
77*2830Sdjl 	(void) snprintf(numstr, 12, "%d", argp->key.number);
780Sstevel@tonic-gate 	return (_nss_files_XY_all(be, argp, 1, numstr, check_rpcnum));
790Sstevel@tonic-gate }
800Sstevel@tonic-gate 
810Sstevel@tonic-gate static files_backend_op_t rpc_ops[] = {
820Sstevel@tonic-gate 	_nss_files_destr,
830Sstevel@tonic-gate 	_nss_files_endent,
840Sstevel@tonic-gate 	_nss_files_setent,
850Sstevel@tonic-gate 	_nss_files_getent_netdb,
860Sstevel@tonic-gate 	getbyname,
870Sstevel@tonic-gate 	getbynumber
880Sstevel@tonic-gate };
890Sstevel@tonic-gate 
900Sstevel@tonic-gate /*ARGSUSED*/
910Sstevel@tonic-gate nss_backend_t *
_nss_files_rpc_constr(dummy1,dummy2,dummy3)920Sstevel@tonic-gate _nss_files_rpc_constr(dummy1, dummy2, dummy3)
930Sstevel@tonic-gate 	const char	*dummy1, *dummy2, *dummy3;
940Sstevel@tonic-gate {
950Sstevel@tonic-gate 	return (_nss_files_constr(rpc_ops,
960Sstevel@tonic-gate 				sizeof (rpc_ops) / sizeof (rpc_ops[0]),
970Sstevel@tonic-gate 				"/etc/rpc",
980Sstevel@tonic-gate 				NSS_LINELEN_RPC,
990Sstevel@tonic-gate 				NULL));
1000Sstevel@tonic-gate }
101