121174Sdist /* 236517Skarels * Copyright (c) 1983, 1988 The Regents of the University of California. 335441Sbostic * All rights reserved. 435441Sbostic * 535441Sbostic * Redistribution and use in source and binary forms are permitted 635441Sbostic * provided that the above copyright notice and this paragraph are 735441Sbostic * duplicated in all such forms and that any documentation, 835441Sbostic * advertising materials, and other materials related to such 935441Sbostic * distribution and use acknowledge that the software was developed 1035441Sbostic * by the University of California, Berkeley. The name of the 1135441Sbostic * University may not be used to endorse or promote products derived 1235441Sbostic * from this software without specific prior written permission. 1335441Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1435441Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1535441Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1621174Sdist */ 1721174Sdist 186446Swnj #ifndef lint 1921174Sdist char copyright[] = 2036517Skarels "@(#) Copyright (c) 1983, 1988 The Regents of the University of California.\n\ 2121174Sdist All rights reserved.\n"; 2235441Sbostic #endif /* not lint */ 236446Swnj 2421174Sdist #ifndef lint 25*36703Skarels static char sccsid[] = "@(#)rlogind.c 5.22.1.6 (Berkeley) 02/07/89"; 2635441Sbostic #endif /* not lint */ 2721174Sdist 2816369Skarels /* 2916369Skarels * remote login server: 3036453Skfall * \0 3116369Skarels * remuser\0 3216369Skarels * locuser\0 3336453Skfall * terminal_type/speed\0 3436518Skarels * data 35*36703Skarels * 36*36703Skarels * Automatic login protocol is done here, using login -f upon success, 37*36703Skarels * unless OLD_LOGIN is defined (then done in login, ala 4.2/4.3BSD). 3816369Skarels */ 3916369Skarels 406446Swnj #include <stdio.h> 41*36703Skarels #include <sys/param.h> 426446Swnj #include <sys/stat.h> 436446Swnj #include <sys/socket.h> 4413554Ssam #include <sys/wait.h> 4518357Ssam #include <sys/file.h> 469208Ssam 479208Ssam #include <netinet/in.h> 489208Ssam 496446Swnj #include <errno.h> 506446Swnj #include <pwd.h> 516446Swnj #include <signal.h> 52*36703Skarels #include <sgtty.h> 536446Swnj #include <stdio.h> 548380Ssam #include <netdb.h> 5517187Sralph #include <syslog.h> 5618357Ssam #include <strings.h> 576446Swnj 5836518Skarels #ifndef TIOCPKT_WINDOW 5936518Skarels #define TIOCPKT_WINDOW 0x80 6036518Skarels #endif 6136518Skarels 6236518Skarels char *env[2]; 6336518Skarels #define NMAX 30 6436517Skarels char lusername[NMAX+1], rusername[NMAX+1]; 6536517Skarels static char term[64] = "TERM="; 6636517Skarels #define ENVSIZE (sizeof("TERM=")-1) /* skip null for concatenation */ 6736517Skarels int keepalive = 1; 6836453Skfall 6936453Skfall #define SUPERUSER(pwd) ((pwd)->pw_uid == 0) 7036453Skfall 7134424Sbostic extern int errno; 7210417Ssam int reapchild(); 7336453Skfall struct passwd *getpwnam(), *pwd; 7424723Smckusick char *malloc(); 7516369Skarels 766446Swnj main(argc, argv) 776446Swnj int argc; 786446Swnj char **argv; 796446Swnj { 8036319Sbostic extern int opterr, optind, _check_rhosts_file; 8136319Sbostic int ch; 8234424Sbostic int on = 1, fromlen; 836446Swnj struct sockaddr_in from; 846446Swnj 8536625Skfall openlog("rlogind", LOG_PID | LOG_CONS, LOG_AUTH); 8636319Sbostic 8736319Sbostic opterr = 0; 88*36703Skarels while ((ch = getopt(argc, argv, "ln")) != EOF) 8936517Skarels switch (ch) { 9036319Sbostic case 'l': 9136319Sbostic _check_rhosts_file = 0; 9236319Sbostic break; 9336517Skarels case 'n': 9436517Skarels keepalive = 0; 9536517Skarels break; 9636319Sbostic case '?': 9736319Sbostic default: 98*36703Skarels syslog(LOG_ERR, "usage: rlogind [-l] [-n]"); 9936319Sbostic break; 10036319Sbostic } 10136319Sbostic argc -= optind; 10236319Sbostic argv += optind; 10336319Sbostic 10416369Skarels fromlen = sizeof (from); 10516369Skarels if (getpeername(0, &from, &fromlen) < 0) { 106*36703Skarels syslog(LOG_ERR, "Couldn't get peer name of remote host: %m"); 107*36703Skarels fatalperror("Can't get peer name of host"); 1088380Ssam } 10936517Skarels if (keepalive && 11036517Skarels setsockopt(0, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof (on)) < 0) 11117187Sralph syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m"); 11216369Skarels doit(0, &from); 1136446Swnj } 1146446Swnj 1156446Swnj int child; 1166446Swnj int cleanup(); 1176446Swnj int netf; 1186446Swnj char *line; 11924724Smckusick extern char *inet_ntoa(); 1206446Swnj 12124889Smckusick struct winsize win = { 0, 0, 0, 0 }; 12224723Smckusick 12324889Smckusick 1246446Swnj doit(f, fromp) 1256446Swnj int f; 1266446Swnj struct sockaddr_in *fromp; 1276446Swnj { 12818357Ssam int i, p, t, pid, on = 1; 129*36703Skarels #ifndef OLD_LOGIN 13036631Skarels int authenticated = 0, hostok = 0; 131*36703Skarels char remotehost[2 * MAXHOSTNAMELEN + 1]; 132*36703Skarels #endif 13336636Skarels register struct hostent *hp; 13424724Smckusick struct hostent hostent; 1358380Ssam char c; 1366446Swnj 1376446Swnj alarm(60); 1386446Swnj read(f, &c, 1); 1396446Swnj if (c != 0) 1406446Swnj exit(1); 14136453Skfall 1426446Swnj alarm(0); 14316227Skarels fromp->sin_port = ntohs((u_short)fromp->sin_port); 1448380Ssam hp = gethostbyaddr(&fromp->sin_addr, sizeof (struct in_addr), 1458380Ssam fromp->sin_family); 14611345Ssam if (hp == 0) { 14724724Smckusick /* 14824724Smckusick * Only the name is used below. 14924724Smckusick */ 15024724Smckusick hp = &hostent; 15124724Smckusick hp->h_name = inet_ntoa(fromp->sin_addr); 152*36703Skarels #ifndef OLD_LOGIN 15336635Skarels hostok++; 154*36703Skarels #endif 155*36703Skarels } 156*36703Skarels #ifndef OLD_LOGIN 157*36703Skarels else if (local_domain(hp->h_name)) { 15836635Skarels /* 15936635Skarels * If name returned by gethostbyaddr is in our domain, 16036635Skarels * attempt to verify that we haven't been fooled by someone 16136635Skarels * in a remote net; look up the name and check that this 16236635Skarels * address corresponds to the name. 16336635Skarels */ 16436635Skarels strncpy(remotehost, hp->h_name, sizeof(remotehost) - 1); 16536635Skarels remotehost[sizeof(remotehost) - 1] = 0; 16636635Skarels hp = gethostbyname(remotehost); 16736635Skarels if (hp) 16836635Skarels for (; hp->h_addr_list[0]; hp->h_addr_list++) 16936635Skarels if (!bcmp(hp->h_addr_list[0], (caddr_t)&fromp->sin_addr, 17036635Skarels sizeof(fromp->sin_addr))) { 17136635Skarels hostok++; 17236635Skarels break; 17336635Skarels } 17436633Skarels } else 17536635Skarels hostok++; 176*36703Skarels #endif 17736636Skarels 178*36703Skarels if (fromp->sin_family != AF_INET || 179*36703Skarels fromp->sin_port >= IPPORT_RESERVED || 180*36703Skarels fromp->sin_port < IPPORT_RESERVED/2) { 181*36703Skarels syslog(LOG_NOTICE, "Connection from %s on illegal port", 182*36703Skarels inet_ntoa(fromp->sin_addr)); 183*36703Skarels fatal(f, "Permission denied"); 184*36703Skarels } 18536702Skarels #ifdef IP_OPTIONS 186*36703Skarels { 187*36703Skarels u_char optbuf[BUFSIZ/3], *cp; 188*36703Skarels char lbuf[BUFSIZ], *lp; 189*36703Skarels int optsize = sizeof(optbuf), ipproto; 190*36703Skarels struct protoent *ip; 19136702Skarels 192*36703Skarels if ((ip = getprotobyname("ip")) != NULL) 193*36703Skarels ipproto = ip->p_proto; 194*36703Skarels else 195*36703Skarels ipproto = IPPROTO_IP; 196*36703Skarels if (getsockopt(0, ipproto, IP_OPTIONS, (char *)optbuf, &optsize) == 0 && 197*36703Skarels optsize != 0) { 198*36703Skarels lp = lbuf; 199*36703Skarels for (cp = optbuf; optsize > 0; cp++, optsize--, lp += 3) 200*36703Skarels sprintf(lp, " %2.2x", *cp); 201*36703Skarels syslog(LOG_NOTICE, 202*36703Skarels "Connection received using IP options (ignored):%s", lbuf); 203*36703Skarels if (setsockopt(0, ipproto, IP_OPTIONS, 204*36703Skarels (char *)NULL, &optsize) != 0) { 205*36703Skarels syslog(LOG_ERR, "setsockopt IP_OPTIONS NULL: %m"); 206*36703Skarels exit(1); 207*36703Skarels } 208*36703Skarels } 209*36703Skarels } 21036702Skarels #endif 211*36703Skarels write(f, "", 1); 212*36703Skarels #ifndef OLD_LOGIN 213*36703Skarels if (do_rlogin(hp->h_name) == 0) { 214*36703Skarels if (hostok) 215*36703Skarels authenticated++; 216*36703Skarels else 217*36703Skarels write(f, "rlogind: Host address mismatch.\r\n", 218*36703Skarels sizeof("rlogind: Host address mismatch.\r\n") - 1); 21936631Skarels } 220*36703Skarels #endif 22136636Skarels 2226446Swnj for (c = 'p'; c <= 's'; c++) { 2236446Swnj struct stat stb; 2246446Swnj line = "/dev/ptyXX"; 2256446Swnj line[strlen("/dev/pty")] = c; 2266446Swnj line[strlen("/dev/ptyp")] = '0'; 2276446Swnj if (stat(line, &stb) < 0) 2286446Swnj break; 2296446Swnj for (i = 0; i < 16; i++) { 23034424Sbostic line[sizeof("/dev/ptyp") - 1] = "0123456789abcdef"[i]; 23134424Sbostic p = open(line, O_RDWR); 2326446Swnj if (p > 0) 2336446Swnj goto gotpty; 2346446Swnj } 2356446Swnj } 23624723Smckusick fatal(f, "Out of ptys"); 2379242Ssam /*NOTREACHED*/ 2386446Swnj gotpty: 23924889Smckusick (void) ioctl(p, TIOCSWINSZ, &win); 24016227Skarels netf = f; 2416446Swnj line[strlen("/dev/")] = 't'; 24234424Sbostic t = open(line, O_RDWR); 24334424Sbostic if (t < 0) 24434424Sbostic fatalperror(f, line); 24534424Sbostic if (fchmod(t, 0)) 24634424Sbostic fatalperror(f, line); 24734424Sbostic (void)signal(SIGHUP, SIG_IGN); 24834424Sbostic vhangup(); 24934424Sbostic (void)signal(SIGHUP, SIG_DFL); 25034424Sbostic t = open(line, O_RDWR); 25134424Sbostic if (t < 0) 25234424Sbostic fatalperror(f, line); 25336453Skfall setup_term(t); 2546446Swnj #ifdef DEBUG 25534424Sbostic { 25634424Sbostic int tt = open("/dev/tty", O_RDWR); 25734424Sbostic if (tt > 0) { 25834424Sbostic (void)ioctl(tt, TIOCNOTTY, 0); 25934424Sbostic (void)close(tt); 26034424Sbostic } 2616446Swnj } 2626446Swnj #endif 2639242Ssam pid = fork(); 2649242Ssam if (pid < 0) 26534424Sbostic fatalperror(f, ""); 26618357Ssam if (pid == 0) { 26718357Ssam close(f), close(p); 26818357Ssam dup2(t, 0), dup2(t, 1), dup2(t, 2); 26916227Skarels close(t); 270*36703Skarels #ifdef OLD_LOGIN 271*36703Skarels execl("/bin/login", "login", "-r", hp->h_name, 0); 272*36703Skarels #else /* OLD_LOGIN */ 27336631Skarels if (authenticated) 274*36703Skarels execl("/bin/login", "login", "-p", "-h", hp->h_name, 275*36703Skarels "-f", lusername, 0); 27636525Skfall else 277*36703Skarels execl("/bin/login", "login", "-p", "-h", hp->h_name, 278*36703Skarels lusername, 0); 279*36703Skarels #endif /* OLD_LOGIN */ 28034424Sbostic fatalperror(2, "/bin/login"); 28118357Ssam /*NOTREACHED*/ 28218357Ssam } 28318357Ssam close(t); 28436453Skfall 285*36703Skarels ioctl(f, FIONBIO, &on); 28618357Ssam ioctl(p, FIONBIO, &on); 28718357Ssam ioctl(p, TIOCPKT, &on); 28818357Ssam signal(SIGTSTP, SIG_IGN); 28918357Ssam signal(SIGCHLD, cleanup); 29024724Smckusick setpgrp(0, 0); 29118357Ssam protocol(f, p); 29230600Smckusick signal(SIGCHLD, SIG_IGN); 29318357Ssam cleanup(); 29418357Ssam } 2959242Ssam 29618357Ssam char magic[2] = { 0377, 0377 }; 29725423Skarels char oobdata[] = {TIOCPKT_WINDOW}; 29818357Ssam 29918357Ssam /* 30018357Ssam * Handle a "control" request (signaled by magic being present) 30118357Ssam * in the data stream. For now, we are only willing to handle 30218357Ssam * window size changes. 30318357Ssam */ 30418357Ssam control(pty, cp, n) 30518357Ssam int pty; 30618357Ssam char *cp; 30718357Ssam int n; 30818357Ssam { 30928705Smckusick struct winsize w; 31018357Ssam 31128705Smckusick if (n < 4+sizeof (w) || cp[2] != 's' || cp[3] != 's') 31218357Ssam return (0); 31325423Skarels oobdata[0] &= ~TIOCPKT_WINDOW; /* we know he heard */ 31428705Smckusick bcopy(cp+4, (char *)&w, sizeof(w)); 31528705Smckusick w.ws_row = ntohs(w.ws_row); 31628705Smckusick w.ws_col = ntohs(w.ws_col); 31728705Smckusick w.ws_xpixel = ntohs(w.ws_xpixel); 31828705Smckusick w.ws_ypixel = ntohs(w.ws_ypixel); 31928705Smckusick (void)ioctl(pty, TIOCSWINSZ, &w); 32028705Smckusick return (4+sizeof (w)); 32118357Ssam } 32218357Ssam 32318357Ssam /* 32418357Ssam * rlogin "protocol" machine. 32518357Ssam */ 32618357Ssam protocol(f, p) 32718357Ssam int f, p; 32818357Ssam { 32918357Ssam char pibuf[1024], fibuf[1024], *pbp, *fbp; 33018357Ssam register pcc = 0, fcc = 0; 33136517Skarels int cc, nfd, pmask, fmask; 33225740Skarels char cntl; 33318357Ssam 33418482Ssam /* 33518484Ssam * Must ignore SIGTTOU, otherwise we'll stop 33618484Ssam * when we try and set slave pty's window shape 33725423Skarels * (our controlling tty is the master pty). 33818482Ssam */ 33918484Ssam (void) signal(SIGTTOU, SIG_IGN); 34025423Skarels send(f, oobdata, 1, MSG_OOB); /* indicate new rlogin */ 34136517Skarels if (f > p) 34236517Skarels nfd = f + 1; 34336517Skarels else 34436517Skarels nfd = p + 1; 34536517Skarels fmask = 1 << f; 34636517Skarels pmask = 1 << p; 34718357Ssam for (;;) { 34825740Skarels int ibits, obits, ebits; 34918357Ssam 35025740Skarels ibits = 0; 35125740Skarels obits = 0; 35218357Ssam if (fcc) 35336517Skarels obits |= pmask; 35418357Ssam else 35536517Skarels ibits |= fmask; 35618357Ssam if (pcc >= 0) 35718357Ssam if (pcc) 35836517Skarels obits |= fmask; 3599242Ssam else 36036517Skarels ibits |= pmask; 36136517Skarels ebits = pmask; 36236517Skarels if (select(nfd, &ibits, obits ? &obits : (int *)NULL, 36336517Skarels &ebits, 0) < 0) { 36418357Ssam if (errno == EINTR) 3656446Swnj continue; 36634424Sbostic fatalperror(f, "select"); 36718357Ssam } 36825740Skarels if (ibits == 0 && obits == 0 && ebits == 0) { 36918357Ssam /* shouldn't happen... */ 37018357Ssam sleep(5); 37118357Ssam continue; 37218357Ssam } 37325740Skarels #define pkcontrol(c) ((c)&(TIOCPKT_FLUSHWRITE|TIOCPKT_NOSTOP|TIOCPKT_DOSTOP)) 37436517Skarels if (ebits & pmask) { 37525740Skarels cc = read(p, &cntl, 1); 37625740Skarels if (cc == 1 && pkcontrol(cntl)) { 37725740Skarels cntl |= oobdata[0]; 37825740Skarels send(f, &cntl, 1, MSG_OOB); 37925740Skarels if (cntl & TIOCPKT_FLUSHWRITE) { 38025740Skarels pcc = 0; 38136517Skarels ibits &= ~pmask; 38225740Skarels } 38325740Skarels } 38425740Skarels } 38536517Skarels if (ibits & fmask) { 386*36703Skarels fcc = read(f, fibuf, sizeof(fibuf)); 38718357Ssam if (fcc < 0 && errno == EWOULDBLOCK) 38818357Ssam fcc = 0; 38918357Ssam else { 39018357Ssam register char *cp; 39118357Ssam int left, n; 39218357Ssam 39318357Ssam if (fcc <= 0) 39416227Skarels break; 39518357Ssam fbp = fibuf; 39624723Smckusick 39718357Ssam top: 39825423Skarels for (cp = fibuf; cp < fibuf+fcc-1; cp++) 39918357Ssam if (cp[0] == magic[0] && 40018357Ssam cp[1] == magic[1]) { 40118357Ssam left = fcc - (cp-fibuf); 40218357Ssam n = control(p, cp, left); 40318357Ssam if (n) { 40418357Ssam left -= n; 40518357Ssam if (left > 0) 40625423Skarels bcopy(cp+n, cp, left); 40718357Ssam fcc -= n; 40818357Ssam goto top; /* n^2 */ 40925423Skarels } 41025423Skarels } 41136517Skarels obits |= pmask; /* try write */ 41225423Skarels } 41325423Skarels } 41424723Smckusick 41536517Skarels if ((obits & pmask) && fcc > 0) { 41625423Skarels cc = write(p, fbp, fcc); 41724723Smckusick if (cc > 0) { 41824723Smckusick fcc -= cc; 41924723Smckusick fbp += cc; 4206446Swnj } 42118357Ssam } 42224723Smckusick 42336517Skarels if (ibits & pmask) { 42418357Ssam pcc = read(p, pibuf, sizeof (pibuf)); 42518357Ssam pbp = pibuf; 42618357Ssam if (pcc < 0 && errno == EWOULDBLOCK) 42718357Ssam pcc = 0; 42818357Ssam else if (pcc <= 0) 42918357Ssam break; 43036517Skarels else if (pibuf[0] == 0) { 43118357Ssam pbp++, pcc--; 432*36703Skarels obits |= fmask; /* try a write */ 43336517Skarels } else { 43418357Ssam if (pkcontrol(pibuf[0])) { 43525423Skarels pibuf[0] |= oobdata[0]; 43618357Ssam send(f, &pibuf[0], 1, MSG_OOB); 43716227Skarels } 43818357Ssam pcc = 0; 4396446Swnj } 44018357Ssam } 44136517Skarels if ((obits & fmask) && pcc > 0) { 442*36703Skarels cc = write(f, pbp, pcc); 44325423Skarels if (cc < 0 && errno == EWOULDBLOCK) { 44425423Skarels /* also shouldn't happen */ 44525423Skarels sleep(5); 44625423Skarels continue; 44725423Skarels } 44818357Ssam if (cc > 0) { 44918357Ssam pcc -= cc; 45018357Ssam pbp += cc; 45118357Ssam } 4526446Swnj } 4536446Swnj } 4546446Swnj } 4556446Swnj 4566446Swnj cleanup() 4576446Swnj { 45835440Sbostic char *p; 45935440Sbostic 46035440Sbostic p = line + sizeof("/dev/") - 1; 46135440Sbostic if (logout(p)) 46235440Sbostic logwtmp(p, "", ""); 46335440Sbostic (void)chmod(line, 0666); 46435440Sbostic (void)chown(line, 0, 0); 46535440Sbostic *p = 'p'; 46635440Sbostic (void)chmod(line, 0666); 46735440Sbostic (void)chown(line, 0, 0); 46810192Ssam shutdown(netf, 2); 4696446Swnj exit(1); 4706446Swnj } 4716446Swnj 4729242Ssam fatal(f, msg) 4739242Ssam int f; 4749242Ssam char *msg; 4759242Ssam { 4769242Ssam char buf[BUFSIZ]; 4779242Ssam 4789242Ssam buf[0] = '\01'; /* error indicator */ 47913554Ssam (void) sprintf(buf + 1, "rlogind: %s.\r\n", msg); 4809242Ssam (void) write(f, buf, strlen(buf)); 4819242Ssam exit(1); 4829242Ssam } 4839242Ssam 48434424Sbostic fatalperror(f, msg) 4859242Ssam int f; 4869242Ssam char *msg; 4879242Ssam { 4889242Ssam char buf[BUFSIZ]; 48916227Skarels extern int sys_nerr; 4909242Ssam extern char *sys_errlist[]; 4919242Ssam 49218357Ssam if ((unsigned)errno < sys_nerr) 49316227Skarels (void) sprintf(buf, "%s: %s", msg, sys_errlist[errno]); 49416227Skarels else 49516227Skarels (void) sprintf(buf, "%s: Error %d", msg, errno); 4969242Ssam fatal(f, buf); 4979242Ssam } 49836453Skfall 499*36703Skarels #ifndef OLD_LOGIN 50036453Skfall do_rlogin(host) 50136518Skarels char *host; 50236453Skfall { 50336453Skfall 50436518Skarels getstr(rusername, sizeof(rusername), "remuser too long"); 50536518Skarels getstr(lusername, sizeof(lusername), "locuser too long"); 50636518Skarels getstr(term+ENVSIZE, sizeof(term)-ENVSIZE, "Terminal type too long"); 50736518Skarels 50836518Skarels if (getuid()) 50936453Skfall return(-1); 51036453Skfall pwd = getpwnam(lusername); 51136518Skarels if (pwd == NULL) 51236453Skfall return(-1); 51336453Skfall return(ruserok(host, SUPERUSER(pwd), rusername, lusername)); 51436453Skfall } 51536453Skfall 51636453Skfall 51736518Skarels getstr(buf, cnt, errmsg) 51836518Skarels char *buf; 51936518Skarels int cnt; 52036518Skarels char *errmsg; 52136453Skfall { 52236518Skarels char c; 52336518Skarels 52436453Skfall do { 52536518Skarels if (read(0, &c, 1) != 1) 52636453Skfall exit(1); 52736518Skarels if (--cnt < 0) 52836518Skarels fatal(1, errmsg); 52936453Skfall *buf++ = c; 53036518Skarels } while (c != 0); 53136453Skfall } 53236453Skfall 53336518Skarels extern char **environ; 53436453Skfall 535*36703Skarels char *speeds[] = { 536*36703Skarels "0", "50", "75", "110", "134", "150", "200", "300", "600", 537*36703Skarels "1200", "1800", "2400", "4800", "9600", "19200", "38400", 538*36703Skarels }; 539*36703Skarels #define NSPEEDS (sizeof(speeds) / sizeof(speeds[0])) 540*36703Skarels 54136519Skarels setup_term(fd) 54236519Skarels int fd; 54336519Skarels { 544*36703Skarels register char *cp = index(term, '/'), **cpp; 545*36703Skarels struct sgttyb sgttyb; 54636519Skarels char *speed; 54736519Skarels 548*36703Skarels (void)ioctl(fd, TIOCGETP, &sgttyb); 54936519Skarels if (cp) { 55036519Skarels *cp++ = '\0'; 55136519Skarels speed = cp; 55236519Skarels cp = index(speed, '/'); 55336519Skarels if (cp) 55436519Skarels *cp++ = '\0'; 555*36703Skarels for (cpp = speeds; cpp < &speeds[NSPEEDS]; cpp++) 556*36703Skarels if (strcmp(*cpp, speed) == 0) { 557*36703Skarels sgttyb.sg_ispeed = sgttyb.sg_ospeed = cpp - speeds; 558*36703Skarels break; 559*36703Skarels } 56036519Skarels } 561*36703Skarels sgttyb.sg_flags = ECHO|CRMOD|ANYP|XTABS; 562*36703Skarels (void)ioctl(fd, TIOCSETP, &sgttyb); 56336519Skarels 56436519Skarels env[0] = term; 56536519Skarels env[1] = 0; 56636519Skarels environ = env; 56736519Skarels } 56836609Skfall 56936609Skfall /* 57036631Skarels * Check whether host h is in our local domain, 57136631Skarels * as determined by the part of the name following 57236631Skarels * the first '.' in its name and in ours. 57336631Skarels * If either name is unqualified (contains no '.'), 57436631Skarels * assume that the host is local, as it will be 57536631Skarels * interpreted as such. 57636631Skarels */ 57736631Skarels local_domain(h) 57836631Skarels char *h; 57936625Skfall { 58036631Skarels char localhost[MAXHOSTNAMELEN]; 58136631Skarels char *p1, *p2 = index(h, '.'); 58236631Skarels 58336631Skarels (void) gethostname(localhost, sizeof(localhost)); 58436631Skarels p1 = index(localhost, '.'); 58536631Skarels if (p1 == NULL || p2 == NULL || !strcasecmp(p1, p2)) 58636625Skfall return(1); 58736625Skfall return(0); 58836625Skfall } 589*36703Skarels #endif /* OLD_LOGIN */ 590