]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/main.c
default REQ_SYSOPTIONS is now 1
[ppp.git] / pppd / main.c
index ad3edebf3f1b580403110e75af77a9c21bf1ca6f..c2064a467d3f091ae37c419fafde9517d9577066 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: main.c,v 1.7 1994/04/18 04:06:26 paulus Exp $";
+static char rcsid[] = "$Id: main.c,v 1.10 1994/05/18 06:00:48 paulus Exp $";
 #endif
 
 #define SETSID
@@ -30,6 +30,7 @@ static char rcsid[] = "$Id: main.c,v 1.7 1994/04/18 04:06:26 paulus Exp $";
 #include <syslog.h>
 #include <netdb.h>
 #include <utmp.h>
+#include <pwd.h>
 #include <sys/wait.h>
 
 /*
@@ -37,11 +38,7 @@ static char rcsid[] = "$Id: main.c,v 1.7 1994/04/18 04:06:26 paulus Exp $";
  * /etc/ppp/options exists.
  */
 #ifndef        REQ_SYSOPTIONS
-#define REQ_SYSOPTIONS 0
-#endif
-
-#ifdef STREAMS
-#undef SGTTY
+#define REQ_SYSOPTIONS 1
 #endif
 
 #ifdef SGTTY
@@ -105,15 +102,16 @@ char *progname;                   /* Name of this program */
 char hostname[MAXNAMELEN];     /* Our hostname */
 char our_name[MAXNAMELEN];
 char remote_name[MAXNAMELEN];
+static char pidfilename[MAXPATHLEN];
 
 static pid_t   pid;            /* Our pid */
 static pid_t   pgrpid;         /* Process Group ID */
-static char pidfilename[MAXPATHLEN];
+uid_t uid;                     /* Our real user-id */
 
 char devname[MAXPATHLEN] = "/dev/tty"; /* Device name */
 int default_device = TRUE;     /* use default device (stdin/out) */
 
-int fd;                                /* Device file descriptor */
+int fd = -1;                   /* Device file descriptor */
 int s;                         /* Socket file descriptor */
 
 int phase;                     /* where the link is at */
@@ -177,9 +175,7 @@ void format_packet __ARGS((u_char *, int,
                           void (*) (void *, char *, ...), void *));
 void pr_log __ARGS((void *, char *, ...));
 
-#ifdef STREAMS
 extern char    *ttyname __ARGS((int));
-#endif
 extern char    *getlogin __ARGS((void));
 
 /*
@@ -211,12 +207,11 @@ main(argc, argv)
     struct cmd *cmdp;
     FILE *pidfile;
     char *p;
+    struct passwd *pw;
 
-#ifdef STREAMS
-    p = ttyname(fileno(stdin));
+    p = ttyname(0);
     if (p)
        strcpy(devname, p);
-#endif
   
     if (gethostname(hostname, MAXNAMELEN) < 0 ) {
        perror("couldn't get hostname");
@@ -225,6 +220,7 @@ main(argc, argv)
     hostname[MAXNAMELEN-1] = 0;
 
     pid = getpid();
+    uid = getuid();
 
     if (!ppp_available()) {
        fprintf(stderr, "Sorry - PPP is not available on this system\n");
@@ -241,9 +237,10 @@ main(argc, argv)
   
     progname = *argv;
 
-    if (!options_from_file(_PATH_SYSOPTIONS, REQ_SYSOPTIONS) ||
+    if (!options_from_file(_PATH_SYSOPTIONS, REQ_SYSOPTIONS, 0) ||
        !options_from_user() ||
-       !parse_args(argc-1, argv+1))
+       !parse_args(argc-1, argv+1) ||
+       !options_for_tty())
        die(1);
     check_auth_options();
     setipdefault();
@@ -269,10 +266,15 @@ main(argc, argv)
     magic_init();
 
     p = getlogin();
-    if (p == NULL)
-       p = "(unknown)";
+    if (p == NULL) {
+       pw = getpwuid(uid);
+       if (pw != NULL && pw->pw_name != NULL)
+           p = pw->pw_name;
+       else
+           p = "(unknown)";
+    }
     syslog(LOG_NOTICE, "pppd %s.%d started by %s, uid %d",
-          VERSION, PATCHLEVEL, p, getuid());
+          VERSION, PATCHLEVEL, p, uid);
 
 #ifdef SETSID
     /*
@@ -390,13 +392,13 @@ main(argc, argv)
     }
 #endif /* TIOCSCTTY */
 
-    /* set line speed, flow control, etc. */
-    set_up_tty(fd);
-
     /* run connection script */
     if (connector) {
        MAINDEBUG((LOG_INFO, "Connecting with <%s>", connector));
 
+       /* set line speed, flow control, etc.; set CLOCAL for now */
+       set_up_tty(fd, 1);
+
        /* drop dtr to hang up in case modem is off hook */
        if (!default_device && modem) {
            setdtr(fd, FALSE);
@@ -414,6 +416,9 @@ main(argc, argv)
        sleep(1);               /* give it time to set up its terminal */
     }
   
+    /* set line speed, flow control, etc.; clear CLOCAL if modem option */
+    set_up_tty(fd, 0);
+
     /* set up the serial device as a ppp interface */
     establish_ppp();
 
@@ -617,13 +622,14 @@ baud_rate_of(speed)
 
 /*
  * set_up_tty: Set up the serial port on `fd' for 8 bits, no parity,
- * at the requested speed, etc.
+ * at the requested speed, etc.  If `local' is true, set CLOCAL
+ * regardless of whether the modem option was specified.
  */
-set_up_tty(fd)
-    int fd;
+set_up_tty(fd, local)
+    int fd, local;
 {
 #ifndef SGTTY
-    int speed;
+    int speed, x;
     struct termios tios;
 
     if (tcgetattr(fd, &tios) < 0) {
@@ -643,7 +649,7 @@ set_up_tty(fd)
 #endif /* CRTSCTS */
 
     tios.c_cflag |= CS8 | CREAD | HUPCL;
-    if (!modem)
+    if (local || !modem)
        tios.c_cflag |= CLOCAL;
     tios.c_iflag = IGNBRK | IGNPAR;
     tios.c_oflag = 0;
@@ -663,6 +669,14 @@ set_up_tty(fd)
        die(1);
     }
 
+#ifdef ultrix
+    x = 0;
+    if (ioctl(fd, (crtscts || modem)? TIOCMODEM: TIOCNMODEM, &x) < 0)
+       syslog(LOG_WARNING, "TIOC(N)MODEM: %m");
+    if (ioctl(fd, (local || !modem)? TIOCNCAR: TIOCCAR) < 0)
+       syslog(LOG_WARNING, "TIOC(N)CAR: %m");
+#endif
+
 #else  /* SGTTY */
     int speed;
     struct sgttyb sgttyb;
@@ -743,7 +757,7 @@ cleanup(status, arg)
        if (modem)
            setdtr(fd, FALSE);
 
-       if (fcntl(fd, F_SETFL, initfdflags) < 0)
+       if (initfdflags != -1 && fcntl(fd, F_SETFL, initfdflags) < 0)
            syslog(LOG_WARNING, "fcntl(F_SETFL, fdflags): %m");
 
        disestablish_ppp();
@@ -1001,6 +1015,8 @@ alrm(sig, code, scp, addr)
 
     MAINDEBUG((LOG_DEBUG, "Alarm"));
 
+    if (callout == NULL)
+       return;
     /*
      * Get the first scheduled timeout and any that were scheduled
      * for the same time as a list, and remove them all from callout