Annotation of researchv10dc/ipc/libipc/ipclogin.c, revision 1.1.1.1

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