uses new getttyent(3) routines.
authorBill Joy <root@ucbvax.Berkeley.EDU>
Tue, 8 May 1984 02:57:09 +0000 (18:57 -0800)
committerBill Joy <root@ucbvax.Berkeley.EDU>
Tue, 8 May 1984 02:57:09 +0000 (18:57 -0800)
SCCS-vsn: old/init/init.c 4.13
SCCS-vsn: sbin/init/init.c 4.13
SCCS-vsn: usr.bin/login/login.c 4.34
SCCS-vsn: usr.bin/login/login.c.1 4.34
SCCS-vsn: usr.bin/tset/tset.c 1.9

usr/src/old/init/init.c
usr/src/sbin/init/init.c
usr/src/usr.bin/login/login.c
usr/src/usr.bin/login/login.c.1
usr/src/usr.bin/tset/tset.c

index 35f3cd4..1ff3be4 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)init.c      4.12 (Berkeley) %G%";
+static char *sccsid = "@(#)init.c      4.13 (Berkeley) %G%";
 #endif
 
 #include <signal.h>
 #endif
 
 #include <signal.h>
@@ -9,8 +9,10 @@ static char *sccsid = "@(#)init.c      4.12 (Berkeley) %G%";
 #include <sys/reboot.h>
 #include <errno.h>
 #include <sys/file.h>
 #include <sys/reboot.h>
 #include <errno.h>
 #include <sys/file.h>
+#include <ttyent.h>
 
 #define        LINSIZ  sizeof(wtmp.ut_line)
 
 #define        LINSIZ  sizeof(wtmp.ut_line)
+#define        TTYSIZ  16
 #define        TABSIZ  100
 #define        ALL     p = &itab[0]; p < &itab[TABSIZ]; p++
 #define        EVER    ;;
 #define        TABSIZ  100
 #define        ALL     p = &itab[0]; p < &itab[TABSIZ]; p++
 #define        EVER    ;;
@@ -22,23 +24,16 @@ char        shell[] = "/bin/sh";
 char   getty[]  = "/etc/getty";
 char   minus[] = "-";
 char   runc[]  = "/etc/rc";
 char   getty[]  = "/etc/getty";
 char   minus[] = "-";
 char   runc[]  = "/etc/rc";
-char   ifile[] = "/etc/ttys";
 char   utmp[]  = "/etc/utmp";
 char   wtmpf[] = "/usr/adm/wtmp";
 char   ctty[]  = "/dev/console";
 char   dev[]   = "/dev/";
 
 struct utmp wtmp;
 char   utmp[]  = "/etc/utmp";
 char   wtmpf[] = "/usr/adm/wtmp";
 char   ctty[]  = "/dev/console";
 char   dev[]   = "/dev/";
 
 struct utmp wtmp;
