2e2c89627b063bf12b5eda47a95e7d363b79283e
2 * Copyright (c) 2009, Sun Microsystems, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * - Neither the name of Sun Microsystems, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
30 * Copyright (c) 1984 by Sun Microsystems, Inc.
34 #include <sys/types.h>
36 //#include <netinet/in.h>
37 //#include <arpa/inet.h>
47 #include <rpcsvc/yp_prot.h>
48 #include <rpcsvc/ypclnt.h>
50 #include <libc_private.h>
55 static struct rpcdata
{
59 char *rpc_aliases
[MAXALIASES
];
69 static struct rpcent
*interpret(char *val
, size_t len
);
72 static int __yp_nomap
= 0;
75 #define RPCDB "/etc/rpc"
77 static struct rpcdata
*_rpcdata(void);
79 static struct rpcdata
*
82 struct rpcdata
*d
= rpcdata
;
85 d
= (struct rpcdata
*)calloc(1, sizeof (struct rpcdata
));
93 getrpcbynumber(number
)
101 struct rpcdata
*d
= _rpcdata();
106 if (!__yp_nomap
&& _yp_check(&d
->domain
)) {
107 sprintf(adrstr
, "%d", number
);
108 reason
= yp_match(d
->domain
, "rpc.bynumber", adrstr
, strlen(adrstr
),
109 &d
->current
, &d
->currentlen
);
121 d
->current
[d
->currentlen
] = '\0';
122 p
= interpret(d
->current
, d
->currentlen
);
123 (void) free(d
->current
);
130 while ((p
= getrpcent()) != NULL
) {
131 if (p
->r_number
== number
)
142 struct rpcent
*rpc
= NULL
;
145 assert(name
!= NULL
);
148 while ((rpc
= getrpcent()) != NULL
) {
149 if (strcmp(rpc
->r_name
, name
) == 0)
151 for (rp
= rpc
->r_aliases
; *rp
!= NULL
; rp
++) {
152 if (strcmp(*rp
, name
) == 0)
166 struct rpcdata
*d
= _rpcdata();
171 if (!__yp_nomap
&& _yp_check(NULL
)) {
181 d
->rpcf
= fopen(RPCDB
, "r");
190 struct rpcdata
*d
= _rpcdata();
195 if (!__yp_nomap
&& _yp_check(NULL
)) {
196 if (d
->current
&& !d
->stayopen
)
204 if (d
->rpcf
&& !d
->stayopen
) {
213 struct rpcdata
*d
= _rpcdata();
224 if (!__yp_nomap
&& _yp_check(&d
->domain
)) {
225 if (d
->current
== NULL
&& d
->currentlen
== 0) {
226 reason
= yp_first(d
->domain
, "rpc.bynumber",
227 &d
->current
, &d
->currentlen
,
230 reason
= yp_next(d
->domain
, "rpc.bynumber",
231 d
->current
, d
->currentlen
,
232 &d
->current
, &d
->currentlen
,
247 hp
= interpret(val
, vallen
);
253 if (d
->rpcf
== NULL
&& (d
->rpcf
= fopen(RPCDB
, "r")) == NULL
)
255 /* -1 so there is room to append a \n below */
256 if (fgets(d
->line
, BUFSIZ
- 1, d
->rpcf
) == NULL
)
258 return (interpret(d
->line
, strlen(d
->line
)));
261 static struct rpcent
*
266 struct rpcdata
*d
= _rpcdata();
274 (void) strncpy(d
->line
, val
, BUFSIZ
);
275 d
->line
[BUFSIZ
] = '\0';
279 return (getrpcent());
280 cp
= strpbrk(p
, "#\n");
282 return (getrpcent());
284 cp
= strpbrk(p
, " \t");
286 return (getrpcent());
288 /* THIS STUFF IS INTERNET SPECIFIC */
289 d
->rpc
.r_name
= d
->line
;
290 while (*cp
== ' ' || *cp
== '\t')
292 d
->rpc
.r_number
= atoi(cp
);
293 q
= d
->rpc
.r_aliases
= d
->rpc_aliases
;
294 cp
= strpbrk(cp
, " \t");
298 if (*cp
== ' ' || *cp
== '\t') {
302 if (q
< &(d
->rpc_aliases
[MAXALIASES
- 1]))
304 cp
= strpbrk(cp
, " \t");