if_vtnet - Default to link up, when VIRTIO_NET_F_STATUS is not negotiated.
[dragonfly.git] / libexec / pppoed / pppoed.c
blobd856c3394c5a97a78996d36a8dd75599a60976af
1 /*-
2 * Copyright (c) 1999-2001 Brian Somers <brian@Awfulhak.org>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
26 * $FreeBSD: src/libexec/pppoed/pppoed.c,v 1.2.6.8 2002/06/17 02:21:25 brian Exp $
27 * $DragonFly: src/libexec/pppoed/pppoed.c,v 1.4 2007/06/04 00:40:31 swildner Exp $
30 #include <sys/param.h>
31 #include <sys/socket.h>
32 #include <sys/un.h>
33 #include <netinet/in.h>
34 #include <arpa/inet.h>
35 #include <netdb.h>
36 #include <netgraph.h>
37 #include <net/ethernet.h>
38 #include <netinet/in_systm.h>
39 #include <netinet/ip.h>
40 #include <netgraph/ether/ng_ether.h>
41 #include <netgraph/ng_message.h>
42 #include <netgraph/pppoe/ng_pppoe.h>
43 #include <netgraph/socket/ng_socket.h>
45 #include <errno.h>
46 #include <paths.h>
47 #include <signal.h>
48 #include <stdio.h>
49 #include <stdarg.h>
50 #include <stdlib.h>
51 #include <string.h>
52 #include <sysexits.h>
53 #include <sys/fcntl.h>
54 #ifndef NOKLDLOAD
55 #include <sys/linker.h>
56 #include <sys/module.h>
57 #endif
58 #include <sys/uio.h>
59 #include <sys/wait.h>
60 #include <syslog.h>
61 #include <termios.h>
62 #include <unistd.h>
65 #define DEFAULT_EXEC_PREFIX "exec /usr/sbin/ppp -direct "
66 #define HISMACADDR "HISMACADDR"
67 #define SESSION_ID "SESSION_ID"
69 static void nglog(const char *, ...) __printflike(1, 2);
70 static void nglogx(const char *, ...) __printflike(1, 2);
72 static int ReceivedSignal;
74 static int
75 usage(const char *prog)
77 fprintf(stderr, "usage: %s [-Fd] [-P pidfile] [-a name] [-e exec | -l label]"
78 " [-p provider] interface\n", prog);
79 return EX_USAGE;
82 static void
83 Farewell(int sig)
85 ReceivedSignal = sig;
88 static int
89 ConfigureNode(const char *prog __unused, const char *iface, const char *provider,
90 int cs, int ds __unused, int debug, struct ngm_connect *ngc)
93 * We're going to do this with the passed `ds' & `cs' descriptors:
95 * .---------.
96 * | ether |
97 * | <iface> |
98 * `---------'
99 * (orphan) ds cs
100 * | | |
101 * | | |
102 * (ethernet) | |
103 * .---------. .-----------.
104 * | pppoe | | socket |
105 * | <iface> |(pppoe-<pid>)<---->(pppoe-<pid>)| <unnamed> |
106 * `--------- `-----------'
107 * (exec-<pid>)
108 * ^ .-----------. .-------------.
109 * | | socket | | ppp -direct |
110 * `--->(exec-<pid>)| <unnamed> |--fd--| provider |
111 * `-----------' `-------------'
113 * where there are potentially many ppp processes running off of the
114 * same PPPoE node.
115 * The exec-<pid> hook isn't made 'till we Spawn().
118 char *epath, *spath;
119 struct ngpppoe_init_data *data;
120 const struct hooklist *hlist;
121 const struct nodeinfo *ninfo;
122 const struct linkinfo *nlink;
123 struct ngm_mkpeer mkp;
124 struct ng_mesg *resp;
125 u_char rbuf[2048];
126 uint32_t f;
127 int plen;
130 * Ask for a list of hooks attached to the "ether" node. This node should
131 * magically exist as a way of hooking stuff onto an ethernet device
133 epath = (char *)alloca(strlen(iface) + 2);
134 sprintf(epath, "%s:", iface);
136 if (debug)
137 fprintf(stderr, "Sending NGM_LISTHOOKS to %s\n", epath);
139 if (NgSendMsg(cs, epath, NGM_GENERIC_COOKIE, NGM_LISTHOOKS, NULL, 0) < 0) {
140 if (errno == ENOENT)
141 fprintf(stderr, "%s Cannot send a netgraph message: Invalid interface\n",
142 epath);
143 else
144 fprintf(stderr, "%s Cannot send a netgraph message: %s\n",
145 epath, strerror(errno));
146 return EX_UNAVAILABLE;
149 /* Get our list back */
150 resp = (struct ng_mesg *)rbuf;
151 if (NgRecvMsg(cs, resp, sizeof rbuf, NULL) <= 0) {
152 perror("Cannot get netgraph response");
153 return EX_UNAVAILABLE;
156 hlist = (const struct hooklist *)resp->data;
157 ninfo = &hlist->nodeinfo;
159 if (debug)
160 fprintf(stderr, "Got reply from id [%x]: Type %s with %d hooks\n",
161 ninfo->id, ninfo->type, ninfo->hooks);
163 /* Make sure we've got the right type of node */
164 if (strncmp(ninfo->type, NG_ETHER_NODE_TYPE, sizeof NG_ETHER_NODE_TYPE - 1)) {
165 fprintf(stderr, "%s Unexpected node type ``%s'' (wanted ``"
166 NG_ETHER_NODE_TYPE "'')\n", epath, ninfo->type);
167 return EX_DATAERR;
170 /* look for a hook already attached. */
171 for (f = 0; f < ninfo->hooks; f++) {
172 nlink = &hlist->link[f];
174 if (debug)
175 fprintf(stderr, " Got [%x]:%s -> [%x]:%s\n", ninfo->id,
176 nlink->ourhook, nlink->nodeinfo.id, nlink->peerhook);
178 if (!strcmp(nlink->ourhook, NG_ETHER_HOOK_ORPHAN) ||
179 !strcmp(nlink->ourhook, NG_ETHER_HOOK_DIVERT)) {
181 * Something is using the data coming out of this `ether' node.
182 * If it's a PPPoE node, we use that node, otherwise we complain that
183 * someone else is using the node.
185 if (strcmp(nlink->nodeinfo.type, NG_PPPOE_NODE_TYPE)) {
186 fprintf(stderr, "%s Node type %s is currently active\n",
187 epath, nlink->nodeinfo.type);
188 return EX_UNAVAILABLE;
190 break;
194 if (f == ninfo->hooks) {
196 * Create a new PPPoE node connected to the `ether' node using
197 * the magic `orphan' and `ethernet' hooks
199 snprintf(mkp.type, sizeof mkp.type, "%s", NG_PPPOE_NODE_TYPE);
200 snprintf(mkp.ourhook, sizeof mkp.ourhook, "%s", NG_ETHER_HOOK_ORPHAN);
201 snprintf(mkp.peerhook, sizeof mkp.peerhook, "%s", NG_PPPOE_HOOK_ETHERNET);
203 if (debug)
204 fprintf(stderr, "Send MKPEER: %s%s -> [type %s]:%s\n", epath,
205 mkp.ourhook, mkp.type, mkp.peerhook);
207 if (NgSendMsg(cs, epath, NGM_GENERIC_COOKIE,
208 NGM_MKPEER, &mkp, sizeof mkp) < 0) {
209 fprintf(stderr, "%s Cannot create a peer PPPoE node: %s\n",
210 epath, strerror(errno));
211 return EX_OSERR;
215 /* Connect the PPPoE node to our socket node. */
216 snprintf(ngc->path, sizeof ngc->path, "%s%s", epath, NG_ETHER_HOOK_ORPHAN);
217 snprintf(ngc->ourhook, sizeof ngc->ourhook, "pppoe-%ld", (long)getpid());
218 memcpy(ngc->peerhook, ngc->ourhook, sizeof ngc->peerhook);
220 if (NgSendMsg(cs, ".:", NGM_GENERIC_COOKIE,
221 NGM_CONNECT, ngc, sizeof *ngc) < 0) {
222 perror("Cannot CONNECT PPPoE and socket nodes");
223 return EX_OSERR;
226 plen = strlen(provider);
228 data = (struct ngpppoe_init_data *)alloca(sizeof *data + plen);
229 snprintf(data->hook, sizeof data->hook, "%s", ngc->peerhook);
230 memcpy(data->data, provider, plen);
231 data->data_len = plen;
233 spath = (char *)alloca(strlen(ngc->peerhook) + 3);
234 strcpy(spath, ".:");
235 strcpy(spath + 2, ngc->ourhook);
237 if (debug) {
238 if (provider)
239 fprintf(stderr, "Sending PPPOE_LISTEN to %s, provider %s\n",
240 spath, provider);
241 else
242 fprintf(stderr, "Sending PPPOE_LISTEN to %s\n", spath);
245 if (NgSendMsg(cs, spath, NGM_PPPOE_COOKIE, NGM_PPPOE_LISTEN,
246 data, sizeof *data + plen) == -1) {
247 fprintf(stderr, "%s: Cannot LISTEN on netgraph node: %s\n",
248 spath, strerror(errno));
249 return EX_OSERR;
252 return 0;
255 static void
256 Spawn(const char *prog __unused, const char *acname, const char *provider,
257 const char *exec, struct ngm_connect ngc, int cs, int ds, void *request,
258 size_t sz, int debug)
260 char msgbuf[sizeof(struct ng_mesg) + sizeof(struct ngpppoe_sts)];
261 struct ng_mesg *rep = (struct ng_mesg *)msgbuf;
262 struct ngpppoe_sts *sts = (struct ngpppoe_sts *)(msgbuf + sizeof *rep);
263 struct ngpppoe_init_data *data;
264 char env[18], unknown[14], sessionid[5], *path;
265 unsigned char *macaddr;
266 const char *msg;
267 int ret, slen;
269 switch ((ret = fork())) {
270 case -1:
271 syslog(LOG_ERR, "fork: %m");
272 break;
274 case 0:
275 switch (fork()) {
276 case 0:
277 break;
278 case -1:
279 _exit(errno);
280 default:
281 _exit(0);
283 close(cs);
284 close(ds);
286 /* Create a new socket node */
287 if (debug)
288 syslog(LOG_INFO, "Creating a new socket node");
290 if (NgMkSockNode(NULL, &cs, &ds) == -1) {
291 syslog(LOG_ERR, "Cannot create netgraph socket node: %m");
292 _exit(EX_CANTCREAT);
295 /* Connect the PPPoE node to our new socket node. */
296 snprintf(ngc.ourhook, sizeof ngc.ourhook, "exec-%ld", (long)getpid());
297 memcpy(ngc.peerhook, ngc.ourhook, sizeof ngc.peerhook);
299 if (debug)
300 syslog(LOG_INFO, "Sending CONNECT from .:%s -> %s.%s",
301 ngc.ourhook, ngc.path, ngc.peerhook);
302 if (NgSendMsg(cs, ".:", NGM_GENERIC_COOKIE,
303 NGM_CONNECT, &ngc, sizeof ngc) < 0) {
304 syslog(LOG_ERR, "Cannot CONNECT PPPoE and socket nodes: %m");
305 _exit(EX_OSERR);
309 * If we tell the socket node not to LINGER, it will go away when
310 * the last hook is removed.
312 if (debug)
313 syslog(LOG_INFO, "Sending NGM_SOCK_CMD_NOLINGER to socket");
314 if (NgSendMsg(cs, ".:", NGM_SOCKET_COOKIE,
315 NGM_SOCK_CMD_NOLINGER, NULL, 0) < 0) {
316 syslog(LOG_ERR, "Cannot send NGM_SOCK_CMD_NOLINGER: %m");
317 _exit(EX_OSERR);
320 /* Put the PPPoE node into OFFER mode */
321 slen = strlen(acname);
322 data = (struct ngpppoe_init_data *)alloca(sizeof *data + slen);
323 snprintf(data->hook, sizeof data->hook, "%s", ngc.ourhook);
324 memcpy(data->data, acname, slen);
325 data->data_len = slen;
327 path = (char *)alloca(strlen(ngc.ourhook) + 3);
328 strcpy(path, ".:");
329 strcpy(path + 2, ngc.ourhook);
331 syslog(LOG_INFO, "Offering to %s as access concentrator %s",
332 path, acname);
333 if (NgSendMsg(cs, path, NGM_PPPOE_COOKIE, NGM_PPPOE_OFFER,
334 data, sizeof *data + slen) == -1) {
335 syslog(LOG_INFO, "%s: Cannot OFFER on netgraph node: %m", path);
336 _exit(EX_OSERR);
338 /* If we have a provider code, set it */
339 if (provider) {
340 slen = strlen(provider);
341 data = (struct ngpppoe_init_data *)alloca(sizeof *data + slen);
342 snprintf(data->hook, sizeof data->hook, "%s", ngc.ourhook);
343 memcpy(data->data, provider, slen);
344 data->data_len = slen;
346 syslog(LOG_INFO, "adding to %s as offered service %s",
347 path, acname);
348 if (NgSendMsg(cs, path, NGM_PPPOE_COOKIE, NGM_PPPOE_SERVICE,
349 data, sizeof *data + slen) == -1) {
350 syslog(LOG_INFO, "%s: Cannot add service on netgraph node: %m", path);
351 _exit(EX_OSERR);
355 /* Put the peer's MAC address in the environment */
356 if (sz >= sizeof(struct ether_header)) {
357 macaddr = ((struct ether_header *)request)->ether_shost;
358 snprintf(env, sizeof(env), "%x:%x:%x:%x:%x:%x",
359 macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4],
360 macaddr[5]);
361 if (setenv(HISMACADDR, env, 1) != 0)
362 syslog(LOG_INFO, "setenv: cannot set %s: %m", HISMACADDR);
365 /* And send our request data to the waiting node */
366 if (debug)
367 syslog(LOG_INFO, "Sending original request to %s (%zu bytes)", path, sz);
368 if (NgSendData(ds, ngc.ourhook, request, sz) == -1) {
369 syslog(LOG_ERR, "Cannot send original request to %s: %m", path);
370 _exit(EX_OSERR);
373 /* Then wait for a success indication */
375 if (debug)
376 syslog(LOG_INFO, "Waiting for a SUCCESS reply %s", path);
378 do {
379 if ((ret = NgRecvMsg(cs, rep, sizeof msgbuf, NULL)) < 0) {
380 syslog(LOG_ERR, "%s: Cannot receive a message: %m", path);
381 _exit(EX_OSERR);
384 if (ret == 0) {
385 /* The socket has been closed */
386 syslog(LOG_INFO, "%s: Client timed out", path);
387 _exit(EX_TEMPFAIL);
390 if (rep->header.version != NG_VERSION) {
391 syslog(LOG_ERR, "%ld: Unexpected netgraph version, expected %ld",
392 (long)rep->header.version, (long)NG_VERSION);
393 _exit(EX_PROTOCOL);
396 if (rep->header.typecookie != NGM_PPPOE_COOKIE) {
397 syslog(LOG_INFO, "%ld: Unexpected netgraph cookie, expected %ld",
398 (long)rep->header.typecookie, (long)NGM_PPPOE_COOKIE);
399 continue;
402 switch (rep->header.cmd) {
403 case NGM_PPPOE_SET_FLAG: msg = "SET_FLAG"; break;
404 case NGM_PPPOE_CONNECT: msg = "CONNECT"; break;
405 case NGM_PPPOE_LISTEN: msg = "LISTEN"; break;
406 case NGM_PPPOE_OFFER: msg = "OFFER"; break;
407 case NGM_PPPOE_SUCCESS: msg = "SUCCESS"; break;
408 case NGM_PPPOE_FAIL: msg = "FAIL"; break;
409 case NGM_PPPOE_CLOSE: msg = "CLOSE"; break;
410 case NGM_PPPOE_GET_STATUS: msg = "GET_STATUS"; break;
411 case NGM_PPPOE_ACNAME:
412 msg = "ACNAME";
413 if (setenv("ACNAME", sts->hook, 1) != 0)
414 syslog(LOG_WARNING, "setenv: cannot set ACNAME=%s: %m",
415 sts->hook);
416 break;
417 case NGM_PPPOE_SESSIONID:
418 msg = "SESSIONID";
419 snprintf(sessionid, sizeof sessionid, "%04x", *(u_int16_t *)sts);
420 if (setenv("SESSIONID", sessionid, 1) != 0)
421 syslog(LOG_WARNING, "setenv: cannot set SESSIONID=%s: %m",
422 sessionid);
423 break;
424 default:
425 snprintf(unknown, sizeof unknown, "<%d>", (int)rep->header.cmd);
426 msg = unknown;
427 break;
430 switch (rep->header.cmd) {
431 case NGM_PPPOE_FAIL:
432 case NGM_PPPOE_CLOSE:
433 syslog(LOG_ERR, "Received NGM_PPPOE_%s (hook \"%s\")",
434 msg, sts->hook);
435 _exit(0);
438 syslog(LOG_INFO, "Received NGM_PPPOE_%s (hook \"%s\")", msg, sts->hook);
439 } while (rep->header.cmd != NGM_PPPOE_SUCCESS);
441 dup2(ds, STDIN_FILENO);
442 dup2(ds, STDOUT_FILENO);
443 close(ds);
444 close(cs);
446 setsid();
447 syslog(LOG_INFO, "Executing: %s", exec);
448 execlp(_PATH_BSHELL, _PATH_BSHELL, "-c", exec, NULL);
449 syslog(LOG_ERR, "execlp failed: %m");
450 _exit(EX_OSFILE);
452 default:
453 wait(&ret);
454 errno = ret;
455 if (errno)
456 syslog(LOG_ERR, "Second fork failed: %m");
457 break;
461 #ifndef NOKLDLOAD
462 static int
463 LoadModules(void)
465 const char *module[] = { "netgraph", "ng_socket", "ng_ether", "ng_pppoe" };
466 size_t f;
468 for (f = 0; f < sizeof module / sizeof *module; f++)
469 if (modfind(module[f]) == -1 && kldload(module[f]) == -1) {
470 fprintf(stderr, "kldload: %s: %s\n", module[f], strerror(errno));
471 return 0;
474 return 1;
476 #endif
478 static void
479 nglog(const char *fmt, ...)
481 char nfmt[256];
482 va_list ap;
484 snprintf(nfmt, sizeof nfmt, "%s: %s", fmt, strerror(errno));
485 va_start(ap, fmt);
486 vsyslog(LOG_INFO, nfmt, ap);
487 va_end(ap);
490 static void
491 nglogx(const char *fmt, ...)
493 va_list ap;
495 va_start(ap, fmt);
496 vsyslog(LOG_INFO, fmt, ap);
497 va_end(ap);
501 main(int argc, char *argv[])
503 char hostname[MAXHOSTNAMELEN], *exec, rhook[NG_HOOKSIZ];
504 unsigned char response[1024];
505 const char *label, *prog, *provider, *acname;
506 struct ngm_connect ngc;
507 struct sigaction act;
508 int ch, cs, ds, ret, optF, optd, optn, sz, f;
509 const char *pidfile;
511 prog = strrchr(argv[0], '/');
512 prog = prog ? prog + 1 : argv[0];
513 pidfile = NULL;
514 exec = NULL;
515 label = NULL;
516 acname = NULL;
517 provider = "";
518 optF = optd = optn = 0;
520 while ((ch = getopt(argc, argv, "FP:a:de:l:n:p:")) != -1) {
521 switch (ch) {
522 case 'F':
523 optF = 1;
524 break;
526 case 'P':
527 pidfile = optarg;
528 break;
530 case 'a':
531 acname = optarg;
532 break;
534 case 'd':
535 optd = 1;
536 break;
538 case 'e':
539 exec = optarg;
540 break;
542 case 'l':
543 label = optarg;
544 break;
546 case 'n':
547 optn = 1;
548 NgSetDebug(atoi(optarg));
549 break;
551 case 'p':
552 provider = optarg;
553 break;
555 default:
556 return usage(prog);
560 if (optind >= argc || optind + 2 < argc)
561 return usage(prog);
563 if (exec != NULL && label != NULL)
564 return usage(prog);
566 if (exec == NULL) {
567 if (label == NULL)
568 label = provider;
569 if (label == NULL) {
570 fprintf(stderr, "%s: Either a provider, a label or an exec command"
571 " must be given\n", prog);
572 return usage(prog);
574 exec = (char *)alloca(sizeof DEFAULT_EXEC_PREFIX + strlen(label));
575 if (exec == NULL) {
576 fprintf(stderr, "%s: Cannot allocate %zu bytes\n", prog,
577 sizeof DEFAULT_EXEC_PREFIX + strlen(label));
578 return EX_OSERR;
580 strcpy(exec, DEFAULT_EXEC_PREFIX);
581 strcpy(exec + sizeof DEFAULT_EXEC_PREFIX - 1, label);
584 if (acname == NULL) {
585 char *dot;
587 if (gethostname(hostname, sizeof hostname))
588 strcpy(hostname, "localhost");
589 else if ((dot = strchr(hostname, '.')))
590 *dot = '\0';
592 acname = hostname;
595 #ifndef NOKLDLOAD
596 if (!LoadModules())
597 return EX_UNAVAILABLE;
598 #endif
600 /* Create a socket node */
601 if (NgMkSockNode(NULL, &cs, &ds) == -1) {
602 perror("Cannot create netgraph socket node");
603 return EX_CANTCREAT;
606 /* Connect it up (and fill in `ngc') */
607 if ((ret = ConfigureNode(prog, argv[optind], provider, cs, ds,
608 optd, &ngc)) != 0) {
609 close(cs);
610 close(ds);
611 return ret;
614 if (!optF && daemon(1, 0) == -1) {
615 perror("daemon()");
616 close(cs);
617 close(ds);
618 return EX_OSERR;
622 if (pidfile != NULL) {
623 FILE *fp;
625 if ((fp = fopen(pidfile, "w")) == NULL) {
626 perror(pidfile);
627 close(cs);
628 close(ds);
629 return EX_CANTCREAT;
630 } else {
631 fprintf(fp, "%d\n", (int)getpid());
632 fclose(fp);
636 openlog(prog, LOG_PID | (optF ? LOG_PERROR : 0), LOG_DAEMON);
637 if (!optF && optn)
638 NgSetErrLog(nglog, nglogx);
640 memset(&act, '\0', sizeof act);
641 act.sa_handler = Farewell;
642 act.sa_flags = 0;
643 sigemptyset(&act.sa_mask);
644 sigaction(SIGHUP, &act, NULL);
645 sigaction(SIGINT, &act, NULL);
646 sigaction(SIGQUIT, &act, NULL);
647 sigaction(SIGTERM, &act, NULL);
649 while (!ReceivedSignal) {
650 if (*provider)
651 syslog(LOG_INFO, "Listening as provider %s", provider);
652 else
653 syslog(LOG_INFO, "Listening");
655 switch (sz = NgRecvData(ds, response, sizeof response, rhook)) {
656 case -1:
657 syslog(LOG_INFO, "NgRecvData: %m");
658 break;
659 case 0:
660 syslog(LOG_INFO, "NgRecvData: socket closed");
661 break;
662 default:
663 if (optd) {
664 char *dbuf, *ptr;
666 ptr = dbuf = alloca(sz * 2 + 1);
667 for (f = 0; f < sz; f++, ptr += 2)
668 sprintf(ptr, "%02x", (u_char)response[f]);
669 *ptr = '\0';
670 syslog(LOG_INFO, "Got %d bytes of data: %s", sz, dbuf);
673 if (sz <= 0) {
674 ret = EX_UNAVAILABLE;
675 break;
677 Spawn(prog, acname, provider, exec, ngc, cs, ds, response, sz, optd);
680 if (pidfile)
681 remove(pidfile);
683 if (ReceivedSignal) {
684 syslog(LOG_INFO, "Received signal %d, exiting", ReceivedSignal);
686 signal(ReceivedSignal, SIG_DFL);
687 raise(ReceivedSignal);
689 /* NOTREACHED */
691 ret = -ReceivedSignal;
694 return ret;