Testing - fix bugs in fsx related to 64-bit systems.
[dragonfly.git] / libexec / pppoed / pppoed.c
blob04e326f24a6675ba308b188df739765e3a33b9ef
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 nglogx(const char *, ...) __printflike(1, 2);
71 static int ReceivedSignal;
73 static int
74 usage(const char *prog)
76 fprintf(stderr, "usage: %s [-Fd] [-P pidfile] [-a name] [-e exec | -l label]"
77 " [-p provider] interface\n", prog);
78 return EX_USAGE;
81 static void
82 Farewell(int sig)
84 ReceivedSignal = sig;
87 static int
88 ConfigureNode(const char *prog __unused, const char *iface, const char *provider,
89 int cs, int ds __unused, int debug, struct ngm_connect *ngc)
92 * We're going to do this with the passed `ds' & `cs' descriptors:
94 * .---------.
95 * | ether |
96 * | <iface> |
97 * `---------'
98 * (orphan) ds cs
99 * | | |
100 * | | |
101 * (ethernet) | |
102 * .---------. .-----------.
103 * | pppoe | | socket |
104 * | <iface> |(pppoe-<pid>)<---->(pppoe-<pid>)| <unnamed> |
105 * `--------- `-----------'
106 * (exec-<pid>)
107 * ^ .-----------. .-------------.
108 * | | socket | | ppp -direct |
109 * `--->(exec-<pid>)| <unnamed> |--fd--| provider |
110 * `-----------' `-------------'
112 * where there are potentially many ppp processes running off of the
113 * same PPPoE node.
114 * The exec-<pid> hook isn't made 'till we Spawn().
117 char *epath, *spath;
118 struct ngpppoe_init_data *data;
119 const struct hooklist *hlist;
120 const struct nodeinfo *ninfo;
121 const struct linkinfo *nlink;
122 struct ngm_mkpeer mkp;
123 struct ng_mesg *resp;
124 u_char rbuf[2048];
125 uint32_t f;
126 int plen;
129 * Ask for a list of hooks attached to the "ether" node. This node should
130 * magically exist as a way of hooking stuff onto an ethernet device
132 epath = (char *)alloca(strlen(iface) + 2);
133 sprintf(epath, "%s:", iface);
135 if (debug)
136 fprintf(stderr, "Sending NGM_LISTHOOKS to %s\n", epath);
138 if (NgSendMsg(cs, epath, NGM_GENERIC_COOKIE, NGM_LISTHOOKS, NULL, 0) < 0) {
139 if (errno == ENOENT)
140 fprintf(stderr, "%s Cannot send a netgraph message: Invalid interface\n",
141 epath);
142 else
143 fprintf(stderr, "%s Cannot send a netgraph message: %s\n",
144 epath, strerror(errno));
145 return EX_UNAVAILABLE;
148 /* Get our list back */
149 resp = (struct ng_mesg *)rbuf;
150 if (NgRecvMsg(cs, resp, sizeof rbuf, NULL) <= 0) {
151 perror("Cannot get netgraph response");
152 return EX_UNAVAILABLE;
155 hlist = (const struct hooklist *)resp->data;
156 ninfo = &hlist->nodeinfo;
158 if (debug)
159 fprintf(stderr, "Got reply from id [%x]: Type %s with %d hooks\n",
160 ninfo->id, ninfo->type, ninfo->hooks);
162 /* Make sure we've got the right type of node */
163 if (strncmp(ninfo->type, NG_ETHER_NODE_TYPE, sizeof NG_ETHER_NODE_TYPE - 1)) {
164 fprintf(stderr, "%s Unexpected node type ``%s'' (wanted ``"
165 NG_ETHER_NODE_TYPE "'')\n", epath, ninfo->type);
166 return EX_DATAERR;
169 /* look for a hook already attached. */
170 for (f = 0; f < ninfo->hooks; f++) {
171 nlink = &hlist->link[f];
173 if (debug)
174 fprintf(stderr, " Got [%x]:%s -> [%x]:%s\n", ninfo->id,
175 nlink->ourhook, nlink->nodeinfo.id, nlink->peerhook);
177 if (!strcmp(nlink->ourhook, NG_ETHER_HOOK_ORPHAN) ||
178 !strcmp(nlink->ourhook, NG_ETHER_HOOK_DIVERT)) {
180 * Something is using the data coming out of this `ether' node.
181 * If it's a PPPoE node, we use that node, otherwise we complain that
182 * someone else is using the node.
184 if (strcmp(nlink->nodeinfo.type, NG_PPPOE_NODE_TYPE)) {
185 fprintf(stderr, "%s Node type %s is currently active\n",
186 epath, nlink->nodeinfo.type);
187 return EX_UNAVAILABLE;
189 break;
193 if (f == ninfo->hooks) {
195 * Create a new PPPoE node connected to the `ether' node using
196 * the magic `orphan' and `ethernet' hooks
198 snprintf(mkp.type, sizeof mkp.type, "%s", NG_PPPOE_NODE_TYPE);
199 snprintf(mkp.ourhook, sizeof mkp.ourhook, "%s", NG_ETHER_HOOK_ORPHAN);
200 snprintf(mkp.peerhook, sizeof mkp.peerhook, "%s", NG_PPPOE_HOOK_ETHERNET);
202 if (debug)
203 fprintf(stderr, "Send MKPEER: %s%s -> [type %s]:%s\n", epath,
204 mkp.ourhook, mkp.type, mkp.peerhook);
206 if (NgSendMsg(cs, epath, NGM_GENERIC_COOKIE,
207 NGM_MKPEER, &mkp, sizeof mkp) < 0) {
208 fprintf(stderr, "%s Cannot create a peer PPPoE node: %s\n",
209 epath, strerror(errno));
210 return EX_OSERR;
214 /* Connect the PPPoE node to our socket node. */
215 snprintf(ngc->path, sizeof ngc->path, "%s%s", epath, NG_ETHER_HOOK_ORPHAN);
216 snprintf(ngc->ourhook, sizeof ngc->ourhook, "pppoe-%ld", (long)getpid());
217 memcpy(ngc->peerhook, ngc->ourhook, sizeof ngc->peerhook);
219 if (NgSendMsg(cs, ".:", NGM_GENERIC_COOKIE,
220 NGM_CONNECT, ngc, sizeof *ngc) < 0) {
221 perror("Cannot CONNECT PPPoE and socket nodes");
222 return EX_OSERR;
225 plen = strlen(provider);
227 data = (struct ngpppoe_init_data *)alloca(sizeof *data + plen);
228 snprintf(data->hook, sizeof data->hook, "%s", ngc->peerhook);
229 memcpy(data->data, provider, plen);
230 data->data_len = plen;
232 spath = (char *)alloca(strlen(ngc->peerhook) + 3);
233 strcpy(spath, ".:");
234 strcpy(spath + 2, ngc->ourhook);
236 if (debug) {
237 if (provider)
238 fprintf(stderr, "Sending PPPOE_LISTEN to %s, provider %s\n",
239 spath, provider);
240 else
241 fprintf(stderr, "Sending PPPOE_LISTEN to %s\n", spath);
244 if (NgSendMsg(cs, spath, NGM_PPPOE_COOKIE, NGM_PPPOE_LISTEN,
245 data, sizeof *data + plen) == -1) {
246 fprintf(stderr, "%s: Cannot LISTEN on netgraph node: %s\n",
247 spath, strerror(errno));
248 return EX_OSERR;
251 return 0;
254 static void
255 Spawn(const char *prog __unused, const char *acname, const char *provider,
256 const char *exec, struct ngm_connect ngc, int cs, int ds, void *request,
257 size_t sz, int debug)
259 char msgbuf[sizeof(struct ng_mesg) + sizeof(struct ngpppoe_sts)];
260 struct ng_mesg *rep = (struct ng_mesg *)msgbuf;
261 struct ngpppoe_sts *sts = (struct ngpppoe_sts *)(msgbuf + sizeof *rep);
262 struct ngpppoe_init_data *data;
263 char env[18], unknown[14], sessionid[5], *path;
264 unsigned char *macaddr;
265 const char *msg;
266 int ret, slen;
268 switch ((ret = fork())) {
269 case -1:
270 syslog(LOG_ERR, "fork: %m");
271 break;
273 case 0:
274 switch (fork()) {
275 case 0:
276 break;
277 case -1:
278 _exit(errno);
279 default:
280 _exit(0);
282 close(cs);
283 close(ds);
285 /* Create a new socket node */
286 if (debug)
287 syslog(LOG_INFO, "Creating a new socket node");
289 if (NgMkSockNode(NULL, &cs, &ds) == -1) {
290 syslog(LOG_ERR, "Cannot create netgraph socket node: %m");
291 _exit(EX_CANTCREAT);
294 /* Connect the PPPoE node to our new socket node. */
295 snprintf(ngc.ourhook, sizeof ngc.ourhook, "exec-%ld", (long)getpid());
296 memcpy(ngc.peerhook, ngc.ourhook, sizeof ngc.peerhook);
298 if (debug)
299 syslog(LOG_INFO, "Sending CONNECT from .:%s -> %s.%s",
300 ngc.ourhook, ngc.path, ngc.peerhook);
301 if (NgSendMsg(cs, ".:", NGM_GENERIC_COOKIE,
302 NGM_CONNECT, &ngc, sizeof ngc) < 0) {
303 syslog(LOG_ERR, "Cannot CONNECT PPPoE and socket nodes: %m");
304 _exit(EX_OSERR);
308 * If we tell the socket node not to LINGER, it will go away when
309 * the last hook is removed.
311 if (debug)
312 syslog(LOG_INFO, "Sending NGM_SOCK_CMD_NOLINGER to socket");
313 if (NgSendMsg(cs, ".:", NGM_SOCKET_COOKIE,
314 NGM_SOCK_CMD_NOLINGER, NULL, 0) < 0) {
315 syslog(LOG_ERR, "Cannot send NGM_SOCK_CMD_NOLINGER: %m");
316 _exit(EX_OSERR);
319 /* Put the PPPoE node into OFFER mode */
320 slen = strlen(acname);
321 data = (struct ngpppoe_init_data *)alloca(sizeof *data + slen);
322 snprintf(data->hook, sizeof data->hook, "%s", ngc.ourhook);
323 memcpy(data->data, acname, slen);
324 data->data_len = slen;
326 path = (char *)alloca(strlen(ngc.ourhook) + 3);
327 strcpy(path, ".:");
328 strcpy(path + 2, ngc.ourhook);
330 syslog(LOG_INFO, "Offering to %s as access concentrator %s",
331 path, acname);
332 if (NgSendMsg(cs, path, NGM_PPPOE_COOKIE, NGM_PPPOE_OFFER,
333 data, sizeof *data + slen) == -1) {
334 syslog(LOG_INFO, "%s: Cannot OFFER on netgraph node: %m", path);
335 _exit(EX_OSERR);
337 /* If we have a provider code, set it */
338 if (provider) {
339 slen = strlen(provider);
340 data = (struct ngpppoe_init_data *)alloca(sizeof *data + slen);
341 snprintf(data->hook, sizeof data->hook, "%s", ngc.ourhook);
342 memcpy(data->data, provider, slen);
343 data->data_len = slen;
345 syslog(LOG_INFO, "adding to %s as offered service %s",
346 path, acname);
347 if (NgSendMsg(cs, path, NGM_PPPOE_COOKIE, NGM_PPPOE_SERVICE,
348 data, sizeof *data + slen) == -1) {
349 syslog(LOG_INFO, "%s: Cannot add service on netgraph node: %m", path);
350 _exit(EX_OSERR);
354 /* Put the peer's MAC address in the environment */
355 if (sz >= sizeof(struct ether_header)) {
356 macaddr = ((struct ether_header *)request)->ether_shost;
357 snprintf(env, sizeof(env), "%x:%x:%x:%x:%x:%x",
358 macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4],
359 macaddr[5]);
360 if (setenv(HISMACADDR, env, 1) != 0)
361 syslog(LOG_INFO, "setenv: cannot set %s: %m", HISMACADDR);
364 /* And send our request data to the waiting node */
365 if (debug)
366 syslog(LOG_INFO, "Sending original request to %s (%zu bytes)", path, sz);
367 if (NgSendData(ds, ngc.ourhook, request, sz) == -1) {
368 syslog(LOG_ERR, "Cannot send original request to %s: %m", path);
369 _exit(EX_OSERR);
372 /* Then wait for a success indication */
374 if (debug)
375 syslog(LOG_INFO, "Waiting for a SUCCESS reply %s", path);
377 do {
378 if ((ret = NgRecvMsg(cs, rep, sizeof msgbuf, NULL)) < 0) {
379 syslog(LOG_ERR, "%s: Cannot receive a message: %m", path);
380 _exit(EX_OSERR);
383 if (ret == 0) {
384 /* The socket has been closed */
385 syslog(LOG_INFO, "%s: Client timed out", path);
386 _exit(EX_TEMPFAIL);
389 if (rep->header.version != NG_VERSION) {
390 syslog(LOG_ERR, "%ld: Unexpected netgraph version, expected %ld",
391 (long)rep->header.version, (long)NG_VERSION);
392 _exit(EX_PROTOCOL);
395 if (rep->header.typecookie != NGM_PPPOE_COOKIE) {
396 syslog(LOG_INFO, "%ld: Unexpected netgraph cookie, expected %ld",
397 (long)rep->header.typecookie, (long)NGM_PPPOE_COOKIE);
398 continue;
401 switch (rep->header.cmd) {
402 case NGM_PPPOE_SET_FLAG: msg = "SET_FLAG"; break;
403 case NGM_PPPOE_CONNECT: msg = "CONNECT"; break;
404 case NGM_PPPOE_LISTEN: msg = "LISTEN"; break;
405 case NGM_PPPOE_OFFER: msg = "OFFER"; break;
406 case NGM_PPPOE_SUCCESS: msg = "SUCCESS"; break;
407 case NGM_PPPOE_FAIL: msg = "FAIL"; break;
408 case NGM_PPPOE_CLOSE: msg = "CLOSE"; break;
409 case NGM_PPPOE_GET_STATUS: msg = "GET_STATUS"; break;
410 case NGM_PPPOE_ACNAME:
411 msg = "ACNAME";
412 if (setenv("ACNAME", sts->hook, 1) != 0)
413 syslog(LOG_WARNING, "setenv: cannot set ACNAME=%s: %m",
414 sts->hook);
415 break;
416 case NGM_PPPOE_SESSIONID:
417 msg = "SESSIONID";
418 snprintf(sessionid, sizeof sessionid, "%04x", *(u_int16_t *)sts);
419 if (setenv("SESSIONID", sessionid, 1) != 0)
420 syslog(LOG_WARNING, "setenv: cannot set SESSIONID=%s: %m",
421 sessionid);
422 break;
423 default:
424 snprintf(unknown, sizeof unknown, "<%d>", (int)rep->header.cmd);
425 msg = unknown;
426 break;
429 switch (rep->header.cmd) {
430 case NGM_PPPOE_FAIL:
431 case NGM_PPPOE_CLOSE:
432 syslog(LOG_ERR, "Received NGM_PPPOE_%s (hook \"%s\")",
433 msg, sts->hook);
434 _exit(0);
437 syslog(LOG_INFO, "Received NGM_PPPOE_%s (hook \"%s\")", msg, sts->hook);
438 } while (rep->header.cmd != NGM_PPPOE_SUCCESS);
440 dup2(ds, STDIN_FILENO);
441 dup2(ds, STDOUT_FILENO);
442 close(ds);
443 close(cs);
445 setsid();
446 syslog(LOG_INFO, "Executing: %s", exec);
447 execlp(_PATH_BSHELL, _PATH_BSHELL, "-c", exec, NULL);
448 syslog(LOG_ERR, "execlp failed: %m");
449 _exit(EX_OSFILE);
451 default:
452 wait(&ret);
453 errno = ret;
454 if (errno)
455 syslog(LOG_ERR, "Second fork failed: %m");
456 break;
460 #ifndef NOKLDLOAD
461 static int
462 LoadModules(void)
464 const char *module[] = { "netgraph", "ng_socket", "ng_ether", "ng_pppoe" };
465 size_t f;
467 for (f = 0; f < sizeof module / sizeof *module; f++)
468 if (modfind(module[f]) == -1 && kldload(module[f]) == -1) {
469 fprintf(stderr, "kldload: %s: %s\n", module[f], strerror(errno));
470 return 0;
473 return 1;
475 #endif
477 static void
478 nglog(const char *fmt, ...)
480 char nfmt[256];
481 va_list ap;
483 snprintf(nfmt, sizeof nfmt, "%s: %s", fmt, strerror(errno));
484 va_start(ap, fmt);
485 vsyslog(LOG_INFO, nfmt, ap);
486 va_end(ap);
489 static void
490 nglogx(const char *fmt, ...)
492 va_list ap;
494 va_start(ap, fmt);
495 vsyslog(LOG_INFO, fmt, ap);
496 va_end(ap);
500 main(int argc, char *argv[])
502 char hostname[MAXHOSTNAMELEN], *exec, rhook[NG_HOOKSIZ];
503 unsigned char response[1024];
504 const char *label, *prog, *provider, *acname;
505 struct ngm_connect ngc;
506 struct sigaction act;
507 int ch, cs, ds, ret, optF, optd, optn, sz, f;
508 const char *pidfile;
510 prog = strrchr(argv[0], '/');
511 prog = prog ? prog + 1 : argv[0];
512 pidfile = NULL;
513 exec = NULL;
514 label = NULL;
515 acname = NULL;
516 provider = "";
517 optF = optd = optn = 0;
519 while ((ch = getopt(argc, argv, "FP:a:de:l:n:p:")) != -1) {
520 switch (ch) {
521 case 'F':
522 optF = 1;
523 break;
525 case 'P':
526 pidfile = optarg;
527 break;
529 case 'a':
530 acname = optarg;
531 break;
533 case 'd':
534 optd = 1;
535 break;
537 case 'e':
538 exec = optarg;
539 break;
541 case 'l':
542 label = optarg;
543 break;
545 case 'n':
546 optn = 1;
547 NgSetDebug(atoi(optarg));
548 break;
550 case 'p':
551 provider = optarg;
552 break;
554 default:
555 return usage(prog);
559 if (optind >= argc || optind + 2 < argc)
560 return usage(prog);
562 if (exec != NULL && label != NULL)
563 return usage(prog);
565 if (exec == NULL) {
566 if (label == NULL)
567 label = provider;
568 if (label == NULL) {
569 fprintf(stderr, "%s: Either a provider, a label or an exec command"
570 " must be given\n", prog);
571 return usage(prog);
573 exec = (char *)alloca(sizeof DEFAULT_EXEC_PREFIX + strlen(label));
574 if (exec == NULL) {
575 fprintf(stderr, "%s: Cannot allocate %zu bytes\n", prog,
576 sizeof DEFAULT_EXEC_PREFIX + strlen(label));
577 return EX_OSERR;
579 strcpy(exec, DEFAULT_EXEC_PREFIX);
580 strcpy(exec + sizeof DEFAULT_EXEC_PREFIX - 1, label);
583 if (acname == NULL) {
584 char *dot;
586 if (gethostname(hostname, sizeof hostname))
587 strcpy(hostname, "localhost");
588 else if ((dot = strchr(hostname, '.')))
589 *dot = '\0';
591 acname = hostname;
594 #ifndef NOKLDLOAD
595 if (!LoadModules())
596 return EX_UNAVAILABLE;
597 #endif
599 /* Create a socket node */
600 if (NgMkSockNode(NULL, &cs, &ds) == -1) {
601 perror("Cannot create netgraph socket node");
602 return EX_CANTCREAT;
605 /* Connect it up (and fill in `ngc') */
606 if ((ret = ConfigureNode(prog, argv[optind], provider, cs, ds,
607 optd, &ngc)) != 0) {
608 close(cs);
609 close(ds);
610 return ret;
613 if (!optF && daemon(1, 0) == -1) {
614 perror("daemon()");
615 close(cs);
616 close(ds);
617 return EX_OSERR;
621 if (pidfile != NULL) {
622 FILE *fp;
624 if ((fp = fopen(pidfile, "w")) == NULL) {
625 perror(pidfile);
626 close(cs);
627 close(ds);
628 return EX_CANTCREAT;
629 } else {
630 fprintf(fp, "%d\n", (int)getpid());
631 fclose(fp);
635 openlog(prog, LOG_PID | (optF ? LOG_PERROR : 0), LOG_DAEMON);
636 if (!optF && optn)
637 NgSetErrLog(nglog, nglogx);
639 memset(&act, '\0', sizeof act);
640 act.sa_handler = Farewell;
641 act.sa_flags = 0;
642 sigemptyset(&act.sa_mask);
643 sigaction(SIGHUP, &act, NULL);
644 sigaction(SIGINT, &act, NULL);
645 sigaction(SIGQUIT, &act, NULL);
646 sigaction(SIGTERM, &act, NULL);
648 while (!ReceivedSignal) {
649 if (*provider)
650 syslog(LOG_INFO, "Listening as provider %s", provider);
651 else
652 syslog(LOG_INFO, "Listening");
654 switch (sz = NgRecvData(ds, response, sizeof response, rhook)) {
655 case -1:
656 syslog(LOG_INFO, "NgRecvData: %m");
657 break;
658 case 0:
659 syslog(LOG_INFO, "NgRecvData: socket closed");
660 break;
661 default:
662 if (optd) {
663 char *dbuf, *ptr;
665 ptr = dbuf = alloca(sz * 2 + 1);
666 for (f = 0; f < sz; f++, ptr += 2)
667 sprintf(ptr, "%02x", (u_char)response[f]);
668 *ptr = '\0';
669 syslog(LOG_INFO, "Got %d bytes of data: %s", sz, dbuf);
672 if (sz <= 0) {
673 ret = EX_UNAVAILABLE;
674 break;
676 Spawn(prog, acname, provider, exec, ngc, cs, ds, response, sz, optd);
679 if (pidfile)
680 remove(pidfile);
682 if (ReceivedSignal) {
683 syslog(LOG_INFO, "Received signal %d, exiting", ReceivedSignal);
685 signal(ReceivedSignal, SIG_DFL);
686 raise(ReceivedSignal);
688 /* NOTREACHED */
690 ret = -ReceivedSignal;
693 return ret;