xref: /titanic_41/usr/src/lib/nsswitch/files/common/getprotoent.c (revision 70025d765b044c6d8594bb965a2247a61e991a99)
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/getprotoent.c -- "files" backend for nsswitch "protocols" database
27  */
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <netdb.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 protoent	*proto = (struct protoent *)args->returnval;
40 	const char		*name = args->key.name;
41 	char			**aliasp;
42 
43 	if (strcmp(proto->p_name, name) == 0)
44 		return (1);
45 	for (aliasp = proto->p_aliases; *aliasp != 0; aliasp++) {
46 		if (strcmp(*aliasp, name) == 0)
47 			return (1);
48 	}
49 	return (0);
50 }
51 
52 static nss_status_t
53 getbyname(be, a)
54 	files_backend_ptr_t	be;
55 	void		*a;
56 {
57 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *) a;
58 
59 	return (_nss_files_XY_all(be, argp, 1, argp->key.name, check_name));
60 }
61 
62 static int
63 check_addr(args)
64 	nss_XbyY_args_t	*args;
65 {
66 	struct protoent	*proto = (struct protoent *)args->returnval;
67 
68 	return (proto->p_proto == args->key.number);
69 }
70 
71 static nss_status_t
72 getbynumber(be, a)
73 	files_backend_ptr_t	be;
74 	void		*a;
75 {
76 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *) a;
77 	char		numstr[12];
78 
79 	sprintf(numstr, "%d", argp->key.number);
80 	return (_nss_files_XY_all(be, argp, 1, 0, check_addr));
81 }
82 
83 static files_backend_op_t proto_ops[] = {
84 	_nss_files_destr,
85 	_nss_files_endent,
86 	_nss_files_setent,
87 	_nss_files_getent_netdb,
88 	getbyname,
89 	getbynumber
90 };
91 
92 /*ARGSUSED*/
93 nss_backend_t *
94 _nss_files_protocols_constr(dummy1, dummy2, dummy3)
95 	const char  *dummy1, *dummy2, *dummy3;
96 {
97 	return (_nss_files_constr(proto_ops,
98 				sizeof (proto_ops) / sizeof (proto_ops[0]),
99 				_PATH_PROTOCOLS,
100 				NSS_LINELEN_PROTOCOLS,
101 				NULL));
102 }
103