Annotation of researchv10no/cmd/uucp/callers.c, revision 1.1

1.1     ! root        1: /*     %W%
        !             2: */
        !             3: #include "uucp.h"
        !             4: VERSION(%W%);
        !             5: 
        !             6: #ifdef BSD4_2
        !             7: #include <netdb.h>
        !             8: #include <netinet/in.h>
        !             9: #include <sys/socket.h>
        !            10: #endif
        !            11: #ifdef UNET
        !            12: #include  "UNET/unetio.h"
        !            13: #include  "UNET/tcp.h"
        !            14: #endif
        !            15: #if defined V8 && defined TCP
        !            16: #include <sys/inet/in.h>
        !            17: #include <sys/inet/tcp_user.h>
        !            18: #endif
        !            19: 
        !            20: 
        !            21: int alarmtr();
        !            22: extern jmp_buf Sjbuf;
        !            23: extern char *fdig();
        !            24: 
        !            25: /*
        !            26:  *     to add a new caller:
        !            27:  *     declare the function that knows how to call on the device,
        !            28:  *     add a line to the callers table giving the name of the device
        !            29:  *     (from Devices file) and the name of the function
        !            30:  *     add the function to the end of this file
        !            31:  */
        !            32: 
        !            33: #ifdef DIAL801
        !            34: int    dial801();
        !            35: #endif
        !            36: 
        !            37: #ifdef DATAKIT
        !            38: int    dkcall();
        !            39: #endif
        !            40: 
        !            41: #ifdef CSERV
        !            42: int    cscall();
        !            43: #endif
        !            44: 
        !            45: #ifdef V8
        !            46: int    Dialout();
        !            47: #endif
        !            48: 
        !            49: #ifdef TCP
        !            50: int    unetcall();
        !            51: int    tcpcall();
        !            52: #endif
        !            53: 
        !            54: #ifdef SYTEK
        !            55: int    sytcall();
        !            56: #endif
        !            57: 
        !            58: struct caller Caller[] = {
        !            59: 
        !            60: #ifdef DIAL801
        !            61:        {"801",         dial801},
        !            62:        {"212",         dial801},
        !            63: #endif
        !            64: 
        !            65: #ifdef V8
        !            66:        {"Dialout",     Dialout},       /* ditto but using dialout(III) */
        !            67: #endif
        !            68: 
        !            69: #ifdef TCP
        !            70: #if defined BSD4_2 || defined V8
        !            71:        {"TCP",         tcpcall},       /* 4.2BSD sockets */
        !            72: #else
        !            73: #ifdef UNET
        !            74:        {"TCP",         unetcall},      /* 3com implementation of tcp */
        !            75:        {"Unetserver",  unetcall},
        !            76: #endif
        !            77: #endif
        !            78: #endif
        !            79: 
        !            80: #ifdef DATAKIT
        !            81:        {"DK",          dkcall},        /* standard AT&T DATAKIT VCS caller */
        !            82: #endif
        !            83: 
        !            84: #ifdef CSERV
        !            85:        {"CS",          cscall},        /* presotto connection server */
        !            86: #endif
        !            87: 
        !            88: #ifdef SYTEK
        !            89:        {"Sytek",       sytcall},       /* untested but should work */
        !            90: #endif
        !            91: 
        !            92:        {NULL,          NULL}           /* this line must be last */
        !            93: };
        !            94: 
        !            95: /***
        !            96:  *     exphone - expand phone number for given prefix and number
        !            97:  *
        !            98:  *     return code - none
        !            99:  */
        !           100: 
        !           101: static void
        !           102: exphone(in, out)
        !           103: char *in, *out;
        !           104: {
        !           105:        FILE *fn;
        !           106:        char pre[MAXPH], npart[MAXPH], tpre[MAXPH], p[MAXPH];
        !           107:        char buf[BUFSIZ];
        !           108:        char *s1;
        !           109: 
        !           110:        if (!isalpha(*in)) {
        !           111:                (void) strcpy(out, in);
        !           112:                return;
        !           113:        }
        !           114: 
        !           115:        s1=pre;
        !           116:        while (isalpha(*in))
        !           117:                *s1++ = *in++;
        !           118:        *s1 = NULLCHAR;
        !           119:        s1 = npart;
        !           120:        while (*in != NULLCHAR)
        !           121:                *s1++ = *in++;
        !           122:        *s1 = NULLCHAR;
        !           123: 
        !           124:        tpre[0] = NULLCHAR;
        !           125:        fn = fopen(DIALFILE, "r");
        !           126:        if (fn != NULL) {
        !           127:                while (fgets(buf, BUFSIZ, fn)) {
        !           128:                        if ( sscanf(buf, "%s%s", p, tpre) < 1)
        !           129:                                continue;
        !           130:                        if (EQUALS(p, pre))
        !           131:                                break;
        !           132:                        tpre[0] = NULLCHAR;
        !           133:                }
        !           134:                fclose(fn);
        !           135:        }
        !           136: 
        !           137:        (void) strcpy(out, tpre);
        !           138:        (void) strcat(out, npart);
        !           139:        return;
        !           140: }
        !           141: 
        !           142: /*
        !           143:  * repphone - Replace \D and \T sequences in arg with phone
        !           144:  * expanding and translating as appropriate.
        !           145:  */
        !           146: static char *
        !           147: repphone(arg, phone, trstr)
        !           148: register char *arg, *phone, *trstr;
        !           149: {
        !           150:        extern void translate();
        !           151:        static char pbuf[2*(MAXPH+2)];
        !           152:        register char *fp, *tp;
        !           153: 
        !           154:        for (tp=pbuf; *arg; arg++) {
        !           155:                if (*arg != '\\') {
        !           156:                        *tp++ = *arg;
        !           157:                        continue;
        !           158:                } else {
        !           159:                        switch (*(arg+1)) {
        !           160:                        case 'T':
        !           161:                                exphone(phone, tp);
        !           162:                                translate(trstr, tp);
        !           163:                                for(; *tp; tp++)
        !           164:                                    ;
        !           165:                                arg++;
        !           166:                                break;
        !           167:                        case 'D':
        !           168:                                for(fp=phone; *tp = *fp++; tp++)
        !           169:                                    ;
        !           170:                                arg++;
        !           171:                                break;
        !           172:                        default:
        !           173:                                *tp++ = *arg;
        !           174:                                break;
        !           175:                        }
        !           176:                }
        !           177:        }
        !           178:        *tp = '\0';
        !           179:        return(pbuf);
        !           180: }
        !           181: 
        !           182: /*
        !           183:  * processdev - Process a line from the Devices file
        !           184:  *
        !           185:  * return codes:
        !           186:  *     file descriptor  -  succeeded
        !           187:  *     FAIL  -  failed
        !           188:  */
        !           189: 
        !           190: processdev(flds, dev)
        !           191: register char *flds[], *dev[];
        !           192: {
        !           193:        register int dcf = -1;
        !           194:        register struct caller  *ca;
        !           195:        char *args[D_MAX+1], dcname[20];
        !           196:        register char **sdev;
        !           197:        extern void translate();
        !           198:        register nullfd;
        !           199:        char *phonecl;                  /* clear phone string */
        !           200:        char phoneex[2*(MAXPH+2)];      /* expanded phone string */
        !           201: 
        !           202:        sdev = dev;
        !           203:        for (ca = Caller; ca->CA_type != NULL; ca++) {
        !           204:                /* This will find built-in caller functions */
        !           205:                if (EQUALS(ca->CA_type, dev[D_CALLER])) {
        !           206:                        DEBUG(5, "Internal caller type %s\n", dev[D_CALLER]);
        !           207:                        if (dev[D_ARG] == NULL) {
        !           208:                                /* if NULL - assume translate */
        !           209:                                dev[D_ARG+1] = NULL;    /* needed for for loop later to mark the end */
        !           210:                                dev[D_ARG] = "\\T";
        !           211:                        }
        !           212:                        dev[D_ARG] = repphone(dev[D_ARG], flds[F_PHONE], "");
        !           213:                        if ((dcf = (*(ca->CA_caller))(flds, dev)) < 0)
        !           214:                                return(dcf) ;
        !           215:                        dev += 2; /* Skip to next CALLER and ARG */
        !           216:                        break;
        !           217:                }
        !           218:        }
        !           219:        if (dcf == -1) {
        !           220:                /* Here if not a built-in caller function */
        !           221:                if (mlock(dev[D_LINE]) == FAIL) { /* Lock the line */
        !           222:                        DEBUG(5, "mlock %s failed\n", dev[D_LINE]);
        !           223:                        Uerror = SS_LOCKED_DEVICE;
        !           224:                        return(FAIL);
        !           225:                }
        !           226:                DEBUG(5, "mlock %s succeeded\n", dev[D_LINE]);
        !           227:                /*
        !           228:                 * Open the line
        !           229:                 */
        !           230:                (void) sprintf(dcname, "/dev/%s", dev[D_LINE]);
        !           231:                /* take care of the possible partial open fd */
        !           232:                (void) close(nullfd = open("/", 0));
        !           233:                if (setjmp(Sjbuf)) {
        !           234:                        (void) close(nullfd);
        !           235:                        DEBUG(1, "generic open timeout\n", "");
        !           236:                        logent("generic open", "TIMEOUT");
        !           237:                        Uerror = SS_CANT_ACCESS_DEVICE;
        !           238:                        goto bad;
        !           239:                }
        !           240:                (void) signal(SIGALRM, alarmtr);
        !           241:                (void) alarm(10);
        !           242:                dcf = open(dcname, 2);
        !           243:                (void) alarm(0);
        !           244:                if (dcf < 0) {
        !           245:                        (void) close(nullfd);
        !           246:                        DEBUG(1, "generic open failed, errno = %d\n", errno);
        !           247:                        logent("generic open", "FAILED");
        !           248:                        Uerror = SS_CANT_ACCESS_DEVICE;
        !           249:                        goto bad;
        !           250:                }
        !           251:                fixline(dcf, atoi(fdig(flds[F_CLASS])), D_DIRECT);
        !           252:        }
        !           253:        /*
        !           254:         * Now loop through the remaining callers and chat
        !           255:         * according to scripts in dialers file.
        !           256:         */
        !           257:        for (; dev[D_CALLER] != NULL; dev += 2) {
        !           258:                register int w;
        !           259:                /*
        !           260:                 * Scan Dialers file to find an entry
        !           261:                 */
        !           262:                if ((w = gdial(dev[D_CALLER], args, D_MAX)) < 1) {
        !           263:                        DEBUG(1, "%s not found in Dialers file\n", dev[D_CALLER]);
        !           264:                        logent("generic call to gdial", "FAILED");
        !           265:                        Uerror = SS_CANT_ACCESS_DEVICE;
        !           266:                        goto bad;
        !           267:                }
        !           268:                if (w <= 2)     /* do nothing - no chat */
        !           269:                        break;
        !           270:                /*
        !           271:                 * Translate the phone number
        !           272:                 */
        !           273:                if (dev[D_ARG] == NULL) {
        !           274:                        /* if NULL - assume no translation */
        !           275:                        dev[D_ARG+1] = NULL; /* needed for for loop to mark the end */
        !           276:                        dev[D_ARG] = "\\D";
        !           277:                }
        !           278:                
        !           279:                phonecl = repphone(dev[D_ARG], flds[F_PHONE], args[1]);
        !           280:                exphone(phonecl, phoneex);
        !           281:                translate(args[1], phoneex);
        !           282:                /*
        !           283:                 * Chat
        !           284:                 */
        !           285:                if (chat(w-2, &args[2], dcf, phonecl, phoneex) != SUCCESS) {
        !           286:                        Uerror = SS_CHAT_FAILED;
        !           287:                        goto bad;
        !           288:                }
        !           289:        }
        !           290:        /*
        !           291:         * Success at last!
        !           292:         */
        !           293:        strcpy(Dc, sdev[D_LINE]);
        !           294:        return(dcf);
        !           295: bad:
        !           296:        (void)close(dcf);
        !           297:        delock(sdev[D_LINE]);
        !           298:        return(FAIL);
        !           299: }
        !           300: 
        !           301: /*
        !           302:  * translate the pairs of characters present in the first
        !           303:  * string whenever the first of the pair appears in the second
        !           304:  * string.
        !           305:  */
        !           306: static void
        !           307: translate(ttab, str)
        !           308: register char *ttab, *str;
        !           309: {
        !           310:        register char *s;
        !           311: 
        !           312:        for(;*ttab && *(ttab+1); ttab += 2)
        !           313:                for(s=str;*s;s++)
        !           314:                        if(*ttab == *s)
        !           315:                                *s = *(ttab+1);
        !           316: }
        !           317: 
        !           318: #define MAXLINE        512
        !           319: /*
        !           320:  * Get the information about the dialer.
        !           321:  * gdial(type, arps, narps)
        !           322:  *     type    -> type of dialer (e.g., penril)
        !           323:  *     arps    -> array of pointers returned by gdial
        !           324:  *     narps   -> number of elements in array returned by gdial
        !           325:  * Return value:
        !           326:  *     -1      -> Can't open DIALERFILE
        !           327:  *     0       -> requested type not found
        !           328:  *     >0      -> success - number of fields filled in
        !           329:  */
        !           330: static
        !           331: gdial(type, arps, narps)
        !           332: register char *type, *arps[];
        !           333: register int narps;
        !           334: {
        !           335:        static char info[MAXLINE];
        !           336:        register FILE *ldial;
        !           337:        register na;
        !           338: 
        !           339:        DEBUG(2, "gdial(%s) called\n", type);
        !           340:        if ((ldial = fopen(DIALERFILE, "r")) == NULL)
        !           341:                return(-1);
        !           342:        while (fgets(info, sizeof(info), ldial) != NULL) {
        !           343:                if ((info[0] == '#') || (info[0] == ' ') ||
        !           344:                    (info[0] == '\t') || (info[0] == '\n'))
        !           345:                        continue;
        !           346:                if ((na = getargs(info, arps, narps)) == 0)
        !           347:                        continue;
        !           348:                if (EQUALS(arps[0], type)) {
        !           349:                        (void)fclose(ldial);
        !           350:                        bsfix(arps);
        !           351:                        return(na);
        !           352:                }
        !           353:        }
        !           354:        (void)fclose(ldial);
        !           355:        return(0);
        !           356: }
        !           357: 
        !           358: 
        !           359: #ifdef DATAKIT
        !           360: 
        !           361: /***
        !           362:  *     dkcall(flds, dev)       make a DATAKIT VCS connection
        !           363:  *                               DATAKIT VCS is a trademark of AT&T
        !           364:  *
        !           365:  *     return codes:
        !           366:  *             >0 - file number - ok
        !           367:  *             FAIL - failed
        !           368:  */
        !           369: 
        !           370: #include "dk.h"
        !           371: 
        !           372: dkcall(flds, dev)
        !           373: char *flds[], *dev[];
        !           374: {
        !           375:        register fd;
        !           376: #ifdef V8
        !           377:        extern int dkp_ld;
        !           378: #endif
        !           379: 
        !           380:        char    dialstring[64];
        !           381: 
        !           382:        strcpy(dialstring, dev[D_ARG]);
        !           383: 
        !           384: #ifndef STANDALONE
        !           385:        if(*flds[F_CLASS] < '0' || *flds[F_CLASS] > '9')
        !           386:                sprintf(dialstring, "%s.%s", dev[D_ARG], flds[F_CLASS]);
        !           387: #endif
        !           388: 
        !           389:        DEBUG(4, "dkcall(%s)\n", dialstring);
        !           390: 
        !           391: 
        !           392: #ifdef V8
        !           393:        if (setjmp(Sjbuf)) {
        !           394:                Uerror = SS_DIAL_FAILED;
        !           395:                return(FAIL);
        !           396:        }
        !           397: 
        !           398:        (void) signal(SIGALRM, alarmtr);
        !           399:        (void) alarm(70);
        !           400:        DEBUG(4, "tdkdial(%s", dialstring);
        !           401:        DEBUG(4, ", %d)\n", atoi(flds[F_CLASS]));
        !           402:        if ((fd = tdkdial(dialstring, atoi(flds[F_CLASS]))) >= 0)
        !           403:            if (dkproto(fd, dkp_ld) < 0)
        !           404:               {
        !           405:                close(fd);
        !           406:                fd = -1;
        !           407:               }
        !           408:        (void) alarm(0);
        !           409: #else  
        !           410:        fd = dkdial(dialstring);
        !           411: #endif
        !           412: 
        !           413:        (void) strcpy(Dc, "DK");
        !           414:        if (fd < 0) {
        !           415:                Uerror = SS_DIAL_FAILED;
        !           416:                return(FAIL);
        !           417:        }
        !           418:        else
        !           419:                return(fd);
        !           420: }
        !           421: 
        !           422: #endif DATAKIT
        !           423: 
        !           424: #ifdef TCP
        !           425: 
        !           426: /***
        !           427:  *     tcpcall(flds, dev)      make ethernet/socket connection
        !           428:  *
        !           429:  *     return codes:
        !           430:  *             >0 - file number - ok
        !           431:  *             FAIL - failed
        !           432:  *
        !           433:  *     the internet address is the phone number
        !           434:  *     the port is the call device
        !           435:  */
        !           436: 
        !           437: #ifdef V8
        !           438: tcpcall(flds, dev)
        !           439: char *flds[], *dev[];
        !           440: {
        !           441:        int ret;
        !           442:        int port;
        !           443:        extern int      errno, sys_nerr;
        !           444:        extern char *sys_errlist[];
        !           445:        struct in_service *sp;
        !           446:        struct tcpuser poot;
        !           447: 
        !           448:        poot.fport = atoi(dev[D_CALLDEV]);
        !           449:        if (poot.fport == 0) {
        !           450:                sp = in_service("uucp", "tcp", 0);
        !           451:                ASSERT(sp != NULL, "No uucp server", 0, 0);
        !           452:                poot.fport = sp->port;
        !           453:        }
        !           454:        if ((poot.faddr = in_address(dev[D_ARG])) == 0) {
        !           455:                logent("tcpopen", "no such host");
        !           456:                Uerror = SS_BADSYSTEM;
        !           457:                return(FAIL);
        !           458:        }
        !           459:        DEBUG(4, "tcpdial host %s, ", dev[D_ARG]);
        !           460:        DEBUG(4, "port %d\n", poot.fport);
        !           461: 
        !           462:        ret = tcp_sock();
        !           463:        if (ret < 0) {
        !           464:                if (errno < sys_nerr) {
        !           465:                        DEBUG(5, "no socket: %s\n", sys_errlist[errno]);
        !           466:                        logent("no socket", sys_errlist[errno]);
        !           467:                }
        !           468:                else {
        !           469:                        DEBUG(5, "no socket, errno %d\n", errno);
        !           470:                        logent("tcpopen", "NO SOCKET");
        !           471:                }
        !           472:                Uerror = SS_NO_DEVICE;
        !           473:                return(FAIL);
        !           474:        }
        !           475:        if (setjmp(Sjbuf)) {
        !           476:                DEBUG(4, "timeout tcpopen\n", "");
        !           477:                logent("tcpopen", "TIMEOUT");
        !           478:                Uerror = SS_DIAL_FAILED;
        !           479:                return(FAIL);
        !           480:        }
        !           481:        (void) signal(SIGALRM, alarmtr);
        !           482:        (void) alarm(30);
        !           483:        DEBUG(7, "addr: %s\n", in_ntoa(poot.faddr));
        !           484:        poot.lport = 0;
        !           485:        poot.param = 0;
        !           486:        poot.laddr = 0;
        !           487:        if (tcp_connect(ret, &poot) < 0) {
        !           488:                (void) alarm(0);
        !           489:                (void) close(ret);
        !           490:                if (errno < sys_nerr) {
        !           491:                        DEBUG(5, "connect failed: %s\n", sys_errlist[errno]);
        !           492:                        logent("connect failed", sys_errlist[errno]);
        !           493:                }
        !           494:                else {
        !           495:                        DEBUG(5, "connect failed, errno %d\n", errno);
        !           496:                        logent("tcpopen", "CONNECT FAILED");
        !           497:                }
        !           498:                Uerror = SS_DIAL_FAILED;
        !           499:                return(FAIL);
        !           500:        }
        !           501:        (void) signal(SIGPIPE, SIG_IGN);  /* watch out for broken ipc link...*/
        !           502:        (void) alarm(0);
        !           503:        (void) strcpy(Dc, "IPC");
        !           504:        return(ret);
        !           505: }
        !           506: #else
        !           507: #ifdef BSD4_2
        !           508: tcpcall(flds, dev)
        !           509: char *flds[], *dev[];
        !           510: {
        !           511:        int ret;
        !           512:        short port;
        !           513:        extern int      errno, sys_nerr;
        !           514:        extern char *sys_errlist[];
        !           515:        struct servent *sp;
        !           516:        struct hostent *hp;
        !           517:        struct sockaddr_in sin;
        !           518: 
        !           519:        port = atoi(dev[D_CALLDEV]);
        !           520:        if (port == 0) {
        !           521:                sp = getservbyname("uucp", "tcp");
        !           522:                ASSERT(sp != NULL, "No uucp server", 0, 0);
        !           523:                port = sp->s_port;
        !           524:        }
        !           525:        else port = htons(port);
        !           526:        hp = gethostbyname(dev[D_ARG]);
        !           527:        if (hp == NULL) {
        !           528:                logent("tcpopen", "no such host");
        !           529:                Uerror = SS_BADSYSTEM;
        !           530:                return(FAIL);
        !           531:        }
        !           532:        DEBUG(4, "tcpdial host %s, ", dev[D_ARG]);
        !           533:        DEBUG(4, "port %d\n", ntohs(port));
        !           534: 
        !           535:        ret = socket(AF_INET, SOCK_STREAM, 0);
        !           536:        if (ret < 0) {
        !           537:                if (errno < sys_nerr) {
        !           538:                        DEBUG(5, "no socket: %s\n", sys_errlist[errno]);
        !           539:                        logent("no socket", sys_errlist[errno]);
        !           540:                }
        !           541:                else {
        !           542:                        DEBUG(5, "no socket, errno %d\n", errno);
        !           543:                        logent("tcpopen", "NO SOCKET");
        !           544:                }
        !           545:                Uerror = SS_NO_DEVICE;
        !           546:                return(FAIL);
        !           547:        }
        !           548:        sin.sin_family = hp->h_addrtype;
        !           549:        bcopy(hp->h_addr, (caddr_t)&sin.sin_addr, hp->h_length);
        !           550:        sin.sin_port = port;
        !           551:        if (setjmp(Sjbuf)) {
        !           552:                DEBUG(4, "timeout tcpopen\n", "");
        !           553:                logent("tcpopen", "TIMEOUT");
        !           554:                Uerror = SS_NO_DEVICE;
        !           555:                return(FAIL);
        !           556:        }
        !           557:        (void) signal(SIGALRM, alarmtr);
        !           558:        (void) alarm(30);
        !           559:        DEBUG(7, "family: %d\n", sin.sin_family);
        !           560:        DEBUG(7, "port: %d\n", sin.sin_port);
        !           561:        DEBUG(7, "addr: %08x\n",*((int *) &sin.sin_addr));
        !           562:        if (connect(ret, (caddr_t)&sin, sizeof (sin)) < 0) {
        !           563:                (void) alarm(0);
        !           564:                (void) close(ret);
        !           565:                if (errno < sys_nerr) {
        !           566:                        DEBUG(5, "connect failed: %s\n", sys_errlist[errno]);
        !           567:                        logent("connect failed", sys_errlist[errno]);
        !           568:                }
        !           569:                else {
        !           570:                        DEBUG(5, "connect failed, errno %d\n", errno);
        !           571:                        logent("tcpopen", "CONNECT FAILED");
        !           572:                }
        !           573:                Uerror = SS_NO_DEVICE;
        !           574:                return(FAIL);
        !           575:        }
        !           576:        (void) signal(SIGPIPE, SIG_IGN);  /* watch out for broken ipc link...*/
        !           577:        (void) alarm(0);
        !           578:        (void) strcpy(Dc, "IPC");
        !           579:        return(ret);
        !           580: }
        !           581: #endif
        !           582: #endif
        !           583: 
        !           584: 
        !           585: /***
        !           586:  *     unetcall(flds, dev)     make ethernet connection
        !           587:  *
        !           588:  *     return codes:
        !           589:  *             >0 - file number - ok
        !           590:  *             FAIL - failed
        !           591:  */
        !           592: 
        !           593: #ifdef UNET
        !           594: unetcall(flds, dev)
        !           595: char *flds[], *dev[];
        !           596: {
        !           597:        int ret;
        !           598:        int port;
        !           599:        extern int      errno;
        !           600: 
        !           601:        port = atoi(dev[D_ARG]);
        !           602:        DEBUG(4, "unetdial host %s, ", flds[F_NAME]);
        !           603:        DEBUG(4, "port %d\n", port);
        !           604:        (void) alarm(30);
        !           605:        ret = tcpopen(flds[F_NAME], port, 0, TO_ACTIVE, "rw");
        !           606:        (void) alarm(0);
        !           607:        endhnent();     /* wave magic wand at 3com and incant "eat it, bruce" */
        !           608:        if (ret < 0) {
        !           609:                DEBUG(5, "tcpopen failed: errno %d\n", errno);
        !           610:                Uerror = SS_DIAL_FAILED;
        !           611:                return(FAIL);
        !           612:        }
        !           613:        (void) strcpy(Dc, "UNET");
        !           614:        return(ret);
        !           615: }
        !           616: #endif UNET
        !           617: 
        !           618: #endif /* TCP */
        !           619: 
        !           620: #ifdef CSERV
        !           621: 
        !           622: #include <ipc.h>
        !           623: 
        !           624: cscall(flds, dev)
        !           625: char   *flds[], *dev[];
        !           626: {
        !           627:        int fd;
        !           628:        register char *p;
        !           629:        char *rem;
        !           630:        extern int errno;
        !           631:        extern char *errstr;
        !           632: 
        !           633:        rem = dev[D_ARG];
        !           634:        if (*dev[D_CALLDEV] == '.') {
        !           635:                for (p = rem; *p; p++)
        !           636:                        if (*p == '.') {
        !           637:                                *p = '!';       /* sad but true */
        !           638:                                break;
        !           639:                        }
        !           640:        }
        !           641:        rem = ipcpath(rem, (char *)NULL, (char *)NULL);
        !           642:        DEBUG(4, "ipcopen(%s, ", rem);
        !           643:        DEBUG(4, "%s)\n", dev[D_LINE]);
        !           644:        if ((fd = ipcopen(rem, dev[D_LINE])) >= 0)
        !           645:                return (fd);
        !           646:        DEBUG(4, "ipcopen failed, error %d ", errno);
        !           647:        DEBUG(4, "%s\n", errstr);
        !           648:        /* should think more about errors */
        !           649:        Uerror = SS_DIAL_FAILED;
        !           650:        return(FAIL);
        !           651: }
        !           652: #endif
        !           653: 
        !           654: #ifdef SYTEK
        !           655: 
        !           656: /****
        !           657:  *     sytcall(flds, dev)      make a sytek connection
        !           658:  *
        !           659:  *     return codes:
        !           660:  *             >0 - file number - ok
        !           661:  *             FAIL - failed
        !           662:  */
        !           663: 
        !           664: /*ARGSUSED*/
        !           665: sytcall(flds, dev)
        !           666: char *flds[], *dev[];
        !           667: {
        !           668:        extern int errno;
        !           669:        int dcr, dcr2, nullfd, ret;
        !           670:        char dcname[20], command[BUFSIZ];
        !           671: 
        !           672:        (void) sprintf(dcname, "/dev/%s", dev[D_LINE]);
        !           673:        DEBUG(4, "dc - %s, ", dcname);
        !           674:        dcr = open(dcname, O_WRONLY|O_NDELAY);
        !           675:        if (dcr < 0) {
        !           676:                Uerror = SS_DIAL_FAILED;
        !           677:                DEBUG(4, "OPEN FAILED %s\n", dcname);
        !           678:                delock(dev[D_LINE]);
        !           679:                return(FAIL);
        !           680:        }
        !           681: 
        !           682:        sytfixline(dcr, atoi(fdig(dev[D_CLASS])), D_DIRECT);
        !           683:        (void) sleep(2);
        !           684:        (void) sprintf(command,"\r\rcall %s\r",flds[F_PHONE]);
        !           685:        ret = write(dcr, command, strlen(command));
        !           686:        (void) sleep(1);
        !           687:        DEBUG(4, "COM1 return = %d\n", ret);
        !           688:        sytfix2line(dcr);
        !           689:        (void) close(nullfd = open("/", 0));
        !           690:        (void) signal(SIGALRM, alarmtr);
        !           691:        if (setjmp(Sjbuf)) {
        !           692:                DEBUG(4, "timeout sytek open\n", "");
        !           693:                (void) close(nullfd);
        !           694:                (void) close(dcr2);
        !           695:                (void) close(dcr);
        !           696:                Uerror = SS_DIAL_FAILED;
        !           697:                delock(dev[D_LINE]);
        !           698:                return(FAIL);
        !           699:        }
        !           700:        (void) alarm(10);
        !           701:        dcr2 = open(dcname,O_RDWR);
        !           702:        (void) alarm(0);
        !           703:        (void) close(dcr);
        !           704:        if (dcr2 < 0) {
        !           705:                DEBUG(4, "OPEN 2 FAILED %s\n", dcname);
        !           706:                Uerror = SS_DIAL_FAILED;
        !           707:                (void) close(nullfd);   /* kernel might think dc2 is open */
        !           708:                delock(dev[D_LINE]);
        !           709:                return(FAIL);
        !           710:        }
        !           711:        return(dcr2);
        !           712: }
        !           713: 
        !           714: #endif SYTEK
        !           715: 
        !           716: #ifdef DIAL801
        !           717: 
        !           718: /***
        !           719:  *     dial801(flds, dev)      dial remote machine on 801/801
        !           720:  *     char *flds[], *dev[];
        !           721:  *
        !           722:  *     return codes:
        !           723:  *             file descriptor  -  succeeded
        !           724:  *             FAIL  -  failed
        !           725:  *
        !           726:  *     unfortunately, open801() is different for usg and non-usg
        !           727:  */
        !           728: 
        !           729: /*ARGSUSED*/
        !           730: dial801(flds, dev)
        !           731: char *flds[], *dev[];
        !           732: {
        !           733:        char dcname[20], dnname[20], phone[MAXPH+2], *fdig();
        !           734:        int dcf = -1, speed;
        !           735: 
        !           736:        if (mlock(dev[D_LINE]) == FAIL) {
        !           737:                DEBUG(5, "mlock %s failed\n", dev[D_LINE]);
        !           738:                Uerror = SS_LOCKED_DEVICE;
        !           739:                return(FAIL);
        !           740:        }
        !           741:        (void) sprintf(dnname, "/dev/%s", dev[D_CALLDEV]);
        !           742:        (void) sprintf(phone, "%s%s", dev[D_ARG]   , ACULAST);
        !           743:        (void) sprintf(dcname, "/dev/%s", dev[D_LINE]);
        !           744:        CDEBUG(1, "Use Port %s, ", dcname);
        !           745:        DEBUG(4, "acu - %s, ", dnname);
        !           746:        CDEBUG(1, "Phone Number  %s\n", phone);
        !           747:        VERBOSE("Trying modem - %s, ", dcname); /* for cu */
        !           748:        VERBOSE("acu - %s, ", dnname);  /* for cu */
        !           749:        VERBOSE("calling  %s:  ", phone);       /* for cu */
        !           750:        speed = atoi(fdig(dev[D_CLASS]));
        !           751:        dcf = open801(dcname, dnname, phone, speed);
        !           752:        if (dcf >= 0) {
        !           753:                fixline(dcf, speed, D_ACU);
        !           754:                (void) strcpy(Dc, dev[D_LINE]); /* for later unlock() */
        !           755:                VERBOSE("SUCCEEDED\n", 0);
        !           756:        } else {
        !           757:                delock(dev[D_LINE]);
        !           758:                VERBOSE("FAILED\n", 0);
        !           759:        }
        !           760:        return(dcf);
        !           761: }
        !           762: 
        !           763: 
        !           764: #ifndef ATTSV
        !           765: /*ARGSUSED*/
        !           766: open801(dcname, dnname, phone, speed)
        !           767: char *dcname, *dnname, *phone;
        !           768: {
        !           769:        int nw, lt, pid = -1, dcf = -1, nullfd, dnf = -1;
        !           770:        int rpid;
        !           771:        unsigned timelim;
        !           772: 
        !           773:        if ((dnf = open(dnname, 1)) < 0) {
        !           774:                DEBUG(5, "can't open %s\n", dnname);
        !           775:                Uerror = SS_CANT_ACCESS_DEVICE;
        !           776:                return(FAIL);
        !           777:        }
        !           778:        DEBUG(5, "%s is open\n", dnname);
        !           779: 
        !           780:        (void) close(nullfd = open("/dev/null", 0));    /* partial open hack */
        !           781:        if (setjmp(Sjbuf)) {
        !           782:                DEBUG(4, "timeout modem open\n", "");
        !           783:                logent("801 open", "TIMEOUT");
        !           784:                (void) close(nullfd);
        !           785:                (void) close(dcf);
        !           786:                (void) close(dnf);
        !           787:                if (pid > 0) {
        !           788:                        kill(pid, 9);
        !           789:                        while ((rpid = wait((int *) 0)) > 0 && rpid != pid)
        !           790:                                ;
        !           791:                }
        !           792:                Uerror = SS_DIAL_FAILED;
        !           793:                return(FAIL);
        !           794:        }
        !           795:        (void) signal(SIGALRM, alarmtr);
        !           796:        timelim = 5 * strlen(phone);
        !           797:        (void) alarm(timelim < 30 ? 30 : timelim);
        !           798:        if ((pid = fork()) == 0) {
        !           799:                sleep(2);
        !           800:                nw = write(dnf, phone, lt = strlen(phone));
        !           801:                if (nw != lt) {
        !           802:                        DEBUG(4, "ACU write error %d\n", errno);
        !           803:                        logent("ACU write", "FAILED");
        !           804:                        exit(1);
        !           805:                }
        !           806:                DEBUG(4, "ACU write ok%s\n", "");
        !           807:                exit(0);
        !           808:        }
        !           809:        /*  open line - will return on carrier */
        !           810:        dcf = open(dcname, 2);
        !           811: 
        !           812:        DEBUG(4, "dcf is %d\n", dcf);
        !           813:        if (dcf < 0) {  /* handle like a timeout */
        !           814:                (void) alarm(0);
        !           815:                longjmp(Sjbuf, 1);
        !           816:        }
        !           817: 
        !           818:        /* modem is open */
        !           819:        while ((nw = wait(&lt)) != pid && nw != -1)
        !           820:                ;
        !           821:        (void) alarm(0);
        !           822: 
        !           823:        (void) close(dnf);      /* no reason to keep the 801 open */
        !           824:        if (lt != 0) {
        !           825:                DEBUG(4, "Fork Stat %o\n", lt);
        !           826:                (void) close(dcf);
        !           827:                Uerror = SS_DIAL_FAILED;
        !           828:                return(FAIL);
        !           829:        }
        !           830:        return(dcf);
        !           831: }
        !           832: 
        !           833: #else
        !           834: 
        !           835: open801(dcname, dnname, phone, speed)
        !           836: char *dcname, *dnname, *phone;
        !           837: {
        !           838:        int nw, lt, dcf = -1, nullfd, dnf = -1, ret;
        !           839:        unsigned timelim;
        !           840: 
        !           841:        (void) close(nullfd = open("/", 0));    /* partial open hack */
        !           842:        if (setjmp(Sjbuf)) {
        !           843:                DEBUG(4, "DN write %s\n", "timeout");
        !           844:                (void) close(dnf);
        !           845:                (void) close(dcf);
        !           846:                (void) close(nullfd);
        !           847:                Uerror = SS_DIAL_FAILED;
        !           848:                return(FAIL);
        !           849:        }
        !           850:        (void) signal(SIGALRM, alarmtr);
        !           851:        timelim = 5 * strlen(phone);
        !           852:        (void) alarm(timelim < 30 ? 30 : timelim);
        !           853: 
        !           854:        if ((dnf = open(dnname, O_WRONLY)) < 0 ) {
        !           855:                DEBUG(5, "can't open %s\n", dnname);
        !           856:                Uerror = SS_CANT_ACCESS_DEVICE;
        !           857:                return(FAIL);
        !           858:        }
        !           859:        DEBUG(5, "%s is open\n", dnname);
        !           860:        if (  (dcf = open(dcname, O_RDWR | O_NDELAY)) < 0 ) {
        !           861:                DEBUG(5, "can't open %s\n", dcname);
        !           862:                Uerror = SS_CANT_ACCESS_DEVICE;
        !           863:                return(FAIL);
        !           864:        }
        !           865: 
        !           866:        DEBUG(4, "dcf is %d\n", dcf);
        !           867:        fixline(dcf, speed, D_ACU);
        !           868:        nw = write(dnf, phone, lt = strlen(phone));
        !           869:        if (nw != lt) {
        !           870:                (void) alarm(0);
        !           871:                DEBUG(4, "ACU write error %d\n", errno);
        !           872:                (void) close(dnf);
        !           873:                (void) close(dcf);
        !           874:                Uerror = SS_DIAL_FAILED;
        !           875:                return(FAIL);
        !           876:        } else 
        !           877:                DEBUG(4, "ACU write ok%s\n", "");
        !           878: 
        !           879:        (void) close(dnf);
        !           880:        (void) close(nullfd = open("/", 0));    /* partial open hack */
        !           881:        ret = open(dcname, 2);  /* wait for carrier  */
        !           882:        (void) alarm(0);
        !           883:        (void) close(ret);      /* close 2nd modem open() */
        !           884:        if (ret < 0) {          /* open() interrupted by alarm */
        !           885:                DEBUG(4, "Line open %s\n", "failed");
        !           886:                Uerror = SS_DIAL_FAILED;
        !           887:                (void) close(nullfd);           /* close partially opened modem */
        !           888:                return(FAIL);
        !           889:        }
        !           890:        (void) fcntl(dcf,F_SETFL, fcntl(dcf, F_GETFL, 0) & ~O_NDELAY);
        !           891:        return(dcf);
        !           892: }
        !           893: #endif
        !           894: 
        !           895: #endif
        !           896: 
        !           897: #ifdef V8
        !           898: Dialout(flds)
        !           899: char *flds[];
        !           900: {
        !           901:     int fd;
        !           902:     char phone[MAXPH+2];
        !           903: 
        !           904:     exphone(flds[F_PHONE], phone);
        !           905: 
        !           906:     DEBUG(4, "call dialout(%s", phone);
        !           907:     DEBUG(4, ", %s)\n", flds[F_CLASS]);
        !           908:     fd = dialout(phone, flds[F_CLASS]);
        !           909:     if (fd >= 0)
        !           910:        fixline(fd, 0, D_ACU);
        !           911:     else if (fd == -1)
        !           912:        Uerror = SS_NO_DEVICE;
        !           913:     else if (fd == -3)
        !           914:        Uerror = SS_DIAL_FAILED;
        !           915:     else if (fd == -9)
        !           916:        Uerror = SS_DEVICE_FAILED;
        !           917: 
        !           918:     (void) strcpy(Dc, "Dialout");
        !           919: 
        !           920:     return(fd);
        !           921: }
        !           922: #endif DIAL801

unix.superglobalmegacorp.com

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