121182Sdist /* 221182Sdist * Copyright (c) 1983 Regents of the University of California. 321182Sdist * All rights reserved. The Berkeley software License Agreement 421182Sdist * specifies the terms and conditions for redistribution. 521182Sdist */ 621182Sdist 76295Sroot #ifndef lint 821182Sdist char copyright[] = 921182Sdist "@(#) Copyright (c) 1983 Regents of the University of California.\n\ 1021182Sdist All rights reserved.\n"; 1121182Sdist #endif not lint 126295Sroot 1321182Sdist #ifndef lint 14*26090Sminshall static char sccsid[] = "@(#)telnetd.c 5.6 (Berkeley) 02/06/86"; 1521182Sdist #endif not lint 1621182Sdist 176002Sroot /* 186002Sroot * Stripped-down telnet server. 196002Sroot */ 209218Ssam #include <sys/types.h> 219218Ssam #include <sys/socket.h> 2213608Ssam #include <sys/wait.h> 2317583Ssam #include <sys/file.h> 2420188Skarels #include <sys/stat.h> 259218Ssam 269218Ssam #include <netinet/in.h> 279218Ssam 2812216Ssam #include <arpa/telnet.h> 2912216Ssam 306002Sroot #include <stdio.h> 316002Sroot #include <signal.h> 326002Sroot #include <errno.h> 336002Sroot #include <sgtty.h> 348346Ssam #include <netdb.h> 3517187Sralph #include <syslog.h> 369218Ssam 3713798Ssam #define BELL '\07' 3823567Sbloom #define BANNER "\r\n\r\n4.3 BSD UNIX (%s)\r\n\r\r\n\r%s" 396002Sroot 406002Sroot char hisopts[256]; 416002Sroot char myopts[256]; 426002Sroot 436002Sroot char doopt[] = { IAC, DO, '%', 'c', 0 }; 446002Sroot char dont[] = { IAC, DONT, '%', 'c', 0 }; 456002Sroot char will[] = { IAC, WILL, '%', 'c', 0 }; 466002Sroot char wont[] = { IAC, WONT, '%', 'c', 0 }; 476002Sroot 486002Sroot /* 496002Sroot * I/O data buffers, pointers, and counters. 506002Sroot */ 516002Sroot char ptyibuf[BUFSIZ], *ptyip = ptyibuf; 526002Sroot char ptyobuf[BUFSIZ], *pfrontp = ptyobuf, *pbackp = ptyobuf; 536002Sroot char netibuf[BUFSIZ], *netip = netibuf; 546388Ssam char netobuf[BUFSIZ], *nfrontp = netobuf, *nbackp = netobuf; 556002Sroot int pcc, ncc; 566002Sroot 576002Sroot int pty, net; 586002Sroot int inter; 5913799Ssam extern char **environ; 606002Sroot extern int errno; 6120188Skarels char *line; 626002Sroot 636002Sroot main(argc, argv) 646002Sroot char *argv[]; 656002Sroot { 6616371Skarels struct sockaddr_in from; 6717156Ssam int on = 1, fromlen; 686002Sroot 6924855Seric openlog("telnetd", LOG_PID | LOG_ODELAY, LOG_DAEMON); 7016371Skarels fromlen = sizeof (from); 7116371Skarels if (getpeername(0, &from, &fromlen) < 0) { 7216371Skarels fprintf(stderr, "%s: ", argv[0]); 7316371Skarels perror("getpeername"); 7416371Skarels _exit(1); 758346Ssam } 7617156Ssam if (setsockopt(0, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof (on)) < 0) { 7717187Sralph syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m"); 7810418Ssam } 7916371Skarels doit(0, &from); 806002Sroot } 816002Sroot 8213799Ssam char *envinit[] = { "TERM=network", 0 }; 836002Sroot int cleanup(); 846002Sroot 856002Sroot /* 866002Sroot * Get a pty, scan input lines. 876002Sroot */ 8812683Ssam doit(f, who) 8912683Ssam int f; 9012683Ssam struct sockaddr_in *who; 916002Sroot { 9220188Skarels char *host, *inet_ntoa(); 9317583Ssam int i, p, t; 946002Sroot struct sgttyb b; 9512683Ssam struct hostent *hp; 9620188Skarels char c; 976002Sroot 9820188Skarels for (c = 'p'; c <= 's'; c++) { 9920188Skarels struct stat stb; 10020188Skarels 10120188Skarels line = "/dev/ptyXX"; 10220188Skarels line[strlen("/dev/pty")] = c; 10320188Skarels line[strlen("/dev/ptyp")] = '0'; 10420188Skarels if (stat(line, &stb) < 0) 10520188Skarels break; 10617583Ssam for (i = 0; i < 16; i++) { 10720188Skarels line[strlen("/dev/ptyp")] = "0123456789abcdef"[i]; 10820188Skarels p = open(line, 2); 10917583Ssam if (p > 0) 11017583Ssam goto gotpty; 11117583Ssam } 1126002Sroot } 1139244Ssam fatal(f, "All network ports in use"); 1149244Ssam /*NOTREACHED*/ 1156002Sroot gotpty: 1166002Sroot dup2(f, 0); 11720188Skarels line[strlen("/dev/")] = 't'; 11817583Ssam t = open("/dev/tty", O_RDWR); 1196002Sroot if (t >= 0) { 1206002Sroot ioctl(t, TIOCNOTTY, 0); 1216002Sroot close(t); 1226002Sroot } 12320188Skarels t = open(line, O_RDWR); 1249244Ssam if (t < 0) 12520188Skarels fatalperror(f, line, errno); 1266002Sroot ioctl(t, TIOCGETP, &b); 1276388Ssam b.sg_flags = CRMOD|XTABS|ANYP; 1286002Sroot ioctl(t, TIOCSETP, &b); 1296388Ssam ioctl(p, TIOCGETP, &b); 1308379Ssam b.sg_flags &= ~ECHO; 1316388Ssam ioctl(p, TIOCSETP, &b); 13212683Ssam hp = gethostbyaddr(&who->sin_addr, sizeof (struct in_addr), 13312683Ssam who->sin_family); 13412683Ssam if (hp) 13512683Ssam host = hp->h_name; 13612683Ssam else 13717444Sralph host = inet_ntoa(who->sin_addr); 1389244Ssam if ((i = fork()) < 0) 1399244Ssam fatalperror(f, "fork", errno); 1406002Sroot if (i) 1416002Sroot telnet(f, p); 1426002Sroot close(f); 1436002Sroot close(p); 1446002Sroot dup2(t, 0); 1456002Sroot dup2(t, 1); 1466002Sroot dup2(t, 2); 1476002Sroot close(t); 14813799Ssam environ = envinit; 14912713Ssam execl("/bin/login", "login", "-h", host, 0); 1509244Ssam fatalperror(f, "/bin/login", errno); 1519244Ssam /*NOTREACHED*/ 1529244Ssam } 1539244Ssam 1549244Ssam fatal(f, msg) 1559244Ssam int f; 1569244Ssam char *msg; 1579244Ssam { 1589244Ssam char buf[BUFSIZ]; 1599244Ssam 16017583Ssam (void) sprintf(buf, "telnetd: %s.\r\n", msg); 1619244Ssam (void) write(f, buf, strlen(buf)); 1626002Sroot exit(1); 1636002Sroot } 1646002Sroot 1659244Ssam fatalperror(f, msg, errno) 1669244Ssam int f; 1679244Ssam char *msg; 1689244Ssam int errno; 1699244Ssam { 1709244Ssam char buf[BUFSIZ]; 1719244Ssam extern char *sys_errlist[]; 1729244Ssam 17317583Ssam (void) sprintf(buf, "%s: %s\r\n", msg, sys_errlist[errno]); 1749244Ssam fatal(f, buf); 1759244Ssam } 1769244Ssam 1776002Sroot /* 1786002Sroot * Main loop. Select from pty and network, and 1796002Sroot * hand data to telnet receiver finite state machine. 1806002Sroot */ 1816002Sroot telnet(f, p) 1826002Sroot { 1836002Sroot int on = 1; 18412713Ssam char hostname[32]; 1856002Sroot 1866002Sroot net = f, pty = p; 1876002Sroot ioctl(f, FIONBIO, &on); 1886002Sroot ioctl(p, FIONBIO, &on); 1896002Sroot signal(SIGTSTP, SIG_IGN); 19013028Ssam signal(SIGCHLD, cleanup); 19126083Slepreau setpgrp(0, 0); 1926002Sroot 1938379Ssam /* 1948379Ssam * Request to do remote echo. 1958379Ssam */ 1968379Ssam dooption(TELOPT_ECHO); 1978379Ssam myopts[TELOPT_ECHO] = 1; 19812713Ssam /* 19912713Ssam * Show banner that getty never gave. 20012713Ssam */ 20112713Ssam gethostname(hostname, sizeof (hostname)); 20212713Ssam sprintf(nfrontp, BANNER, hostname, ""); 20312713Ssam nfrontp += strlen(nfrontp); 2046002Sroot for (;;) { 2056002Sroot int ibits = 0, obits = 0; 2066002Sroot register int c; 2076002Sroot 2086002Sroot /* 2096002Sroot * Never look for input if there's still 2106002Sroot * stuff in the corresponding output buffer 2116002Sroot */ 21217583Ssam if (nfrontp - nbackp || pcc > 0) 2136002Sroot obits |= (1 << f); 2146002Sroot else 2156002Sroot ibits |= (1 << p); 21617583Ssam if (pfrontp - pbackp || ncc > 0) 2176002Sroot obits |= (1 << p); 2186002Sroot else 2196002Sroot ibits |= (1 << f); 2206002Sroot if (ncc < 0 && pcc < 0) 2216002Sroot break; 2229218Ssam select(16, &ibits, &obits, 0, 0); 2236002Sroot if (ibits == 0 && obits == 0) { 2246002Sroot sleep(5); 2256002Sroot continue; 2266002Sroot } 2276002Sroot 2286002Sroot /* 2296002Sroot * Something to read from the network... 2306002Sroot */ 2316002Sroot if (ibits & (1 << f)) { 2326002Sroot ncc = read(f, netibuf, BUFSIZ); 2336002Sroot if (ncc < 0 && errno == EWOULDBLOCK) 2346002Sroot ncc = 0; 2356002Sroot else { 2366002Sroot if (ncc <= 0) 2376002Sroot break; 2386002Sroot netip = netibuf; 2396002Sroot } 2406002Sroot } 2416002Sroot 2426002Sroot /* 2436002Sroot * Something to read from the pty... 2446002Sroot */ 2456002Sroot if (ibits & (1 << p)) { 2466002Sroot pcc = read(p, ptyibuf, BUFSIZ); 2476002Sroot if (pcc < 0 && errno == EWOULDBLOCK) 2486002Sroot pcc = 0; 2496002Sroot else { 2506002Sroot if (pcc <= 0) 2516002Sroot break; 2526002Sroot ptyip = ptyibuf; 2536002Sroot } 2546002Sroot } 2556002Sroot 2566002Sroot while (pcc > 0) { 2576002Sroot if ((&netobuf[BUFSIZ] - nfrontp) < 2) 2586002Sroot break; 2596002Sroot c = *ptyip++ & 0377, pcc--; 2606002Sroot if (c == IAC) 2616002Sroot *nfrontp++ = c; 2626002Sroot *nfrontp++ = c; 2636002Sroot } 2646002Sroot if ((obits & (1 << f)) && (nfrontp - nbackp) > 0) 2656002Sroot netflush(); 2666002Sroot if (ncc > 0) 2676002Sroot telrcv(); 2686002Sroot if ((obits & (1 << p)) && (pfrontp - pbackp) > 0) 2696002Sroot ptyflush(); 2706002Sroot } 2716002Sroot cleanup(); 2726002Sroot } 2736002Sroot 2746002Sroot /* 2756002Sroot * State for recv fsm 2766002Sroot */ 2776002Sroot #define TS_DATA 0 /* base state */ 2786002Sroot #define TS_IAC 1 /* look for double IAC's */ 2796002Sroot #define TS_CR 2 /* CR-LF ->'s CR */ 2806002Sroot #define TS_BEGINNEG 3 /* throw away begin's... */ 2816002Sroot #define TS_ENDNEG 4 /* ...end's (suboption negotiation) */ 2826002Sroot #define TS_WILL 5 /* will option negotiation */ 2836002Sroot #define TS_WONT 6 /* wont " */ 2846002Sroot #define TS_DO 7 /* do " */ 2856002Sroot #define TS_DONT 8 /* dont " */ 2866002Sroot 2876002Sroot telrcv() 2886002Sroot { 2896002Sroot register int c; 2906002Sroot static int state = TS_DATA; 2916002Sroot struct sgttyb b; 2926002Sroot 2936002Sroot while (ncc > 0) { 2946002Sroot if ((&ptyobuf[BUFSIZ] - pfrontp) < 2) 2956002Sroot return; 2966002Sroot c = *netip++ & 0377, ncc--; 2976002Sroot switch (state) { 2986002Sroot 299*26090Sminshall case TS_CR: 300*26090Sminshall state = TS_DATA; 301*26090Sminshall if (c == 0) { 302*26090Sminshall *pfrontp++ = '\r'; 303*26090Sminshall break; 304*26090Sminshall } else if (c == '\n') { 305*26090Sminshall *pfrontp++ = c; 306*26090Sminshall break; 307*26090Sminshall } else 308*26090Sminshall *pfrontp++ = '\r'; 309*26090Sminshall /* FALL THROUGH */ 310*26090Sminshall 3116002Sroot case TS_DATA: 3126002Sroot if (c == IAC) { 3136002Sroot state = TS_IAC; 3146002Sroot break; 3156002Sroot } 3166002Sroot if (inter > 0) 3176002Sroot break; 3186002Sroot if (!myopts[TELOPT_BINARY] && c == '\r') 3196002Sroot state = TS_CR; 320*26090Sminshall else 3216002Sroot *pfrontp++ = c; 3226002Sroot break; 3236002Sroot 3246002Sroot case TS_IAC: 3256002Sroot switch (c) { 3266002Sroot 3276002Sroot /* 3286002Sroot * Send the process on the pty side an 3296002Sroot * interrupt. Do this with a NULL or 3306002Sroot * interrupt char; depending on the tty mode. 3316002Sroot */ 3326002Sroot case BREAK: 3336002Sroot case IP: 3346002Sroot interrupt(); 3356002Sroot break; 3366002Sroot 3376002Sroot /* 3386002Sroot * Are You There? 3396002Sroot */ 3406002Sroot case AYT: 34117583Ssam strcpy(nfrontp, "\r\n[Yes]\r\n"); 34217583Ssam nfrontp += 9; 3436002Sroot break; 3446002Sroot 3456002Sroot /* 3466002Sroot * Erase Character and 3476002Sroot * Erase Line 3486002Sroot */ 3496002Sroot case EC: 3506002Sroot case EL: 3516002Sroot ptyflush(); /* half-hearted */ 3526002Sroot ioctl(pty, TIOCGETP, &b); 3536002Sroot *pfrontp++ = (c == EC) ? 3546002Sroot b.sg_erase : b.sg_kill; 3556002Sroot break; 3566002Sroot 3576002Sroot /* 3586002Sroot * Check for urgent data... 3596002Sroot */ 3606002Sroot case DM: 3616002Sroot break; 3626002Sroot 3636002Sroot /* 3646002Sroot * Begin option subnegotiation... 3656002Sroot */ 3666002Sroot case SB: 3676002Sroot state = TS_BEGINNEG; 3686002Sroot continue; 3696002Sroot 3706002Sroot case WILL: 3716002Sroot case WONT: 3726002Sroot case DO: 3736002Sroot case DONT: 3746002Sroot state = TS_WILL + (c - WILL); 3756002Sroot continue; 3766002Sroot 3776002Sroot case IAC: 3786002Sroot *pfrontp++ = c; 3796002Sroot break; 3806002Sroot } 3816002Sroot state = TS_DATA; 3826002Sroot break; 3836002Sroot 3846002Sroot case TS_BEGINNEG: 3856002Sroot if (c == IAC) 3866002Sroot state = TS_ENDNEG; 3876002Sroot break; 3886002Sroot 3896002Sroot case TS_ENDNEG: 3906002Sroot state = c == SE ? TS_DATA : TS_BEGINNEG; 3916002Sroot break; 3926002Sroot 3936002Sroot case TS_WILL: 3946002Sroot if (!hisopts[c]) 3956002Sroot willoption(c); 3966002Sroot state = TS_DATA; 3976002Sroot continue; 3986002Sroot 3996002Sroot case TS_WONT: 4006002Sroot if (hisopts[c]) 4016002Sroot wontoption(c); 4026002Sroot state = TS_DATA; 4036002Sroot continue; 4046002Sroot 4056002Sroot case TS_DO: 4066002Sroot if (!myopts[c]) 4076002Sroot dooption(c); 4086002Sroot state = TS_DATA; 4096002Sroot continue; 4106002Sroot 4116002Sroot case TS_DONT: 4126002Sroot if (myopts[c]) { 4136002Sroot myopts[c] = 0; 4146002Sroot sprintf(nfrontp, wont, c); 4158379Ssam nfrontp += sizeof (wont) - 2; 4166002Sroot } 4176002Sroot state = TS_DATA; 4186002Sroot continue; 4196002Sroot 4206002Sroot default: 4219218Ssam printf("telnetd: panic state=%d\n", state); 4226002Sroot exit(1); 4236002Sroot } 4246002Sroot } 4256002Sroot } 4266002Sroot 4276002Sroot willoption(option) 4286002Sroot int option; 4296002Sroot { 4306002Sroot char *fmt; 4316002Sroot 4326002Sroot switch (option) { 4336002Sroot 4346002Sroot case TELOPT_BINARY: 4356002Sroot mode(RAW, 0); 4366002Sroot goto common; 4376002Sroot 4386002Sroot case TELOPT_ECHO: 4396002Sroot mode(0, ECHO|CRMOD); 4406002Sroot /*FALL THRU*/ 4416002Sroot 4426002Sroot case TELOPT_SGA: 4436002Sroot common: 4446002Sroot hisopts[option] = 1; 4456002Sroot fmt = doopt; 4466002Sroot break; 4476002Sroot 4486002Sroot case TELOPT_TM: 4496002Sroot fmt = dont; 4506002Sroot break; 4516002Sroot 4526002Sroot default: 4536002Sroot fmt = dont; 4546002Sroot break; 4556002Sroot } 4566023Ssam sprintf(nfrontp, fmt, option); 4578379Ssam nfrontp += sizeof (dont) - 2; 4586002Sroot } 4596002Sroot 4606002Sroot wontoption(option) 4616002Sroot int option; 4626002Sroot { 4636002Sroot char *fmt; 4646002Sroot 4656002Sroot switch (option) { 4666002Sroot 4676002Sroot case TELOPT_ECHO: 4686002Sroot mode(ECHO|CRMOD, 0); 4696002Sroot goto common; 4706002Sroot 4716002Sroot case TELOPT_BINARY: 4726002Sroot mode(0, RAW); 4736002Sroot /*FALL THRU*/ 4746002Sroot 4756002Sroot case TELOPT_SGA: 4766002Sroot common: 4776002Sroot hisopts[option] = 0; 4786002Sroot fmt = dont; 4796002Sroot break; 4806002Sroot 4816002Sroot default: 4826002Sroot fmt = dont; 4836002Sroot } 4846002Sroot sprintf(nfrontp, fmt, option); 4858379Ssam nfrontp += sizeof (doopt) - 2; 4866002Sroot } 4876002Sroot 4886002Sroot dooption(option) 4896002Sroot int option; 4906002Sroot { 4916002Sroot char *fmt; 4926002Sroot 4936002Sroot switch (option) { 4946002Sroot 4956002Sroot case TELOPT_TM: 4966002Sroot fmt = wont; 4976002Sroot break; 4986002Sroot 4996002Sroot case TELOPT_ECHO: 5006002Sroot mode(ECHO|CRMOD, 0); 5016002Sroot goto common; 5026002Sroot 5036002Sroot case TELOPT_BINARY: 5046002Sroot mode(RAW, 0); 5056002Sroot /*FALL THRU*/ 5066002Sroot 5076002Sroot case TELOPT_SGA: 5086002Sroot common: 5096002Sroot fmt = will; 5106002Sroot break; 5116002Sroot 5126002Sroot default: 5136002Sroot fmt = wont; 5146002Sroot break; 5156002Sroot } 5166002Sroot sprintf(nfrontp, fmt, option); 5178379Ssam nfrontp += sizeof (doopt) - 2; 5186002Sroot } 5196002Sroot 5206002Sroot mode(on, off) 5216002Sroot int on, off; 5226002Sroot { 5236002Sroot struct sgttyb b; 5246002Sroot 5256002Sroot ptyflush(); 5266002Sroot ioctl(pty, TIOCGETP, &b); 5276002Sroot b.sg_flags |= on; 5286002Sroot b.sg_flags &= ~off; 5296002Sroot ioctl(pty, TIOCSETP, &b); 5306002Sroot } 5316002Sroot 5326002Sroot /* 5336002Sroot * Send interrupt to process on other side of pty. 5346002Sroot * If it is in raw mode, just write NULL; 5356002Sroot * otherwise, write intr char. 5366002Sroot */ 5376002Sroot interrupt() 5386002Sroot { 5396002Sroot struct sgttyb b; 5406002Sroot struct tchars tchars; 5416002Sroot 5426002Sroot ptyflush(); /* half-hearted */ 5436002Sroot ioctl(pty, TIOCGETP, &b); 5446002Sroot if (b.sg_flags & RAW) { 5456002Sroot *pfrontp++ = '\0'; 5466002Sroot return; 5476002Sroot } 5486002Sroot *pfrontp++ = ioctl(pty, TIOCGETC, &tchars) < 0 ? 5496002Sroot '\177' : tchars.t_intrc; 5506002Sroot } 5516002Sroot 5526002Sroot ptyflush() 5536002Sroot { 5546002Sroot int n; 5556002Sroot 5566002Sroot if ((n = pfrontp - pbackp) > 0) 5576002Sroot n = write(pty, pbackp, n); 5588346Ssam if (n < 0) 5598346Ssam return; 5606002Sroot pbackp += n; 5616002Sroot if (pbackp == pfrontp) 5626002Sroot pbackp = pfrontp = ptyobuf; 5636002Sroot } 5646002Sroot 5656002Sroot netflush() 5666002Sroot { 5676002Sroot int n; 5686002Sroot 5696002Sroot if ((n = nfrontp - nbackp) > 0) 5706002Sroot n = write(net, nbackp, n); 5718346Ssam if (n < 0) { 5728346Ssam if (errno == EWOULDBLOCK) 5738346Ssam return; 5748346Ssam /* should blow this guy away... */ 5758346Ssam return; 5768346Ssam } 5776002Sroot nbackp += n; 5786002Sroot if (nbackp == nfrontp) 5796002Sroot nbackp = nfrontp = netobuf; 5806002Sroot } 5816002Sroot 5826002Sroot cleanup() 5836002Sroot { 5846002Sroot 5856002Sroot rmut(); 58610008Ssam vhangup(); /* XXX */ 58710191Ssam shutdown(net, 2); 5886002Sroot exit(1); 5896002Sroot } 5906002Sroot 5916002Sroot #include <utmp.h> 5926002Sroot 5936002Sroot struct utmp wtmp; 5946002Sroot char wtmpf[] = "/usr/adm/wtmp"; 59523567Sbloom char utmpf[] = "/etc/utmp"; 59623567Sbloom #define SCPYN(a, b) strncpy(a, b, sizeof(a)) 59723567Sbloom #define SCMPN(a, b) strncmp(a, b, sizeof(a)) 5986002Sroot 5996002Sroot rmut() 6006002Sroot { 6016002Sroot register f; 6026002Sroot int found = 0; 60323567Sbloom struct utmp *u, *utmp; 60423567Sbloom int nutmp; 60523567Sbloom struct stat statbf; 6066002Sroot 60723567Sbloom f = open(utmpf, O_RDWR); 6086002Sroot if (f >= 0) { 60923567Sbloom fstat(f, &statbf); 61023567Sbloom utmp = (struct utmp *)malloc(statbf.st_size); 61123567Sbloom if (!utmp) 61223567Sbloom syslog(LOG_ERR, "utmp malloc failed"); 61323567Sbloom if (statbf.st_size && utmp) { 61423567Sbloom nutmp = read(f, utmp, statbf.st_size); 61523567Sbloom nutmp /= sizeof(struct utmp); 61623567Sbloom 61723567Sbloom for (u = utmp ; u < &utmp[nutmp] ; u++) { 61823567Sbloom if (SCMPN(u->ut_line, line+5) || 61923567Sbloom u->ut_name[0]==0) 62023567Sbloom continue; 62123567Sbloom lseek(f, ((long)u)-((long)utmp), L_SET); 62223567Sbloom SCPYN(u->ut_name, ""); 62323567Sbloom SCPYN(u->ut_host, ""); 62423567Sbloom time(&u->ut_time); 62523567Sbloom write(f, (char *)u, sizeof(wtmp)); 62623567Sbloom found++; 62723567Sbloom } 6286002Sroot } 6296002Sroot close(f); 6306002Sroot } 6316002Sroot if (found) { 63217583Ssam f = open(wtmpf, O_WRONLY|O_APPEND); 6336002Sroot if (f >= 0) { 6346002Sroot SCPYN(wtmp.ut_line, line+5); 6356002Sroot SCPYN(wtmp.ut_name, ""); 63612683Ssam SCPYN(wtmp.ut_host, ""); 6376002Sroot time(&wtmp.ut_time); 63823567Sbloom write(f, (char *)&wtmp, sizeof(wtmp)); 6396002Sroot close(f); 6406002Sroot } 6416002Sroot } 6426002Sroot chmod(line, 0666); 6436002Sroot chown(line, 0, 0); 6446002Sroot line[strlen("/dev/")] = 'p'; 6456002Sroot chmod(line, 0666); 6466002Sroot chown(line, 0, 0); 6476002Sroot } 648