|
|
1.1 ! root 1: /* ! 2: * log a user into a remote system via datakit ! 3: * ! 4: * first attempt at a valid userid came from tdkdial(), ! 5: * who sent it as part of the setup request. Remote ! 6: * system responds to that with either "OK" or "NO". ! 7: * If the latter, we must send a string containing ! 8: * "userid,password<newline>" until either we receive ! 9: * the OK response or our user here gives up. ! 10: */ ! 11: ! 12: #include <sgtty.h> ! 13: #include <stdio.h> ! 14: extern char *dkerror; ! 15: ! 16: /* this better be larger than either login names or passwords */ ! 17: #define PWDSIZE 16 ! 18: ! 19: char *_tdkgetpass(); ! 20: ! 21: tdklogin(fd) ! 22: { ! 23: # define BFS 2*PWDSIZE + 3 /* <log>,<pswd>\n\0 */ ! 24: int cc; ! 25: struct sgttyb echo, noecho; ! 26: char buf[BFS]; ! 27: char *rbuf; ! 28: FILE *tty; ! 29: ! 30: cc = read(fd, buf, 2) ; ! 31: if (cc <= 0) { ! 32: dkerror = "tdklogin can't read remote system"; ! 33: return(-1); ! 34: } ! 35: if (buf[0] == 'O' && buf[1] == 'K') ! 36: return fd ; ! 37: tty = fopen("/dev/tty", "r+"); ! 38: if (tty == NULL) { ! 39: dkerror = "tdklogin can't open /dev/tty"; ! 40: return -1; ! 41: } ! 42: ioctl(fileno(tty), TIOCGETP, &echo); ! 43: ioctl(fileno(tty), TIOCGETP, &noecho); ! 44: noecho.sg_flags &= ~ECHO; ! 45: write (fileno(tty), "please ", 7) ; ! 46: while (1) { ! 47: rbuf = _tdkgetpass (tty, "login: "); ! 48: if (rbuf == 0) { ! 49: cc = -1; ! 50: break; ! 51: } ! 52: strcpy (buf, rbuf); ! 53: strcat (buf, ","); ! 54: ! 55: ioctl(fileno(tty), TIOCSETP, &noecho) ; ! 56: rbuf = _tdkgetpass (tty, "Password:"); ! 57: ioctl(fileno(tty), TIOCSETP, &echo) ; ! 58: write(fileno(tty), "\n", 1); ! 59: if (rbuf == 0) { ! 60: cc = -2; ! 61: break; ! 62: } ! 63: strcat (buf, rbuf); ! 64: strcat (buf, "\n"); ! 65: ! 66: write(fd, buf, strlen (buf)) ; ! 67: cc = read(fd, buf, 2) ; ! 68: if (cc <= 0) ! 69: break ; ! 70: if (buf[0] == 'O' && buf[1] == 'K') ! 71: break ; ! 72: } ! 73: fclose(tty); ! 74: if (cc <= 0) { ! 75: close(fd); ! 76: dkerror = "tdklogin can't log in"; ! 77: return -1; ! 78: } ! 79: return fd; ! 80: } ! 81: ! 82: ! 83: char * ! 84: _tdkgetpass(tty, prompt) ! 85: FILE *tty; ! 86: char * prompt; ! 87: { ! 88: char c; ! 89: char *cp; ! 90: static char buf[PWDSIZE + 1]; ! 91: ! 92: write (fileno(tty), prompt, strlen (prompt)); ! 93: ! 94: cp = buf; ! 95: while ((c = getc(tty)) != '\n' && c != EOF && c != '\04') { ! 96: if (cp < &buf[PWDSIZE]) ! 97: *cp++ = c; ! 98: } ! 99: *cp = '\0'; ! 100: ! 101: if (buf[0] == '\0' && (c == EOF || c== '\04')) ! 102: return ((char *)0); ! 103: if (buf[0] == '~' && buf[1] == '.') ! 104: return ((char *)0); ! 105: ! 106: return (buf); ! 107: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.