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