code cleanup, change b*() to mem*()
authorDave A. Borman <dab@ucbvax.Berkeley.EDU>
Wed, 31 May 1995 13:02:52 +0000 (05:02 -0800)
committerDave A. Borman <dab@ucbvax.Berkeley.EDU>
Wed, 31 May 1995 13:02:52 +0000 (05:02 -0800)
Add setting up of LINEMODE environment variable.

SCCS-vsn: libexec/telnetd/authenc.c 8.2
SCCS-vsn: libexec/telnetd/slc.c 8.2
SCCS-vsn: libexec/telnetd/state.c 8.5
SCCS-vsn: libexec/telnetd/sys_term.c 8.4
SCCS-vsn: libexec/telnetd/telnetd.c 8.4
SCCS-vsn: libexec/telnetd/termstat.c 8.2
SCCS-vsn: libexec/telnetd/utility.c 8.4

usr/src/libexec/telnetd/authenc.c
usr/src/libexec/telnetd/slc.c
usr/src/libexec/telnetd/state.c
usr/src/libexec/telnetd/sys_term.c
usr/src/libexec/telnetd/telnetd.c
usr/src/libexec/telnetd/termstat.c
usr/src/libexec/telnetd/utility.c

index bda7009..5384cc7 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)authenc.c  8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)authenc.c  8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #if    defined(AUTHENTICATION) || defined(ENCRYPTION)
 #endif /* not lint */
 
 #if    defined(AUTHENTICATION) || defined(ENCRYPTION)
@@ -19,7 +19,7 @@ net_write(str, len)
        int len;
 {
        if (nfrontp + len < netobuf + BUFSIZ) {
        int len;
 {
        if (nfrontp + len < netobuf + BUFSIZ) {
-               bcopy((void *)str, (void *)nfrontp, len);
+               memmove((void *)nfrontp, (void *)str, len);
                nfrontp += len;
                return(len);
        }
                nfrontp += len;
                return(len);
        }
index db06091..7dc424a 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)slc.c      8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)slc.c      8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "telnetd.h"
 #endif /* not lint */
 
 #include "telnetd.h"
@@ -83,10 +83,10 @@ get_slc_defaults()
        init_termbuf();
 
        for (i = 1; i <= NSLC; i++) {
        init_termbuf();
 
        for (i = 1; i <= NSLC; i++) {
-               slctab[i].defset.flag = 
+               slctab[i].defset.flag =
                        spcset(i, &slctab[i].defset.val, &slctab[i].sptr);
                        spcset(i, &slctab[i].defset.val, &slctab[i].sptr);
-               slctab[i].current.flag = SLC_NOSUPPORT; 
-               slctab[i].current.val = 0; 
+               slctab[i].current.flag = SLC_NOSUPPORT;
+               slctab[i].current.val = 0;
        }
 
 }  /* end of get_slc_defaults */
        }
 
 }  /* end of get_slc_defaults */
@@ -260,7 +260,7 @@ change_slc(func, flag, val)
        register cc_t val;
 {
        register int hislevel, mylevel;
        register cc_t val;
 {
        register int hislevel, mylevel;
-       
+
        hislevel = flag & SLC_LEVELBITS;
        mylevel = slctab[func].defset.flag & SLC_LEVELBITS;
        /*
        hislevel = flag & SLC_LEVELBITS;
        mylevel = slctab[func].defset.flag & SLC_LEVELBITS;
        /*
@@ -319,7 +319,7 @@ change_slc(func, flag, val)
                * request as he asks.
                *
                * If our level is DEFAULT, then just ack whatever was
                * request as he asks.
                *
                * If our level is DEFAULT, then just ack whatever was
-               * sent. 
+               * sent.
                *
                * If he can't change and we can't change,
                * then degenerate to NOSUPPORT.
                *
                * If he can't change and we can't change,
                * then degenerate to NOSUPPORT.
@@ -346,7 +346,6 @@ change_slc(func, flag, val)
                                        slctab[func].defset.val;
                                val = slctab[func].current.val;
                        }
                                        slctab[func].defset.val;
                                val = slctab[func].current.val;
                        }
-                       
                }
                add_slc(func, flag, val);
        }
                }
                add_slc(func, flag, val);
        }
@@ -397,7 +396,6 @@ check_slc()
                                                slctab[i].current.val);
                }
        }
                                                slctab[i].current.val);
                }
        }
-                       
 }  /* check_slc */
 
 /*
 }  /* check_slc */
 
 /*
@@ -439,7 +437,7 @@ do_opt_slc(ptr, len)
                        def_slcbuf = (unsigned char *)malloc((unsigned)len);
                        if (def_slcbuf == (unsigned char *)0)
                                return;  /* too bad */
                        def_slcbuf = (unsigned char *)malloc((unsigned)len);
                        if (def_slcbuf == (unsigned char *)0)
                                return;  /* too bad */
-                       bcopy(ptr, def_slcbuf, len);
+                       memmove(def_slcbuf, ptr, len);
                }
        }
 
                }
        }
 
index be507ac..ceab5ba 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)state.c    8.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)state.c    8.5 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "telnetd.h"
 #endif /* not lint */
 
 #include "telnetd.h"
