command.c (47844) | command.c (47849) |
---|---|
1/* 2 * PPP User command processing module 3 * 4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp) 5 * 6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by the Internet Initiative Japan, Inc. The name of the 14 * IIJ may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 * | 1/* 2 * PPP User command processing module 3 * 4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp) 5 * 6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by the Internet Initiative Japan, Inc. The name of the 14 * IIJ may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 * |
20 * $Id: command.c,v 1.198 1999/06/05 21:35:48 brian Exp $ | 20 * $Id: command.c,v 1.199 1999/06/08 20:11:57 brian Exp $ |
21 * 22 */ 23#include <sys/param.h> 24#include <netinet/in_systm.h> 25#include <netinet/in.h> 26#include <netinet/ip.h> 27#include <arpa/inet.h> 28#include <sys/socket.h> --- 109 unchanged lines hidden (view full) --- 138#define NEG_PPPDDEFLATE 47 139#define NEG_PRED1 48 140#define NEG_PROTOCOMP 49 141#define NEG_SHORTSEQ 50 142#define NEG_VJCOMP 51 143#define NEG_DNS 52 144 145const char Version[] = "2.22"; | 21 * 22 */ 23#include <sys/param.h> 24#include <netinet/in_systm.h> 25#include <netinet/in.h> 26#include <netinet/ip.h> 27#include <arpa/inet.h> 28#include <sys/socket.h> --- 109 unchanged lines hidden (view full) --- 138#define NEG_PPPDDEFLATE 47 139#define NEG_PRED1 48 140#define NEG_PROTOCOMP 49 141#define NEG_SHORTSEQ 50 142#define NEG_VJCOMP 51 143#define NEG_DNS 52 144 145const char Version[] = "2.22"; |
146const char VersionDate[] = "$Date: 1999/06/05 21:35:48 $"; | 146const char VersionDate[] = "$Date: 1999/06/08 20:11:57 $"; |
147 148static int ShowCommand(struct cmdargs const *); 149static int TerminalCommand(struct cmdargs const *); 150static int QuitCommand(struct cmdargs const *); 151static int OpenCommand(struct cmdargs const *); 152static int CloseCommand(struct cmdargs const *); 153static int DownCommand(struct cmdargs const *); 154static int SetCommand(struct cmdargs const *); --- 235 unchanged lines hidden (view full) --- 390 bcopy(newstr, word, lnewstr); 391 } while ((word = strstrword(word, oldstr))); 392 393 return tgt; 394} 395 396void 397command_Expand(char **nargv, int argc, char const *const *oargv, | 147 148static int ShowCommand(struct cmdargs const *); 149static int TerminalCommand(struct cmdargs const *); 150static int QuitCommand(struct cmdargs const *); 151static int OpenCommand(struct cmdargs const *); 152static int CloseCommand(struct cmdargs const *); 153static int DownCommand(struct cmdargs const *); 154static int SetCommand(struct cmdargs const *); --- 235 unchanged lines hidden (view full) --- 390 bcopy(newstr, word, lnewstr); 391 } while ((word = strstrword(word, oldstr))); 392 393 return tgt; 394} 395 396void 397command_Expand(char **nargv, int argc, char const *const *oargv, |
398 struct bundle *bundle, int inc0) | 398 struct bundle *bundle, int inc0, pid_t pid) |
399{ 400 int arg; | 399{ 400 int arg; |
401 char pid[12]; | 401 char pidstr[12]; |
402 403 if (inc0) 404 arg = 0; /* Start at arg 0 */ 405 else { 406 nargv[0] = strdup(oargv[0]); 407 arg = 1; 408 } | 402 403 if (inc0) 404 arg = 0; /* Start at arg 0 */ 405 else { 406 nargv[0] = strdup(oargv[0]); 407 arg = 1; 408 } |
409 snprintf(pid, sizeof pid, "%d", getpid()); | 409 snprintf(pidstr, sizeof pidstr, "%d", (int)pid); |
410 for (; arg < argc; arg++) { 411 nargv[arg] = strdup(oargv[arg]); 412 nargv[arg] = subst(nargv[arg], "HISADDR", 413 inet_ntoa(bundle->ncp.ipcp.peer_ip)); 414 nargv[arg] = subst(nargv[arg], "AUTHNAME", bundle->cfg.auth.name); 415 nargv[arg] = subst(nargv[arg], "INTERFACE", bundle->iface->name); 416 nargv[arg] = subst(nargv[arg], "MYADDR", inet_ntoa(bundle->ncp.ipcp.my_ip)); 417 nargv[arg] = subst(nargv[arg], "USER", bundle->ncp.mp.peer.authname); 418 nargv[arg] = subst(nargv[arg], "PEER_ENDDISC", 419 mp_Enddisc(bundle->ncp.mp.peer.enddisc.class, 420 bundle->ncp.mp.peer.enddisc.address, 421 bundle->ncp.mp.peer.enddisc.len)); 422 nargv[arg] = subst(nargv[arg], "ENDDISC", 423 mp_Enddisc(bundle->ncp.mp.cfg.enddisc.class, 424 bundle->ncp.mp.cfg.enddisc.address, 425 bundle->ncp.mp.cfg.enddisc.len)); | 410 for (; arg < argc; arg++) { 411 nargv[arg] = strdup(oargv[arg]); 412 nargv[arg] = subst(nargv[arg], "HISADDR", 413 inet_ntoa(bundle->ncp.ipcp.peer_ip)); 414 nargv[arg] = subst(nargv[arg], "AUTHNAME", bundle->cfg.auth.name); 415 nargv[arg] = subst(nargv[arg], "INTERFACE", bundle->iface->name); 416 nargv[arg] = subst(nargv[arg], "MYADDR", inet_ntoa(bundle->ncp.ipcp.my_ip)); 417 nargv[arg] = subst(nargv[arg], "USER", bundle->ncp.mp.peer.authname); 418 nargv[arg] = subst(nargv[arg], "PEER_ENDDISC", 419 mp_Enddisc(bundle->ncp.mp.peer.enddisc.class, 420 bundle->ncp.mp.peer.enddisc.address, 421 bundle->ncp.mp.peer.enddisc.len)); 422 nargv[arg] = subst(nargv[arg], "ENDDISC", 423 mp_Enddisc(bundle->ncp.mp.cfg.enddisc.class, 424 bundle->ncp.mp.cfg.enddisc.address, 425 bundle->ncp.mp.cfg.enddisc.len)); |
426 nargv[arg] = subst(nargv[arg], "PROCESSID", pid); | 426 nargv[arg] = subst(nargv[arg], "PROCESSID", pidstr); |
427 nargv[arg] = subst(nargv[arg], "LABEL", bundle_GetLabel(bundle)); 428 } 429 nargv[arg] = NULL; 430} 431 432static int 433ShellCommand(struct cmdargs const *arg, int bg) 434{ 435 const char *shell; | 427 nargv[arg] = subst(nargv[arg], "LABEL", bundle_GetLabel(bundle)); 428 } 429 nargv[arg] = NULL; 430} 431 432static int 433ShellCommand(struct cmdargs const *arg, int bg) 434{ 435 const char *shell; |
436 pid_t shpid; | 436 pid_t shpid, pid; |
437 438#ifdef SHELL_ONLY_INTERACTIVELY 439 /* we're only allowed to shell when we run ppp interactively */ 440 if (arg->prompt && arg->prompt->owner) { 441 log_Printf(LogWARN, "Can't start a shell from a network connection\n"); 442 return 1; 443 } 444#endif --- 9 unchanged lines hidden (view full) --- 454 return 1; 455 } else if (bg) { 456 log_Printf(LogWARN, "Can only start an interactive shell in" 457 " the foreground mode\n"); 458 return 1; 459 } 460 } 461 | 437 438#ifdef SHELL_ONLY_INTERACTIVELY 439 /* we're only allowed to shell when we run ppp interactively */ 440 if (arg->prompt && arg->prompt->owner) { 441 log_Printf(LogWARN, "Can't start a shell from a network connection\n"); 442 return 1; 443 } 444#endif --- 9 unchanged lines hidden (view full) --- 454 return 1; 455 } else if (bg) { 456 log_Printf(LogWARN, "Can only start an interactive shell in" 457 " the foreground mode\n"); 458 return 1; 459 } 460 } 461 |
462 pid = getpid(); |
|
462 if ((shpid = fork()) == 0) { 463 int i, fd; 464 465 if ((shell = getenv("SHELL")) == 0) 466 shell = _PATH_BSHELL; 467 468 timer_TermService(); 469 --- 14 unchanged lines hidden (view full) --- 484 /* substitute pseudo args */ 485 char *argv[MAXARGS]; 486 int argc = arg->argc - arg->argn; 487 488 if (argc >= sizeof argv / sizeof argv[0]) { 489 argc = sizeof argv / sizeof argv[0] - 1; 490 log_Printf(LogWARN, "Truncating shell command to %d args\n", argc); 491 } | 463 if ((shpid = fork()) == 0) { 464 int i, fd; 465 466 if ((shell = getenv("SHELL")) == 0) 467 shell = _PATH_BSHELL; 468 469 timer_TermService(); 470 --- 14 unchanged lines hidden (view full) --- 485 /* substitute pseudo args */ 486 char *argv[MAXARGS]; 487 int argc = arg->argc - arg->argn; 488 489 if (argc >= sizeof argv / sizeof argv[0]) { 490 argc = sizeof argv / sizeof argv[0] - 1; 491 log_Printf(LogWARN, "Truncating shell command to %d args\n", argc); 492 } |
492 command_Expand(argv, argc, arg->argv + arg->argn, arg->bundle, 0); | 493 command_Expand(argv, argc, arg->argv + arg->argn, arg->bundle, 0, pid); |
493 if (bg) { 494 pid_t p; 495 496 p = getpid(); 497 if (daemon(1, 1) == -1) { 498 log_Printf(LogERROR, "%d: daemon: %s\n", (int)p, strerror(errno)); 499 exit(1); 500 } --- 2031 unchanged lines hidden (view full) --- 2532 arg->bundle->argv[1] = arg->bundle->argv1; 2533 return 0; 2534 } 2535 2536 if (argc >= sizeof argv / sizeof argv[0]) { 2537 argc = sizeof argv / sizeof argv[0] - 1; 2538 log_Printf(LogWARN, "Truncating proc title to %d args\n", argc); 2539 } | 494 if (bg) { 495 pid_t p; 496 497 p = getpid(); 498 if (daemon(1, 1) == -1) { 499 log_Printf(LogERROR, "%d: daemon: %s\n", (int)p, strerror(errno)); 500 exit(1); 501 } --- 2031 unchanged lines hidden (view full) --- 2533 arg->bundle->argv[1] = arg->bundle->argv1; 2534 return 0; 2535 } 2536 2537 if (argc >= sizeof argv / sizeof argv[0]) { 2538 argc = sizeof argv / sizeof argv[0] - 1; 2539 log_Printf(LogWARN, "Truncating proc title to %d args\n", argc); 2540 } |
2540 command_Expand(argv, argc, arg->argv + arg->argn, arg->bundle, 1); | 2541 command_Expand(argv, argc, arg->argv + arg->argn, arg->bundle, 1, getpid()); |
2541 2542 ptr = title; 2543 remaining = sizeof title - 1; 2544 for (f = 0; f < argc && remaining; f++) { 2545 if (f) { 2546 *ptr++ = ' '; 2547 remaining--; 2548 } --- 14 unchanged lines hidden --- | 2542 2543 ptr = title; 2544 remaining = sizeof title - 1; 2545 for (f = 0; f < argc && remaining; f++) { 2546 if (f) { 2547 *ptr++ = ' '; 2548 remaining--; 2549 } --- 14 unchanged lines hidden --- |