xref: /titanic_44/usr/src/lib/nsswitch/nis/common/getprotoent.c (revision 4496171313bed39e96f21bc2f9faf2868e267ae3)
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  *	nis/getprotoent.c -- "nis" backend for nsswitch "protocols" database
24  *
25  *	Copyright (c) 1988-1992 Sun Microsystems Inc
26  *	All Rights Reserved.
27  */
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <stdio.h>
32 #include "nis_common.h"
33 #include <synch.h>
34 #include <netdb.h>
35 #include <string.h>
36 
37 static nss_status_t
38 getbyname(be, a)
39 	nis_backend_ptr_t	be;
40 	void			*a;
41 {
42 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *) a;
43 
44 	return (_nss_nis_lookup(be, argp, 1, "protocols.byname",
45 		argp->key.name, 0));
46 }
47 
48 static nss_status_t
49 getbynumber(be, a)
50 	nis_backend_ptr_t	be;
51 	void			*a;
52 {
53 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *) a;
54 	char			numstr[12];
55 
56 	(void) sprintf(numstr, "%d", argp->key.number);
57 	return (_nss_nis_lookup(be, argp, 1, "protocols.bynumber",
58 				numstr, 0));
59 }
60 
61 static nis_backend_op_t proto_ops[] = {
62 	_nss_nis_destr,
63 	_nss_nis_endent,
64 	_nss_nis_setent,
65 	_nss_nis_getent_netdb,
66 	getbyname,
67 	getbynumber
68 };
69 
70 /*ARGSUSED*/
71 nss_backend_t *
72 _nss_nis_protocols_constr(dummy1, dummy2, dummy3)
73 	const char	*dummy1, *dummy2, *dummy3;
74 {
75 	return (_nss_nis_constr(proto_ops,
76 				sizeof (proto_ops) / sizeof (proto_ops[0]),
77 				"protocols.bynumber"));
78 }
79