@@ -340,7 +340,7 @@ gotiac:                     switch (c) {
                char    xbuf2[BUFSIZ];
                register char *cp;
                int n = pfrontp - opfrontp, oc;
                char    xbuf2[BUFSIZ];
                register char *cp;
                int n = pfrontp - opfrontp, oc;
-               bcopy(opfrontp, xptyobuf, n);
+               memmove(xptyobuf, opfrontp, n);
                pfrontp = opfrontp;
                pfrontp += term_input(xptyobuf, pfrontp, n, BUFSIZ+NETSLOP,
                                        xbuf2, &oc, BUFSIZ);
                pfrontp = opfrontp;
                pfrontp += term_input(xptyobuf, pfrontp, n, BUFSIZ+NETSLOP,
                                        xbuf2, &oc, BUFSIZ);
@@ -362,7 +362,7 @@ gotiac:                     switch (c) {
  * All state defaults are negative, and resp defaults to 0.
  *
  * When initiating a request to change state to new_state:
  * All state defaults are negative, and resp defaults to 0.
  *
  * When initiating a request to change state to new_state:
- * 
+ *
  * if ((want_resp == 0 && new_state == my_state) || want_state == new_state) {
  *     do nothing;
  * } else {
  * if ((want_resp == 0 && new_state == my_state) || want_state == new_state) {
  *     do nothing;
  * } else {
index 980455c..27d5eec 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)sys_term.c 8.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)sys_term.c 8.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "telnetd.h"
 #endif /* not lint */
 
 #include "telnetd.h"
@@ -43,21 +43,16 @@ char        wtmpf[] = "/etc/wtmp";
 # ifdef CRAY
 #include <tmpdir.h>
 #include <sys/wait.h>
 # ifdef CRAY
 #include <tmpdir.h>
 #include <sys/wait.h>
-#  if defined(_SC_CRAY_SECURE_SYS) && !defined(SCM_SECURITY)
-   /*
-    * UNICOS 6.0/6.1 do not have SCM_SECURITY defined, so we can
-    * use it to tell us to turn off all the socket security code,
-    * since that is only used in UNICOS 7.0 and later.
-    */
-#   undef _SC_CRAY_SECURE_SYS
+#  if (UNICOS_LVL == '7.0') || (UNICOS_LVL == '7.1')
+#   define UNICOS7x
 #  endif
 
 #  endif
 
-#  if defined(_SC_CRAY_SECURE_SYS)
+#  ifdef UNICOS7x
 #include <sys/sysv.h>
 #include <sys/secstat.h>
 extern int secflag;
 extern struct sysv sysv;
 #include <sys/sysv.h>
 #include <sys/secstat.h>
 extern int secflag;
 extern struct sysv sysv;
-#  endif /* _SC_CRAY_SECURE_SYS */
+#  endif /* UNICOS7x */
 # endif        /* CRAY */
 #endif /* NEWINIT */
 
 # endif        /* CRAY */
 #endif /* NEWINIT */
 
@@ -189,7 +184,7 @@ copy_termbuf(cp, len)
 {
        if (len > sizeof(termbuf))
                len = sizeof(termbuf);
 {
        if (len > sizeof(termbuf))
                len = sizeof(termbuf);
-       bcopy(cp, (char *)&termbuf, len);
+       memmove((char *)&termbuf, cp, len);
        termbuf2 = termbuf;
 }
 #endif /* defined(LINEMODE) && defined(TIOCPKT_IOCTL) */
        termbuf2 = termbuf;
 }
 #endif /* defined(LINEMODE) && defined(TIOCPKT_IOCTL) */
@@ -201,17 +196,19 @@ set_termbuf()
         * Only make the necessary changes.
         */
 #ifndef        USE_TERMIO
         * Only make the necessary changes.
         */
 #ifndef        USE_TERMIO
-       if (bcmp((char *)&termbuf.sg, (char *)&termbuf2.sg, sizeof(termbuf.sg)))
+       if (memcmp((char *)&termbuf.sg, (char *)&termbuf2.sg,
+                                                       sizeof(termbuf.sg)))
                (void) ioctl(pty, TIOCSETN, (char *)&termbuf.sg);
                (void) ioctl(pty, TIOCSETN, (char *)&termbuf.sg);
-       if (bcmp((char *)&termbuf.tc, (char *)&termbuf2.tc, sizeof(termbuf.tc)))
+       if (memcmp((char *)&termbuf.tc, (char *)&termbuf2.tc,
+                                                       sizeof(termbuf.tc)))
                (void) ioctl(pty, TIOCSETC, (char *)&termbuf.tc);
                (void) ioctl(pty, TIOCSETC, (char *)&termbuf.tc);
-       if (bcmp((char *)&termbuf.ltc, (char *)&termbuf2.ltc,
+       if (memcmp((char *)&termbuf.ltc, (char *)&termbuf2.ltc,
                                                        sizeof(termbuf.ltc)))
                (void) ioctl(pty, TIOCSLTC, (char *)&termbuf.ltc);
        if (termbuf.lflags != termbuf2.lflags)
                (void) ioctl(pty, TIOCLSET, (char *)&termbuf.lflags);
 #else  /* USE_TERMIO */
                                                        sizeof(termbuf.ltc)))
                (void) ioctl(pty, TIOCSLTC, (char *)&termbuf.ltc);
        if (termbuf.lflags != termbuf2.lflags)
                (void) ioctl(pty, TIOCLSET, (char *)&termbuf.lflags);
 #else  /* USE_TERMIO */
-       if (bcmp((char *)&termbuf, (char *)&termbuf2, sizeof(termbuf)))
+       if (memcmp((char *)&termbuf, (char *)&termbuf2, sizeof(termbuf)))
 # ifdef  STREAMSPTY
                (void) tcsetattr(ttyfd, TCSANOW, &termbuf);
 # else
 # ifdef  STREAMSPTY
                (void) tcsetattr(ttyfd, TCSANOW, &termbuf);
 # else
@@ -936,9 +933,9 @@ struct termspeeds {
        { 110,    B110 },    { 134,   B134 },   { 150,    B150 },
        { 200,    B200 },    { 300,   B300 },   { 600,    B600 },
        { 1200,   B1200 },   { 1800,  B1800 },  { 2400,   B2400 },
        { 110,    B110 },    { 134,   B134 },   { 150,    B150 },
        { 200,    B200 },    { 300,   B300 },   { 600,    B600 },
        { 1200,   B1200 },   { 1800,  B1800 },  { 2400,   B2400 },
-       { 4800,   B4800 },  
+       { 4800,   B4800 },
 #ifdef B7200
 #ifdef B7200
-       { 7200,  B7200 }, 
+       { 7200,  B7200 },
 #endif
        { 9600,   B9600 },
 #ifdef B14400
 #endif
        { 9600,   B9600 },
 #ifdef B14400
@@ -1097,7 +1094,7 @@ getptyslave()
 #ifdef USE_TERMIO
        ttyfd = t;
 #endif
 #ifdef USE_TERMIO
        ttyfd = t;
 #endif
-       if (ioctl(t, I_PUSH, "ptem") < 0) 
+       if (ioctl(t, I_PUSH, "ptem") < 0)
                fatal(net, "I_PUSH ptem");
        if (ioctl(t, I_PUSH, "ldterm") < 0)
                fatal(net, "I_PUSH ldterm");
                fatal(net, "I_PUSH ptem");
        if (ioctl(t, I_PUSH, "ldterm") < 0)
                fatal(net, "I_PUSH ldterm");
@@ -1113,7 +1110,7 @@ getptyslave()
        init_termbuf();
 # ifdef        TIOCGWINSZ
        if (def_row || def_col) {
        init_termbuf();
 # ifdef        TIOCGWINSZ
        if (def_row || def_col) {
-               bzero((char *)&ws, sizeof(ws));
+               memset((char *)&ws, 0, sizeof(ws));
                ws.ws_col = def_col;
                ws.ws_row = def_row;
                (void)ioctl(t, TIOCSWINSZ, (char *)&ws);
                ws.ws_col = def_col;
                ws.ws_row = def_row;
                (void)ioctl(t, TIOCSWINSZ, (char *)&ws);
@@ -1193,9 +1190,9 @@ cleanopen(line)
        char *line;
 {
        register int t;
        char *line;
 {
        register int t;
-#if    defined(_SC_CRAY_SECURE_SYS)
+#ifdef UNICOS7x
        struct secstat secbuf;
        struct secstat secbuf;
-#endif /* _SC_CRAY_SECURE_SYS */
+#endif /* UNICOS7x */
 
 #ifndef STREAMSPTY
        /*
 
 #ifndef STREAMSPTY
        /*
@@ -1209,7 +1206,7 @@ cleanopen(line)
 # if !defined(CRAY) && (BSD > 43)
        (void) revoke(line);
 # endif
 # if !defined(CRAY) && (BSD > 43)
        (void) revoke(line);
 # endif
-#if    defined(_SC_CRAY_SECURE_SYS)
+#ifdef UNICOS7x
        if (secflag) {
                if (secstat(line, &secbuf) < 0)
                        return(-1);
        if (secflag) {
                if (secstat(line, &secbuf) < 0)
                        return(-1);
@@ -1218,18 +1215,18 @@ cleanopen(line)
                if (setucmp(secbuf.st_compart) < 0)
                        return(-1);
        }
                if (setucmp(secbuf.st_compart) < 0)
                        return(-1);
        }
-#endif /* _SC_CRAY_SECURE_SYS */
+#endif /* UNICOS7x */
 
        t = open(line, O_RDWR|O_NOCTTY);
 
 
        t = open(line, O_RDWR|O_NOCTTY);
 
-#if    defined(_SC_CRAY_SECURE_SYS)
+#ifdef UNICOS7x
        if (secflag) {
                if (setulvl(sysv.sy_minlvl) < 0)
                        return(-1);
                if (setucmp(0) < 0)
                        return(-1);
        }
        if (secflag) {
                if (setulvl(sysv.sy_minlvl) < 0)
                        return(-1);
                if (setucmp(0) < 0)
                        return(-1);
        }
-#endif /* _SC_CRAY_SECURE_SYS */
+#endif /* UNICOS7x */
 
        if (t < 0)
                return(-1);
 
        if (t < 0)
                return(-1);
@@ -1252,9 +1249,8 @@ cleanopen(line)
                (void) signal(SIGHUP, SIG_IGN);
                (void) ioctl(t, TCVHUP, (char *)0);
                (void) signal(SIGHUP, SIG_DFL);
                (void) signal(SIGHUP, SIG_IGN);
                (void) ioctl(t, TCVHUP, (char *)0);
                (void) signal(SIGHUP, SIG_DFL);
-               setpgrp();
 
 
-#if            defined(_SC_CRAY_SECURE_SYS)
+#ifdef UNICOS7x
                if (secflag) {
                        if (secstat(line, &secbuf) < 0)
                                return(-1);
                if (secflag) {
                        if (secstat(line, &secbuf) < 0)
                                return(-1);
@@ -1263,18 +1259,18 @@ cleanopen(line)
                        if (setucmp(secbuf.st_compart) < 0)
                                return(-1);
                }
                        if (setucmp(secbuf.st_compart) < 0)
                                return(-1);
                }
-#endif         /* _SC_CRAY_SECURE_SYS */
+#endif /* UNICOS7x */
 
                i = open(line, O_RDWR);
 
 
                i = open(line, O_RDWR);
 
-#if            defined(_SC_CRAY_SECURE_SYS)
+#ifdef UNICOS7x
                if (secflag) {
                        if (setulvl(sysv.sy_minlvl) < 0)
                                return(-1);
                        if (setucmp(0) < 0)
                                return(-1);
                }
                if (secflag) {
                        if (setulvl(sysv.sy_minlvl) < 0)
                                return(-1);
                        if (setucmp(0) < 0)
                                return(-1);
                }
-#endif         /* _SC_CRAY_SECURE_SYS */
+#endif /* UNICOS7x */
 
                if (i < 0)
                        return(-1);
 
                if (i < 0)
                        return(-1);
@@ -1323,7 +1319,11 @@ login_tty(t)
         * setsid() call above may have set our pgrp, so clear
         * it out before opening the tty...
         */
         * setsid() call above may have set our pgrp, so clear
         * it out before opening the tty...
         */
+#  ifndef SOLARIS
        (void) setpgrp(0, 0);
        (void) setpgrp(0, 0);
+#  else
+       (void) setpgrp();
+#  endif
        close(open(line, O_RDWR));
 # endif
        if (t != 0)
        close(open(line, O_RDWR));
 # endif
        if (t != 0)
@@ -1534,7 +1534,7 @@ start_login(host, autologin, name)
         * Create utmp entry for child
         */
 
         * Create utmp entry for child
         */
 
-       bzero(&utmpx, sizeof(utmpx));
+       memset(&utmpx, 0, sizeof(utmpx));
        SCPYN(utmpx.ut_user, ".telnet");
        SCPYN(utmpx.ut_line, line + sizeof("/dev/") - 1);
        utmpx.ut_pid = pid;
        SCPYN(utmpx.ut_user, ".telnet");
        SCPYN(utmpx.ut_line, line + sizeof("/dev/") - 1);
        utmpx.ut_pid = pid;
@@ -1589,6 +1589,19 @@ start_login(host, autologin, name)
 #if    !defined(NO_LOGIN_P)
        argv = addarg(argv, "-p");
 #endif
 #if    !defined(NO_LOGIN_P)
        argv = addarg(argv, "-p");
 #endif
+#ifdef LINEMODE
+       /*
+        * Set the environment variable "LINEMODE" to either
+        * "real" or "kludge" if we are operating in either
+        * real or kludge linemode.
+        */
+       if (lmodetype == REAL_LINEMODE)
+               setenv("LINEMODE", "real", 1);
+# ifdef KLUDGELINEMODE
+       else if (lmodetype == KLUDGE_LINEMODE || lmodetype == KLUDGE_OK)
+               setenv("LINEMODE", "kludge", 1);
+# endif
+#endif
 #ifdef BFTPDAEMON
        /*
         * Are we working as the bftp daemon?  If so, then ask login
 #ifdef BFTPDAEMON
        /*
         * Are we working as the bftp daemon?  If so, then ask login
@@ -1597,7 +1610,7 @@ start_login(host, autologin, name)
        if (bftpd) {
                argv = addarg(argv, "-e");
                argv = addarg(argv, BFTPPATH);
        if (bftpd) {
                argv = addarg(argv, "-e");
                argv = addarg(argv, BFTPPATH);
-       } else 
+       } else
 #endif
 #if    defined (SecurID)
        /*
 #endif
 #if    defined (SecurID)
        /*
@@ -1712,7 +1725,7 @@ start_login(host, autologin, name)
 #ifdef SOLARIS
        else {
                char **p;
 #ifdef SOLARIS
        else {
                char **p;
+
                argv = addarg(argv, "");        /* no login name */
                for (p = environ; *p; p++) {
                        argv = addarg(argv, *p);
                argv = addarg(argv, "");        /* no login name */
                for (p = environ; *p; p++) {
                        argv = addarg(argv, *p);
@@ -1812,6 +1825,8 @@ cleanup(sig)
 #  ifdef CRAY
        static int incleanup = 0;
        register int t;
 #  ifdef CRAY
        static int incleanup = 0;
        register int t;
+       int child_status; /* status of child process as returned by waitpid */
+       int flags = WNOHANG|WUNTRACED;
 
        /*
         * 1: Pick up the zombie, if we are being called
 
        /*
         * 1: Pick up the zombie, if we are being called
@@ -1822,9 +1837,17 @@ cleanup(sig)
         * 5: Close down the network and pty connections.
         * 6: Finish up the TMPDIR cleanup, if needed.
         */
         * 5: Close down the network and pty connections.
         * 6: Finish up the TMPDIR cleanup, if needed.
         */
-       if (sig == SIGCHLD)
-               while (waitpid(-1, 0, WNOHANG) > 0)
+       if (sig == SIGCHLD) {
+               while (waitpid(-1, &child_status, flags) > 0)
                        ;       /* VOID */
                        ;       /* VOID */
+               /* Check if the child process was stopped
+                * rather than exited.  We want cleanup only if
+                * the child has died.
+                */
+               if (WIFSTOPPED(child_status)) {
+                       return;
+               }
+       }
        t = sigblock(sigmask(SIGCHLD));
        if (incleanup) {
                sigsetmask(t);
        t = sigblock(sigmask(SIGCHLD));
        if (incleanup) {
                sigsetmask(t);
@@ -1832,6 +1855,7 @@ cleanup(sig)
        }
        incleanup = 1;
        sigsetmask(t);
        }
        incleanup = 1;
        sigsetmask(t);
+#ifdef UNICOS7x
        if (secflag) {
                /*
                 *      We need to set ourselves back to a null
        if (secflag) {
                /*
                 *      We need to set ourselves back to a null
@@ -1841,6 +1865,7 @@ cleanup(sig)
                setulvl(sysv.sy_minlvl);
                setucmp((long)0);
        }
                setulvl(sysv.sy_minlvl);
                setucmp((long)0);
        }
+#endif /* UNICOS7x */
 
        t = cleantmp(&wtmp);
        setutent();     /* just to make sure */
 
        t = cleantmp(&wtmp);
        setutent();     /* just to make sure */
@@ -1940,6 +1965,28 @@ sigjob(sig)
        }
 }
 
        }
 }
 
+/*
+ *     jid_getutid:
+ *             called by jobend() before calling cleantmp()
+ *             to find the correct $TMPDIR to cleanup.
+ */
+
+       struct utmp *
+jid_getutid(jid)
+       int jid;
+{
+       struct utmp *cur = NULL;
+
+       setutent();     /* just to make sure */
+       while (cur = getutent()) {
+               if ( (cur->ut_type != NULL) && (jid == cur->ut_jid) ) {
+                       return(cur);
+               }
+       }
+
+       return(0);
+}
+
 /*
  * Clean up the TMPDIR that login created.
  * The first time this is called we pick up the info
 /*
  * Clean up the TMPDIR that login created.
  * The first time this is called we pick up the info
@@ -1996,9 +2043,27 @@ jobend(jid, path, user)
        register char *user;
 {
        static int saved_jid = 0;
        register char *user;
 {
        static int saved_jid = 0;
+       static int pty_saved_jid = 0;
        static char saved_path[sizeof(wtmp.ut_tpath)+1];
        static char saved_user[sizeof(wtmp.ut_user)+1];
 
        static char saved_path[sizeof(wtmp.ut_tpath)+1];
        static char saved_user[sizeof(wtmp.ut_user)+1];
 
+       /*
+        * this little piece of code comes into play
+        * only when ptyreconnect is used to reconnect
+        * to an previous session.
+        *
+        * this is the only time when the
+        * "saved_jid != jid" code is executed.
+        */
+
+       if ( saved_jid && saved_jid != jid ) {
+               if (!path) {    /* called from signal handler */
+                       pty_saved_jid = jid;
+               } else {
+                       pty_saved_jid = saved_jid;
+               }
+       }
+
        if (path) {
                strncpy(saved_path, path, sizeof(wtmp.ut_tpath));
                strncpy(saved_user, user, sizeof(wtmp.ut_user));
        if (path) {
                strncpy(saved_path, path, sizeof(wtmp.ut_tpath));
                strncpy(saved_user, user, sizeof(wtmp.ut_user));
@@ -2009,6 +2074,24 @@ jobend(jid, path, user)
                saved_jid = jid;
                return(0);
        }
                saved_jid = jid;
                return(0);
        }
+
+       /* if the jid has changed, get the correct entry from the utmp file */
+
+       if ( saved_jid != jid ) {
+               struct utmp *utp = NULL;
+               struct utmp *jid_getutid();
+
+               utp = jid_getutid(pty_saved_jid);
+
+               if (utp == 0) {
+                       syslog(LOG_ERR, "Can't get /etc/utmp entry to clean TMPDIR");
+                       return(-1);
+               }
+
+               cleantmpdir(jid, utp->ut_tpath, utp->ut_user);
+               return(1);
+       }
+
        cleantmpdir(jid, saved_path, saved_user);
        return(1);
 }
        cleantmpdir(jid, saved_path, saved_user);
        return(1);
 }
@@ -2098,7 +2181,7 @@ rmut()
                if (statbf.st_size && utmp) {
                        nutmp = read(f, (char *)utmp, (int)statbf.st_size);
                        nutmp /= sizeof(struct utmp);
                if (statbf.st_size && utmp) {
                        nutmp = read(f, (char *)utmp, (int)statbf.st_size);
                        nutmp /= sizeof(struct utmp);
-               
+
                        for (u = utmp ; u < &utmp[nutmp] ; u++) {
                                if (SCMPN(u->ut_line, line+5) ||
                                    u->ut_name[0]==0)
                        for (u = utmp ; u < &utmp[nutmp] ; u++) {
                                if (SCMPN(u->ut_line, line+5) ||
                                    u->ut_name[0]==0)
index 7d21309..ed7a3a4 100644 (file)
@@ -12,7 +12,7 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)telnetd.c  8.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)telnetd.c  8.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "telnetd.h"
 #endif /* not lint */
 
 #include "telnetd.h"
@@ -425,7 +425,7 @@ main(argc, argv)
                int szi = sizeof(int);
 #endif /* SO_SEC_MULTI */
 
                int szi = sizeof(int);
 #endif /* SO_SEC_MULTI */
 
-               bzero((char *)&dv, sizeof(dv));
+               memset((char *)&dv, 0, sizeof(dv));
 
                if (getsysv(&sysv, sizeof(struct sysv)) != 0) {
                        perror("getsysv");
 
                if (getsysv(&sysv, sizeof(struct sysv)) != 0) {
                        perror("getsysv");
@@ -611,34 +611,40 @@ getterminaltype(name)
        static unsigned char sb[] =
                        { IAC, SB, TELOPT_TSPEED, TELQUAL_SEND, IAC, SE };
 
        static unsigned char sb[] =
                        { IAC, SB, TELOPT_TSPEED, TELQUAL_SEND, IAC, SE };
 
-       bcopy(sb, nfrontp, sizeof sb);
+       memmove(nfrontp, sb, sizeof sb);
        nfrontp += sizeof sb;
        nfrontp += sizeof sb;
+       DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2););
     }
     if (his_state_is_will(TELOPT_XDISPLOC)) {
        static unsigned char sb[] =
                        { IAC, SB, TELOPT_XDISPLOC, TELQUAL_SEND, IAC, SE };
 
     }
     if (his_state_is_will(TELOPT_XDISPLOC)) {
        static unsigned char sb[] =
                        { IAC, SB, TELOPT_XDISPLOC, TELQUAL_SEND, IAC, SE };
 
-       bcopy(sb, nfrontp, sizeof sb);
+       memmove(nfrontp, sb, sizeof sb);
        nfrontp += sizeof sb;
        nfrontp += sizeof sb;
+       DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2););
     }
     if (his_state_is_will(TELOPT_NEW_ENVIRON)) {
        static unsigned char sb[] =
                        { IAC, SB, TELOPT_NEW_ENVIRON, TELQUAL_SEND, IAC, SE };
 
     }
     if (his_state_is_will(TELOPT_NEW_ENVIRON)) {
        static unsigned char sb[] =
                        { IAC, SB, TELOPT_NEW_ENVIRON, TELQUAL_SEND, IAC, SE };
 
-       bcopy(sb, nfrontp, sizeof sb);
+       memmove(nfrontp, sb, sizeof sb);
        nfrontp += sizeof sb;
        nfrontp += sizeof sb;
+       DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2););
     }
     else if (his_state_is_will(TELOPT_OLD_ENVIRON)) {
        static unsigned char sb[] =
                        { IAC, SB, TELOPT_OLD_ENVIRON, TELQUAL_SEND, IAC, SE };
 
     }
     else if (his_state_is_will(TELOPT_OLD_ENVIRON)) {
        static unsigned char sb[] =
                        { IAC, SB, TELOPT_OLD_ENVIRON, TELQUAL_SEND, IAC, SE };
 
-       bcopy(sb, nfrontp, sizeof sb);
+       memmove(nfrontp, sb, sizeof sb);
        nfrontp += sizeof sb;
        nfrontp += sizeof sb;
+       DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2););
     }
     if (his_state_is_will(TELOPT_TTYPE)) {
 
     }
     if (his_state_is_will(TELOPT_TTYPE)) {
 
-       bcopy(ttytype_sbbuf, nfrontp, sizeof ttytype_sbbuf);
+       memmove(nfrontp, ttytype_sbbuf, sizeof ttytype_sbbuf);
        nfrontp += sizeof ttytype_sbbuf;
        nfrontp += sizeof ttytype_sbbuf;
+       DIAG(TD_OPTIONS, printsub('>', ttytype_sbbuf + 2,
+                                       sizeof ttytype_sbbuf - 2););
     }
     if (his_state_is_will(TELOPT_TSPEED)) {
        while (sequenceIs(tspeedsubopt, baseline))
     }
     if (his_state_is_will(TELOPT_TSPEED)) {
        while (sequenceIs(tspeedsubopt, baseline))
@@ -711,8 +717,10 @@ _gettermname()
     if (his_state_is_wont(TELOPT_TTYPE))
        return;
     settimer(baseline);
     if (his_state_is_wont(TELOPT_TTYPE))
        return;
     settimer(baseline);
-    bcopy(ttytype_sbbuf, nfrontp, sizeof ttytype_sbbuf);
+    memmove(nfrontp, ttytype_sbbuf, sizeof ttytype_sbbuf);
     nfrontp += sizeof ttytype_sbbuf;
     nfrontp += sizeof ttytype_sbbuf;
+    DIAG(TD_OPTIONS, printsub('>', ttytype_sbbuf + 2,
+                                       sizeof ttytype_sbbuf - 2););
     while (sequenceIs(ttypesubopt, baseline))
        ttloop();
 }
     while (sequenceIs(ttypesubopt, baseline))
        ttloop();
 }
