1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741
|
/*
* pptpctrl.c
*
* PPTP control connection between PAC-PNS pair
*
* $Id: pptpctrl.c,v 1.4 1999/12/29 16:06:41 patl Exp $
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef __linux__
#define _GNU_SOURCE 1 /* kill() prototype, broken arpa/inet.h */
#endif
#if HAVE_SYSLOG_H
#include <syslog.h>
#else
#include "our_syslog.h"
#endif
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#ifdef HAVE_OPENPTY
#ifdef HAVE_PTY_H
#include <pty.h>
#endif
#ifdef HAVE_LIBUTIL_H
#include <libutil.h>
#endif
#endif
#ifndef HAVE_SETPROCTITLE
#include "inststr.h"
#endif
#include "compat.h"
#include "pptpctrl.h"
#include "pptpgre.h"
#include "pptpdefs.h"
#include "ctrlpacket.h"
#include "defaults.h"
/* Globals because i'm lazy -tmk */
static char speed[32];
static char pppdxfig[256];
/*
* Global to handle dying
*
* I'd be nice if someone could figure out a way to do it
* without the global, but i don't think you can.. -tmk
*/
#define clientSocket 0 /* in case it changes back to a variable */
static u_int32_t call_id_pair; /* call id (to terminate call) */
/* Needed by this and ctrlpacket.c */
int pptpctrl_debug = 0; /* specifies if debugging is on or off */
/* Local function prototypes */
static void bail(int sigraised);
static void pptp_handle_ctrl_connection(char **pppaddrs, struct in_addr *inetaddrs);
static int startCall(char **pppaddrs);
static void launch_pppd(char **pppaddrs);
/* Oh the horror.. lets hope this covers all the ones we have to handle */
#if defined(O_NONBLOCK) && !defined(__sun__) && !defined(__sun)
#define OUR_NB_MODE O_NONBLOCK
#else
#define OUR_NB_MODE O_NDELAY
#endif
/* Simple function */
static void die_if_invalid(char *ptr) {
if (!ptr) {
fprintf(stderr,
"pptpctrl: Ran out of command line arguments.\n\n"
"\tpptpctrl should either be run from pptpd or from inetd as instructed\n"
"\tin pptpd(8) or pptpctrl(8) manual pages.\n"
);
exit(2);
}
}
/* Macro to read command line args */
#define GETARG(X) \
die_if_invalid(*argv); \
if(atoi(argv[arg++]) != 0) { \
die_if_invalid(*argv); \
strlcpy(X, argv[arg++], sizeof(X)); \
} else \
*X = '\0'
int main(int argc, char **argv)
{
char pppLocal[16]; /* local IP to pass to pppd */
char pppRemote[16]; /* remote IP address to pass to pppd */
char ipx[16]; /* IPX network number */
struct sockaddr_in addr; /* client address */
socklen_t addrlen;
int arg = 1;
#ifndef HAVE_SETPROCTITLE
char proctitle[32];
#endif
int flags;
struct in_addr inetaddrs[2];
char *pppaddrs[3] = { pppLocal, pppRemote, ipx };
/* open a connection to the syslog daemon */
openlog("pptpd", LOG_PID, LOG_PPTP);
/* autoreap if supported */
signal(SIGCHLD, SIG_IGN);
die_if_invalid(*argv);
pptpctrl_debug = atoi(argv[arg++]);
GETARG(pppdxfig);
GETARG(speed);
GETARG(pppLocal);
GETARG(pppRemote);
GETARG(ipx);
if (pptpctrl_debug) {
if (*pppLocal)
syslog(LOG_DEBUG, "CTRL: local address = %s", pppLocal);
if (*pppRemote)
syslog(LOG_DEBUG, "CTRL: remote address = %s", pppRemote);
if (*speed)
syslog(LOG_DEBUG, "CTRL: pppd speed = %s", speed);
if (*pppdxfig)
syslog(LOG_DEBUG, "CTRL: pppd options file = %s", pppdxfig);
}
addrlen = sizeof(addr);
if (getsockname(clientSocket, (struct sockaddr *) &addr, &addrlen) != 0) {
syslog(LOG_ERR, "CTRL: getsockname() failed");
perror("getsockname");
close(clientSocket);
bail(0); /* NORETURN */
}
inetaddrs[0] = addr.sin_addr;
addrlen = sizeof(addr);
if (getpeername(clientSocket, (struct sockaddr *) &addr, &addrlen) != 0) {
syslog(LOG_ERR, "CTRL: getpeername() failed");
perror("getpeername");
close(clientSocket);
bail(0); /* NORETURN */
}
inetaddrs[1] = addr.sin_addr;
/* Set non-blocking */
if ((flags = fcntl(clientSocket, F_GETFL, arg /* ignored */)) == -1 ||
fcntl(clientSocket, F_SETFL, flags|OUR_NB_MODE) == -1) {
syslog(LOG_ERR, "CTRL: Failed to set client socket non-blocking");
perror("fcntl");
close(clientSocket);
bail(0); /* NORETURN */
}
/* Fiddle with argv */
#if HAVE_SETPROCTITLE
setproctitle("pptpd [%s]", inet_ntoa(addr.sin_addr));
#else
sprintf(proctitle, "pptpd [%s]", inet_ntoa(addr.sin_addr));
inststr(argc, argv, proctitle);
#endif
/* be ready for a grisly death */
signal(SIGTERM, &bail);
NOTE_VALUE(PAC, call_id_pair, htons(-1));
NOTE_VALUE(PNS, call_id_pair, htons(-1));
syslog(LOG_INFO, "CTRL: Client %s control connection started", inet_ntoa(addr.sin_addr));
pptp_handle_ctrl_connection(pppaddrs, inetaddrs);
syslog(LOG_INFO, "CTRL: Client %s control connection finished", inet_ntoa(addr.sin_addr));
bail(0); /* NORETURN */
return 1; /* make gcc happy */
}
/*
* Local functions only below
*/
/*
* pptp_handle_ctrl_connection
*
* 1. read a packet (should be start_ctrl_conn_rqst)
* 2. reply to packet (send a start_ctrl_conn_rply)
* 3. proceed with GRE and CTRL connections
*
* args: pppaddrs - ppp local and remote addresses (strings)
* inetaddrs - local and client socket address
* retn: 0 success, -1 failure
*/
static void pptp_handle_ctrl_connection(char **pppaddrs, struct in_addr *inetaddrs)
{
/* For echo requests used to check link is alive */
int echo_wait = FALSE; /* Waiting for echo? */
u_int32_t echo_count = 0; /* Sequence # of echo */
time_t echo_time; /* Time last echo req sent */
struct timeval idleTime; /* How long to select() */
/* General local variables */
ssize_t rply_size; /* Reply packet size */
fd_set readfds; /* For select() */
fd_set writefds; /* For select() */
int maxfd = clientSocket; /* For select() */
int send_packet; /* Send a packet this time? */
#if BSDUSER_PPP || SLIRP
/* not needed by stuff which uses socketpair() in startCall() */
#define init 1
#else
int init = 0; /* Has pppd initialized the pty? */
#endif
struct gre_state *gre = NULL;
unsigned char packet[PPTP_MAX_CTRL_PCKT_SIZE];
unsigned char rply_packet[PPTP_MAX_CTRL_PCKT_SIZE];
u_int16_t max_window_size;
int new_pty_fd = -1;
for (;;) {
FD_ZERO(&readfds);
FD_ZERO(&writefds);
/* always willing to read from the control channel */
FD_SET (clientSocket, &readfds);
/* always willing to read from the GRE socket */
if (gre && gre->gre_fd != -1 && init)
FD_SET (gre->gre_fd, &readfds);
/* Willing to read from the PTY if the buffer is empty */
if (gre && gre->pty_fd != -1
&& gre->pty_bytes_processed == gre->pty_bytes_read)
FD_SET (gre->pty_fd, &readfds);
/* want to write to the GRE socket if we have a packet ready */
if (gre && gre->gre_fd != -1 && gre->gre_packet_ready)
FD_SET (gre->gre_fd, &writefds);
/* want to write to the PTY if the output buffer is nonempty */
if (gre && gre->pty_fd != -1 && init
&& gre->pty_output_size != gre->pty_bytes_written)
FD_SET (gre->pty_fd, &writefds);
/* set timeout */
/* FIXME: need to do adaptive timeouts / windowing */
idleTime.tv_sec = IDLE_WAIT;
idleTime.tv_usec = 0;
/* default: do nothing */
send_packet = FALSE;
switch (select(maxfd + 1, &readfds, &writefds, NULL, &idleTime)) {
case -1: /* Error with select() */
if (errno != EINTR)
syslog(LOG_ERR, "CTRL: Error with select(), quitting");
goto leave_clear_call;
case 0:
if (echo_wait != TRUE) {
/* Timeout. Start idle link detection. */
echo_count++;
if (pptpctrl_debug)
syslog(LOG_DEBUG, "CTRL: Sending ECHO REQ id %d", echo_count);
time(&echo_time);
make_echo_req_packet(rply_packet, &rply_size, echo_count);
echo_wait = TRUE;
send_packet = TRUE;
}
break;
default:
break;
}
/* detect startup of pppd */
#ifndef init
if (!init && gre && gre->pty_fd != -1 && FD_ISSET(gre->pty_fd, &readfds))
init = 1;
#endif
/* handle actual packets */
/* send from pty off via GRE */
if (gre) {
if (do_gre_to_pty (gre) < 0) {
syslog(LOG_ERR,
"CTRL: PTY read or GRE write failed (pty,gre)=(%d,%d)",
gre->pty_fd, gre->gre_fd);
break;
}
if (do_pty_to_gre (gre) < 0) {
syslog(LOG_ERR,
"CTRL: GRE read or PTY write failed (gre,pty)=(%d,%d)",
gre->gre_fd, gre->pty_fd);
break;
}
}
if (FD_ISSET(clientSocket, &readfds)) {
send_packet = TRUE;
switch (read_pptp_packet(clientSocket, packet,
rply_packet, &rply_size)) {
case 0:
syslog(LOG_ERR, "CTRL: CTRL read failed");
goto leave_drop_call;
case -1:
send_packet = FALSE;
break;
case STOP_CTRL_CONN_RQST:
if (pptpctrl_debug)
syslog(LOG_DEBUG, "CTRL: Received STOP CTRL CONN request (disconnecting)");
if (gre)
syslog(LOG_WARNING, "CTRL: closing...");
send_pptp_packet(clientSocket, rply_packet, rply_size);
goto leave_drop_call;
case CALL_CLR_RQST:
if(pptpctrl_debug)
syslog(LOG_DEBUG, "CTRL: Received CALL CLR request (closing call)");
if (!gre || gre->gre_fd == -1 || gre->pty_fd == -1)
syslog(LOG_WARNING, "CTRL: Request to close call but call not open");
if (gre) {
if (gre->gre_fd != -1) {
close(gre->gre_fd);
gre->gre_fd = -1;
}
if (gre->pty_fd != -1) {
close(gre->pty_fd);
gre->pty_fd = -1;
}
NOTE_VALUE(PAC, call_id_pair, htons(-1));
NOTE_VALUE(PNS, call_id_pair, htons(-1));
break;
}
case OUT_CALL_RQST:
/* for killing off the link later (ugly) */
NOTE_VALUE (PAC, call_id_pair,
((struct pptp_out_call_rply *) (rply_packet))->call_id);
NOTE_VALUE(PNS, call_id_pair, ((struct pptp_out_call_rply *)
(rply_packet))->call_id_peer);
max_window_size =
ntoh16 (((struct pptp_out_call_rqst *)packet)->pckt_recv_size);
if (gre) {
syslog(LOG_WARNING, "CTRL: Request to open call when call is already open, closing");
if (gre->gre_fd != -1) {
close (gre->gre_fd);
gre->gre_fd = -1;
}
if (gre->pty_fd != -1) {
close (gre->pty_fd);
gre->pty_fd = -1;
}
free (gre);
}
/* Start the call */
syslog(LOG_INFO, "CTRL: Starting call (launching pppd, opening GRE)");
if ((new_pty_fd = startCall(pppaddrs)) > maxfd)
maxfd = new_pty_fd;
gre = pptp_gre_init(call_id_pair, max_window_size,
new_pty_fd, inetaddrs);
if (!gre) {
syslog (LOG_ERR, "pptp_gre_init failed; exiting");
exit (-1);
}
if (gre->gre_fd > maxfd)
maxfd = gre->gre_fd;
break;
case ECHO_RPLY:
if (echo_wait == TRUE && ((struct pptp_echo_rply *) (packet))->identifier == echo_count)
echo_wait = FALSE;
else
syslog(LOG_WARNING, "CTRL: Unexpected ECHO REPLY packet");
/* FALLTHRU */
case SET_LINK_INFO:
send_packet = FALSE;
break;
case CALL_DISCONN_NTFY:
case STOP_CTRL_CONN_RPLY:
/* These don't generate replies. Also they come from things
we don't send in this section. */
syslog(LOG_WARNING, "CTRL: Got a reply to a packet we didn't send");
send_packet = FALSE;
break;
/* Otherwise, the already-formed reply will do fine, so send it */
}
}
/* send reply packet - this may block, but it should be very rare */
if (send_packet == TRUE
&& send_pptp_packet(clientSocket, rply_packet, rply_size) < 0) {
syslog(LOG_ERR, "CTRL: Error sending GRE, aborting call");
goto leave_clear_call;
}
/* waiting for echo reply and curtime - echo_time > max wait */
if (echo_wait == TRUE && (time(NULL) - echo_time) > MAX_ECHO_WAIT) {
syslog(LOG_INFO, "CTRL: Session timed out, ending call");
goto leave_clear_call;
}
}
/* Finished! :-) */
leave_drop_call:
NOTE_VALUE(PAC, call_id_pair, htons(-1));
NOTE_VALUE(PNS, call_id_pair, htons(-1));
close(clientSocket);
leave_clear_call:
/* leave clientSocket and call_id_pair alone for bail() */
if (gre->gre_fd != -1)
close(gre->gre_fd);
if (gre->pty_fd != -1)
close(gre->pty_fd);
return;
#ifdef init
#undef init
#endif
}
/*
* This is the custom exit() for this program.
*
* Updated to also be the default SIGTERM handler, and if
* the link is going down for unnatural reasons, we will close it
* right now, it's only been tested for win98, other tests would be nice
* -tmk
*/
static void bail(int sigraised)
{
if (sigraised)
syslog(LOG_INFO, "CTRL: Exiting on signal");
/* send a disconnect to the other end */
/* ignore any errors */
if (GET_VALUE(PAC, call_id_pair) != htons(-1)) {
fd_set connSet; /* fd_set for select() */
struct timeval tv; /* time to wait for reply */
unsigned char packet[PPTP_MAX_CTRL_PCKT_SIZE];
unsigned char rply_packet[PPTP_MAX_CTRL_PCKT_SIZE];
ssize_t rply_size; /* reply packet size */
int pkt;
if (pptpctrl_debug)
syslog(LOG_DEBUG, "CTRL: Exiting with active call");
make_call_admin_shutdown(rply_packet, &rply_size);
if(send_pptp_packet(clientSocket, rply_packet, rply_size) < 0)
goto skip;
make_stop_ctrl_req(rply_packet, &rply_size);
if(send_pptp_packet(clientSocket, rply_packet, rply_size) < 0)
goto skip;
FD_ZERO(&connSet);
FD_SET(clientSocket, &connSet);
tv.tv_sec = 5; /* wait 5 secs for a reply then quit */
tv.tv_usec = 0;
/* Wait for STOP CTRL CONN RQST or RPLY */
while (select(clientSocket + 1, &connSet, NULL, NULL,
&tv) == 1) {
pkt = read_pptp_packet(clientSocket, packet,
rply_packet, &rply_size);
if (pkt == 0) {
syslog (LOG_WARNING,
"EOF reading control message");
break;
}
else switch (pkt) {
case STOP_CTRL_CONN_RQST:
send_pptp_packet(clientSocket, rply_packet, rply_size);
goto skip;
case CALL_CLR_RQST:
syslog(LOG_WARNING, "CTRL: Got call clear request after call manually shutdown - buggy client");
break;
case STOP_CTRL_CONN_RPLY:
goto skip;
case 0:
syslog(LOG_WARNING, "CTRL: Client already disconnected control stream");
goto skip;
case -1:
syslog(LOG_WARNING, "CTRL: Error reading control stream during disconnect, aborting");
goto skip;
default:
syslog(LOG_WARNING, "CTRL: Unexpected control message %d in disconnect sequence", pkt);
}
tv.tv_sec = 5; /* wait 5 secs for another reply then quit */
tv.tv_usec = 0;
}
skip:
close(clientSocket);
}
if (pptpctrl_debug)
syslog(LOG_DEBUG, "CTRL: Exiting now");
exit((GET_VALUE(PAC, call_id_pair)==htons(-1)) ? 0 : 1);
}
/*
* startCall
*
* Launches PPPD for the call.
*
* args: pppaddrs - local/remote IPs or "" for either/both if none
* retn: pty file descriptor
*
*/
static int startCall(char **pppaddrs)
{
/* PTY/TTY pair for talking to PPPd */
int pty_fd, tty_fd;
int flags;
#if BSDUSER_PPP || SLIRP
int sockfd[2];
#ifndef AF_LOCAL
#ifdef AF_UNIX
#define AF_LOCAL AF_UNIX /* Old BSD */
#else
#define AF_LOCAL AF_FILE /* POSIX */
#endif
#endif
/* userspace ppp doesn't need to waste a real pty/tty pair */
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sockfd)) {
syslog(LOG_ERR, "CTRL: socketpair() error");
perror("socketpair");
exit(3);
}
tty_fd = sockfd[0];
pty_fd = sockfd[1];
#else
/* Finds an open pty/tty pair */
if (openpty(&pty_fd, &tty_fd, NULL, NULL, NULL) != 0) {
syslog(LOG_ERR, "CTRL: openpty() error");
perror("openpty");
exit(3);
}
#endif
if (pptpctrl_debug) {
syslog(LOG_DEBUG, "CTRL: pty_fd = %d", pty_fd);
syslog(LOG_DEBUG, "CTRL: tty_fd = %d", tty_fd);
}
/* Launch the PPPD */
#ifndef HAVE_FORK
switch (vfork()) {
#else
switch (fork()) {
#endif
case -1: /* fork() error */
syslog(LOG_ERR, "CTRL: Error forking to exec pppd");
break;
case 0: /* child */
dup2(tty_fd, 0);
dup2(tty_fd, 1);
#if 0
/* This must never be used if !HAVE_SYSLOG since that logs to stderr.
* Trying just never using it to see if it causes anyone else problems.
* It may let people see the pppd errors, which would be good.
*/
dup2(tty_fd, 2);
#endif
if (tty_fd > 2)
close(tty_fd);
if (pty_fd > 2)
close(pty_fd);
/* In case we move clientSocket back off stdin */
#ifndef clientSocket
if (clientSocket > 2)
close(clientSocket);
#elif clientSocket > 2
close(clientSocket);
#endif
launch_pppd(pppaddrs);
syslog(LOG_ERR, "CTRL: PPPD launch failed!");
exit(3);
}
close(tty_fd);
flags = fcntl (pty_fd, F_GETFL, 0);
if (flags < 0)
syslog (LOG_ERR, "CTRL: Couldn't get flags for TTY!");
else if (fcntl (pty_fd, F_SETFL, flags | O_NONBLOCK) < 0)
syslog (LOG_ERR, "CTRL: Cound't set flags for TTY!");
return pty_fd;
}
/*
* lanuch_pppd
*
* Launches the PPP daemon. The PPP daemon is responsible for assigning the
* PPTP client its IP address.. These values are assigned via the command
* line.
*
* retn: 0 on success, -1 on failure.
*
*/
static void launch_pppd(char **pppaddrs)
{
char *pppd_argv[16];
int an = 0;
pppd_argv[an++] = PPP_BINARY;
#if BSDUSER_PPP
/* The way that Brian Somers' user-land ppp works is to use the
* system name as a reference for most of the useful options. Hence
* most things can't be defined on the command line. On OpenBSD at
* least the file used for the systems is /etc/ppp/ppp.conf, where
* the pptp stanza should look something like:
pptp:
set speed sync
enable pap
enable chap
set dns a.a.a.a b.b.b.b
set ndbs x.x.x.x y.y.y.y
accept dns
add 10.0.0/24
* To be honest, at the time of writing, I haven't had the thing
* working enough to understand :) I will update this comment and
* make a sample config available when I get there.
*/
/* options for BSDUSER_PPP
*
* ignores IP addresses, config file option, speed
* fix usage info in pptpd.c and configure script if this changes
*
* IP addresses can be specified in /etc/ppp/ppp.secret per user
*/
pppd_argv[an++] = "-direct";
pppd_argv[an++] = "pptp"; /* XXX this is the system name */
/* should be dynamic - PMG */
#elif SLIRP
/* options for SLIRP
*
* ignores IP addresses from config - SLIRP handles this
*/
pppd_argv[an++] = "-P";
pppd_argv[an++] = "+chap";
pppd_argv[an++] = "-b";
/* If a speed has been specified, use it
* if not, use "smart" default (defaults.h)
*/
if (*speed) {
pppd_argv[an++] = speed;
} else {
pppd_argv[an++] = PPP_SPEED_DEFAULT;
}
if (*pppdxfig) {
pppd_argv[an++] = "-f";
pppd_argv[an++] = pppdxfig;
}
if (pptpctrl_debug) {
syslog(LOG_DEBUG, "CTRL (PPPD Launcher): Connection speed = %s", pppd_argv[an - 1]);
}
#else
/* options for 'normal' pppd */
pppd_argv[an++] = "local";
/* If a pppd option file is specified, use it
* if not, pppd will default to /etc/ppp/options
*/
if (*pppdxfig) {
pppd_argv[an++] = "file";
pppd_argv[an++] = pppdxfig;
}
/* If a speed has been specified, use it
* if not, use "smart" default (defaults.h)
*/
if (*speed) {
pppd_argv[an++] = speed;
} else {
pppd_argv[an++] = PPP_SPEED_DEFAULT;
}
if (pptpctrl_debug) {
syslog(LOG_DEBUG, "CTRL (PPPD Launcher): Connection speed = %s", pppd_argv[an - 1]);
if (*pppaddrs[0])
syslog(LOG_DEBUG, "CTRL (PPPD Launcher): local address = %s", pppaddrs[0]);
if (*pppaddrs[1])
syslog(LOG_DEBUG, "CTRL (PPPD Launcher): remote address = %s", pppaddrs[1]);
if (*pppaddrs[2])
syslog(LOG_DEBUG, "CTRL (PPPD Launcher): ipx network = %s", pppaddrs[2]);
}
if (*pppaddrs[0] || *pppaddrs[1]) {
char pppInterfaceIPs[33];
sprintf(pppInterfaceIPs, "%s:%s", pppaddrs[0], pppaddrs[1]);
pppd_argv[an++] = pppInterfaceIPs;
}
if (*pppaddrs[2]) {
pppd_argv[an++] = "ipx-network";
pppd_argv[an++] = pppaddrs[2];
}
#endif
/* argv arrays must always be NULL terminated */
pppd_argv[an] = NULL;
execvp(pppd_argv[0], pppd_argv);
/* execvp() failed */
syslog(LOG_ERR, "CTRL (PPPD Launcher): Failed to launch PPP daemon.");
}
|