1: # 2: /* 3: * getty -- adapt to terminal speed on dialup, and call login 4: */ 5: 6: /* 7: * tty flags 8: */ 9: #define HUPCL 01 10: #define XTABS 02 11: #define LCASE 04 12: #define ECHO 010 13: #define CRMOD 020 14: #define RAW 040 15: #define ODDP 0100 16: #define EVENP 0200 17: #define ANYP 0300 18: 19: /* 20: * Delay algorithms 21: */ 22: #define CR1 010000 23: #define CR2 020000 24: #define CR3 030000 25: #define NL1 000400 26: #define NL2 001000 27: #define NL3 001400 28: #define TAB1 002000 29: #define TAB2 004000 30: #define TAB3 006000 31: #define FF1 040000 32: 33: #define ERASE '#' 34: #define KILL '@' 35: 36: /* 37: * speeds 38: */ 39: #define B110 3 40: #define B150 5 41: #define B300 7 42: #define B9600 13 43: 44: #define SIGINT 2 45: #define SIGQIT 3 46: 47: struct sgtty { 48: char sgispd, sgospd; 49: char sgerase, sgkill; 50: int sgflag; 51: } tmode; 52: 53: struct tab { 54: int tname; /* this table name */ 55: int nname; /* successor table name */ 56: int iflags; /* initial flags */ 57: int fflags; /* final flags */ 58: int ispeed; /* input speed */ 59: int ospeed; /* output speed */ 60: char *message; /* login message */ 61: } itab[] { 62: 63: /* table '0'-1-2 300,150,110 */ 64: 65: '0', 1, 66: ANYP+RAW+NL1+CR1, ANYP+ECHO+CR1, 67: B300, B300, 68: "\n\r\033;\007login: ", 69: 70: 1, 2, 71: ANYP+RAW+NL1+CR1, EVENP+ECHO+FF1+CR2+TAB1+NL1, 72: B150, B150, 73: "\n\r\033:\006\006\017login: ", 74: 75: 2, '0', 76: ANYP+RAW+NL1+CR1, ANYP+ECHO+CRMOD+XTABS+LCASE+CR1, 77: B110, B110, 78: "\n\rlogin: ", 79: 80: /* table '-' -- Console TTY 110 */ 81: '-', '-', 82: ANYP+RAW+NL1+CR1, ANYP+ECHO+CRMOD+XTABS+LCASE+CR1, 83: B110, B110, 84: "\n\rlogin: ", 85: 86: /* table '1' -- 150 */ 87: '1', '1', 88: ANYP+RAW+NL1+CR1, EVENP+ECHO+FF1+CR2+TAB1+NL1, 89: B150, B150, 90: "\n\r\033:\006\006\017login: ", 91: 92: /* table '2' -- 9600 */ 93: '2', '2', 94: ANYP+RAW+NL1+CR1, ANYP+XTABS+ECHO+CRMOD+FF1, 95: B9600, B9600, 96: "\n\r\033;login: ", 97: }; 98: 99: #define NITAB sizeof itab/sizeof itab[0] 100: 101: char name[16]; 102: int crmod; 103: int upper; 104: int lower; 105: 106: main(argc, argv) 107: char **argv; 108: { 109: register struct tab *tabp; 110: register tname; 111: 112: /* 113: signal(SIGINT, 1); 114: signal(SIGQIT, 0); 115: */ 116: tname = '0'; 117: if (argc > 1) 118: tname = *argv[1]; 119: for (;;) { 120: for(tabp = itab; tabp < &itab[NITAB]; tabp++) 121: if(tabp->tname == tname) 122: break; 123: if(tabp >= &itab[NITAB]) 124: tabp = itab; 125: tmode.sgispd = tabp->ispeed; 126: tmode.sgospd = tabp->ospeed; 127: tmode.sgflag = tabp->iflags; 128: tmode.sgispd = tabp->ispeed; 129: tmode.sgospd = tabp->ospeed; 130: stty(0, &tmode); 131: puts(tabp->message); 132: stty(0, &tmode); 133: if(getname()) { 134: tmode.sgerase = ERASE; 135: tmode.sgkill = KILL; 136: tmode.sgflag = tabp->fflags; 137: if(crmod) 138: tmode.sgflag =| CRMOD; 139: if(upper) 140: tmode.sgflag =| LCASE; 141: if(lower) 142: tmode.sgflag =& ~LCASE; 143: stty(0, &tmode); 144: execl("/bin/login", "login", name, 0); 145: exit(1); 146: } 147: tname = tabp->nname; 148: } 149: } 150: 151: getname() 152: { 153: register char *np; 154: register c; 155: static cs; 156: 157: crmod = 0; 158: upper = 0; 159: lower = 0; 160: np = name; 161: do { 162: if (read(0, &cs, 1) <= 0) 163: exit(0); 164: if ((c = cs&0177) == 0) 165: return(0); 166: write(1, &cs, 1); 167: if (c>='a' && c <='z') 168: lower++; 169: else if (c>='A' && c<='Z') { 170: upper++; 171: c =+ 'a'-'A'; 172: } else if (c==ERASE) { 173: if (np > name) 174: np--; 175: continue; 176: } else if (c==KILL) { 177: np = name; 178: continue; 179: } 180: *np++ = c; 181: } while (c!='\n' && c!='\r' && np <= &name[16]); 182: *--np = 0; 183: if (c == '\r') { 184: write(1, "\n", 1); 185: crmod++; 186: } else 187: write(1, "\r", 1); 188: return(1); 189: } 190: 191: puts(as) 192: char *as; 193: { 194: register char *s; 195: 196: s = as; 197: while (*s) 198: write(1, s++, 1); 199: }