xref: /illumos-gate/usr/src/lib/libnsl/nss/getrpcent.c (revision e8031f0a)
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 2006 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 "mt.h"
35 #include <rpc/rpcent.h>
36 #include <nss_dbdefs.h>
37 
38 #ifdef	NSS_INCLUDE_UNSAFE
39 
40 /*
41  * Don't free this, even on an endrpcent(), because bitter experience shows
42  * that there's production code that does getXXXbyYYY(), then endXXXent(),
43  * and then continues to use the pointer it got back.
44  */
45 static nss_XbyY_buf_t *buffer;
46 #define	GETBUF()	\
47 	NSS_XbyY_ALLOC(&buffer, sizeof (struct rpcent), NSS_BUFLEN_RPC)
48 	/* === ?? set ENOMEM on failure?  */
49 
50 struct rpcent *
51 getrpcbyname(const char *nam)
52 {
53 	nss_XbyY_buf_t	*b;
54 
55 	if ((b = GETBUF()) == 0)
56 		return (NULL);
57 	return (getrpcbyname_r(nam, b->result, b->buffer, b->buflen));
58 }
59 
60 struct rpcent *
61 getrpcbynumber(const int num)
62 {
63 	nss_XbyY_buf_t	*b;
64 
65 	if ((b = GETBUF()) == 0)
66 		return (NULL);
67 	return (getrpcbynumber_r(num, b->result, b->buffer, b->buflen));
68 }
69 
70 struct rpcent *
71 getrpcent(void)
72 {
73 	nss_XbyY_buf_t	*b;
74 
75 	if ((b = GETBUF()) == 0)
76 		return (NULL);
77 	return (getrpcent_r(b->result, b->buffer, b->buflen));
78 }
79 #endif	/* NSS_INCLUDE_UNSAFE */
80