xref: /illumos-gate/usr/src/lib/libnsl/nss/getrpcent.c (revision cc6c5292fa8a241fe50604cf6a918edfbf7cd7d2)
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 /*
24  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 /*
29  * Ye olde non-reentrant interface (MT-unsafe, caveat utor)
30  */
31 
32 #pragma ident	"%Z%%M%	%I%	%E% SMI"
33 
34 #include <rpc/rpcent.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(const char *nam)
51 {
52 	nss_XbyY_buf_t	*b;
53 
54 	if ((b = GETBUF()) == 0)
55 		return (NULL);
56 	return (getrpcbyname_r(nam, b->result, b->buffer, b->buflen));
57 }
58 
59 struct rpcent *
60 getrpcbynumber(const int num)
61 {
62 	nss_XbyY_buf_t	*b;
63 
64 	if ((b = GETBUF()) == 0)
65 		return (NULL);
66 	return (getrpcbynumber_r(num, b->result, b->buffer, b->buflen));
67 }
68 
69 struct rpcent *
70 getrpcent(void)
71 {
72 	nss_XbyY_buf_t	*b;
73 
74 	if ((b = GETBUF()) == 0)
75 		return (NULL);
76 	return (getrpcent_r(b->result, b->buffer, b->buflen));
77 }
78 #endif	/* NSS_INCLUDE_UNSAFE */
79