File: | src/usr.sbin/ypserv/ypserv/ypserv.c |
Warning: | line 488, column 9 5th function call argument is an uninitialized value |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* $OpenBSD: ypserv.c,v 1.45 2023/03/08 04:43:15 guenther Exp $ */ | |||
2 | ||||
3 | /* | |||
4 | * Copyright (c) 1994 Mats O Jansson <moj@stacken.kth.se> | |||
5 | * All rights reserved. | |||
6 | * | |||
7 | * Redistribution and use in source and binary forms, with or without | |||
8 | * modification, are permitted provided that the following conditions | |||
9 | * are met: | |||
10 | * 1. Redistributions of source code must retain the above copyright | |||
11 | * notice, this list of conditions and the following disclaimer. | |||
12 | * 2. Redistributions in binary form must reproduce the above copyright | |||
13 | * notice, this list of conditions and the following disclaimer in the | |||
14 | * documentation and/or other materials provided with the distribution. | |||
15 | * | |||
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS | |||
17 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | |||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |||
22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |||
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |||
24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
26 | * SUCH DAMAGE. | |||
27 | */ | |||
28 | ||||
29 | #include <sys/types.h> | |||
30 | #include <sys/socket.h> | |||
31 | #include <sys/ioctl.h> | |||
32 | #include <netinet/in.h> | |||
33 | #include <rpcsvc/yp.h> | |||
34 | #include "ypv1.h" | |||
35 | #include <stdio.h> | |||
36 | #include <stdlib.h> | |||
37 | #include <string.h> | |||
38 | #include <netdb.h> | |||
39 | #include <signal.h> | |||
40 | #include <errno(*__errno()).h> | |||
41 | #include <util.h> | |||
42 | #include <unistd.h> | |||
43 | #include <fcntl.h> | |||
44 | #include <rpc/pmap_clnt.h> | |||
45 | #include <ndbm.h> | |||
46 | #include <syslog.h> | |||
47 | #include "acl.h" | |||
48 | #include "yplog.h" | |||
49 | #include "ypdef.h" | |||
50 | #include "ypserv.h" | |||
51 | #include <sys/wait.h> | |||
52 | ||||
53 | void ypdb_init(void); | |||
54 | ||||
55 | #ifdef DEBUG | |||
56 | #define RPC_SVC_FG | |||
57 | #endif | |||
58 | ||||
59 | #define _RPCSVC_CLOSEDOWN120 120 | |||
60 | static int _rpcpmstart; /* Started by a port monitor ? */ | |||
61 | static int _rpcfdtype; /* Whether Stream or Datagram ? */ | |||
62 | static int _rpcsvcdirty; /* Still serving ? */ | |||
63 | ||||
64 | int usedns = FALSE(0); | |||
65 | char *aclfile = NULL0; | |||
66 | ||||
67 | void sig_child(int); | |||
68 | void sig_hup(int); | |||
69 | volatile sig_atomic_t wantsighup; | |||
70 | ||||
71 | static void | |||
72 | _msgout(char *msg) | |||
73 | { | |||
74 | #ifdef RPC_SVC_FG | |||
75 | if (_rpcpmstart) | |||
76 | syslog(LOG_ERR3, "%s", msg); | |||
77 | else | |||
78 | (void) fprintf(stderr(&__sF[2]), "%s\n", msg); | |||
79 | #else | |||
80 | syslog(LOG_ERR3, "%s", msg); | |||
81 | #endif | |||
82 | } | |||
83 | ||||
84 | static void | |||
85 | closedown(int sig) | |||
86 | { | |||
87 | int save_errno = errno(*__errno()); | |||
88 | ||||
89 | if (_rpcsvcdirty == 0) { | |||
90 | int i, openfd; | |||
91 | ||||
92 | if (_rpcfdtype == SOCK_DGRAM2) | |||
93 | exit(0); | |||
94 | for (i = 0, openfd = 0; i < svc_max_pollfd && openfd < 2; i++) | |||
95 | if (svc_pollfd[i].fd != -1) | |||
96 | openfd++; | |||
97 | if (openfd <= (_rpcpmstart ? 0 : 1)) | |||
98 | _exit(0); | |||
99 | } | |||
100 | (void) alarm(_RPCSVC_CLOSEDOWN120); | |||
101 | errno(*__errno()) = save_errno; | |||
102 | } | |||
103 | ||||
104 | static void | |||
105 | ypprog_1(struct svc_req *rqstp, SVCXPRT *transp) | |||
106 | { | |||
107 | union { | |||
108 | domainname ypoldproc_domain_1_arg; | |||
109 | domainname ypoldproc_domain_nonack_1_arg; | |||
110 | yprequest ypoldproc_match_1_arg; | |||
111 | yprequest ypoldproc_first_1_arg; | |||
112 | yprequest ypoldproc_next_1_arg; | |||
113 | yprequest ypoldproc_poll_1_arg; | |||
114 | yprequest ypoldproc_push_1_arg; | |||
115 | yprequest ypoldproc_pull_1_arg; | |||
116 | yprequest ypoldproc_get_1_arg; | |||
117 | } argument; | |||
118 | char *result; | |||
119 | xdrproc_t xdr_argument, xdr_result; | |||
120 | char *(*local)(char *, struct svc_req *); | |||
121 | ||||
122 | _rpcsvcdirty = 1; | |||
123 | switch (rqstp->rq_proc) { | |||
124 | case YPOLDPROC_NULL((u_long)0): | |||
125 | xdr_argument = (xdrproc_t) xdr_void; | |||
126 | xdr_result = (xdrproc_t) xdr_void; | |||
127 | local = (char *(*)(char *, struct svc_req *)) ypoldproc_null_1_svc; | |||
128 | break; | |||
129 | ||||
130 | case YPOLDPROC_DOMAIN((u_long)1): | |||
131 | xdr_argument = (xdrproc_t) xdr_domainname; | |||
132 | xdr_result = (xdrproc_t) xdr_bool; | |||
133 | local = (char *(*)(char *, struct svc_req *)) ypoldproc_domain_1_svc; | |||
134 | break; | |||
135 | ||||
136 | case YPOLDPROC_DOMAIN_NONACK((u_long)2): | |||
137 | xdr_argument = (xdrproc_t) xdr_domainname; | |||
138 | xdr_result = (xdrproc_t) xdr_bool; | |||
139 | local = (char *(*)(char *, struct svc_req *)) ypoldproc_domain_nonack_1_svc; | |||
140 | break; | |||
141 | ||||
142 | case YPOLDPROC_MATCH((u_long)3): | |||
143 | xdr_argument = (xdrproc_t) xdr_yprequest; | |||
144 | xdr_result = (xdrproc_t) xdr_ypresponse; | |||
145 | local = (char *(*)(char *, struct svc_req *)) ypoldproc_match_1_svc; | |||
146 | break; | |||
147 | ||||
148 | case YPOLDPROC_FIRST((u_long)4): | |||
149 | xdr_argument = (xdrproc_t) xdr_yprequest; | |||
150 | xdr_result = (xdrproc_t) xdr_ypresponse; | |||
151 | local = (char *(*)(char *, struct svc_req *)) ypoldproc_first_1_svc; | |||
152 | break; | |||
153 | ||||
154 | case YPOLDPROC_NEXT((u_long)5): | |||
155 | xdr_argument = (xdrproc_t) xdr_yprequest; | |||
156 | xdr_result = (xdrproc_t) xdr_ypresponse; | |||
157 | local = (char *(*)(char *, struct svc_req *)) ypoldproc_next_1_svc; | |||
158 | break; | |||
159 | ||||
160 | case YPOLDPROC_POLL((u_long)6): | |||
161 | xdr_argument = (xdrproc_t) xdr_yprequest; | |||
162 | xdr_result = (xdrproc_t) xdr_ypresponse; | |||
163 | local = (char *(*)(char *, struct svc_req *)) ypoldproc_poll_1_svc; | |||
164 | break; | |||
165 | ||||
166 | case YPOLDPROC_PUSH((u_long)7): | |||
167 | xdr_argument = (xdrproc_t) xdr_yprequest; | |||
168 | xdr_result = (xdrproc_t) xdr_void; | |||
169 | local = (char *(*)(char *, struct svc_req *)) ypoldproc_push_1_svc; | |||
170 | break; | |||
171 | ||||
172 | case YPOLDPROC_PULL((u_long)8): | |||
173 | xdr_argument = (xdrproc_t) xdr_yprequest; | |||
174 | xdr_result = (xdrproc_t) xdr_void; | |||
175 | local = (char *(*)(char *, struct svc_req *)) ypoldproc_pull_1_svc; | |||
176 | break; | |||
177 | ||||
178 | case YPOLDPROC_GET((u_long)9): | |||
179 | xdr_argument = (xdrproc_t) xdr_yprequest; | |||
180 | xdr_result = (xdrproc_t) xdr_void; | |||
181 | local = (char *(*)(char *, struct svc_req *)) ypoldproc_get_1_svc; | |||
182 | break; | |||
183 | ||||
184 | default: | |||
185 | svcerr_noproc(transp); | |||
186 | _rpcsvcdirty = 0; | |||
187 | return; | |||
188 | } | |||
189 | (void) memset(&argument, 0, sizeof(argument)); | |||
190 | if (!svc_getargs(transp, xdr_argument, (caddr_t)&argument)(*(transp)->xp_ops->xp_getargs)((transp), (xdr_argument ), ((caddr_t)&argument))) { | |||
191 | svcerr_decode(transp); | |||
192 | _rpcsvcdirty = 0; | |||
193 | return; | |||
194 | } | |||
195 | result = (*local)((char *)&argument, rqstp); | |||
196 | if (result != NULL0 && !svc_sendreply(transp, xdr_result, result)) { | |||
197 | svcerr_systemerr(transp); | |||
198 | } | |||
199 | if (!svc_freeargs(transp, xdr_argument, (caddr_t)&argument)(*(transp)->xp_ops->xp_freeargs)((transp), (xdr_argument ), ((caddr_t)&argument))) { | |||
200 | _msgout("unable to free arguments"); | |||
201 | exit(1); | |||
202 | } | |||
203 | _rpcsvcdirty = 0; | |||
204 | } | |||
205 | ||||
206 | static void | |||
207 | ypprog_2(struct svc_req *rqstp, SVCXPRT *transp) | |||
208 | { | |||
209 | union { | |||
210 | domainname ypproc_domain_2_arg; | |||
211 | domainname ypproc_domain_nonack_2_arg; | |||
212 | ypreq_key ypproc_match_2_arg; | |||
213 | ypreq_nokey ypproc_first_2_arg; | |||
214 | ypreq_key ypproc_next_2_arg; | |||
215 | ypreq_xfr ypproc_xfr_2_arg; | |||
216 | ypreq_nokey ypproc_all_2_arg; | |||
217 | ypreq_nokey ypproc_master_2_arg; | |||
218 | ypreq_nokey ypproc_order_2_arg; | |||
219 | domainname ypproc_maplist_2_arg; | |||
220 | } argument; | |||
221 | char *result; | |||
222 | xdrproc_t xdr_argument, xdr_result; | |||
223 | char *(*local)(char *, struct svc_req *); | |||
224 | ||||
225 | _rpcsvcdirty = 1; | |||
226 | switch (rqstp->rq_proc) { | |||
227 | case YPPROC_NULL((u_long)0): | |||
228 | xdr_argument = (xdrproc_t) xdr_void; | |||
229 | xdr_result = (xdrproc_t) xdr_void; | |||
230 | local = (char *(*)(char *, struct svc_req *)) ypproc_null_2_svc; | |||
231 | break; | |||
232 | ||||
233 | case YPPROC_DOMAIN((u_long)1): | |||
234 | xdr_argument = (xdrproc_t) xdr_domainname; | |||
235 | xdr_result = (xdrproc_t) xdr_bool; | |||
236 | local = (char *(*)(char *, struct svc_req *)) ypproc_domain_2_svc; | |||
237 | break; | |||
238 | ||||
239 | case YPPROC_DOMAIN_NONACK((u_long)2): | |||
240 | xdr_argument = (xdrproc_t) xdr_domainname; | |||
241 | xdr_result = (xdrproc_t) xdr_bool; | |||
242 | local = (char *(*)(char *, struct svc_req *)) ypproc_domain_nonack_2_svc; | |||
243 | break; | |||
244 | ||||
245 | case YPPROC_MATCH((u_long)3): | |||
246 | xdr_argument = (xdrproc_t) xdr_ypreq_key; | |||
247 | xdr_result = (xdrproc_t) xdr_ypresp_val; | |||
248 | local = (char *(*)(char *, struct svc_req *)) ypproc_match_2_svc; | |||
249 | break; | |||
250 | ||||
251 | case YPPROC_FIRST((u_long)4): | |||
252 | xdr_argument = (xdrproc_t) xdr_ypreq_nokey; | |||
253 | xdr_result = (xdrproc_t) xdr_ypresp_key_val; | |||
254 | local = (char *(*)(char *, struct svc_req *)) ypproc_first_2_svc; | |||
255 | break; | |||
256 | ||||
257 | case YPPROC_NEXT((u_long)5): | |||
258 | xdr_argument = (xdrproc_t) xdr_ypreq_key; | |||
259 | xdr_result = (xdrproc_t) xdr_ypresp_key_val; | |||
260 | local = (char *(*)(char *, struct svc_req *)) ypproc_next_2_svc; | |||
261 | break; | |||
262 | ||||
263 | case YPPROC_XFR((u_long)6): | |||
264 | xdr_argument = (xdrproc_t) xdr_ypreq_xfr; | |||
265 | xdr_result = (xdrproc_t) xdr_ypresp_xfr; | |||
266 | local = (char *(*)(char *, struct svc_req *)) ypproc_xfr_2_svc; | |||
267 | break; | |||
268 | ||||
269 | case YPPROC_CLEAR((u_long)7): | |||
270 | xdr_argument = (xdrproc_t) xdr_void; | |||
271 | xdr_result = (xdrproc_t) xdr_void; | |||
272 | local = (char *(*)(char *, struct svc_req *)) ypproc_clear_2_svc; | |||
273 | break; | |||
274 | ||||
275 | case YPPROC_ALL((u_long)8): | |||
276 | xdr_argument = (xdrproc_t) xdr_ypreq_nokey; | |||
277 | xdr_result = (xdrproc_t) xdr_ypresp_all; | |||
278 | local = (char *(*)(char *, struct svc_req *)) ypproc_all_2_svc; | |||
279 | break; | |||
280 | ||||
281 | case YPPROC_MASTER((u_long)9): | |||
282 | xdr_argument = (xdrproc_t) xdr_ypreq_nokey; | |||
283 | xdr_result = (xdrproc_t) xdr_ypresp_master; | |||
284 | local = (char *(*)(char *, struct svc_req *)) ypproc_master_2_svc; | |||
285 | break; | |||
286 | ||||
287 | case YPPROC_ORDER((u_long)10): | |||
288 | xdr_argument = (xdrproc_t) xdr_ypreq_nokey; | |||
289 | xdr_result = (xdrproc_t) xdr_ypresp_order; | |||
290 | local = (char *(*)(char *, struct svc_req *)) ypproc_order_2_svc; | |||
291 | break; | |||
292 | ||||
293 | case YPPROC_MAPLIST((u_long)11): | |||
294 | xdr_argument = (xdrproc_t) xdr_domainname; | |||
295 | xdr_result = (xdrproc_t) xdr_ypresp_maplist; | |||
296 | local = (char *(*)(char *, struct svc_req *)) ypproc_maplist_2_svc; | |||
297 | break; | |||
298 | ||||
299 | default: | |||
300 | svcerr_noproc(transp); | |||
301 | _rpcsvcdirty = 0; | |||
302 | return; | |||
303 | } | |||
304 | (void) memset(&argument, 0, sizeof(argument)); | |||
305 | if (!svc_getargs(transp, xdr_argument, (caddr_t)&argument)(*(transp)->xp_ops->xp_getargs)((transp), (xdr_argument ), ((caddr_t)&argument))) { | |||
306 | svcerr_decode(transp); | |||
307 | _rpcsvcdirty = 0; | |||
308 | return; | |||
309 | } | |||
310 | result = (*local)((char *)&argument, rqstp); | |||
311 | if (result != NULL0 && !svc_sendreply(transp, xdr_result, result)) { | |||
312 | svcerr_systemerr(transp); | |||
313 | } | |||
314 | if (!svc_freeargs(transp, xdr_argument, (caddr_t)&argument)(*(transp)->xp_ops->xp_freeargs)((transp), (xdr_argument ), ((caddr_t)&argument))) { | |||
315 | _msgout("unable to free arguments"); | |||
316 | exit(1); | |||
317 | } | |||
318 | _rpcsvcdirty = 0; | |||
319 | } | |||
320 | ||||
321 | static void | |||
322 | hup(void) | |||
323 | { | |||
324 | /* Handle the log. */ | |||
325 | ypcloselog(); | |||
326 | ypopenlog(); | |||
327 | ||||
328 | acl_reset(); | |||
329 | if (aclfile != NULL0) { | |||
330 | yplog("sig_hup: reread %s", aclfile); | |||
331 | (void)acl_init(aclfile); | |||
332 | } else { | |||
333 | yplog("sig_hup: reread %s", YP_SECURENET_FILE"/var/yp/securenet"); | |||
334 | (void)acl_securenet(YP_SECURENET_FILE"/var/yp/securenet"); | |||
335 | } | |||
336 | ||||
337 | ypdb_close_all(); | |||
338 | } | |||
339 | ||||
340 | static void | |||
341 | my_svc_run(void) | |||
342 | { | |||
343 | struct pollfd *pfd = NULL0, *newp; | |||
344 | int nready, saved_max_pollfd = 0; | |||
345 | ||||
346 | for (;;) { | |||
347 | if (wantsighup) { | |||
348 | wantsighup = 0; | |||
349 | hup(); | |||
350 | } | |||
351 | if (svc_max_pollfd > saved_max_pollfd) { | |||
352 | newp = reallocarray(pfd, svc_max_pollfd, sizeof(*pfd)); | |||
353 | if (newp == NULL0) { | |||
354 | free(pfd); | |||
355 | perror("svc_run: - realloc failed"); | |||
356 | return; | |||
357 | } | |||
358 | pfd = newp; | |||
359 | saved_max_pollfd = svc_max_pollfd; | |||
360 | } | |||
361 | memcpy(pfd, svc_pollfd, sizeof(*pfd) * svc_max_pollfd); | |||
362 | ||||
363 | nready = poll(pfd, svc_max_pollfd, INFTIM(-1)); | |||
364 | switch (nready) { | |||
365 | case -1: | |||
366 | if (errno(*__errno()) == EINTR4) | |||
367 | continue; | |||
368 | perror("svc_run: - poll failed"); | |||
369 | free(pfd); | |||
370 | return; | |||
371 | case 0: | |||
372 | continue; | |||
373 | default: | |||
374 | svc_getreq_poll(pfd, nready); | |||
375 | } | |||
376 | } | |||
377 | } | |||
378 | ||||
379 | static void | |||
380 | usage(void) | |||
381 | { | |||
382 | (void)fprintf(stderr(&__sF[2]), "usage: ypserv [-1dx] [-a aclfile]\n"); | |||
383 | exit(1); | |||
384 | } | |||
385 | ||||
386 | int | |||
387 | main(int argc, char *argv[]) | |||
388 | { | |||
389 | int xflag = 0, allowv1 = 0, ch, sock, proto; | |||
| ||||
390 | struct sockaddr_in saddr; | |||
391 | socklen_t asize = sizeof(saddr); | |||
392 | extern char *optarg; | |||
393 | SVCXPRT *transp = NULL0; | |||
394 | ||||
395 | while ((ch = getopt(argc, argv, "1a:dx")) != -1) | |||
396 | switch (ch) { | |||
397 | case '1': | |||
398 | allowv1 = TRUE(1); | |||
399 | break; | |||
400 | case 'a': | |||
401 | aclfile = optarg; | |||
402 | break; | |||
403 | case 'd': | |||
404 | usedns = TRUE(1); | |||
405 | break; | |||
406 | case 'x': | |||
407 | xflag = TRUE(1); | |||
408 | break; | |||
409 | default: | |||
410 | usage(); | |||
411 | break; | |||
412 | } | |||
413 | ||||
414 | if (geteuid() != 0) { | |||
415 | (void)fprintf(stderr(&__sF[2]), "ypserv: must be root to run.\n"); | |||
416 | exit(1); | |||
417 | } | |||
418 | ||||
419 | if (aclfile
| |||
420 | (void)acl_init(aclfile); | |||
421 | else | |||
422 | (void)acl_securenet(YP_SECURENET_FILE"/var/yp/securenet"); | |||
423 | ||||
424 | if (xflag
| |||
425 | exit(1); | |||
426 | ||||
427 | if (getsockname(0, (struct sockaddr *)&saddr, &asize) == 0) { | |||
428 | socklen_t ssize = sizeof(int); | |||
429 | ||||
430 | if (saddr.sin_family != AF_INET2) | |||
431 | exit(1); | |||
432 | if (getsockopt(0, SOL_SOCKET0xffff, SO_TYPE0x1008, | |||
433 | &_rpcfdtype, &ssize) == -1) | |||
434 | exit(1); | |||
435 | sock = 0; | |||
436 | _rpcpmstart = 1; | |||
437 | proto = 0; | |||
438 | openlog("ypserv", LOG_PID0x01, LOG_DAEMON(3<<3)); | |||
439 | } else { | |||
440 | #ifndef RPC_SVC_FG | |||
441 | int i; | |||
442 | pid_t pid; | |||
443 | ||||
444 | pid = fork(); | |||
445 | if (pid < 0) { | |||
446 | perror("cannot fork"); | |||
447 | exit(1); | |||
448 | } | |||
449 | if (pid) | |||
450 | exit(0); | |||
451 | closefrom(0); | |||
452 | i = open("/dev/console", O_RDWR0x0002); | |||
453 | (void) dup2(i, 1); | |||
454 | (void) dup2(i, 2); | |||
455 | i = open("/dev/tty", O_RDWR0x0002); | |||
456 | if (i >= 0) { | |||
457 | (void) ioctl(i, TIOCNOTTY((unsigned long)0x20000000 | ((0 & 0x1fff) << 16) | ((('t')) << 8) | ((113))), NULL0); | |||
458 | (void) close(i); | |||
459 | } | |||
460 | openlog("ypserv", LOG_PID0x01, LOG_DAEMON(3<<3)); | |||
461 | #endif | |||
462 | sock = RPC_ANYSOCK-1; | |||
463 | (void) pmap_unset(YPPROG((u_long)100004), YPVERS((u_long)2)); | |||
464 | (void) pmap_unset(YPPROG((u_long)100004), YPOLDVERS((u_long)1)); | |||
465 | } | |||
466 | ||||
467 | ypopenlog(); /* open log file */ | |||
468 | ypdb_init(); /* init db stuff */ | |||
469 | ||||
470 | chdir("/"); | |||
471 | ||||
472 | (void)signal(SIGCHLD20, sig_child); | |||
473 | (void)signal(SIGHUP1, sig_hup); | |||
474 | ||||
475 | if (_rpcfdtype == 0 || _rpcfdtype == SOCK_DGRAM2) { | |||
476 | transp = svcudp_create(sock); | |||
477 | if (transp == NULL0) { | |||
478 | _msgout("cannot create udp service."); | |||
479 | exit(1); | |||
480 | } | |||
481 | if (transp->xp_port >= IPPORT_RESERVED1024) { | |||
482 | _msgout("cannot allocate udp privileged port."); | |||
483 | exit(1); | |||
484 | } | |||
485 | if (!_rpcpmstart) | |||
486 | proto = IPPROTO_UDP17; | |||
487 | if (allowv1
| |||
488 | if (!svc_register(transp, YPPROG((u_long)100004), YPOLDVERS((u_long)1), ypprog_1, proto)) { | |||
| ||||
489 | _msgout("unable to register (YPPROG, YPOLDVERS, udp)."); | |||
490 | exit(1); | |||
491 | } | |||
492 | } | |||
493 | if (!svc_register(transp, YPPROG((u_long)100004), YPVERS((u_long)2), ypprog_2, proto)) { | |||
494 | _msgout("unable to register (YPPROG, YPVERS, udp)."); | |||
495 | exit(1); | |||
496 | } | |||
497 | } | |||
498 | ||||
499 | if (_rpcfdtype == 0 || _rpcfdtype == SOCK_STREAM1) { | |||
500 | if (_rpcpmstart) | |||
501 | transp = svcfd_create(sock, 0, 0); | |||
502 | else | |||
503 | transp = svctcp_create(sock, 0, 0); | |||
504 | if (transp == NULL0) { | |||
505 | _msgout("cannot create tcp service."); | |||
506 | exit(1); | |||
507 | } | |||
508 | if (transp->xp_port >= IPPORT_RESERVED1024) { | |||
509 | _msgout("cannot allocate tcp privileged port."); | |||
510 | exit(1); | |||
511 | } | |||
512 | if (!_rpcpmstart) | |||
513 | proto = IPPROTO_TCP6; | |||
514 | if (allowv1) { | |||
515 | if (!svc_register(transp, YPPROG((u_long)100004), YPOLDVERS((u_long)1), ypprog_1, proto)) { | |||
516 | _msgout("unable to register (YPPROG, YPOLDVERS, tcp)."); | |||
517 | exit(1); | |||
518 | } | |||
519 | } | |||
520 | if (!svc_register(transp, YPPROG((u_long)100004), YPVERS((u_long)2), ypprog_2, proto)) { | |||
521 | _msgout("unable to register (YPPROG, YPVERS, tcp)."); | |||
522 | exit(1); | |||
523 | } | |||
524 | } | |||
525 | ||||
526 | if (transp == NULL0) { | |||
527 | _msgout("could not create a handle"); | |||
528 | exit(1); | |||
529 | } | |||
530 | if (_rpcpmstart) { | |||
531 | (void) signal(SIGALRM14, closedown); | |||
532 | (void) alarm(_RPCSVC_CLOSEDOWN120); | |||
533 | } | |||
534 | my_svc_run(); | |||
535 | _msgout("svc_run returned"); | |||
536 | exit(1); | |||
537 | /* NOTREACHED */ | |||
538 | } | |||
539 | ||||
540 | void | |||
541 | sig_child(int signo) | |||
542 | { | |||
543 | int save_errno = errno(*__errno()); | |||
544 | ||||
545 | while (wait3(NULL0, WNOHANG0x01, NULL0) > 0) | |||
546 | ; | |||
547 | errno(*__errno()) = save_errno; | |||
548 | } | |||
549 | ||||
550 | void | |||
551 | sig_hup(int signo) | |||
552 | { | |||
553 | wantsighup = 1; | |||
554 | } |