xref: /titanic_44/usr/src/lib/libnsl/nss/getrpcent.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Ye olde non-reentrant interface (MT-unsafe, caveat utor)
29  */
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include <rpc/rpcent.h>
34 #include <rpc/trace.h>
35 #include <nss_dbdefs.h>
36 
37 #ifdef	NSS_INCLUDE_UNSAFE
38 
39 /*
40  * Don't free this, even on an endrpcent(), because bitter experience shows
41  * that there's production code that does getXXXbyYYY(), then endXXXent(),
42  * and then continues to use the pointer it got back.
43  */
44 static nss_XbyY_buf_t *buffer;
45 #define	GETBUF()	\
46 	NSS_XbyY_ALLOC(&buffer, sizeof (struct rpcent), NSS_BUFLEN_RPC)
47 	/* === ?? set ENOMEM on failure?  */
48 
49 struct rpcent *
50 getrpcbyname(nam)
51 	const char	*nam;
52 {
53 	nss_XbyY_buf_t	*b;
54 	struct rpcent	*res = 0;
55 
56 	trace1(TR_getrpcbyname, 0);
57 	if ((b = GETBUF()) != 0) {
58 		res = getrpcbyname_r(nam, b->result, b->buffer, b->buflen);
59 	}
60 	trace1(TR_getrpcbyname, 1);
61 	return (res);
62 }
63 
64 struct rpcent *
65 getrpcbynumber(num)
66 	const int	num;
67 {
68 	nss_XbyY_buf_t	*b;
69 	struct rpcent	*res = 0;
70 
71 	trace2(TR_getrpcbynumber, 0, num);
72 	if ((b = GETBUF()) != 0) {
73 		res = getrpcbynumber_r(num, b->result, b->buffer, b->buflen);
74 	}
75 	trace2(TR_getrpcbynumber, 1, num);
76 	return (res);
77 }
78 
79 struct rpcent *
80 getrpcent()
81 {
82 	nss_XbyY_buf_t	*b;
83 	struct rpcent	*res = 0;
84 
85 	trace1(TR_getrpcent, 0);
86 	if ((b = GETBUF()) != 0) {
87 		res = getrpcent_r(b->result, b->buffer, b->buflen);
88 	}
89 	trace1(TR_getrpcent, 1);
90 	return (res);
91 }
92 
93 #endif	/* NSS_INCLUDE_UNSAFE */
94