-struct
-{
-       char    line[LINSIZ];
-       char    comn;
-       char    flag;
-} line;
 struct tab
 {
        char    line[LINSIZ];
 struct tab
 {
        char    line[LINSIZ];
-       char    comn;
+       char    comn[TTYSIZ];
        char    xflag;
        int     pid;
        time_t  gettytime;
        char    xflag;
        int     pid;
        time_t  gettytime;
@@ -182,6 +177,7 @@ single()
                        signal(SIGTERM, SIG_DFL);
                        signal(SIGHUP, SIG_DFL);
                        signal(SIGALRM, SIG_DFL);
                        signal(SIGTERM, SIG_DFL);
                        signal(SIGHUP, SIG_DFL);
                        signal(SIGALRM, SIG_DFL);
+                       signal(SIGTSTP, SIG_IGN);
                        (void) open(ctty, O_RDWR);
                        dup2(0, 1);
                        dup2(0, 2);
                        (void) open(ctty, O_RDWR);
                        dup2(0, 1);
                        dup2(0, 2);
@@ -266,35 +262,40 @@ multiple()
 merge()
 {
        register struct tab *p;
 merge()
 {
        register struct tab *p;
+       register struct ttyent *t;
 
 
-       fi = open(ifile, 0);
-       if (fi < 0)
-               return;
        for (ALL)
                p->xflag = 0;
        for (ALL)
                p->xflag = 0;
-       while (rline()) {
+       setttyent();
+       while (t = getttyent()) {
+               if ((t->ty_status & TTY_ON) == 0)
+                       continue;
+               strcpy(tty, dev);
+               strcat(tty, t->ty_name);
+               if (access(tty, R_OK|W_OK) < 0)
+                       continue;
                for (ALL) {
                for (ALL) {
-                       if (SCMPN(p->line, line.line))
+                       if (SCMPN(p->line, t->ty_name))
                                continue;
                        p->xflag |= FOUND;
                                continue;
                        p->xflag |= FOUND;
-                       if (line.comn != p->comn) {
+                       if (SCMPN(p->comn, t->ty_getty)) {
                                p->xflag |= CHANGE;
                                p->xflag |= CHANGE;
-                               p->comn = line.comn;
+                               SCPYN(p->comn, t->ty_getty);
                        }
                        goto contin1;
                }
                for (ALL) {
                        if (p->line[0] != 0)
                                continue;
                        }
                        goto contin1;
                }
                for (ALL) {
                        if (p->line[0] != 0)
                                continue;
-                       SCPYN(p->line, line.line);
+                       SCPYN(p->line, t->ty_name);
                        p->xflag |= FOUND|CHANGE;
                        p->xflag |= FOUND|CHANGE;
-                       p->comn = line.comn;
+                       SCPYN(p->comn, t->ty_getty);
                        goto contin1;
                }
        contin1:
                ;
        }
                        goto contin1;
                }
        contin1:
                ;
        }
-       close(fi);
+       endttyent();
        for (ALL) {
                if ((p->xflag&FOUND) == 0) {
                        term(p);
        for (ALL) {
                if ((p->xflag&FOUND) == 0) {
                        term(p);
@@ -318,52 +319,6 @@ term(p)
        p->pid = 0;
 }
 
        p->pid = 0;
 }
 
-rline()
-{
-       register c, i;
-
-loop:
-       c = get();
-       if (c < 0)
-               return(0);
-       if (c == 0)
-               goto loop;
-       line.flag = c;
-       c = get();
-       if (c <= 0)
-               goto loop;
-       line.comn = c;
-       SCPYN(line.line, "");
-       for (i = 0; i < LINSIZ; i++) {
-               c = get();
-               if (c <= 0)
-                       break;
-               line.line[i] = c;
-       }
-       while (c > 0)
-               c = get();
-       if (line.line[0] == 0)
-               goto loop;
-       if (line.flag == '0')
-               goto loop;
-       strcpy(tty, dev);
-       strncat(tty, line.line, LINSIZ);
-       if (access(tty, 06) < 0)
-               goto loop;
-       return (1);
-}
-
-get()
-{
-       char b;
-
-       if (read(fi, &b, 1) != 1)
-               return (-1);
-       if (b == '\n')
-               return (0);
-       return (b);
-}
-
 #include <sys/ioctl.h>
 
 dfork(p)
 #include <sys/ioctl.h>
 
 dfork(p)
@@ -438,8 +393,8 @@ dfork(p)
                close(0);
                dup(1);
                dup(0);
                close(0);
                dup(1);
                dup(0);
-               tty[0] = p->comn;
-               tty[1] = 0;
+               strncpy(tty, p->comn, sizeof(p->comn));
+               tty[sizeof(p->comn)] = 0;
                execl(getty, minus, tty, (char *)0);
                exit(0);
        }
                execl(getty, minus, tty, (char *)0);
                exit(0);
        }
index 35f3cd4..1ff3be4 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)init.c      4.12 (Berkeley) %G%";
+static char *sccsid = "@(#)init.c      4.13 (Berkeley) %G%";
 #endif
 
 #include <signal.h>
 #endif
 
 #include <signal.h>
@@ -9,8 +9,10 @@ static char *sccsid = "@(#)init.c      4.12 (Berkeley) %G%";
 #include <sys/reboot.h>
 #include <errno.h>
 #include <sys/file.h>
 #include <sys/reboot.h>
 #include <errno.h>
 #include <sys/file.h>
+#include <ttyent.h>
 
 #define        LINSIZ  sizeof(wtmp.ut_line)
 
 #define        LINSIZ  sizeof(wtmp.ut_line)
+#define        TTYSIZ  16
 #define        TABSIZ  100
 #define        ALL     p = &itab[0]; p < &itab[TABSIZ]; p++
 #define        EVER    ;;
 #define        TABSIZ  100
 #define        ALL     p = &itab[0]; p < &itab[TABSIZ]; p++
 #define        EVER    ;;
@@ -22,23 +24,16 @@ char        shell[] = "/bin/sh";
 char   getty[]  = "/etc/getty";
 char   minus[] = "-";
 char   runc[]  = "/etc/rc";
 char   getty[]  = "/etc/getty";
 char   minus[] = "-";
 char   runc[]  = "/etc/rc";
-char   ifile[] = "/etc/ttys";
 char   utmp[]  = "/etc/utmp";
 char   wtmpf[] = "/usr/adm/wtmp";
 char   ctty[]  = "/dev/console";
 char   dev[]   = "/dev/";
 
 struct utmp wtmp;
 char   utmp[]  = "/etc/utmp";
 char   wtmpf[] = "/usr/adm/wtmp";
 char   ctty[]  = "/dev/console";
 char   dev[]   = "/dev/";
 
 struct utmp wtmp;
-struct
-{
-       char    line[LINSIZ];
-       char    comn;
-       char    flag;
-} line;
 struct tab
 {
        char    line[LINSIZ];
 struct tab
 {
        char    line[LINSIZ];
-       char    comn;
+       char    comn[TTYSIZ];
        char    xflag;
        int     pid;
        time_t  gettytime;
        char    xflag;
        int     pid;
        time_t  gettytime;
@@ -182,6 +177,7 @@ single()
                        signal(SIGTERM, SIG_DFL);
                        signal(SIGHUP, SIG_DFL);
                        signal(SIGALRM, SIG_DFL);
                        signal(SIGTERM, SIG_DFL);
                        signal(SIGHUP, SIG_DFL);
                        signal(SIGALRM, SIG_DFL);
+                       signal(SIGTSTP, SIG_IGN);
                        (void) open(ctty, O_RDWR);
                        dup2(0, 1);
                        dup2(0, 2);
                        (void) open(ctty, O_RDWR);
                        dup2(0, 1);
                        dup2(0, 2);
@@ -266,35 +262,40 @@ multiple()
 merge()
 {
        register struct tab *p;
 merge()
 {
        register struct tab *p;
+       register struct ttyent *t;
 
 
-       fi = open(ifile, 0);
-       if (fi < 0)
-               return;
        for (ALL)
                p->xflag = 0;
        for (ALL)
                p->xflag = 0;
-       while (rline()) {
+       setttyent();
+       while (t = getttyent()) {
+               if ((t->ty_status & TTY_ON) == 0)
+                       continue;
+               strcpy(tty, dev);
+               strcat(tty, t->ty_name);
+               if (access(tty, R_OK|W_OK) < 0)
+                       continue;
                for (ALL) {
                for (ALL) {
-                       if (SCMPN(p->line, line.line))
+                       if (SCMPN(p->line, t->ty_name))
                                continue;
                        p->xflag |= FOUND;
                                continue;
                        p->xflag |= FOUND;
-                       if (line.comn != p->comn) {
+                       if (SCMPN(p->comn, t->ty_getty)) {
                                p->xflag |= CHANGE;
                                p->xflag |= CHANGE;
-                               p->comn = line.comn;
+                               SCPYN(p->comn, t->ty_getty);
                        }
                        goto contin1;
                }
                for (ALL) {
                        if (p->line[0] != 0)
                                continue;
                        }
                        goto contin1;
                }
                for (ALL) {
                        if (p->line[0] != 0)
                                continue;
-                       SCPYN(p->line, line.line);
+                       SCPYN(p->line, t->ty_name);
                        p->xflag |= FOUND|CHANGE;
                        p->xflag |= FOUND|CHANGE;
-                       p->comn = line.comn;
+                       SCPYN(p->comn, t->ty_getty);
                        goto contin1;
                }
        contin1:
                ;
        }
                        goto contin1;
                }
        contin1:
                ;
        }
-       close(fi);
+       endttyent();
        for (ALL) {
                if ((p->xflag&FOUND) == 0) {
                        term(p);
        for (ALL) {
                if ((p->xflag&FOUND) == 0) {
                        term(p);
@@ -318,52 +319,6 @@ term(p)
        p->pid = 0;
 }
 
        p->pid = 0;
 }
 
-rline()
-{
-       register c, i;
-
-loop:
-       c = get();
-       if (c < 0)
-               return(0);
-       if (c == 0)
-               goto loop;
-       line.flag = c;
-       c = get();
-       if (c <= 0)
-               goto loop;
-       line.comn = c;
-       SCPYN(line.line, "");
-       for (i = 0; i < LINSIZ; i++) {
-               c = get();
-               if (c <= 0)
-                       break;
-               line.line[i] = c;
-       }
-       while (c > 0)
-               c = get();
-       if (line.line[0] == 0)
-               goto loop;
-       if (line.flag == '0')
-               goto loop;
-       strcpy(tty, dev);
-       strncat(tty, line.line, LINSIZ);
-       if (access(tty, 06) < 0)
-               goto loop;
-       return (1);
-}
-
-get()
-{
-       char b;
-
-       if (read(fi, &b, 1) != 1)
-               return (-1);
-       if (b == '\n')
-               return (0);
-       return (b);
-}
-
 #include <sys/ioctl.h>
 
 dfork(p)
 #include <sys/ioctl.h>
 
 dfork(p)
@@ -438,8 +393,8 @@ dfork(p)
                close(0);
                dup(1);
                dup(0);
                close(0);
                dup(1);
                dup(0);
-               tty[0] = p->comn;
-               tty[1] = 0;
+               strncpy(tty, p->comn, sizeof(p->comn));
+               tty[sizeof(p->comn)] = 0;
                execl(getty, minus, tty, (char *)0);
                exit(0);
        }
                execl(getty, minus, tty, (char *)0);
                exit(0);
        }
index 22066ab..4c08cb8 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)login.c     4.33 (Berkeley) 83/09/02";
+static char *sccsid = "@(#)login.c     4.34 (Berkeley) 84/05/07";
 #endif
 
 /*
 #endif
 
 /*
@@ -13,6 +13,7 @@ static        char *sccsid = "@(#)login.c     4.33 (Berkeley) 83/09/02";
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/resource.h>
+#include <sys/file.h>
 
 #include <sgtty.h>
 #include <utmp.h>
 
 #include <sgtty.h>
 #include <utmp.h>
@@ -21,7 +22,10 @@ static       char *sccsid = "@(#)login.c     4.33 (Berkeley) 83/09/02";
 #include <stdio.h>
 #include <lastlog.h>
 #include <errno.h>
 #include <stdio.h>
 #include <lastlog.h>
 #include <errno.h>
+#include <ttyent.h>
+#include <syslog.h>
 
 
+#define        SCMPN(a, b)     strncmp(a, b, sizeof(a))
 #define        SCPYN(a, b)     strncpy(a, b, sizeof(a))
 
 #define NMAX   sizeof(utmp.ut_name)
 #define        SCPYN(a, b)     strncpy(a, b, sizeof(a))
 
 #define NMAX   sizeof(utmp.ut_name)
@@ -31,7 +35,6 @@ static        char *sccsid = "@(#)login.c     4.33 (Berkeley) 83/09/02";
 
 char   nolog[] =       "/etc/nologin";
 char   qlog[]  =       ".hushlogin";
 
 char   nolog[] =       "/etc/nologin";
 char   qlog[]  =       ".hushlogin";
-char   securetty[] =   "/etc/securetty";
 char   maildir[30] =   "/usr/spool/mail/";
 char   lastlog[] =     "/usr/adm/lastlog";
 struct passwd nouser = {"", "nope", -1, -1, -1, "", "", "", "" };
 char   maildir[30] =   "/usr/spool/mail/";
 char   lastlog[] =     "/usr/adm/lastlog";
 struct passwd nouser = {"", "nope", -1, -1, -1, "", "", "", "" };
@@ -53,9 +56,7 @@ char  *envinit[] =
     { homedir, shell, "PATH=:/usr/ucb:/bin:/usr/bin", term, user, 0 };
 
 struct passwd *pwd;
     { homedir, shell, "PATH=:/usr/ucb:/bin:/usr/bin", term, user, 0 };
 
 struct passwd *pwd;
-struct passwd *getpwnam();
 char   *strcat(), *rindex(), *index();
 char   *strcat(), *rindex(), *index();
-int    setpwent();
 int    timedout();
 char   *ttyname();
 char   *crypt();
 int    timedout();
 char   *ttyname();
 char   *crypt();
@@ -81,10 +82,10 @@ main(argc, argv)
        char *argv[];
 {
        register char *namep;
        char *argv[];
 {
        register char *namep;
-       int t, f, c, i;
+       int t, f, c;
        int invalid, quietlog;
        FILE *nlfd;
        int invalid, quietlog;
        FILE *nlfd;
-       char *ttyn;
+       char *ttyn, *tty;
        int ldisc = 0, zero = 0;
 
        signal(SIGALRM, timedout);
        int ldisc = 0, zero = 0;
 
        signal(SIGALRM, timedout);
@@ -127,8 +128,15 @@ main(argc, argv)
        for (t = getdtablesize(); t > 3; t--)
                close(t);
        ttyn = ttyname(0);
        for (t = getdtablesize(); t > 3; t--)
                close(t);
        ttyn = ttyname(0);
-       if (ttyn==(char *)0)
+       if (ttyn == (char *)0)
                ttyn = "/dev/tty??";
                ttyn = "/dev/tty??";
+       tty = rindex(ttyn, '/');
+       if (tty == NULL)
+               tty = ttyn;
+       else
+               tty++;
+       openlog("login", 0, 0);
+       t = 0;
        do {
                ldisc = 0;
                ioctl(0, TIOCSETD, &ldisc);
        do {
                ldisc = 0;
                ioctl(0, TIOCSETD, &ldisc);
@@ -185,21 +193,26 @@ main(argc, argv)
                 * If valid so far and root is logging in,
                 * see if root logins on this terminal are permitted.
                 */
                 * If valid so far and root is logging in,
                 * see if root logins on this terminal are permitted.
                 */
-               if (!invalid && pwd->pw_uid == 0 &&
-                   !rootterm(ttyn+sizeof("/dev/")-1)) {
-                       logerr("ROOT LOGIN REFUSED %s",
-                           ttyn+sizeof("/dev/")-1);
+               if (!invalid && pwd->pw_uid == 0 && !rootterm(tty)) {
+                       syslog(LOG_INFO, "ROOT LOGIN REFUSED %s", tty);
                        invalid = TRUE;
                }
                if (invalid) {
                        printf("Login incorrect\n");
                        invalid = TRUE;
                }
                if (invalid) {
                        printf("Login incorrect\n");
-                       if (ttyn[sizeof("/dev/tty")-1] == 'd')
-                               logerr("BADDIALUP %s %s",
-                                   ttyn+sizeof("/dev/")-1, utmp.ut_name);
+                       if (++t >= 5) {
+                               syslog(LOG_INFO,
+                                   "REPEATED LOGIN FAILURES %s, %s",
+                                       tty, utmp.ut_name);
+                               ioctl(0, TIOCHPCL, (struct sgttyb *) 0);
+                               close(0);
+                               close(1);
+                               close(2);
+                               sleep(10);
+                               exit(1);
+                       }
                }
                if (*pwd->pw_shell == '\0')
                        pwd->pw_shell = "/bin/sh";
                }
                if (*pwd->pw_shell == '\0')
                        pwd->pw_shell = "/bin/sh";
-               i = strlen(pwd->pw_shell);
                if (chdir(pwd->pw_dir) < 0 && !invalid ) {
                        if (chdir("/") < 0) {
                                printf("No directory!\n");
                if (chdir(pwd->pw_dir) < 0 && !invalid ) {
                        if (chdir("/") < 0) {
                                printf("No directory!\n");
@@ -234,19 +247,18 @@ main(argc, argv)
        }
        time(&utmp.ut_time);
        t = ttyslot();
        }
        time(&utmp.ut_time);
        t = ttyslot();
-       if (t > 0 && (f = open("/etc/utmp", 1)) >= 0) {
+       if (t > 0 && (f = open("/etc/utmp", O_WRONLY)) >= 0) {
                lseek(f, (long)(t*sizeof(utmp)), 0);
                lseek(f, (long)(t*sizeof(utmp)), 0);
-               SCPYN(utmp.ut_line, rindex(ttyn, '/')+1);
+               SCPYN(utmp.ut_line, tty);
                write(f, (char *)&utmp, sizeof(utmp));
                close(f);
        }
                write(f, (char *)&utmp, sizeof(utmp));
                close(f);
        }
-       if (t > 0 && (f = open("/usr/adm/wtmp", 1)) >= 0) {
-               lseek(f, 0L, 2);
+       if ((f = open("/usr/adm/wtmp", O_WRONLY|O_APPEND)) >= 0) {
                write(f, (char *)&utmp, sizeof(utmp));
                close(f);
        }
                write(f, (char *)&utmp, sizeof(utmp));
                close(f);
        }
-       quietlog = access(qlog, 0) == 0;
-       if ((f = open(lastlog, 2)) >= 0) {
+       quietlog = access(qlog, F_OK) == 0;
+       if ((f = open(lastlog, O_RDWR)) >= 0) {
                struct lastlog ll;
 
                lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
                struct lastlog ll;
 
                lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
@@ -263,7 +275,7 @@ main(argc, argv)
                }
                lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
                time(&ll.ll_time);
                }
                lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
                time(&ll.ll_time);
-               SCPYN(ll.ll_line, rindex(ttyn, '/')+1);
+               SCPYN(ll.ll_line, tty);
                SCPYN(ll.ll_host, utmp.ut_host);
                write(f, (char *) &ll, sizeof ll);
                close(f);
                SCPYN(ll.ll_host, utmp.ut_host);
                write(f, (char *) &ll, sizeof ll);
                close(f);
@@ -280,21 +292,19 @@ main(argc, argv)
        strncat(homedir, pwd->pw_dir, sizeof(homedir)-6);
        strncat(shell, pwd->pw_shell, sizeof(shell)-7);
        if (term[strlen("TERM=")] == 0)
        strncat(homedir, pwd->pw_dir, sizeof(homedir)-6);
        strncat(shell, pwd->pw_shell, sizeof(shell)-7);
        if (term[strlen("TERM=")] == 0)
-               strncat(term, stypeof(ttyn), sizeof(term)-6);
+               strncat(term, stypeof(tty), sizeof(term)-6);
        strncat(user, pwd->pw_name, sizeof(user)-6);
        if ((namep = rindex(pwd->pw_shell, '/')) == NULL)
                namep = pwd->pw_shell;
        else
                namep++;
        strcat(minusnam, namep);
        strncat(user, pwd->pw_name, sizeof(user)-6);
        if ((namep = rindex(pwd->pw_shell, '/')) == NULL)
                namep = pwd->pw_shell;
        else
                namep++;
        strcat(minusnam, namep);
-       umask(022);
-       if (ttyn[sizeof("/dev/tty")-1] == 'd')
-               logerr("DIALUP %s %s",
-                   ttyn+sizeof("/dev/")-1, pwd->pw_name);
+       if (tty[sizeof("tty")-1] == 'd')
+               syslog(LOG_INFO, "DIALUP %s %s", tty, pwd->pw_name);
        if (!quietlog) {
                showmotd();
                strcat(maildir, pwd->pw_name);
        if (!quietlog) {
                showmotd();
                strcat(maildir, pwd->pw_name);
-               if (access(maildir,4)==0) {
+               if (access(maildir, R_OK) == 0) {
                        struct stat statb;
                        stat(maildir, &statb);
                        if (statb.st_size)
                        struct stat statb;
                        stat(maildir, &statb);
                        if (statb.st_size)
@@ -331,10 +341,8 @@ getloginname(up)
        }
        strncpy(lusername, up->ut_name, NMAX);
        lusername[NMAX] = 0;
        }
        strncpy(lusername, up->ut_name, NMAX);
        lusername[NMAX] = 0;
-       setpwent();
        if ((pwd = getpwnam(lusername)) == NULL)
                pwd = &nouser;
        if ((pwd = getpwnam(lusername)) == NULL)
                pwd = &nouser;
-       endpwent();
 }
 
 timedout()
 }
 
 timedout()
@@ -355,20 +363,13 @@ catch()
 rootterm(tty)
        char *tty;
 {
 rootterm(tty)
        char *tty;
 {
-       register FILE *fd;
-       char buf[100];
-
-       if ((fd = fopen(securetty, "r")) == NULL)
-               return(1);
-       while (fgets(buf, sizeof buf, fd) != NULL) {
-               buf[strlen(buf)-1] = '\0';
-               if (strcmp(tty, buf) == 0) {
-                       fclose(fd);
-                       return(1);
-               }
+       register struct ttyent *t;
+
+       if ((t = getttynam(tty)) != NULL) {
+               if (t->ty_status & TTY_SECURE)
+                       return (1);
        }
        }
-       fclose(fd);
-       return(0);
+       return (0);
 }
 
 showmotd()
 }
 
 showmotd()
@@ -377,7 +378,7 @@ showmotd()
        register c;
 
        signal(SIGINT, catch);
        register c;
 
        signal(SIGINT, catch);
-       if ((mf = fopen("/etc/motd","r")) != NULL) {
+       if ((mf = fopen("/etc/motd", "r")) != NULL) {
                while ((c = getc(mf)) != EOF && stopmotd == 0)
                        putchar(c);
                fclose(mf);
                while ((c = getc(mf)) != EOF && stopmotd == 0)
                        putchar(c);
                fclose(mf);
@@ -392,39 +393,11 @@ char *
 stypeof(ttyid)
        char *ttyid;
 {
 stypeof(ttyid)
        char *ttyid;
 {
-       static char typebuf[16];
-       char buf[50];
-       register FILE *f;
-       register char *p, *t, *q;
+       register struct ttyent *t;
 
 
-       if (ttyid == NULL)
+       if (ttyid == NULL || (t = getttynam(ttyid)) == NULL)
                return (UNKNOWN);
                return (UNKNOWN);
-       f = fopen("/etc/ttytype", "r");
-       if (f == NULL)
-               return (UNKNOWN);
-       /* split off end of name */
-       for (p = q = ttyid; *p != 0; p++)
-               if (*p == '/')
-                       q = p + 1;
-
-       /* scan the file */
-       while (fgets(buf, sizeof buf, f) != NULL) {
-               for (t = buf; *t != ' ' && *t != '\t'; t++)
-                       ;
-               *t++ = 0;
-               while (*t == ' ' || *t == '\t')
-                       t++;
-               for (p = t; *p > ' '; p++)
-                       ;
-               *p = 0;
-               if (strcmp(q,t) == 0) {
-                       strcpy(typebuf, buf);
-                       fclose(f);
-                       return (typebuf);
-               }
-       }
-       fclose (f);
-       return (UNKNOWN);
+       return (t->ty_type);
 }
 
 doremotelogin(host)
 }
 
 doremotelogin(host)
@@ -440,9 +413,7 @@ doremotelogin(host)
                pwd = &nouser;
                goto bad;
        }
                pwd = &nouser;
                goto bad;
        }
-       setpwent();
        pwd = getpwnam(lusername);
        pwd = getpwnam(lusername);
-       endpwent();
        if (pwd == NULL) {
                pwd = &nouser;
                goto bad;
        if (pwd == NULL) {
                pwd = &nouser;
                goto bad;
@@ -533,17 +504,3 @@ doremoteterm(term, tp)
        }
        tp->sg_flags = ECHO|CRMOD|ANYP|XTABS;
 }
        }
        tp->sg_flags = ECHO|CRMOD|ANYP|XTABS;
 }
-
-logerr(fmt, a1, a2, a3)
-       char *fmt, *a1, *a2, *a3;
-{
-#ifdef LOGERR
-       FILE *cons = fopen("/dev/console", "w");
-
-       if (cons != NULL) {
-               fprintf(cons, fmt, a1, a2, a3);
-               fprintf(cons, "\n\r");
-               fclose(cons);
-       }
-#endif
-}
index aae6385..98d441c 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)login.c.1   4.33 (Berkeley) 83/09/02";
+static char *sccsid = "@(#)login.c.1   4.34 (Berkeley) 84/05/07";
 #endif
 
 /*
 #endif
 
 /*
@@ -13,6 +13,7 @@ static        char *sccsid = "@(#)login.c.1   4.33 (Berkeley) 83/09/02";
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/resource.h>
+#include <sys/file.h>
 
 #include <sgtty.h>
 #include <utmp.h>
 
 #include <sgtty.h>
 #include <utmp.h>
@@ -21,7 +22,10 @@ static       char *sccsid = "@(#)login.c.1   4.33 (Berkeley) 83/09/02";
 #include <stdio.h>
 #include <lastlog.h>
 #include <errno.h>
 #include <stdio.h>
 #include <lastlog.h>
 #include <errno.h>
+#include <ttyent.h>
+#include <syslog.h>
 
 
+#define        SCMPN(a, b)     strncmp(a, b, sizeof(a))
 #define        SCPYN(a, b)     strncpy(a, b, sizeof(a))
 
 #define NMAX   sizeof(utmp.ut_name)
 #define        SCPYN(a, b)     strncpy(a, b, sizeof(a))
 
 #define NMAX   sizeof(utmp.ut_name)
@@ -31,7 +35,6 @@ static        char *sccsid = "@(#)login.c.1   4.33 (Berkeley) 83/09/02";
 
 char   nolog[] =       "/etc/nologin";
 char   qlog[]  =       ".hushlogin";
 
 char   nolog[] =       "/etc/nologin";
 char   qlog[]  =       ".hushlogin";
-char   securetty[] =   "/etc/securetty";
 char   maildir[30] =   "/usr/spool/mail/";
 char   lastlog[] =     "/usr/adm/lastlog";
 struct passwd nouser = {"", "nope", -1, -1, -1, "", "", "", "" };
 char   maildir[30] =   "/usr/spool/mail/";
 char   lastlog[] =     "/usr/adm/lastlog";
 struct passwd nouser = {"", "nope", -1, -1, -1, "", "", "", "" };
@@ -53,9 +56,7 @@ char  *envinit[] =
     { homedir, shell, "PATH=:/usr/ucb:/bin:/usr/bin", term, user, 0 };
 
 struct passwd *pwd;
     { homedir, shell, "PATH=:/usr/ucb:/bin:/usr/bin", term, user, 0 };
 
 struct passwd *pwd;
-struct passwd *getpwnam();
 char   *strcat(), *rindex(), *index();
 char   *strcat(), *rindex(), *index();
-int    setpwent();
 int    timedout();
 char   *ttyname();
 char   *crypt();
 int    timedout();
 char   *ttyname();
 char   *crypt();
@@ -81,10 +82,10 @@ main(argc, argv)
        char *argv[];
 {
        register char *namep;
        char *argv[];
 {
        register char *namep;
-       int t, f, c, i;
+       int t, f, c;
        int invalid, quietlog;
        FILE *nlfd;
        int invalid, quietlog;
        FILE *nlfd;
-       char *ttyn;
+       char *ttyn, *tty;
        int ldisc = 0, zero = 0;
 
        signal(SIGALRM, timedout);
        int ldisc = 0, zero = 0;
 
        signal(SIGALRM, timedout);
@@ -127,8 +128,15 @@ main(argc, argv)
        for (t = getdtablesize(); t > 3; t--)
                close(t);
        ttyn = ttyname(0);
        for (t = getdtablesize(); t > 3; t--)
                close(t);
        ttyn = ttyname(0);
-       if (ttyn==(char *)0)
+       if (ttyn == (char *)0)
                ttyn = "/dev/tty??";
                ttyn = "/dev/tty??";
+       tty = rindex(ttyn, '/');
+       if (tty == NULL)
+               tty = ttyn;
+       else
+               tty++;
+       openlog("login", 0, 0);
+       t = 0;
        do {
                ldisc = 0;
                ioctl(0, TIOCSETD, &ldisc);
        do {
                ldisc = 0;
                ioctl(0, TIOCSETD, &ldisc);
@@ -185,21 +193,26 @@ main(argc, argv)
                 * If valid so far and root is logging in,
                 * see if root logins on this terminal are permitted.
                 */
                 * If valid so far and root is logging in,
                 * see if root logins on this terminal are permitted.
                 */
-               if (!invalid && pwd->pw_uid == 0 &&
-                   !rootterm(ttyn+sizeof("/dev/")-1)) {
-                       logerr("ROOT LOGIN REFUSED %s",
-                           ttyn+sizeof("/dev/")-1);
+               if (!invalid && pwd->pw_uid == 0 && !rootterm(tty)) {
+                       syslog(LOG_INFO, "ROOT LOGIN REFUSED %s", tty);
                        invalid = TRUE;
                }
                if (invalid) {
                        printf("Login incorrect\n");
                        invalid = TRUE;
                }
                if (invalid) {
                        printf("Login incorrect\n");
-                       if (ttyn[sizeof("/dev/tty")-1] == 'd')
-                               logerr("BADDIALUP %s %s",
-                                   ttyn+sizeof("/dev/")-1, utmp.ut_name);
+                       if (++t >= 5) {
+                               syslog(LOG_INFO,
+                                   "REPEATED LOGIN FAILURES %s, %s",
+                                       tty, utmp.ut_name);
+                               ioctl(0, TIOCHPCL, (struct sgttyb *) 0);
+                               close(0);
+                               close(1);
+                               close(2);
+                               sleep(10);
+                               exit(1);
+                       }
                }
                if (*pwd->pw_shell == '\0')
                        pwd->pw_shell = "/bin/sh";
                }
                if (*pwd->pw_shell == '\0')
                        pwd->pw_shell = "/bin/sh";
-               i = strlen(pwd->pw_shell);
                if (chdir(pwd->pw_dir) < 0 && !invalid ) {
                        if (chdir("/") < 0) {
                                printf("No directory!\n");
                if (chdir(pwd->pw_dir) < 0 && !invalid ) {
                        if (chdir("/") < 0) {
                                printf("No directory!\n");
@@ -234,19 +247,18 @@ main(argc, argv)
        }
        time(&utmp.ut_time);
        t = ttyslot();
        }
        time(&utmp.ut_time);
        t = ttyslot();
-       if (t > 0 && (f = open("/etc/utmp", 1)) >= 0) {
+       if (t > 0 && (f = open("/etc/utmp", O_WRONLY)) >= 0) {
                lseek(f, (long)(t*sizeof(utmp)), 0);
                lseek(f, (long)(t*sizeof(utmp)), 0);
-               SCPYN(utmp.ut_line, rindex(ttyn, '/')+1);
+               SCPYN(utmp.ut_line, tty);
                write(f, (char *)&utmp, sizeof(utmp));
                close(f);
        }
                write(f, (char *)&utmp, sizeof(utmp));
                close(f);
        }
-       if (t > 0 && (f = open("/usr/adm/wtmp", 1)) >= 0) {
-               lseek(f, 0L, 2);
+       if ((f = open("/usr/adm/wtmp", O_WRONLY|O_APPEND)) >= 0) {
                write(f, (char *)&utmp, sizeof(utmp));
                close(f);
        }
                write(f, (char *)&utmp, sizeof(utmp));
                close(f);
        }
-       quietlog = access(qlog, 0) == 0;
-       if ((f = open(lastlog, 2)) >= 0) {
+       quietlog = access(qlog, F_OK) == 0;
+       if ((f = open(lastlog, O_RDWR)) >= 0) {
                struct lastlog ll;
 
                lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
                struct lastlog ll;
 
                lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
@@ -263,7 +275,7 @@ main(argc, argv)
                }
                lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
                time(&ll.ll_time);
                }
                lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
                time(&ll.ll_time);
-               SCPYN(ll.ll_line, rindex(ttyn, '/')+1);
+               SCPYN(ll.ll_line, tty);
                SCPYN(ll.ll_host, utmp.ut_host);
                write(f, (char *) &ll, sizeof ll);
                close(f);
                SCPYN(ll.ll_host, utmp.ut_host);
                write(f, (char *) &ll, sizeof ll);
                close(f);
@@ -280,21 +292,19 @@ main(argc, argv)
        strncat(homedir, pwd->pw_dir, sizeof(homedir)-6);
        strncat(shell, pwd->pw_shell, sizeof(shell)-7);
        if (term[strlen("TERM=")] == 0)
        strncat(homedir, pwd->pw_dir, sizeof(homedir)-6);
        strncat(shell, pwd->pw_shell, sizeof(shell)-7);
        if (term[strlen("TERM=")] == 0)
-               strncat(term, stypeof(ttyn), sizeof(term)-6);
+               strncat(term, stypeof(tty), sizeof(term)-6);
        strncat(user, pwd->pw_name, sizeof(user)-6);
        if ((namep = rindex(pwd->pw_shell, '/')) == NULL)
                namep = pwd->pw_shell;
        else
                namep++;
        strcat(minusnam, namep);
        strncat(user, pwd->pw_name, sizeof(user)-6);
        if ((namep = rindex(pwd->pw_shell, '/')) == NULL)
                namep = pwd->pw_shell;
        else
                namep++;
        strcat(minusnam, namep);
-       umask(022);
-       if (ttyn[sizeof("/dev/tty")-1] == 'd')
-               logerr("DIALUP %s %s",
-                   ttyn+sizeof("/dev/")-1, pwd->pw_name);
+       if (tty[sizeof("tty")-1] == 'd')
+               syslog(LOG_INFO, "DIALUP %s %s", tty, pwd->pw_name);
        if (!quietlog) {
                showmotd();
                strcat(maildir, pwd->pw_name);
        if (!quietlog) {
                showmotd();
                strcat(maildir, pwd->pw_name);
-               if (access(maildir,4)==0) {
+               if (access(maildir, R_OK) == 0) {
                        struct stat statb;
                        stat(maildir, &statb);
                        if (statb.st_size)
                        struct stat statb;
                        stat(maildir, &statb);
                        if (statb.st_size)
@@ -331,10 +341,8 @@ getloginname(up)
        }
        strncpy(lusername, up->ut_name, NMAX);
        lusername[NMAX] = 0;
        }
        strncpy(lusername, up->ut_name, NMAX);
        lusername[NMAX] = 0;
-       setpwent();
        if ((pwd = getpwnam(lusername)) == NULL)
                pwd = &nouser;
        if ((pwd = getpwnam(lusername)) == NULL)
                pwd = &nouser;
-       endpwent();
 }
 
 timedout()
 }
 
 timedout()
@@ -355,20 +363,13 @@ catch()
 rootterm(tty)
        char *tty;
 {
 rootterm(tty)
        char *tty;
 {
-       register FILE *fd;
-       char buf[100];
-
-       if ((fd = fopen(securetty, "r")) == NULL)
-               return(1);
-       while (fgets(buf, sizeof buf, fd) != NULL) {
-               buf[strlen(buf)-1] = '\0';
-               if (strcmp(tty, buf) == 0) {
-                       fclose(fd);
-                       return(1);
-               }
+       register struct ttyent *t;
+
+       if ((t = getttynam(tty)) != NULL) {
+               if (t->ty_status & TTY_SECURE)
+                       return (1);
        }
        }
-       fclose(fd);
-       return(0);
+       return (0);
 }
 
 showmotd()
 }
 
 showmotd()
@@ -377,7 +378,7 @@ showmotd()
        register c;
 
        signal(SIGINT, catch);
        register c;
 
        signal(SIGINT, catch);
-       if ((mf = fopen("/etc/motd","r")) != NULL) {
+       if ((mf = fopen("/etc/motd", "r")) != NULL) {
                while ((c = getc(mf)) != EOF && stopmotd == 0)
                        putchar(c);
                fclose(mf);
                while ((c = getc(mf)) != EOF && stopmotd == 0)
                        putchar(c);
                fclose(mf);
@@ -392,39 +393,11 @@ char *
 stypeof(ttyid)
        char *ttyid;
 {
 stypeof(ttyid)
        char *ttyid;
 {
-       static char typebuf[16];
-       char buf[50];
-       register FILE *f;
-       register char *p, *t, *q;
+       register struct ttyent *t;
 
 
-       if (ttyid == NULL)
+       if (ttyid == NULL || (t = getttynam(ttyid)) == NULL)
                return (UNKNOWN);
                return (UNKNOWN);
-       f = fopen("/etc/ttytype", "r");
-       if (f == NULL)
-               return (UNKNOWN);
-       /* split off end of name */
-       for (p = q = ttyid; *p != 0; p++)
-               if (*p == '/')
-                       q = p + 1;
-
-       /* scan the file */
-       while (fgets(buf, sizeof buf, f) != NULL) {
-               for (t = buf; *t != ' ' && *t != '\t'; t++)
-                       ;
-               *t++ = 0;
-               while (*t == ' ' || *t == '\t')
-                       t++;
-               for (p = t; *p > ' '; p++)
-                       ;
-               *p = 0;
-               if (strcmp(q,t) == 0) {
-                       strcpy(typebuf, buf);
-                       fclose(f);
-                       return (typebuf);
-               }
-       }
-       fclose (f);
-       return (UNKNOWN);
+       return (t->ty_type);
 }
 
 doremotelogin(host)
 }
 
 doremotelogin(host)
@@ -440,9 +413,7 @@ doremotelogin(host)
                pwd = &nouser;
                goto bad;
        }
                pwd = &nouser;
                goto bad;
        }
-       setpwent();
        pwd = getpwnam(lusername);
        pwd = getpwnam(lusername);
-       endpwent();
        if (pwd == NULL) {
                pwd = &nouser;
                goto bad;
        if (pwd == NULL) {
                pwd = &nouser;
                goto bad;
@@ -533,17 +504,3 @@ doremoteterm(term, tp)
        }
        tp->sg_flags = ECHO|CRMOD|ANYP|XTABS;
 }
        }
        tp->sg_flags = ECHO|CRMOD|ANYP|XTABS;
 }
-
-logerr(fmt, a1, a2, a3)
-       char *fmt, *a1, *a2, *a3;
-{
-#ifdef LOGERR
-       FILE *cons = fopen("/dev/console", "w");
-
-       if (cons != NULL) {
-               fprintf(cons, fmt, a1, a2, a3);
-               fprintf(cons, "\n\r");
-               fclose(cons);
-       }
-#endif
-}
index 8a94afb..2b10f60 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)tset.c     1.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)tset.c     1.9 (Berkeley) %G%";
 #endif
 
 /*
 #endif
 
 /*
@@ -91,8 +91,8 @@ static char sccsid[] = "@(#)tset.c    1.8 (Berkeley) %G%";
 **                     (-d type  ->  -m dialup:type)
 **                     (-p type  ->  -m plug:type)
 **                     Syntax: -m identifier [test baudrate] :type
 **                     (-d type  ->  -m dialup:type)
 **                     (-p type  ->  -m plug:type)
 **                     Syntax: -m identifier [test baudrate] :type
-**                     where: ``identifier'' is whatever is found in
-**                     /etc/ttytype for this port, (abscence of an identifier
+**                     where: ``identifier'' is terminal type found in
+**                     /etc/ttys for this port, (abscence of an identifier
 **                     matches any identifier); ``test'' may be any combination
 **                     of  >  =  <  !  @; ``baudrate'' is as with stty(1);
 **                     ``type'' is the actual terminal type to use if the
 **                     matches any identifier); ``test'' may be any combination
 **                     of  >  =  <  !  @; ``baudrate'' is as with stty(1);
 **                     ``type'' is the actual terminal type to use if the
@@ -136,7 +136,7 @@ static char sccsid[] = "@(#)tset.c  1.8 (Berkeley) %G%";
 **                     the output of -s to use virtual terminal sequences.
 **
 **     Files:
 **                     the output of -s to use virtual terminal sequences.
 **
 **     Files:
-**             /etc/ttytype
+**             /etc/ttys
 **                     contains a terminal id -> terminal type
 **                     mapping; used when any user mapping is specified,
 **                     or the environment doesn't have TERM set.
 **                     contains a terminal id -> terminal type
 **                     mapping; used when any user mapping is specified,
 **                     or the environment doesn't have TERM set.
@@ -166,7 +166,7 @@ static char sccsid[] = "@(#)tset.c  1.8 (Berkeley) %G%";
 **                     and compiles code to look there.
 **
 **     Requires:
 **                     and compiles code to look there.
 **
 **     Requires:
-**             Routines to handle htmp, ttytype, and ttycap.
+**             Routines to handle htmp, ttys, and ttycap.
 **
 **     Compilation Flags:
 **             OLDFLAGS -- must be defined to compile code for any of
 **
 **     Compilation Flags:
 **             OLDFLAGS -- must be defined to compile code for any of
@@ -174,11 +174,9 @@ static char sccsid[] = "@(#)tset.c 1.8 (Berkeley) %G%";
 **             OLDDIALUP -- accept the -d flag.
 **             OLDPLUGBOARD -- accept the -p flag.
 **             OLDARPANET -- accept the -a flag.
 **             OLDDIALUP -- accept the -d flag.
 **             OLDPLUGBOARD -- accept the -p flag.
 **             OLDARPANET -- accept the -a flag.
-**             FULLLOGIN -- if defined, login sets the ttytype from
-**                     /etc/ttytype file.
 **             V6 -- if clear, use environments, not htmp.
 **                     also use TIOCSETN rather than stty to avoid flushing
 **             V6 -- if clear, use environments, not htmp.
 **                     also use TIOCSETN rather than stty to avoid flushing
-**             GTTYN -- if set, compiles code to look at /etc/ttytype.
+**             GTTYN -- if set, compiles code to look at /etc/ttys.
 **             UCB_NTTY -- set to handle new tty driver modes.
 **
 **     Trace Flags:
 **             UCB_NTTY -- set to handle new tty driver modes.
 **
 **     Trace Flags:
@@ -245,7 +243,7 @@ static char sccsid[] = "@(#)tset.c  1.8 (Berkeley) %G%";
 **             12/78 -- modified for eventual migration to VAX/UNIX,
 **                     so the '-' option is changed to output only
 **                     the terminal type to STDOUT instead of
 **             12/78 -- modified for eventual migration to VAX/UNIX,
 **                     so the '-' option is changed to output only
 **                     the terminal type to STDOUT instead of
-**                     FILEDES.  FULLLOGIN flag added.
+**                     FILEDES.
 **             9/78 -- '-' and '-p' options added (now fully
 **                     compatible with ttytype!), and spaces are
 **                     permitted between the -d and the type.
 **             9/78 -- '-' and '-p' options added (now fully
 **                     compatible with ttytype!), and spaces are
 **                     permitted between the -d and the type.
@@ -269,11 +267,9 @@ static char sccsid[] = "@(#)tset.c 1.8 (Berkeley) %G%";
 #  define oldkill oldmode.sg_kill
 # endif
 
 #  define oldkill oldmode.sg_kill
 # endif
 
-/*
-# define       FULLLOGIN       1
-/*/
 # ifndef V6
 # ifndef V6
-# define       GTTYN           "/etc/ttytype"
+# define       GTTYN
+# include      <ttyent.h>
 # endif
 
 # ifndef USG
 # endif
 
 # ifndef USG
@@ -1610,18 +1606,13 @@ char *
 stypeof(ttyid)
 char   *ttyid;
 {
 stypeof(ttyid)
 char   *ttyid;
 {
-       static char     typebuf[BUFSIZ];
        register char   *PortType;
        register char   *PortName;
        register char   *TtyId;
        register char   *PortType;
        register char   *PortName;
        register char   *TtyId;
-       register char   *p;
-       register FILE   *f;
+       struct ttyent *t;
 
        if (ttyid == NOTTY)
                return (DEFTYPE);
 
        if (ttyid == NOTTY)
                return (DEFTYPE);
-       f = fopen(GTTYN, "r");
-       if (f == NULL)
-               return (DEFTYPE);
 
        /* split off end of name */
        TtyId = ttyid;
 
        /* split off end of name */
        TtyId = ttyid;
@@ -1630,37 +1621,17 @@ char    *ttyid;
                        TtyId = ttyid;
 
        /* scan the file */
                        TtyId = ttyid;
 
        /* scan the file */
-       while (fgets(typebuf, sizeof typebuf, f) != NULL)
+       if ((t = getttynam(TtyId)) != NULL)
        {
        {
-               p = PortType = typebuf;
-               while (*p && isalnum(*p))
-                       p++;
-               *p++ = NULL;
-
-               /* skip separator */
-               while (*p && !isalnum(*p))
-                       p++;
-
-               PortName = p;
-               /* put NULL at end of name */
-               while (*p && isalnum(*p))
-                       p++;
-               *p = NULL;
-
-               /* check match on port name */
-               if (sequal(PortName, TtyId))    /* found it */
-               {
-                       fclose (f);
-                       /* get aliases from termcap entry */
-                       if (Mapped && tgetent(Capbuf, PortType) > 0) {
-                               makealias(Capbuf);
-                               if (sequal(Alias[0], PortType) && Alias[1])
-                                       PortType = Alias[1];
-                       }
-                       return(PortType);
+               PortType = t->ty_type;
+               /* get aliases from termcap entry */
+               if (Mapped && tgetent(Capbuf, PortType) > 0) {
+                       makealias(Capbuf);
+                       if (sequal(Alias[0], PortType) && Alias[1])
+                               PortType = Alias[1];
                }
                }
+               return (PortType);
        }
        }
-       fclose (f);
        return (DEFTYPE);
 }
 # endif
        return (DEFTYPE);
 }
 # endif