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.
33 #include <sys/types.h>
35 #include <netinet/in.h>
36 #include <arpa/inet.h>
46 #include <rpcsvc/yp_prot.h>
47 #include <rpcsvc/ypclnt.h>
49 #if defined(__FreeBSD__) || defined(__NetBSD__)
50 #include <libc_private.h>
56 static struct rpcdata {
60 char *rpc_aliases[MAXALIASES];
70 static struct rpcent *interpret(char *val, size_t len);
73 static int __yp_nomap = 0;
76 #define RPCDB "/etc/rpc"
78 static struct rpcdata *_rpcdata(void);
80 static struct rpcdata *
83 struct rpcdata *d = rpcdata;
86 d = (struct rpcdata *)calloc(1, sizeof (struct rpcdata));
94 getrpcbynumber(number)
102 struct rpcdata *d = _rpcdata();
107 if (!__yp_nomap && _yp_check(&d->domain)) {
108 sprintf(adrstr, "%d", number);
109 reason = yp_match(d->domain, "rpc.bynumber", adrstr, strlen(adrstr),
110 &d->current, &d->currentlen);
122 d->current[d->currentlen] = '\0';
123 p = interpret(d->current, d->currentlen);
124 (void) free(d->current);
131 while ((p = getrpcent()) != NULL) {
132 if (p->r_number == number)
143 struct rpcent *rpc = NULL;
146 assert(name != NULL);
149 while ((rpc = getrpcent()) != NULL) {
150 if (strcmp(rpc->r_name, name) == 0)
152 for (rp = rpc->r_aliases; *rp != NULL; rp++) {
153 if (strcmp(*rp, name) == 0)
167 struct rpcdata *d = _rpcdata();
172 if (!__yp_nomap && _yp_check(NULL)) {
182 d->rpcf = fopen(RPCDB, "r");
191 struct rpcdata *d = _rpcdata();
196 if (!__yp_nomap && _yp_check(NULL)) {
197 if (d->current && !d->stayopen)
205 if (d->rpcf && !d->stayopen) {
214 struct rpcdata *d = _rpcdata();
225 if (!__yp_nomap && _yp_check(&d->domain)) {
226 if (d->current == NULL && d->currentlen == 0) {
227 reason = yp_first(d->domain, "rpc.bynumber",
228 &d->current, &d->currentlen,
231 reason = yp_next(d->domain, "rpc.bynumber",
232 d->current, d->currentlen,
233 &d->current, &d->currentlen,
248 hp = interpret(val, vallen);
254 if (d->rpcf == NULL && (d->rpcf = fopen(RPCDB, "r")) == NULL)
256 /* -1 so there is room to append a \n below */
257 if (fgets(d->line, BUFSIZ - 1, d->rpcf) == NULL)
259 return (interpret(d->line, strlen(d->line)));
262 static struct rpcent *
267 struct rpcdata *d = _rpcdata();
275 (void) strncpy(d->line, val, BUFSIZ);
276 d->line[BUFSIZ] = '\0';
280 return (getrpcent());
281 cp = strpbrk(p, "#\n");
283 return (getrpcent());
285 cp = strpbrk(p, " \t");
287 return (getrpcent());
289 /* THIS STUFF IS INTERNET SPECIFIC */
290 d->rpc.r_name = d->line;
291 while (*cp == ' ' || *cp == '\t')
293 d->rpc.r_number = atoi(cp);
294 q = d->rpc.r_aliases = d->rpc_aliases;
295 cp = strpbrk(cp, " \t");
299 if (*cp == ' ' || *cp == '\t') {
303 if (q < &(d->rpc_aliases[MAXALIASES - 1]))
305 cp = strpbrk(cp, " \t");