Annotation of researchv10dc/ipc/libipc/oipclogin.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include <ipc.h>
        !             3: #include <sys/ttyio.h>
        !             4: #include "defs.h"
        !             5: #include "libc.h"
        !             6: 
        !             7: /* this better be larger than either login names or passwords */
        !             8: #define PWDSIZE 16
        !             9: 
        !            10: char *_ipcgetpass();
        !            11: 
        !            12: /*
        !            13:  * log a user into a remote system in the v9 style
        !            14:  *
        !            15:  * First attempt at a valid userid came from ipcopen(),
        !            16:  * who sent it as part of the setup request.  Remote
        !            17:  * system responds to that with either "OK" or "NO".
        !            18:  * If the latter, we must send a string containing
        !            19:  * "userid,password<newline>" until either we receive
        !            20:  * the OK response or our user here gives up.
        !            21:  */
        !            22: ipclogin(fd)
        !            23: {
        !            24: #      define BFS 2*PWDSIZE + 3        /* <log>,<pswd>\n\0 */
        !            25:        int     cc;
        !            26:        struct sgttyb echo, noecho;
        !            27:        char    buf[BFS];
        !            28:        char    *rbuf;
        !            29:        FILE    *tty;
        !            30: 
        !            31:        cc = read(fd, buf, 2) ;
        !            32:        if (cc <= 0) {
        !            33:                errstr = "ipclogin can't read remote system";
        !            34:                return(-1);
        !            35:        }
        !            36:        if (buf[0] == 'O' && buf[1] == 'K')
        !            37:                return fd ;
        !            38:        tty = fopen("/dev/tty", "r+");
        !            39:        if (tty == NULL) {
        !            40:                errstr = "ipclogin can't open /dev/tty";
        !            41:                return -1;
        !            42:        }
        !            43:        if (ioctl(fileno(tty), TIOCGETP, &echo) < 0) {
        !            44:                errstr = "ipclogin can't log in";
        !            45:                return(-1);
        !            46:        }
        !            47:        noecho = echo;
        !            48:        noecho.sg_flags &= ~ECHO;
        !            49:        write (fileno(tty), "please ", 7) ;
        !            50:        while (1) {
        !            51:                rbuf = _ipcgetpass (tty, "login: ");
        !            52:                if (rbuf == 0) {
        !            53:                        cc = -1;
        !            54:                        break;
        !            55:                }
        !            56:                strcpy (buf, rbuf);
        !            57:                strcat (buf, ",");
        !            58: 
        !            59:                ioctl(fileno(tty), TIOCSETP, &noecho) ;
        !            60:                rbuf = _ipcgetpass (tty, "Password:");
        !            61:                ioctl(fileno(tty), TIOCSETP, &echo) ;
        !            62:                write(fileno(tty), "\n", 1);
        !            63:                if (rbuf == 0) {
        !            64:                        cc = -2;
        !            65:                        break;
        !            66:                }
        !            67:                strcat (buf, rbuf);
        !            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:                errstr = "ipclogin can't log in";
        !            80:                return -1;
        !            81:        }
        !            82:        return fd;
        !            83: }
        !            84: 
        !            85: /*
        !            86:  * log a user into a remote system in the Berkeley style
        !            87:  *
        !            88:  * Send a string to the other side of the form
        !            89:  *     "terminal_type<NULL>"
        !            90:  * The response is either
        !            91:  *     "<NULL>"                to indicate success or
        !            92:  *     "<non_0_byte>string"    where `string' is the error message
        !            93:  */
        !            94: ipcrogin(fd, opt)
        !            95:        int fd;
        !            96:        char *opt;
        !            97: {
        !            98:        char buf[32];
        !            99: 
        !           100:        write(fd, opt, strlen(opt)+1);
        !           101:        if(read(fd, buf, 1) != 1)
        !           102:                return -1;
        !           103:        if(buf[0] != 0){
        !           104:                while(read(fd, buf, 1) == 1){
        !           105:                        write(2, buf, 1);
        !           106:                        if(buf[0] == '\n')
        !           107:                                break;
        !           108:                }
        !           109:                return -1;
        !           110:        }
        !           111:        return 0;
        !           112: }
        !           113: 
        !           114: char *
        !           115: _ipcgetpass(tty, prompt)
        !           116: FILE *tty;
        !           117: char * prompt;
        !           118: {
        !           119:        char c;
        !           120:        char *cp;
        !           121:        static char buf[PWDSIZE + 1];
        !           122: 
        !           123:        write (fileno(tty), prompt, strlen (prompt));
        !           124: 
        !           125:        cp = buf;
        !           126:        while ((c = getc(tty)) != '\n' && c != EOF && c != '\04') {
        !           127:                if (cp < &buf[PWDSIZE])
        !           128:                        *cp++ = c;
        !           129:        }
        !           130:        *cp = '\0';
        !           131: 
        !           132:        if (buf[0] == '\0' && (c == EOF || c== '\04'))
        !           133:                return ((char *)0);
        !           134:        if (buf[0] == '~' && buf[1] == '.')
        !           135:                return ((char *)0);
        !           136: 
        !           137:        return (buf);
        !           138: }

unix.superglobalmegacorp.com

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