@@ -790,7 +798,7 @@ doit(who)
 
 #if    defined(_SC_CRAY_SECURE_SYS)
        /*
 
 #if    defined(_SC_CRAY_SECURE_SYS)
        /*
-        *      set ttyp line security label 
+        *      set ttyp line security label
         */
        if (secflag) {
                char slave_dev[16];
         */
        if (secflag) {
                char slave_dev[16];
@@ -810,9 +818,10 @@ doit(who)
 
        if (hp == NULL && registerd_host_only) {
                fatal(net, "Couldn't resolve your address into a host name.\r\n\
 
        if (hp == NULL && registerd_host_only) {
                fatal(net, "Couldn't resolve your address into a host name.\r\n\
-         Please contact your net administrator");
+        Please contact your net administrator");
        } else if (hp &&
        } else if (hp &&
-           (strlen(hp->h_name) <= ((utmp_len < 0) ? -utmp_len : utmp_len))) {
+           (strlen(hp->h_name) <= (unsigned int)((utmp_len < 0) ? -utmp_len
+                                                                : utmp_len))) {
                host = hp->h_name;
        } else {
                host = inet_ntoa(who->sin_addr);
                host = hp->h_name;
        } else {
                host = inet_ntoa(who->sin_addr);
@@ -1302,6 +1311,9 @@ telnet(f, p, host)
                                        *nfrontp++ = IAC;
                                        *nfrontp++ = DM;
                                        neturg = nfrontp-1; /* off by one XXX */
                                        *nfrontp++ = IAC;
                                        *nfrontp++ = DM;
                                        neturg = nfrontp-1; /* off by one XXX */
+                                       DIAG(TD_OPTIONS,
+                                           printoption("td: send IAC", DM));
+
 #endif
                                }
                                if (his_state_is_will(TELOPT_LFLOW) &&
 #endif
                                }
                                if (his_state_is_will(TELOPT_LFLOW) &&
@@ -1318,6 +1330,9 @@ telnet(f, p, host)
                                                                 : LFLOW_OFF,
                                                        IAC, SE);
                                                nfrontp += 6;
                                                                 : LFLOW_OFF,
                                                        IAC, SE);
                                                nfrontp += 6;
+                                               DIAG(TD_OPTIONS, printsub('>',
+                                                   (unsigned char *)nfrontp-4,
+                                                   4););
                                        }
                                }
                                pcc--;
                                        }
                                }
                                pcc--;
