Annotation of researchv10dc/dk/libc/tdklogin.c, revision 1.1.1.1

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:        if (ioctl(fileno(tty), TIOCGETP, &echo) < 0) {
                     43:                dkerror = "tdklogin can't log in";
                     44:                return(-1);
                     45:        }
                     46:        noecho = echo;
                     47:        noecho.sg_flags &= ~ECHO;
                     48:        write (fileno(tty), "please ", 7) ;
                     49:        while (1) {
                     50:                rbuf = _tdkgetpass (tty, "login: ");
                     51:                if (rbuf == 0) {
                     52:                        cc = -1;
                     53:                        break;
                     54:                }
                     55:                strcpy (buf, rbuf);
                     56:                strcat (buf, ",");
                     57: 
                     58:                ioctl(fileno(tty), TIOCSETP, &noecho) ;
                     59:                rbuf = _tdkgetpass (tty, "Password:");
                     60:                ioctl(fileno(tty), TIOCSETP, &echo) ;
                     61:                write(fileno(tty), "\n", 1);
                     62:                if (rbuf == 0) {
                     63:                        cc = -2;
                     64:                        break;
                     65:                }
                     66:                strcat (buf, rbuf);
                     67:                strcat (buf, "\n");
                     68: 
                     69:                write(fd, buf, strlen (buf) + 1) ;
                     70:                cc = read(fd, buf, 2) ;
                     71:                if (cc <= 0)
                     72:                        break ;
                     73:                if (buf[0] == 'O' && buf[1] == 'K')
                     74:                        break ;
                     75:        }
                     76:        fclose(tty);
                     77:        if (cc <= 0) {
                     78:                close(fd);
                     79:                dkerror = "tdklogin can't log in";
                     80:                return -1;
                     81:        }
                     82:        return fd;
                     83: }
                     84: 
                     85: 
                     86: char *
                     87: _tdkgetpass(tty, prompt)
                     88: FILE *tty;
                     89: char * prompt;
                     90: {
                     91:        char c;
                     92:        char *cp;
                     93:        static char buf[PWDSIZE + 1];
                     94: 
                     95:        write (fileno(tty), prompt, strlen (prompt));
                     96: 
                     97:        cp = buf;
                     98:        while ((c = getc(tty)) != '\n' && c != EOF && c != '\04') {
                     99:                if (cp < &buf[PWDSIZE])
                    100:                        *cp++ = c;
                    101:        }
                    102:        *cp = '\0';
                    103: 
                    104:        if (buf[0] == '\0' && (c == EOF || c== '\04'))
                    105:                return ((char *)0);
                    106:        if (buf[0] == '~' && buf[1] == '.')
                    107:                return ((char *)0);
                    108: 
                    109:        return (buf);
                    110: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.