]>
Commit | Line | Data |
---|---|---|
03fb6eb0 A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
ad21edcc A |
6 | * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights |
7 | * Reserved. This file contains Original Code and/or Modifications of | |
8 | * Original Code as defined in and that are subject to the Apple Public | |
9 | * Source License Version 1.1 (the "License"). You may not use this file | |
10 | * except in compliance with the License. Please obtain a copy of the | |
11 | * License at http://www.apple.com/publicsource and read it before using | |
12 | * this file. | |
03fb6eb0 A |
13 | * |
14 | * The Original Code and all software distributed under the License are | |
ad21edcc | 15 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
03fb6eb0 A |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
ad21edcc A |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the |
19 | * License for the specific language governing rights and limitations | |
20 | * under the License. | |
03fb6eb0 A |
21 | * |
22 | * @APPLE_LICENSE_HEADER_END@ | |
23 | */ | |
24 | /* | |
25 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for | |
26 | * unrestricted use provided that this legend is included on all tape | |
27 | * media and as a part of the software program in whole or part. Users | |
28 | * may copy or modify Sun RPC without charge, but are not authorized | |
29 | * to license or distribute it to anyone else except as part of a product or | |
30 | * program developed by the user or with the express written consent of | |
31 | * Sun Microsystems, Inc. | |
32 | * | |
33 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE | |
34 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR | |
35 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. | |
36 | * | |
37 | * Sun RPC is provided with no support and without any obligation on the | |
38 | * part of Sun Microsystems, Inc. to assist in its use, correction, | |
39 | * modification or enhancement. | |
40 | * | |
41 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE | |
42 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC | |
43 | * OR ANY PART THEREOF. | |
44 | * | |
45 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue | |
46 | * or profits or other special, indirect and consequential damages, even if | |
47 | * Sun has been advised of the possibility of such damages. | |
48 | * | |
49 | * Sun Microsystems, Inc. | |
50 | * 2550 Garcia Avenue | |
51 | * Mountain View, California 94043 | |
52 | */ | |
53 | ||
54 | #if defined(LIBC_SCCS) && !defined(lint) | |
55 | /*static char *sccsid = "from: @(#)getrpcent.c 1.14 91/03/11 Copyr 1984 Sun Micro";*/ | |
3b7c7bd7 | 56 | static char *rcsid = "$Id: getrpcent.c,v 1.3 2002/02/19 20:36:23 epeyton Exp $"; |
03fb6eb0 A |
57 | #endif |
58 | ||
59 | /* | |
60 | * Copyright (c) 1984 by Sun Microsystems, Inc. | |
61 | */ | |
62 | ||
63 | #include <stdio.h> | |
3b7c7bd7 | 64 | #include <stdlib.h> |
03fb6eb0 A |
65 | #include <sys/types.h> |
66 | #include <string.h> | |
67 | #include <rpc/rpc.h> | |
68 | ||
d49d4c81 A |
69 | /* forward */ |
70 | void _old_setrpcent(int f); | |
71 | struct rpcent *_old_getrpcent(); | |
72 | void _old_endrpcent(); | |
73 | ||
03fb6eb0 A |
74 | /* |
75 | * Internet version. | |
76 | */ | |
77 | struct rpcdata { | |
78 | FILE *rpcf; | |
79 | int stayopen; | |
80 | #define MAXALIASES 35 | |
81 | char *rpc_aliases[MAXALIASES]; | |
82 | struct rpcent rpc; | |
83 | char line[BUFSIZ+1]; | |
84 | } *rpcdata; | |
85 | ||
86 | static struct rpcent *interpret(); | |
87 | struct hostent *gethostent(); | |
88 | char *inet_ntoa(); | |
89 | ||
90 | static char RPCDB[] = "/etc/rpc"; | |
91 | ||
92 | static struct rpcdata * | |
93 | _rpcdata() | |
94 | { | |
95 | register struct rpcdata *d = rpcdata; | |
96 | ||
97 | if (d == 0) { | |
98 | d = (struct rpcdata *)calloc(1, sizeof (struct rpcdata)); | |
99 | rpcdata = d; | |
100 | } | |
101 | return (d); | |
102 | } | |
103 | ||
104 | struct rpcent * | |
d49d4c81 | 105 | _old_getrpcbynumber(number) |
b3dd680f A |
106 | #ifdef __LP64__ |
107 | int32_t number; | |
108 | #else | |
03fb6eb0 | 109 | register long number; |
b3dd680f | 110 | #endif |
03fb6eb0 A |
111 | { |
112 | register struct rpcdata *d = _rpcdata(); | |
113 | register struct rpcent *p; | |
b3dd680f A |
114 | #ifdef __LP64__ |
115 | int x; | |
116 | ||
117 | x = number; | |
118 | #endif | |
03fb6eb0 A |
119 | |
120 | if (d == 0) | |
121 | return (0); | |
d49d4c81 A |
122 | _old_setrpcent(0); |
123 | while ((p = _old_getrpcent())) | |
b3dd680f A |
124 | { |
125 | #ifdef __LP64__ | |
126 | if (p->r_number == x) break; | |
127 | #else | |
128 | if (p->r_number == number) break; | |
129 | #endif | |
03fb6eb0 | 130 | } |
d49d4c81 | 131 | _old_endrpcent(); |
03fb6eb0 A |
132 | return (p); |
133 | } | |
134 | ||
135 | struct rpcent * | |
d49d4c81 | 136 | _old_getrpcbyname(name) |
03fb6eb0 A |
137 | #if defined(__APPLE__) |
138 | const char *name; | |
139 | #else | |
140 | char *name; | |
141 | #endif | |
142 | { | |
143 | struct rpcent *rpc; | |
144 | char **rp; | |
145 | ||
d49d4c81 A |
146 | _old_setrpcent(0); |
147 | while ((rpc = _old_getrpcent())) { | |
03fb6eb0 A |
148 | if (strcmp(rpc->r_name, name) == 0) |
149 | return (rpc); | |
150 | for (rp = rpc->r_aliases; *rp != NULL; rp++) { | |
151 | if (strcmp(*rp, name) == 0) | |
152 | return (rpc); | |
153 | } | |
154 | } | |
d49d4c81 | 155 | _old_endrpcent(); |
03fb6eb0 A |
156 | return (NULL); |
157 | } | |
158 | ||
159 | void | |
d49d4c81 | 160 | _old_setrpcent(f) |
03fb6eb0 A |
161 | int f; |
162 | { | |
163 | register struct rpcdata *d = _rpcdata(); | |
164 | ||
165 | if (d == 0) | |
166 | return; | |
167 | if (d->rpcf == NULL) | |
168 | d->rpcf = fopen(RPCDB, "r"); | |
169 | else | |
170 | rewind(d->rpcf); | |
171 | d->stayopen |= f; | |
172 | } | |
173 | ||
174 | void | |
d49d4c81 | 175 | _old_endrpcent() |
03fb6eb0 A |
176 | { |
177 | register struct rpcdata *d = _rpcdata(); | |
178 | ||
179 | if (d == 0) | |
180 | return; | |
181 | if (d->rpcf && !d->stayopen) { | |
182 | fclose(d->rpcf); | |
183 | d->rpcf = NULL; | |
184 | } | |
185 | } | |
186 | ||
187 | struct rpcent * | |
d49d4c81 | 188 | _old_getrpcent() |
03fb6eb0 | 189 | { |
03fb6eb0 A |
190 | register struct rpcdata *d = _rpcdata(); |
191 | ||
192 | if (d == 0) | |
193 | return(NULL); | |
194 | if (d->rpcf == NULL && (d->rpcf = fopen(RPCDB, "r")) == NULL) | |
195 | return (NULL); | |
196 | if (fgets(d->line, BUFSIZ, d->rpcf) == NULL) | |
197 | return (NULL); | |
198 | return (interpret(d->line, strlen(d->line))); | |
199 | } | |
200 | ||
201 | static struct rpcent * | |
202 | interpret(val, len) | |
203 | char *val; | |
e6b95798 | 204 | u_int len; |
03fb6eb0 A |
205 | { |
206 | register struct rpcdata *d = _rpcdata(); | |
207 | char *p; | |
208 | register char *cp, **q; | |
209 | ||
210 | if (d == 0) | |
211 | return (0); | |
212 | (void) strncpy(d->line, val, len); | |
213 | p = d->line; | |
214 | d->line[len] = '\n'; | |
215 | if (*p == '#') | |
d49d4c81 | 216 | return (_old_getrpcent()); |
03fb6eb0 A |
217 | cp = strpbrk(p, "#\n"); |
218 | if (cp == NULL) | |
d49d4c81 | 219 | return (_old_getrpcent()); |
03fb6eb0 A |
220 | *cp = '\0'; |
221 | cp = strpbrk(p, " \t"); | |
222 | if (cp == NULL) | |
d49d4c81 | 223 | return (_old_getrpcent()); |
03fb6eb0 A |
224 | *cp++ = '\0'; |
225 | /* THIS STUFF IS INTERNET SPECIFIC */ | |
226 | d->rpc.r_name = d->line; | |
227 | while (*cp == ' ' || *cp == '\t') | |
228 | cp++; | |
229 | d->rpc.r_number = atoi(cp); | |
230 | q = d->rpc.r_aliases = d->rpc_aliases; | |
231 | cp = strpbrk(cp, " \t"); | |
232 | if (cp != NULL) | |
233 | *cp++ = '\0'; | |
234 | while (cp && *cp) { | |
235 | if (*cp == ' ' || *cp == '\t') { | |
236 | cp++; | |
237 | continue; | |
238 | } | |
239 | if (q < &(d->rpc_aliases[MAXALIASES - 1])) | |
240 | *q++ = cp; | |
241 | cp = strpbrk(cp, " \t"); | |
242 | if (cp != NULL) | |
243 | *cp++ = '\0'; | |
244 | } | |
245 | *q = NULL; | |
246 | return (&d->rpc); | |
247 | } | |
248 |