@@ -1376,7 +1391,7 @@ telnet(f, p, host)
        }
        cleanup(0);
 }  /* end of telnet */
        }
        cleanup(0);
 }  /* end of telnet */
-       
+
 #ifndef        TCSIG
 # ifdef        TIOCSIG
 #  define TCSIG TIOCSIG
 #ifndef        TCSIG
 # ifdef        TIOCSIG
 #  define TCSIG TIOCSIG
@@ -1452,7 +1467,7 @@ int readstream(p, ibuf, bufsize)
                        tp = (struct termio *) (ibuf+1 + sizeof(struct iocblk));
                        vstop = tp->c_cc[VSTOP];
                        vstart = tp->c_cc[VSTART];
                        tp = (struct termio *) (ibuf+1 + sizeof(struct iocblk));
                        vstop = tp->c_cc[VSTOP];
                        vstart = tp->c_cc[VSTART];
-                       ixon = tp->c_iflag & IXON;      
+                       ixon = tp->c_iflag & IXON;
                        break;
                default:
                        errno = EAGAIN;
                        break;
                default:
                        errno = EAGAIN;
index 55abb17..8076d4d 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)termstat.c 8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)termstat.c 8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "telnetd.h"
 #endif /* not lint */
 
 #include "telnetd.h"
@@ -294,7 +294,7 @@ localstat()
                        nfrontp += 7;
                        editmode = useeditmode;
                }
                        nfrontp += 7;
                        editmode = useeditmode;
                }
