|
|
1.1 ! root 1: #ifndef lint ! 2: static char sccsid[] = "@(#)main.c 4.5 (Berkeley) 83/08/01"; ! 3: #endif ! 4: ! 5: /* ! 6: * getty -- adapt to terminal speed on dialup, and call login ! 7: * ! 8: * Melbourne getty, June 83, kre. ! 9: */ ! 10: ! 11: #include <sgtty.h> ! 12: #include <signal.h> ! 13: #include <ctype.h> ! 14: #include <setjmp.h> ! 15: #include "gettytab.h" ! 16: ! 17: struct sgttyb tmode = { ! 18: 0, 0, CERASE, CKILL, 0, 0 ! 19: }; ! 20: struct tchars tc = { ! 21: CINTR, CQUIT, CSTART, ! 22: CSTOP, CEOF, CBRK, ! 23: }; ! 24: struct ltchars ltc = { ! 25: CSUSP, CDSUSP, CRPRNT, ! 26: CFLUSH, CWERASE, CLNEXT ! 27: }; ! 28: ! 29: int crmod; ! 30: int upper; ! 31: int lower; ! 32: int digit; ! 33: ! 34: char hostname[32]; ! 35: char name[16]; ! 36: char *portselector(); ! 37: ! 38: #define OBUFSIZ 128 ! 39: #define TABBUFSIZ 512 ! 40: ! 41: char defent[TABBUFSIZ]; ! 42: char defstrs[TABBUFSIZ]; ! 43: char tabent[TABBUFSIZ]; ! 44: char tabstrs[TABBUFSIZ]; ! 45: ! 46: char *env[128]; ! 47: ! 48: char partab[] = { ! 49: 0001,0201,0201,0001,0201,0001,0001,0201, ! 50: 0202,0004,0003,0205,0005,0206,0201,0001, ! 51: 0201,0001,0001,0201,0001,0201,0201,0001, ! 52: 0001,0201,0201,0001,0201,0001,0001,0201, ! 53: 0200,0000,0000,0200,0000,0200,0200,0000, ! 54: 0000,0200,0200,0000,0200,0000,0000,0200, ! 55: 0000,0200,0200,0000,0200,0000,0000,0200, ! 56: 0200,0000,0000,0200,0000,0200,0200,0000, ! 57: 0200,0000,0000,0200,0000,0200,0200,0000, ! 58: 0000,0200,0200,0000,0200,0000,0000,0200, ! 59: 0000,0200,0200,0000,0200,0000,0000,0200, ! 60: 0200,0000,0000,0200,0000,0200,0200,0000, ! 61: 0000,0200,0200,0000,0200,0000,0000,0200, ! 62: 0200,0000,0000,0200,0000,0200,0200,0000, ! 63: 0200,0000,0000,0200,0000,0200,0200,0000, ! 64: 0000,0200,0200,0000,0200,0000,0000,0201 ! 65: }; ! 66: ! 67: #define ERASE tmode.sg_erase ! 68: #define KILL tmode.sg_kill ! 69: #define EOT tc.t_eofc ! 70: ! 71: jmp_buf timeout; ! 72: ! 73: dingdong() ! 74: { ! 75: ! 76: alarm(0); ! 77: signal(SIGALRM, SIG_DFL); ! 78: longjmp(timeout, 1); ! 79: } ! 80: ! 81: jmp_buf intrupt; ! 82: ! 83: interrupt() ! 84: { ! 85: ! 86: signal(SIGINT, interrupt); ! 87: longjmp(intrupt, 1); ! 88: } ! 89: ! 90: main(argc, argv) ! 91: char *argv[]; ! 92: { ! 93: char *tname; ! 94: long allflags; ! 95: ! 96: signal(SIGINT, SIG_IGN); ! 97: /* ! 98: signal(SIGQUIT, SIG_DFL); ! 99: */ ! 100: gethostname(hostname, sizeof(hostname)); ! 101: if (hostname[0] == '\0') ! 102: strcpy(hostname, "32BV_Unix"); ! 103: gettable("default", defent, defstrs); ! 104: gendefaults(); ! 105: tname = "default"; ! 106: if (argc > 1) ! 107: tname = argv[1]; ! 108: for (;;) { ! 109: int ldisp = OTTYDISC; ! 110: ! 111: gettable(tname, tabent, tabstrs); ! 112: if (OPset || EPset || APset) ! 113: APset++, OPset++, EPset++; ! 114: setdefaults(); ! 115: ioctl(0, TIOCFLUSH, 0); /* clear out the crap */ ! 116: if (IS) ! 117: tmode.sg_ispeed = speed(IS); ! 118: else if (SP) ! 119: tmode.sg_ispeed = speed(SP); ! 120: if (OS) ! 121: tmode.sg_ospeed = speed(OS); ! 122: else if (SP) ! 123: tmode.sg_ospeed = speed(SP); ! 124: if (SB) ! 125: tmode.sg_stopbits = stopbits(SB); ! 126: tmode.sg_flags = setflags(0); ! 127: ioctl(0, TIOCSETP, &tmode); ! 128: setchars(); ! 129: ioctl(0, TIOCSETC, &tc); ! 130: ioctl(0, TIOCSETD, &ldisp); ! 131: if (HC) ! 132: ioctl(0, TIOCHPCL, 0); ! 133: if (PS) { ! 134: tname = portselector(); ! 135: continue; ! 136: } ! 137: if (CL && *CL) ! 138: putpad(CL); ! 139: edithost(HE); ! 140: if (IM && *IM) ! 141: putf(IM); ! 142: if (setjmp(timeout)) { ! 143: tmode.sg_ispeed = tmode.sg_ospeed = 0; ! 144: ioctl(0, TIOCSETP, &tmode); ! 145: exit(1); ! 146: } ! 147: if (TO) { ! 148: signal(SIGALRM, dingdong); ! 149: alarm(TO); ! 150: } ! 151: if (getname()) { ! 152: alarm(0); ! 153: signal(SIGALRM, SIG_DFL); ! 154: if (!(upper || lower || digit)) ! 155: continue; ! 156: allflags = setflags(2); ! 157: tmode.sg_flags = allflags & 0xffff; ! 158: allflags >>= 16; ! 159: if (crmod || NL) ! 160: tmode.sg_flags |= CRMOD; ! 161: if (upper || UC) ! 162: tmode.sg_flags |= LCASE; ! 163: if (lower || LC) ! 164: tmode.sg_flags &= ~LCASE; ! 165: ioctl(0, TIOCSETP, &tmode); ! 166: ioctl(0, TIOCSLTC, <c); ! 167: ioctl(0, TIOCLSET, &allflags); ! 168: putchr('\n'); ! 169: oflush(); ! 170: makeenv(env); ! 171: signal(SIGINT, SIG_DFL); ! 172: execle(LO, "login", name, (char *)0, env); ! 173: exit(1); ! 174: } ! 175: alarm(0); ! 176: signal(SIGALRM, SIG_DFL); ! 177: signal(SIGINT, SIG_IGN); ! 178: if (NX && *NX) ! 179: tname = NX; ! 180: } ! 181: } ! 182: ! 183: getname() ! 184: { ! 185: register char *np; ! 186: register c; ! 187: char cs; ! 188: ! 189: /* ! 190: * Interrupt may happen if we use CBREAK mode ! 191: */ ! 192: if (setjmp(intrupt)) { ! 193: signal(SIGINT, SIG_IGN); ! 194: return (0); ! 195: } ! 196: signal(SIGINT, interrupt); ! 197: tmode.sg_flags = setflags(0); ! 198: ioctl(0, TIOCSETP, &tmode); ! 199: tmode.sg_flags = setflags(1); ! 200: prompt(); ! 201: if (PF > 0) { ! 202: oflush(); ! 203: sleep(PF); ! 204: PF = 0; ! 205: } ! 206: ioctl(0, TIOCSETP, &tmode); ! 207: crmod = 0; ! 208: upper = 0; ! 209: lower = 0; ! 210: digit = 0; ! 211: np = name; ! 212: for (;;) { ! 213: oflush(); ! 214: if (read(0, &cs, 1) <= 0) ! 215: exit(0); ! 216: if ((c = cs&0177) == 0) ! 217: return (0); ! 218: if (c == EOT) ! 219: exit(1); ! 220: if (c == '\r' || c == '\n' || np >= &name[16]) ! 221: break; ! 222: ! 223: if (c >= 'a' && c <= 'z') ! 224: lower++; ! 225: else if (c >= 'A' && c <= 'Z') { ! 226: upper++; ! 227: } else if (c == ERASE || c == '#' || c == '\b') { ! 228: if (np > name) { ! 229: np--; ! 230: if (tmode.sg_ospeed >= B1200) ! 231: puts("\b \b"); ! 232: else ! 233: putchr(cs); ! 234: } ! 235: continue; ! 236: } else if (c == KILL || c == '@') { ! 237: putchr(cs); ! 238: putchr('\r'); ! 239: if (tmode.sg_ospeed < B1200) ! 240: putchr('\n'); ! 241: /* this is the way they do it down under ... */ ! 242: else if (np > name) ! 243: puts(" \r"); ! 244: prompt(); ! 245: np = name; ! 246: continue; ! 247: } else if (c == ' ') ! 248: c = '_'; ! 249: else if (c >= '0' && c <= '9') ! 250: digit++; ! 251: if (IG && (c < ' ' || c > 0176)) ! 252: continue; ! 253: *np++ = c; ! 254: putchr(cs); ! 255: } ! 256: signal(SIGINT, SIG_IGN); ! 257: *np = 0; ! 258: if (c == '\r') ! 259: crmod++; ! 260: if (upper && !lower && !LC || UC) ! 261: for (np = name; *np; np++) ! 262: if (isupper(*np)) ! 263: *np = tolower(*np); ! 264: return (1); ! 265: } ! 266: ! 267: static ! 268: short tmspc10[] = { ! 269: 0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5, 15 ! 270: }; ! 271: ! 272: putpad(s) ! 273: register char *s; ! 274: { ! 275: register pad = 0; ! 276: register mspc10; ! 277: ! 278: if (isdigit(*s)) { ! 279: while (isdigit(*s)) { ! 280: pad *= 10; ! 281: pad += *s++ - '0'; ! 282: } ! 283: pad *= 10; ! 284: if (*s == '.' && isdigit(s[1])) { ! 285: pad += s[1] - '0'; ! 286: s += 2; ! 287: } ! 288: } ! 289: ! 290: puts(s); ! 291: /* ! 292: * If no delay needed, or output speed is ! 293: * not comprehensible, then don't try to delay. ! 294: */ ! 295: if (pad == 0) ! 296: return; ! 297: if (tmode.sg_ospeed <= 0 || ! 298: tmode.sg_ospeed >= (sizeof tmspc10 / sizeof tmspc10[0])) ! 299: return; ! 300: ! 301: /* ! 302: * Round up by a half a character frame, ! 303: * and then do the delay. ! 304: * Too bad there are no user program accessible programmed delays. ! 305: * Transmitting pad characters slows many ! 306: * terminals down and also loads the system. ! 307: */ ! 308: mspc10 = tmspc10[tmode.sg_ospeed]; ! 309: pad += mspc10 / 2; ! 310: for (pad /= mspc10; pad > 0; pad--) ! 311: putchr(*PC); ! 312: } ! 313: ! 314: puts(s) ! 315: register char *s; ! 316: { ! 317: ! 318: while (*s) ! 319: putchr(*s++); ! 320: } ! 321: ! 322: char outbuf[OBUFSIZ]; ! 323: int obufcnt = 0; ! 324: ! 325: putchr(cc) ! 326: { ! 327: char c; ! 328: ! 329: c = cc; ! 330: c |= partab[c&0177] & 0200; ! 331: if (OP) ! 332: c ^= 0200; ! 333: if (!UB) { ! 334: outbuf[obufcnt++] = c; ! 335: if (obufcnt >= OBUFSIZ) ! 336: oflush(); ! 337: } else ! 338: write(1, &c, 1); ! 339: } ! 340: ! 341: oflush() ! 342: { ! 343: if (obufcnt) ! 344: write(1, outbuf, obufcnt); ! 345: obufcnt = 0; ! 346: } ! 347: ! 348: prompt() ! 349: { ! 350: ! 351: putf(LM); ! 352: if (CO) ! 353: putchr('\n'); ! 354: } ! 355: ! 356: putf(cp) ! 357: register char *cp; ! 358: { ! 359: extern char editedhost[]; ! 360: ! 361: while (*cp) { ! 362: if (*cp != '%') { ! 363: putchr(*cp++); ! 364: continue; ! 365: } ! 366: switch (*++cp) { ! 367: ! 368: case 'h': ! 369: puts(editedhost); ! 370: break; ! 371: ! 372: case '%': ! 373: putchr('%'); ! 374: break; ! 375: } ! 376: cp++; ! 377: } ! 378: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.