X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fsys-svr4.c;h=abc7d9643661421c14292f5b9b511aa0dcce8d1e;hp=c87c9d060e763cde474fd94b3a4f38b90713077b;hb=10d17d19d3f7fe61e3b1f46a97198c521b535589;hpb=fdc0c58f5a318a320f15e922f4df879b6bd75c71 diff --git a/pppd/sys-svr4.c b/pppd/sys-svr4.c index c87c9d0..abc7d96 100644 --- a/pppd/sys-svr4.c +++ b/pppd/sys-svr4.c @@ -26,7 +26,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: sys-svr4.c,v 1.27 1999/03/19 01:29:50 paulus Exp $"; +static char rcsid[] = "$Id: sys-svr4.c,v 1.30 1999/04/12 06:24:51 paulus Exp $"; #endif #include @@ -92,6 +92,7 @@ static int link_mtu, link_mru; #define NMODULES 32 static int tty_nmodules; static char tty_modules[NMODULES][FMNAMESZ+1]; +static int tty_npushed; static int if_is_up; /* Interface has been marked up */ static u_int32_t remote_addr; /* IP address of peer */ @@ -128,7 +129,7 @@ sys_init() if (ipfd < 0) fatal("Couldn't open IP device: %m"); - if (default_device) + if (default_device && !notty) tty_sid = getsid((pid_t)0); pppfd = open("/dev/ppp", O_RDWR | O_NONBLOCK, 0); @@ -221,7 +222,7 @@ sys_check_options() return 1; } - +#if 0 /* * daemon - Detach us from controlling terminal session. */ @@ -245,6 +246,7 @@ daemon(nochdir, noclose) } return 0; } +#endif /* * ppp_available - check whether the system has any ppp interfaces @@ -269,27 +271,36 @@ establish_ppp(fd) /* Pop any existing modules off the tty stream. */ for (i = 0;; ++i) if (ioctl(fd, I_LOOK, tty_modules[i]) < 0 + || strcmp(tty_modules[i], "ptem") == 0 || ioctl(fd, I_POP, 0) < 0) break; tty_nmodules = i; /* Push the async hdlc module and the compressor module. */ - if (ioctl(fd, I_PUSH, "ppp_ahdl") < 0) - fatal("Couldn't push PPP Async HDLC module: %m"); + tty_npushed = 0; + if (ioctl(fd, I_PUSH, "ppp_ahdl") < 0) { + error("Couldn't push PPP Async HDLC module: %m"); + return -1; + } + ++tty_npushed; if (kdebugflag & 4) { i = PPPDBG_LOG + PPPDBG_AHDLC; strioctl(pppfd, PPPIO_DEBUG, &i, sizeof(int), 0); } if (ioctl(fd, I_PUSH, "ppp_comp") < 0) error("Couldn't push PPP compression module: %m"); + else + ++tty_npushed; if (kdebugflag & 2) { i = PPPDBG_LOG + PPPDBG_COMP; strioctl(pppfd, PPPIO_DEBUG, &i, sizeof(int), 0); } /* Link the serial port under the PPP multiplexor. */ - if ((fdmuxid = ioctl(pppfd, I_LINK, fd)) < 0) - fatal("Can't link tty to PPP mux: %m"); + if ((fdmuxid = ioctl(pppfd, I_LINK, fd)) < 0) { + error("Can't link tty to PPP mux: %m"); + return -1; + } return pppfd; } @@ -322,8 +333,8 @@ disestablish_ppp(fd) fdmuxid = -1; if (!hungup) { - while (ioctl(fd, I_POP, 0) >= 0) - ; + while (tty_npushed > 0 && ioctl(fd, I_POP, 0) >= 0) + --tty_npushed; for (i = tty_nmodules - 1; i >= 0; --i) if (ioctl(fd, I_PUSH, tty_modules[i]) < 0) error("Couldn't restore tty module %s: %m", @@ -443,6 +454,9 @@ struct speed { #ifdef B57600 { 57600, B57600 }, #endif +#ifdef B76800 + { 76800, B76800 }, +#endif #ifdef B115200 { 115200, B115200 }, #endif @@ -683,7 +697,8 @@ wait_input(timo) /* * add_fd - add an fd to the set that wait_input waits for. */ -void add_fd(int fd) +void add_fd(fd) + int fd; { int n; @@ -701,7 +716,8 @@ void add_fd(int fd) /* * remove_fd - remove an fd from the set that wait_input waits for. */ -void remove_fd(int fd) +void remove_fd(fd) + int fd; { int n; @@ -930,6 +946,25 @@ get_idle_time(u, ip) return strioctl(pppfd, PPPIO_GIDLE, ip, 0, sizeof(struct ppp_idle)) >= 0; } +/* + * get_ppp_stats - return statistics for the link. + */ +int +get_ppp_stats(u, stats) + int u; + struct pppd_stats *stats; +{ + struct ppp_stats s; + + if (strioctl(pppfd, PPPIO_GETSTAT, &s, 0, sizeof(s)) < 0) { + error("Couldn't get link statistics: %m"); + return 0; + } + stats->bytes_in = s.p.ppp_ibytes; + stats->bytes_out = s.p.ppp_obytes; + return 1; +} + #if 0 /* * set_filters - transfer the pass and active filters to the kernel. @@ -1579,9 +1614,9 @@ logwtmp(line, name, host) if (name[0] != 0) { /* logging in */ - strlcpy(utmpx.ut_user, name, sizeof(utmpx.ut_user)); - strlcpy(utmpx.ut_id, ifname, sizeof(utmpx.ut_id)); - strlcpy(utmpx.ut_line, line, sizeof(utmpx.ut_line)); + strncpy(utmpx.ut_user, name, sizeof(utmpx.ut_user)); + strncpy(utmpx.ut_id, ifname, sizeof(utmpx.ut_id)); + strncpy(utmpx.ut_line, line, sizeof(utmpx.ut_line)); utmpx.ut_pid = getpid(); utmpx.ut_type = USER_PROCESS; } else { @@ -1625,6 +1660,7 @@ strioctl(fd, cmd, ptr, ilen, olen) return 0; } +#if 0 /* * lock - create a lock file for the named lock device */ @@ -1702,7 +1738,7 @@ unlock() lock_file[0] = 0; } } - +#endif /* * cifroute - delete a route through the addresses given. @@ -1835,3 +1871,54 @@ have_route_to(addr) close(fd); return 0; } + +/* + * get_pty - get a pty master/slave pair and chown the slave side to + * the uid given. Assumes slave_name points to MAXPATHLEN bytes of space. + */ +int +get_pty(master_fdp, slave_fdp, slave_name, uid) + int *master_fdp; + int *slave_fdp; + char *slave_name; + int uid; +{ + int mfd, sfd; + char *pty_name; + struct termios tios; + + mfd = open("/dev/ptmx", O_RDWR); + if (mfd < 0) { + error("Couldn't open pty master: %m"); + return 0; + } + + pty_name = ptsname(mfd); + if (pty_name == NULL) { + error("Couldn't get name of pty slave"); + close(mfd); + return 0; + } + if (chown(pty_name, uid, -1) < 0) + warn("Couldn't change owner of pty slave: %m"); + if (chmod(pty_name, S_IRUSR | S_IWUSR) < 0) + warn("Couldn't change permissions on pty slave: %m"); + if (unlockpt(mfd) < 0) + warn("Couldn't unlock pty slave: %m"); + + sfd = open(pty_name, O_RDWR); + if (sfd < 0) { + error("Couldn't open pty slave %s: %m", pty_name); + close(mfd); + return 0; + } + if (ioctl(sfd, I_PUSH, "ptem") < 0) + warn("Couldn't push ptem module on pty slave: %m"); + + dbglog("Using %s", pty_name); + strlcpy(slave_name, pty_name, MAXPATHLEN); + *master_fdp = mfd; + *slave_fdp = sfd; + + return 1; +}