-                                                       
+
 
                /*
                 * Check for changes to special characters in use.
 
                /*
                 * Check for changes to special characters in use.
@@ -396,7 +396,7 @@ clientstat(code, parm1, parm2)
                                        uselinemode = 1;
                                }
                        }
                                        uselinemode = 1;
                                }
                        }
-               
+
                        /*
                         * Quit now if we can't do it.
                         */
                        /*
                         * Quit now if we can't do it.
                         */
@@ -437,7 +437,7 @@ clientstat(code, parm1, parm2)
                                send_will(TELOPT_ECHO, 1);
                }
                break;
                                send_will(TELOPT_ECHO, 1);
                }
                break;
-       
+
        case LM_MODE:
            {
                register int ack, changed;
        case LM_MODE:
            {
                register int ack, changed;
@@ -486,7 +486,7 @@ clientstat(code, parm1, parm2)
                                        IAC, SE);
                                nfrontp += 7;
                        }
                                        IAC, SE);
                                nfrontp += 7;
                        }
-               
+
                        editmode = useeditmode;
                }
 
                        editmode = useeditmode;
                }
 
@@ -520,9 +520,9 @@ clientstat(code, parm1, parm2)
                (void) ioctl(pty, TIOCSWINSZ, (char *)&ws);
            }
 #endif /* TIOCSWINSZ */
                (void) ioctl(pty, TIOCSWINSZ, (char *)&ws);
            }
 #endif /* TIOCSWINSZ */
