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*23567Sbloom static char sccsid[] = "@(#)telnetd.c 5.2 (Berkeley) 06/19/85"; 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' 38*23567Sbloom #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 6916371Skarels fromlen = sizeof (from); 7016371Skarels if (getpeername(0, &from, &fromlen) < 0) { 7116371Skarels fprintf(stderr, "%s: ", argv[0]); 7216371Skarels perror("getpeername"); 7316371Skarels _exit(1); 748346Ssam } 7517156Ssam if (setsockopt(0, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof (on)) < 0) { 7617187Sralph openlog(argv[0], LOG_PID, 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); 1916002Sroot 1928379Ssam /* 1938379Ssam * Request to do remote echo. 1948379Ssam */ 1958379Ssam dooption(TELOPT_ECHO); 1968379Ssam myopts[TELOPT_ECHO] = 1; 19712713Ssam /* 19812713Ssam * Show banner that getty never gave. 19912713Ssam */ 20012713Ssam gethostname(hostname, sizeof (hostname)); 20112713Ssam sprintf(nfrontp, BANNER, hostname, ""); 20212713Ssam nfrontp += strlen(nfrontp); 2036002Sroot for (;;) { 2046002Sroot int ibits = 0, obits = 0; 2056002Sroot register int c; 2066002Sroot 2076002Sroot /* 2086002Sroot * Never look for input if there's still 2096002Sroot * stuff in the corresponding output buffer 2106002Sroot */ 21117583Ssam if (nfrontp - nbackp || pcc > 0) 2126002Sroot obits |= (1 << f); 2136002Sroot else 2146002Sroot ibits |= (1 << p); 21517583Ssam if (pfrontp - pbackp || ncc > 0) 2166002Sroot obits |= (1 << p); 2176002Sroot else 2186002Sroot ibits |= (1 << f); 2196002Sroot if (ncc < 0 && pcc < 0) 2206002Sroot break; 2219218Ssam select(16, &ibits, &obits, 0, 0); 2226002Sroot if (ibits == 0 && obits == 0) { 2236002Sroot sleep(5); 2246002Sroot continue; 2256002Sroot } 2266002Sroot 2276002Sroot /* 2286002Sroot * Something to read from the network... 2296002Sroot */ 2306002Sroot if (ibits & (1 << f)) { 2316002Sroot ncc = read(f, netibuf, BUFSIZ); 2326002Sroot if (ncc < 0 && errno == EWOULDBLOCK) 2336002Sroot ncc = 0; 2346002Sroot else { 2356002Sroot if (ncc <= 0) 2366002Sroot break; 2376002Sroot netip = netibuf; 2386002Sroot } 2396002Sroot } 2406002Sroot 2416002Sroot /* 2426002Sroot * Something to read from the pty... 2436002Sroot */ 2446002Sroot if (ibits & (1 << p)) { 2456002Sroot pcc = read(p, ptyibuf, BUFSIZ); 2466002Sroot if (pcc < 0 && errno == EWOULDBLOCK) 2476002Sroot pcc = 0; 2486002Sroot else { 2496002Sroot if (pcc <= 0) 2506002Sroot break; 2516002Sroot ptyip = ptyibuf; 2526002Sroot } 2536002Sroot } 2546002Sroot 2556002Sroot while (pcc > 0) { 2566002Sroot if ((&netobuf[BUFSIZ] - nfrontp) < 2) 2576002Sroot break; 2586002Sroot c = *ptyip++ & 0377, pcc--; 2596002Sroot if (c == IAC) 2606002Sroot *nfrontp++ = c; 2616002Sroot *nfrontp++ = c; 2626002Sroot } 2636002Sroot if ((obits & (1 << f)) && (nfrontp - nbackp) > 0) 2646002Sroot netflush(); 2656002Sroot if (ncc > 0) 2666002Sroot telrcv(); 2676002Sroot if ((obits & (1 << p)) && (pfrontp - pbackp) > 0) 2686002Sroot ptyflush(); 2696002Sroot } 2706002Sroot cleanup(); 2716002Sroot } 2726002Sroot 2736002Sroot /* 2746002Sroot * State for recv fsm 2756002Sroot */ 2766002Sroot #define TS_DATA 0 /* base state */ 2776002Sroot #define TS_IAC 1 /* look for double IAC's */ 2786002Sroot #define TS_CR 2 /* CR-LF ->'s CR */ 2796002Sroot #define TS_BEGINNEG 3 /* throw away begin's... */ 2806002Sroot #define TS_ENDNEG 4 /* ...end's (suboption negotiation) */ 2816002Sroot #define TS_WILL 5 /* will option negotiation */ 2826002Sroot #define TS_WONT 6 /* wont " */ 2836002Sroot #define TS_DO 7 /* do " */ 2846002Sroot #define TS_DONT 8 /* dont " */ 2856002Sroot 2866002Sroot telrcv() 2876002Sroot { 2886002Sroot register int c; 2896002Sroot static int state = TS_DATA; 2906002Sroot struct sgttyb b; 2916002Sroot 2926002Sroot while (ncc > 0) { 2936002Sroot if ((&ptyobuf[BUFSIZ] - pfrontp) < 2) 2946002Sroot return; 2956002Sroot c = *netip++ & 0377, ncc--; 2966002Sroot switch (state) { 2976002Sroot 2986002Sroot case TS_DATA: 2996002Sroot if (c == IAC) { 3006002Sroot state = TS_IAC; 3016002Sroot break; 3026002Sroot } 3036002Sroot if (inter > 0) 3046002Sroot break; 3056002Sroot *pfrontp++ = c; 3066002Sroot if (!myopts[TELOPT_BINARY] && c == '\r') 3076002Sroot state = TS_CR; 3086002Sroot break; 3096002Sroot 3106002Sroot case TS_CR: 3116002Sroot if (c && c != '\n') 3126002Sroot *pfrontp++ = c; 3136002Sroot state = TS_DATA; 3146002Sroot break; 3156002Sroot 3166002Sroot case TS_IAC: 3176002Sroot switch (c) { 3186002Sroot 3196002Sroot /* 3206002Sroot * Send the process on the pty side an 3216002Sroot * interrupt. Do this with a NULL or 3226002Sroot * interrupt char; depending on the tty mode. 3236002Sroot */ 3246002Sroot case BREAK: 3256002Sroot case IP: 3266002Sroot interrupt(); 3276002Sroot break; 3286002Sroot 3296002Sroot /* 3306002Sroot * Are You There? 3316002Sroot */ 3326002Sroot case AYT: 33317583Ssam strcpy(nfrontp, "\r\n[Yes]\r\n"); 33417583Ssam nfrontp += 9; 3356002Sroot break; 3366002Sroot 3376002Sroot /* 3386002Sroot * Erase Character and 3396002Sroot * Erase Line 3406002Sroot */ 3416002Sroot case EC: 3426002Sroot case EL: 3436002Sroot ptyflush(); /* half-hearted */ 3446002Sroot ioctl(pty, TIOCGETP, &b); 3456002Sroot *pfrontp++ = (c == EC) ? 3466002Sroot b.sg_erase : b.sg_kill; 3476002Sroot break; 3486002Sroot 3496002Sroot /* 3506002Sroot * Check for urgent data... 3516002Sroot */ 3526002Sroot case DM: 3536002Sroot break; 3546002Sroot 3556002Sroot /* 3566002Sroot * Begin option subnegotiation... 3576002Sroot */ 3586002Sroot case SB: 3596002Sroot state = TS_BEGINNEG; 3606002Sroot continue; 3616002Sroot 3626002Sroot case WILL: 3636002Sroot case WONT: 3646002Sroot case DO: 3656002Sroot case DONT: 3666002Sroot state = TS_WILL + (c - WILL); 3676002Sroot continue; 3686002Sroot 3696002Sroot case IAC: 3706002Sroot *pfrontp++ = c; 3716002Sroot break; 3726002Sroot } 3736002Sroot state = TS_DATA; 3746002Sroot break; 3756002Sroot 3766002Sroot case TS_BEGINNEG: 3776002Sroot if (c == IAC) 3786002Sroot state = TS_ENDNEG; 3796002Sroot break; 3806002Sroot 3816002Sroot case TS_ENDNEG: 3826002Sroot state = c == SE ? TS_DATA : TS_BEGINNEG; 3836002Sroot break; 3846002Sroot 3856002Sroot case TS_WILL: 3866002Sroot if (!hisopts[c]) 3876002Sroot willoption(c); 3886002Sroot state = TS_DATA; 3896002Sroot continue; 3906002Sroot 3916002Sroot case TS_WONT: 3926002Sroot if (hisopts[c]) 3936002Sroot wontoption(c); 3946002Sroot state = TS_DATA; 3956002Sroot continue; 3966002Sroot 3976002Sroot case TS_DO: 3986002Sroot if (!myopts[c]) 3996002Sroot dooption(c); 4006002Sroot state = TS_DATA; 4016002Sroot continue; 4026002Sroot 4036002Sroot case TS_DONT: 4046002Sroot if (myopts[c]) { 4056002Sroot myopts[c] = 0; 4066002Sroot sprintf(nfrontp, wont, c); 4078379Ssam nfrontp += sizeof (wont) - 2; 4086002Sroot } 4096002Sroot state = TS_DATA; 4106002Sroot continue; 4116002Sroot 4126002Sroot default: 4139218Ssam printf("telnetd: panic state=%d\n", state); 4146002Sroot exit(1); 4156002Sroot } 4166002Sroot } 4176002Sroot } 4186002Sroot 4196002Sroot willoption(option) 4206002Sroot int option; 4216002Sroot { 4226002Sroot char *fmt; 4236002Sroot 4246002Sroot switch (option) { 4256002Sroot 4266002Sroot case TELOPT_BINARY: 4276002Sroot mode(RAW, 0); 4286002Sroot goto common; 4296002Sroot 4306002Sroot case TELOPT_ECHO: 4316002Sroot mode(0, ECHO|CRMOD); 4326002Sroot /*FALL THRU*/ 4336002Sroot 4346002Sroot case TELOPT_SGA: 4356002Sroot common: 4366002Sroot hisopts[option] = 1; 4376002Sroot fmt = doopt; 4386002Sroot break; 4396002Sroot 4406002Sroot case TELOPT_TM: 4416002Sroot fmt = dont; 4426002Sroot break; 4436002Sroot 4446002Sroot default: 4456002Sroot fmt = dont; 4466002Sroot break; 4476002Sroot } 4486023Ssam sprintf(nfrontp, fmt, option); 4498379Ssam nfrontp += sizeof (dont) - 2; 4506002Sroot } 4516002Sroot 4526002Sroot wontoption(option) 4536002Sroot int option; 4546002Sroot { 4556002Sroot char *fmt; 4566002Sroot 4576002Sroot switch (option) { 4586002Sroot 4596002Sroot case TELOPT_ECHO: 4606002Sroot mode(ECHO|CRMOD, 0); 4616002Sroot goto common; 4626002Sroot 4636002Sroot case TELOPT_BINARY: 4646002Sroot mode(0, RAW); 4656002Sroot /*FALL THRU*/ 4666002Sroot 4676002Sroot case TELOPT_SGA: 4686002Sroot common: 4696002Sroot hisopts[option] = 0; 4706002Sroot fmt = dont; 4716002Sroot break; 4726002Sroot 4736002Sroot default: 4746002Sroot fmt = dont; 4756002Sroot } 4766002Sroot sprintf(nfrontp, fmt, option); 4778379Ssam nfrontp += sizeof (doopt) - 2; 4786002Sroot } 4796002Sroot 4806002Sroot dooption(option) 4816002Sroot int option; 4826002Sroot { 4836002Sroot char *fmt; 4846002Sroot 4856002Sroot switch (option) { 4866002Sroot 4876002Sroot case TELOPT_TM: 4886002Sroot fmt = wont; 4896002Sroot break; 4906002Sroot 4916002Sroot case TELOPT_ECHO: 4926002Sroot mode(ECHO|CRMOD, 0); 4936002Sroot goto common; 4946002Sroot 4956002Sroot case TELOPT_BINARY: 4966002Sroot mode(RAW, 0); 4976002Sroot /*FALL THRU*/ 4986002Sroot 4996002Sroot case TELOPT_SGA: 5006002Sroot common: 5016002Sroot fmt = will; 5026002Sroot break; 5036002Sroot 5046002Sroot default: 5056002Sroot fmt = wont; 5066002Sroot break; 5076002Sroot } 5086002Sroot sprintf(nfrontp, fmt, option); 5098379Ssam nfrontp += sizeof (doopt) - 2; 5106002Sroot } 5116002Sroot 5126002Sroot mode(on, off) 5136002Sroot int on, off; 5146002Sroot { 5156002Sroot struct sgttyb b; 5166002Sroot 5176002Sroot ptyflush(); 5186002Sroot ioctl(pty, TIOCGETP, &b); 5196002Sroot b.sg_flags |= on; 5206002Sroot b.sg_flags &= ~off; 5216002Sroot ioctl(pty, TIOCSETP, &b); 5226002Sroot } 5236002Sroot 5246002Sroot /* 5256002Sroot * Send interrupt to process on other side of pty. 5266002Sroot * If it is in raw mode, just write NULL; 5276002Sroot * otherwise, write intr char. 5286002Sroot */ 5296002Sroot interrupt() 5306002Sroot { 5316002Sroot struct sgttyb b; 5326002Sroot struct tchars tchars; 5336002Sroot 5346002Sroot ptyflush(); /* half-hearted */ 5356002Sroot ioctl(pty, TIOCGETP, &b); 5366002Sroot if (b.sg_flags & RAW) { 5376002Sroot *pfrontp++ = '\0'; 5386002Sroot return; 5396002Sroot } 5406002Sroot *pfrontp++ = ioctl(pty, TIOCGETC, &tchars) < 0 ? 5416002Sroot '\177' : tchars.t_intrc; 5426002Sroot } 5436002Sroot 5446002Sroot ptyflush() 5456002Sroot { 5466002Sroot int n; 5476002Sroot 5486002Sroot if ((n = pfrontp - pbackp) > 0) 5496002Sroot n = write(pty, pbackp, n); 5508346Ssam if (n < 0) 5518346Ssam return; 5526002Sroot pbackp += n; 5536002Sroot if (pbackp == pfrontp) 5546002Sroot pbackp = pfrontp = ptyobuf; 5556002Sroot } 5566002Sroot 5576002Sroot netflush() 5586002Sroot { 5596002Sroot int n; 5606002Sroot 5616002Sroot if ((n = nfrontp - nbackp) > 0) 5626002Sroot n = write(net, nbackp, n); 5638346Ssam if (n < 0) { 5648346Ssam if (errno == EWOULDBLOCK) 5658346Ssam return; 5668346Ssam /* should blow this guy away... */ 5678346Ssam return; 5688346Ssam } 5696002Sroot nbackp += n; 5706002Sroot if (nbackp == nfrontp) 5716002Sroot nbackp = nfrontp = netobuf; 5726002Sroot } 5736002Sroot 5746002Sroot cleanup() 5756002Sroot { 5766002Sroot 5776002Sroot rmut(); 57810008Ssam vhangup(); /* XXX */ 57910191Ssam shutdown(net, 2); 5806002Sroot kill(0, SIGKILL); 5816002Sroot exit(1); 5826002Sroot } 5836002Sroot 5846002Sroot #include <utmp.h> 5856002Sroot 5866002Sroot struct utmp wtmp; 5876002Sroot char wtmpf[] = "/usr/adm/wtmp"; 588*23567Sbloom char utmpf[] = "/etc/utmp"; 589*23567Sbloom #define SCPYN(a, b) strncpy(a, b, sizeof(a)) 590*23567Sbloom #define SCMPN(a, b) strncmp(a, b, sizeof(a)) 5916002Sroot 5926002Sroot rmut() 5936002Sroot { 5946002Sroot register f; 5956002Sroot int found = 0; 596*23567Sbloom struct utmp *u, *utmp; 597*23567Sbloom int nutmp; 598*23567Sbloom struct stat statbf; 5996002Sroot 600*23567Sbloom f = open(utmpf, O_RDWR); 6016002Sroot if (f >= 0) { 602*23567Sbloom fstat(f, &statbf); 603*23567Sbloom utmp = (struct utmp *)malloc(statbf.st_size); 604*23567Sbloom if (!utmp) 605*23567Sbloom syslog(LOG_ERR, "utmp malloc failed"); 606*23567Sbloom if (statbf.st_size && utmp) { 607*23567Sbloom nutmp = read(f, utmp, statbf.st_size); 608*23567Sbloom nutmp /= sizeof(struct utmp); 609*23567Sbloom 610*23567Sbloom for (u = utmp ; u < &utmp[nutmp] ; u++) { 611*23567Sbloom if (SCMPN(u->ut_line, line+5) || 612*23567Sbloom u->ut_name[0]==0) 613*23567Sbloom continue; 614*23567Sbloom lseek(f, ((long)u)-((long)utmp), L_SET); 615*23567Sbloom SCPYN(u->ut_name, ""); 616*23567Sbloom SCPYN(u->ut_host, ""); 617*23567Sbloom time(&u->ut_time); 618*23567Sbloom write(f, (char *)u, sizeof(wtmp)); 619*23567Sbloom found++; 620*23567Sbloom } 6216002Sroot } 6226002Sroot close(f); 6236002Sroot } 6246002Sroot if (found) { 62517583Ssam f = open(wtmpf, O_WRONLY|O_APPEND); 6266002Sroot if (f >= 0) { 6276002Sroot SCPYN(wtmp.ut_line, line+5); 6286002Sroot SCPYN(wtmp.ut_name, ""); 62912683Ssam SCPYN(wtmp.ut_host, ""); 6306002Sroot time(&wtmp.ut_time); 631*23567Sbloom write(f, (char *)&wtmp, sizeof(wtmp)); 6326002Sroot close(f); 6336002Sroot } 6346002Sroot } 6356002Sroot chmod(line, 0666); 6366002Sroot chown(line, 0, 0); 6376002Sroot line[strlen("/dev/")] = 'p'; 6386002Sroot chmod(line, 0666); 6396002Sroot chown(line, 0, 0); 6406002Sroot } 641