Annotation of researchv8dc/dk/cmd/dkdialsub.c, revision 1.1.1.1

1.1       root        1: #define DKMSGS 1
                      2: #include <sys/types.h>
                      3: #include <stdio.h>
                      4: #include <dk.h>
                      5: #include <pwd.h>
                      6: #include <signal.h>
                      7: #include <sys/ioctl.h>
                      8: #include "dkdial.h"
                      9: #include <sys/stat.h>
                     10: 
                     11: void   alarmcatch();
                     12: struct passwd *getpwuid();
                     13: struct dialout reply;
                     14: int pipefd;
                     15: 
                     16: main (argc, argv)
                     17: int argc;
                     18: char **argv;
                     19: {
                     20:        int fd, server ;
                     21:        int retval, listener;
                     22:        struct listenin d;
                     23:        register char **p;
                     24:        struct passwd *pw;
                     25:        struct stat st;
                     26:        char dialstr[64] ;
                     27:        char dialtone[2] ;
                     28:        int rc ;
                     29:        int traffic ;
                     30:        char *cp ;
                     31: 
                     32:        /* pick up and decode arguments */
                     33:        if (argc != 6)
                     34:                bugout(ILLEG);
                     35:        p = argv + 1;
                     36:        fd = atoi (*p++);
                     37:        pipefd = atoi (*p++);
                     38:        server = atoi (*p++);
                     39:        if (server==1)
                     40:                server = 3;
                     41:        traffic = atoi(*p++) ;
                     42:        strcpy(dialstr, *p) ;
                     43:        cp = dialstr ;
                     44:        while (*cp) {
                     45:                if (*cp == '\n')
                     46:                        *cp = '\0' ;
                     47:                cp++ ;
                     48:        }
                     49: 
                     50:        /* set up the parameter block for the initial request */
                     51:        fstat(fd, &st);
                     52:        d.l_type = T_SRV;
                     53:        d.l_lchan = minor(st.st_rdev);
                     54:        d.l_srv = 256 - server;
                     55:        d.l_param0 = traffic ;
                     56:        d.l_param1 = 0;
                     57:        d.l_param2 = 0;
                     58:        d.l_param3 = 0;
                     59:        d.l_param4 = 0;
                     60:        d.l_param5 = 0;
                     61:        strcat(dialstr, "\n") ;
                     62:        pw = getpwuid(getuid()) ;
                     63:        if (pw == 0)
                     64:                bugout(NOUID) ;
                     65:        strcat(dialstr, pw->pw_name) ;
                     66:        strcat(dialstr, "\n") ;
                     67:        signal (SIGALRM, alarmcatch);
                     68:        alarm (15);
                     69:        listener = dkctlchan(traffic) ;
                     70:        if (listener < 0)
                     71:                bugout(NOMGR);
                     72:        write(listener, (char *)&d, sizeof(d));
                     73:        close(listener);
                     74:        rc = read(fd, dialtone, 1) ;
                     75:        if (rc < 0)
                     76:                bugout(NODIALT) ;
                     77:        if (dialtone[0] != 'O')
                     78:                bugout(NODIALT) ;
                     79:        ioctl(fd, DIOCSTOP, 0);
                     80:        write(fd, dialstr, strlen(dialstr)) ;
                     81:        alarm(60);
                     82:        rc = read(fd, &reply, sizeof reply);
                     83:        alarm (0);
                     84:        if (rc <= 0)
                     85:                bugout(NOREP);
                     86:        write(pipefd, &reply, sizeof reply);
                     87: 
                     88:        /* assume normal exit */
                     89:        retval = NORM;
                     90: 
                     91:        /* successful reply, analyze it */
                     92:        switch (reply.srv) {
                     93:        case D_OPEN:
                     94:                break ;
                     95:        case D_FAIL:
                     96:                exit(ERRBASE + (reply.param1&0x7f));
                     97:        }
                     98:        return retval;
                     99: }
                    100: 
                    101: void
                    102: alarmcatch()
                    103: {
                    104: }
                    105: 
                    106: /*
                    107:  * write some sort of reply
                    108:  * (obsolete, but some old callers use it)
                    109:  */
                    110: bugout(r)
                    111: {
                    112:        reply.srv = D_FAIL;
                    113:        write(pipefd, (char *)&reply, sizeof(reply));
                    114:        exit(r);
                    115: }

unix.superglobalmegacorp.com

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