-               
+
                break;
                break;
-       
+
        case TELOPT_TSPEED:
            {
                def_tspeed = parm1;
        case TELOPT_TSPEED:
            {
                def_tspeed = parm1;
@@ -587,7 +587,7 @@ _termstat()
  *
  * Some things should not be done until after the login process has started
  * and all the pty modes are set to what they are supposed to be.  This
  *
  * Some things should not be done until after the login process has started
  * and all the pty modes are set to what they are supposed to be.  This
- * function is called when the pty state has been processed for the first time. 
+ * function is called when the pty state has been processed for the first time.
  * It calls other functions that do things that were deferred in each module.
  */
        void
  * It calls other functions that do things that were deferred in each module.
  */
        void
@@ -606,7 +606,7 @@ defer_terminit()
        if (def_col || def_row) {
                struct winsize ws;
 
        if (def_col || def_row) {
                struct winsize ws;
 
-               bzero((char *)&ws, sizeof(ws));
+               memset((char *)&ws, 0, sizeof(ws));
                ws.ws_col = def_col;
                ws.ws_row = def_row;
                (void) ioctl(pty, TIOCSWINSZ, (char *)&ws);
                ws.ws_col = def_col;
                ws.ws_row = def_row;
                (void) ioctl(pty, TIOCSWINSZ, (char *)&ws);
index ca1dccd..e020cd0 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)utility.c  8.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)utility.c  8.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #define PRINTOPTIONS
 #endif /* not lint */
 
 #define PRINTOPTIONS
@@ -194,7 +194,7 @@ netclear()
                next = nextitem(next);
            } while (wewant(next) && (nfrontp > next));
            length = next-thisitem;
                next = nextitem(next);
            } while (wewant(next) && (nfrontp > next));
            length = next-thisitem;
