X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/8c5eec2f1483710dd0abd91a5708e55e267e49f9..d9b06a2d1c63996e5d1d2acf20bbb48cc4fe1336:/usr/src/libexec/telnetd/telnetd.c diff --git a/usr/src/libexec/telnetd/telnetd.c b/usr/src/libexec/telnetd/telnetd.c index e8928a7819..a2d93ce7c8 100644 --- a/usr/src/libexec/telnetd/telnetd.c +++ b/usr/src/libexec/telnetd/telnetd.c @@ -11,7 +11,7 @@ char copyright[] = #endif not lint #ifndef lint -static char sccsid[] = "@(#)telnetd.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)telnetd.c 5.4 (Berkeley) %G%"; #endif not lint /* @@ -35,7 +35,7 @@ static char sccsid[] = "@(#)telnetd.c 5.1 (Berkeley) %G%"; #include #define BELL '\07' -#define BANNER "\r\n\r\n4.2 BSD UNIX (%s)\r\n\r\r\n\r%s" +#define BANNER "\r\n\r\n4.3 BSD UNIX (%s)\r\n\r\r\n\r%s" char hisopts[256]; char myopts[256]; @@ -66,6 +66,7 @@ main(argc, argv) struct sockaddr_in from; int on = 1, fromlen; + openlog("telnetd", LOG_PID | LOG_ODELAY, LOG_DAEMON); fromlen = sizeof (from); if (getpeername(0, &from, &fromlen) < 0) { fprintf(stderr, "%s: ", argv[0]); @@ -73,7 +74,6 @@ main(argc, argv) _exit(1); } if (setsockopt(0, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof (on)) < 0) { - openlog(argv[0], LOG_PID, 0); syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m"); } doit(0, &from); @@ -577,7 +577,6 @@ cleanup() rmut(); vhangup(); /* XXX */ shutdown(net, 2); - kill(0, SIGKILL); exit(1); } @@ -585,26 +584,39 @@ cleanup() struct utmp wtmp; char wtmpf[] = "/usr/adm/wtmp"; -char utmp[] = "/etc/utmp"; -#define SCPYN(a, b) strncpy(a, b, sizeof (a)) -#define SCMPN(a, b) strncmp(a, b, sizeof (a)) +char utmpf[] = "/etc/utmp"; +#define SCPYN(a, b) strncpy(a, b, sizeof(a)) +#define SCMPN(a, b) strncmp(a, b, sizeof(a)) rmut() { register f; int found = 0; + struct utmp *u, *utmp; + int nutmp; + struct stat statbf; - f = open(utmp, O_RDWR); + f = open(utmpf, O_RDWR); if (f >= 0) { - while(read(f, (char *)&wtmp, sizeof (wtmp)) == sizeof (wtmp)) { - if (SCMPN(wtmp.ut_line, line+5) || wtmp.ut_name[0]==0) - continue; - lseek(f, -(long)sizeof (wtmp), L_INCR); - SCPYN(wtmp.ut_name, ""); - SCPYN(wtmp.ut_host, ""); - time(&wtmp.ut_time); - write(f, (char *)&wtmp, sizeof (wtmp)); - found++; + fstat(f, &statbf); + utmp = (struct utmp *)malloc(statbf.st_size); + if (!utmp) + syslog(LOG_ERR, "utmp malloc failed"); + if (statbf.st_size && utmp) { + nutmp = read(f, utmp, 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) + continue; + lseek(f, ((long)u)-((long)utmp), L_SET); + SCPYN(u->ut_name, ""); + SCPYN(u->ut_host, ""); + time(&u->ut_time); + write(f, (char *)u, sizeof(wtmp)); + found++; + } } close(f); } @@ -615,7 +627,7 @@ rmut() SCPYN(wtmp.ut_name, ""); SCPYN(wtmp.ut_host, ""); time(&wtmp.ut_time); - write(f, (char *)&wtmp, sizeof (wtmp)); + write(f, (char *)&wtmp, sizeof(wtmp)); close(f); } }