summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ppp/main.c
diff options
context:
space:
mode:
authoramurai <amurai@FreeBSD.org>1995-09-02 17:20:54 +0000
committeramurai <amurai@FreeBSD.org>1995-09-02 17:20:54 +0000
commit9a28cf053e0253a84225e0cd75dda5047d6bba8c (patch)
tree4e6b794c1199fd47264885cc1e6f40b97af13fb1 /usr.sbin/ppp/main.c
parent5c97b17f6e144daf5501e5001506baf86759318e (diff)
downloadFreeBSD-src-9a28cf053e0253a84225e0cd75dda5047d6bba8c.zip
FreeBSD-src-9a28cf053e0253a84225e0cd75dda5047d6bba8c.tar.gz
1. Do not log the password itself to ppp.log ( Mr. Rich Murphey )
2. Add ability to execute shell commands and suspend back into invoking shell (Mr. J Wunsch) Reviewed by: amurai@spec.co.jp Submitted by: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch) Rich Murphey <rich@lamprey.utmb.edu>
Diffstat (limited to 'usr.sbin/ppp/main.c')
-rw-r--r--usr.sbin/ppp/main.c82
1 files changed, 60 insertions, 22 deletions
diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c
index e6aae6e..4367750 100644
--- a/usr.sbin/ppp/main.c
+++ b/usr.sbin/ppp/main.c
@@ -59,6 +59,7 @@ extern void DecodeCommand(), Prompt();
extern int IsInteractive();
extern struct in_addr ifnetmask;
static void DoLoop(void);
+static void TerminalStop();
static struct termios oldtio; /* Original tty mode */
static struct termios comtio; /* Command level tty mode */
@@ -91,8 +92,9 @@ TtyInit()
/*
* Set tty into command mode. We allow canonical input and echo processing.
*/
-static void
-TtyCommandMode()
+void
+TtyCommandMode(prompt)
+int prompt;
{
struct termios newtio;
int stat;
@@ -100,7 +102,7 @@ TtyCommandMode()
if (!(mode & MODE_INTER))
return;
tcgetattr(0, &newtio);
- newtio.c_lflag |= (ECHO|ICANON);
+ newtio.c_lflag |= (ECHO|ISIG|ICANON);
newtio.c_iflag = oldtio.c_iflag;
newtio.c_oflag |= OPOST;
tcsetattr(0, TCSADRAIN, &newtio);
@@ -108,7 +110,7 @@ TtyCommandMode()
stat |= O_NONBLOCK;
fcntl(0, F_SETFL, stat);
TermMode = 0;
- Prompt(0);
+ if(prompt) Prompt(0);
}
/*
@@ -127,18 +129,23 @@ TtyTermMode()
}
void
-Cleanup(excode)
-int excode;
+TtyOldMode()
{
int stat;
- OsLinkdown();
-#ifdef notdef
stat = fcntl(0, F_GETFL, 0);
stat &= ~O_NONBLOCK;
fcntl(0, F_SETFL, stat);
tcsetattr(0, TCSANOW, &oldtio);
-#endif
+}
+
+void
+Cleanup(excode)
+int excode;
+{
+ int stat;
+
+ OsLinkdown();
OsCloseLink(1);
sleep(1);
if (mode & MODE_AUTO)
@@ -148,12 +155,7 @@ int excode;
LogClose();
if (server > 0)
close(server);
-#ifndef notdef
- stat = fcntl(0, F_GETFL, 0);
- stat &= ~O_NONBLOCK;
- fcntl(0, F_SETFL, stat);
- tcsetattr(0, TCSANOW, &oldtio);
-#endif
+ TtyOldMode();
exit(excode);
}
@@ -162,7 +164,6 @@ static void
Hangup()
{
LogPrintf(LOG_PHASE, "SIGHUP\n");
- signal(SIGHUP, Hangup);
Cleanup(EX_HANGUP);
}
@@ -174,10 +175,30 @@ CloseSession()
Cleanup(EX_TERM);
}
+
+static void
+TerminalCont()
+{
+ (void)signal(SIGCONT, SIG_DFL);
+ (void)signal(SIGTSTP, TerminalStop);
+ TtyCommandMode(getpgrp() == tcgetpgrp(0));
+}
+
+static void
+TerminalStop(signo)
+int signo;
+{
+ (void)signal(SIGCONT, TerminalCont);
+ TtyOldMode();
+ signal(SIGTSTP, SIG_DFL);
+ kill(getpid(), signo);
+}
+
+
void
Usage()
{
- fprintf(stderr, "Usage: ppp [-auto | -direct -dedicated] [system]\n");
+ fprintf(stderr, "Usage: ppp [-auto | -direct | -dedicated] [system]\n");
exit(EX_START);
}
@@ -280,6 +301,7 @@ char **argv;
signal(SIGHUP, Hangup);
signal(SIGTERM, CloseSession);
signal(SIGINT, CloseSession);
+ signal(SIGQUIT, CloseSession);
#ifdef SIGSEGV
signal(SIGSEGV, Hangup);
#endif
@@ -289,6 +311,18 @@ char **argv;
#ifdef SIGALRM
signal(SIGALRM, SIG_IGN);
#endif
+ if(mode & MODE_INTER)
+ {
+#ifdef SIGTSTP
+ signal(SIGTSTP, TerminalStop);
+#endif
+#ifdef SIGTTIN
+ signal(SIGTTIN, TerminalStop);
+#endif
+#ifdef SIGTTOU
+ signal(SIGTTOU, SIG_IGN);
+#endif
+ }
if (dstsystem) {
if (SelectSystem(dstsystem, CONFFILE) < 0) {
@@ -348,7 +382,7 @@ char **argv;
} else {
server = -1;
TtyInit();
- TtyCommandMode();
+ TtyCommandMode(1);
}
LogPrintf(LOG_PHASE, "PPP Started.\n");
@@ -383,7 +417,7 @@ PacketMode()
else
LcpOpen(VarOpenMode);
if ((mode & (MODE_INTER|MODE_AUTO)) == MODE_INTER) {
- TtyCommandMode();
+ TtyCommandMode(1);
fprintf(stderr, "Packet mode.\r\n");
}
}
@@ -391,7 +425,7 @@ PacketMode()
static void
ShowHelp()
{
- fprintf(stderr, "Following commands are available\r\n");
+ fprintf(stderr, "The following commands are available:\r\n");
fprintf(stderr, " ~p\tEnter to Packet mode\r\n");
fprintf(stderr, " ~.\tTerminate program\r\n");
}
@@ -475,7 +509,7 @@ ReadTty()
#endif
case '.':
TermMode = 1;
- TtyCommandMode();
+ TtyCommandMode(1);
break;
default:
if (write(modem, &ch, n) < 0)
@@ -554,6 +588,9 @@ DoLoop()
u_char rbuff[MAX_MRU];
int dial_up;
int qlen;
+ pid_t pgroup;
+
+ pgroup = getpgrp();
if (mode & MODE_DIRECT) {
modem = OpenModem(mode);
@@ -699,7 +736,8 @@ DoLoop()
Prompt(0);
}
- if ((mode & MODE_INTER) && FD_ISSET(netfd, &rfds)) {
+ if ((mode & MODE_INTER) && FD_ISSET(netfd, &rfds) &&
+ pgroup == tcgetpgrp(0)) {
/* something to read from tty */
ReadTty();
}
OpenPOWER on IntegriCloud