-           bcopy(thisitem, good, length);
+           memmove(good, thisitem, length);
            good += length;
            thisitem = next;
        } else {
            good += length;
            thisitem = next;
        } else {
@@ -301,7 +301,7 @@ writenet(ptr, len)
                netflush();
        }
 
                netflush();
        }
 
-       bcopy(ptr, nfrontp, len);
+       memmove(nfrontp, ptr, len);
        nfrontp += len;
 
 }  /* end of writenet */
        nfrontp += len;
 
 }  /* end of writenet */
@@ -423,9 +423,9 @@ putf(cp, where)
        time_t t;
        char db[100];
 #ifdef STREAMSPTY
        time_t t;
        char db[100];
 #ifdef STREAMSPTY
-       extern char *index();
+       extern char *strchr();
 #else
 #else
-       extern char *rindex();
+       extern char *strrchr();
 #endif
 
        putlocation = where;
 #endif
 
        putlocation = where;
@@ -440,9 +440,9 @@ putf(cp, where)
                case 't':
 #ifdef STREAMSPTY
                        /* names are like /dev/pts/2 -- we want pts/2 */
                case 't':
 #ifdef STREAMSPTY
                        /* names are like /dev/pts/2 -- we want pts/2 */
-                       slash = index(line+1, '/');
+                       slash = strchr(line+1, '/');
 #else
 #else
-                       slash = rindex(line, '/');
+                       slash = strrchr(line, '/');
 #endif
                        if (slash == (char *) 0)
                                putstr(line);
 #endif
                        if (slash == (char *) 0)
                                putstr(line);
@@ -496,7 +496,7 @@ printsub(direction, pointer, length)
     register int i;
     char buf[512];
 
     register int i;
     char buf[512];
 
-        if (!(diagnostic & TD_OPTIONS))
+       if (!(diagnostic & TD_OPTIONS))
                return;
 
        if (direction) {
                return;
 
        if (direction) {
@@ -687,7 +687,7 @@ printsub(direction, pointer, length)
                    break;
                }
                break;
                    break;
                }
                break;
-               
+
            case LM_SLC:
                sprintf(nfrontp, "SLC");
                nfrontp += strlen(nfrontp);
            case LM_SLC:
                sprintf(nfrontp, "SLC");
                nfrontp += strlen(nfrontp);
@@ -837,7 +837,7 @@ printsub(direction, pointer, length)
                        nfrontp += strlen(nfrontp);
 
                        break;
                        nfrontp += strlen(nfrontp);
 
                        break;
-                               
+
                    default:
                        sprintf(nfrontp, " %d", pointer[i]);
                        nfrontp += strlen(nfrontp);
                    default:
                        sprintf(nfrontp, " %d", pointer[i]);
                        nfrontp += strlen(nfrontp);
@@ -940,7 +940,7 @@ printsub(direction, pointer, length)
        case TELOPT_AUTHENTICATION:
            sprintf(nfrontp, "AUTHENTICATION");
            nfrontp += strlen(nfrontp);
        case TELOPT_AUTHENTICATION:
            sprintf(nfrontp, "AUTHENTICATION");
            nfrontp += strlen(nfrontp);
-       
+
            if (length < 2) {
                sprintf(nfrontp, " (empty suboption??\?)");
                nfrontp += strlen(nfrontp);
            if (length < 2) {
                sprintf(nfrontp, " (empty suboption??\?)");
                nfrontp += strlen(nfrontp);
@@ -1108,9 +1108,9 @@ printsub(direction, pointer, length)
 
        default:
            if (TELOPT_OK(pointer[0]))
 
        default:
            if (TELOPT_OK(pointer[0]))
-               sprintf(nfrontp, "%s (unknown)", TELOPT(pointer[0]));
+               sprintf(nfrontp, "%s (unknown)", TELOPT(pointer[0]));
            else
            else
-               sprintf(nfrontp, "%d (unknown)", pointer[i]);
+               sprintf(nfrontp, "%d (unknown)", pointer[i]);
            nfrontp += strlen(nfrontp);
            for (i = 1; i < length; i++) {
                sprintf(nfrontp, " %d", pointer[i]);
            nfrontp += strlen(nfrontp);
            for (i = 1; i < length; i++) {
                sprintf(nfrontp, " %d", pointer[i]);
@@ -1145,13 +1145,13 @@ printdata(tag, ptr, cnt)
                nfrontp += strlen(nfrontp);
                for (i = 0; i < 20 && cnt; i++) {
                        sprintf(nfrontp, "%02x", *ptr);
                nfrontp += strlen(nfrontp);
                for (i = 0; i < 20 && cnt; i++) {
                        sprintf(nfrontp, "%02x", *ptr);
-                       nfrontp += strlen(nfrontp); 
+                       nfrontp += strlen(nfrontp);
                        if (isprint(*ptr)) {
                                xbuf[i] = *ptr;
                        } else {
                                xbuf[i] = '.';
                        }
                        if (isprint(*ptr)) {
                                xbuf[i] = *ptr;
                        } else {
                                xbuf[i] = '.';
                        }
-                       if (i % 2) { 
+                       if (i % 2) {
                                *nfrontp = ' ';
                                nfrontp++;
                        }
                                *nfrontp = ' ';
                                nfrontp++;
                        }
@@ -1161,6 +1161,6 @@ printdata(tag, ptr, cnt)
                xbuf[i] = '\0';
                sprintf(nfrontp, " %s\r\n", xbuf );
                nfrontp += strlen(nfrontp);
                xbuf[i] = '\0';
                sprintf(nfrontp, " %s\r\n", xbuf );
                nfrontp += strlen(nfrontp);
-       } 
+       }
 }
 #endif /* DIAGNOSTICS */
 }
 #endif /* DIAGNOSTICS */