17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5004388ebScasper * Common Development and Distribution License (the "License"). 6004388ebScasper * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 2161961e0fSrobinson 227c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 237c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate /* 26*d67944fbSScott Rotondo * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 277c478bd9Sstevel@tonic-gate * Use is subject to license terms. 287c478bd9Sstevel@tonic-gate */ 297c478bd9Sstevel@tonic-gate 30e8031f0aSraf #include "mt.h" 317c478bd9Sstevel@tonic-gate #include "uucp.h" 327c478bd9Sstevel@tonic-gate 3361961e0fSrobinson static void alarmtr(int); 3461961e0fSrobinson static jmp_buf Sjbuf; 3561961e0fSrobinson static char *fdig(char *); 3661961e0fSrobinson #ifndef SMALL 3761961e0fSrobinson static char *strecpy(char *, char *, char *); 387c478bd9Sstevel@tonic-gate #endif 3961961e0fSrobinson static int interface(const char *); 4061961e0fSrobinson static int fd_mklock(int); 4161961e0fSrobinson static int getdialline(char *, int); 4261961e0fSrobinson static int chat(int, char *[], int, char *, char *); 4361961e0fSrobinson static void fixline(), fd_rmlock(); 4461961e0fSrobinson static void translate(char *, char *); 4561961e0fSrobinson static int gdial(char *, char *[], int); 4661961e0fSrobinson static int Modemctrl; 4761961e0fSrobinson static unsigned connecttime; 4861961e0fSrobinson static int (*Setup)(); 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /* 517c478bd9Sstevel@tonic-gate * to add a new caller: 527c478bd9Sstevel@tonic-gate * declare the function that knows how to call on the device, 537c478bd9Sstevel@tonic-gate * add a line to the callers table giving the name of the device 547c478bd9Sstevel@tonic-gate * (from Devices file) and the name of the function 557c478bd9Sstevel@tonic-gate * add the function to the end of this file 567c478bd9Sstevel@tonic-gate */ 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate #ifdef TLI 5961961e0fSrobinson static int tlicall(char *[], char *[]); 607c478bd9Sstevel@tonic-gate #endif /* TLI */ 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate static struct caller Caller[] = { 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate #ifdef TLI 657c478bd9Sstevel@tonic-gate {"TLI", tlicall}, /* AT&T Transport Layer Interface */ 667c478bd9Sstevel@tonic-gate #ifdef TLIS 677c478bd9Sstevel@tonic-gate {"TLIS", tlicall}, /* AT&T Transport Layer Interface */ 687c478bd9Sstevel@tonic-gate #endif /* TLIS */ 697c478bd9Sstevel@tonic-gate #endif /* TLI */ 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate {NULL, NULL} /* this line must be last */ 727c478bd9Sstevel@tonic-gate }; 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate /* 757c478bd9Sstevel@tonic-gate * exphone - expand phone number for given prefix and number 767c478bd9Sstevel@tonic-gate * 777c478bd9Sstevel@tonic-gate * return code - none 787c478bd9Sstevel@tonic-gate */ 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate static void 8161961e0fSrobinson exphone(char *in, char *out) 827c478bd9Sstevel@tonic-gate { 837c478bd9Sstevel@tonic-gate FILE *fn; 847c478bd9Sstevel@tonic-gate char pre[MAXPH], npart[MAXPH], tpre[MAXPH], p[MAXPH]; 857c478bd9Sstevel@tonic-gate char buf[BUFSIZ]; 867c478bd9Sstevel@tonic-gate char *s1; 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate if (!isalpha(*in)) { 897c478bd9Sstevel@tonic-gate (void) strcpy(out, in); 907c478bd9Sstevel@tonic-gate return; 917c478bd9Sstevel@tonic-gate } 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate s1 = pre; 947c478bd9Sstevel@tonic-gate while (isalpha(*in)) 957c478bd9Sstevel@tonic-gate *s1++ = *in++; 967c478bd9Sstevel@tonic-gate *s1 = NULLCHAR; 977c478bd9Sstevel@tonic-gate s1 = npart; 987c478bd9Sstevel@tonic-gate while (*in != NULLCHAR) 997c478bd9Sstevel@tonic-gate *s1++ = *in++; 1007c478bd9Sstevel@tonic-gate *s1 = NULLCHAR; 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate tpre[0] = NULLCHAR; 103004388ebScasper fn = fopen(DIALCODES, "rF"); 1047c478bd9Sstevel@tonic-gate if (fn != NULL) { 1057c478bd9Sstevel@tonic-gate while (fgets(buf, BUFSIZ, fn)) { 10661961e0fSrobinson if (sscanf(buf, "%60s%60s", p, tpre) < 1) 1077c478bd9Sstevel@tonic-gate continue; 1087c478bd9Sstevel@tonic-gate if (EQUALS(p, pre)) 1097c478bd9Sstevel@tonic-gate break; 1107c478bd9Sstevel@tonic-gate tpre[0] = NULLCHAR; 1117c478bd9Sstevel@tonic-gate } 11261961e0fSrobinson (void) fclose(fn); 1137c478bd9Sstevel@tonic-gate } 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate (void) strcpy(out, tpre); 1167c478bd9Sstevel@tonic-gate (void) strcat(out, npart); 1177c478bd9Sstevel@tonic-gate } 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate /* 1207c478bd9Sstevel@tonic-gate * repphone - Replace \D and \T sequences in arg with phone 1217c478bd9Sstevel@tonic-gate * expanding and translating as appropriate. 1227c478bd9Sstevel@tonic-gate */ 1237c478bd9Sstevel@tonic-gate static char * 12461961e0fSrobinson repphone(char *arg, char *phone, char *trstr) 1257c478bd9Sstevel@tonic-gate { 1267c478bd9Sstevel@tonic-gate static char *pbuf; /* dynamically allocated below */ 12761961e0fSrobinson char *fp, *tp; 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate if (pbuf == NULL) { 13061961e0fSrobinson pbuf = malloc(2*(MAXPH+2)); 1317c478bd9Sstevel@tonic-gate if (pbuf == NULL) 1327c478bd9Sstevel@tonic-gate return (arg); 1337c478bd9Sstevel@tonic-gate } 1347c478bd9Sstevel@tonic-gate for (tp = pbuf; *arg; arg++) { 1357c478bd9Sstevel@tonic-gate if (*arg != '\\') { 1367c478bd9Sstevel@tonic-gate *tp++ = *arg; 1377c478bd9Sstevel@tonic-gate continue; 1387c478bd9Sstevel@tonic-gate } else { 1397c478bd9Sstevel@tonic-gate switch (*(arg+1)) { 1407c478bd9Sstevel@tonic-gate case 'T': 1417c478bd9Sstevel@tonic-gate exphone(phone, tp); 1427c478bd9Sstevel@tonic-gate translate(trstr, tp); 1437c478bd9Sstevel@tonic-gate for (; *tp; tp++) 1447c478bd9Sstevel@tonic-gate ; 1457c478bd9Sstevel@tonic-gate arg++; 1467c478bd9Sstevel@tonic-gate break; 1477c478bd9Sstevel@tonic-gate case 'D': 1487c478bd9Sstevel@tonic-gate for (fp = phone; *tp = *fp++; tp++) 1497c478bd9Sstevel@tonic-gate ; 1507c478bd9Sstevel@tonic-gate arg++; 1517c478bd9Sstevel@tonic-gate break; 1527c478bd9Sstevel@tonic-gate default: 1537c478bd9Sstevel@tonic-gate *tp++ = *arg; 1547c478bd9Sstevel@tonic-gate break; 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate } 1577c478bd9Sstevel@tonic-gate } 1587c478bd9Sstevel@tonic-gate *tp = '\0'; 1597c478bd9Sstevel@tonic-gate return (pbuf); 1607c478bd9Sstevel@tonic-gate } 1617c478bd9Sstevel@tonic-gate 16261961e0fSrobinson static uint_t saved_mode; 1637c478bd9Sstevel@tonic-gate static char saved_dcname[20]; 1647c478bd9Sstevel@tonic-gate 165*d67944fbSScott Rotondo static int pop_push(int); 166*d67944fbSScott Rotondo static void setdevcfg(char *, char *); 167*d67944fbSScott Rotondo static void ttygenbrk(int); 1687c478bd9Sstevel@tonic-gate /* 1697c478bd9Sstevel@tonic-gate * processdev - Process a line from the Devices file 1707c478bd9Sstevel@tonic-gate * 1717c478bd9Sstevel@tonic-gate * return codes: 1727c478bd9Sstevel@tonic-gate * file descriptor - succeeded 1737c478bd9Sstevel@tonic-gate * FAIL - failed 1747c478bd9Sstevel@tonic-gate */ 17561961e0fSrobinson static int 17661961e0fSrobinson processdev(char *flds[], char *dev[]) 1777c478bd9Sstevel@tonic-gate { 1787c478bd9Sstevel@tonic-gate int dcf = -1; 17961961e0fSrobinson struct caller *ca; 1807c478bd9Sstevel@tonic-gate char *args[D_MAX+1], dcname[20]; 18161961e0fSrobinson char **sdev; 1827c478bd9Sstevel@tonic-gate int nullfd; 1837c478bd9Sstevel@tonic-gate char *phonecl; /* clear phone string */ 1847c478bd9Sstevel@tonic-gate char phoneex[2*(MAXPH+2)]; /* expanded phone string */ 1857c478bd9Sstevel@tonic-gate struct termio tty_orig; 1867c478bd9Sstevel@tonic-gate int ret_orig = -1; 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate sdev = dev; 1897c478bd9Sstevel@tonic-gate /* set up default "break" routine */ 1907c478bd9Sstevel@tonic-gate genbrk = ttygenbrk; 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate /* initialize Devconfig info */ 1937c478bd9Sstevel@tonic-gate DEBUG(5, "processdev: calling setdevcfg(%s, ", Progname); 1947c478bd9Sstevel@tonic-gate DEBUG(5, "%s)\n", flds[F_TYPE]); 1957c478bd9Sstevel@tonic-gate setdevcfg(Progname, flds[F_TYPE]); 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate for (ca = Caller; ca->CA_type != NULL; ca++) { 1987c478bd9Sstevel@tonic-gate /* This will find built-in caller functions */ 1997c478bd9Sstevel@tonic-gate if (EQUALS(ca->CA_type, dev[D_CALLER])) { 2007c478bd9Sstevel@tonic-gate DEBUG(5, "Internal caller type %s\n", dev[D_CALLER]); 2017c478bd9Sstevel@tonic-gate if (dev[D_ARG] == NULL) { 2027c478bd9Sstevel@tonic-gate /* if NULL - assume translate */ 20361961e0fSrobinson /* needed for for loop later to mark the end */ 20461961e0fSrobinson dev[D_ARG+1] = NULL; 2057c478bd9Sstevel@tonic-gate dev[D_ARG] = "\\T"; 2067c478bd9Sstevel@tonic-gate } 2077c478bd9Sstevel@tonic-gate dev[D_ARG] = repphone(dev[D_ARG], flds[F_PHONE], ""); 20861961e0fSrobinson if ((dcf = (*(ca->CA_caller))(flds, dev)) < 0) 2097c478bd9Sstevel@tonic-gate return (dcf); 2107c478bd9Sstevel@tonic-gate if (interface(ca->CA_type)) { 2117c478bd9Sstevel@tonic-gate DEBUG(5, "interface(%s) failed", ca->CA_type); 2127c478bd9Sstevel@tonic-gate Uerror = SS_DEVICE_FAILED; 2137c478bd9Sstevel@tonic-gate /* restore vanilla unix interface */ 2147c478bd9Sstevel@tonic-gate (void) interface("UNIX"); 2157c478bd9Sstevel@tonic-gate return (FAIL); 2167c478bd9Sstevel@tonic-gate } 2177c478bd9Sstevel@tonic-gate dev += 2; /* Skip to next CALLER and ARG */ 2187c478bd9Sstevel@tonic-gate break; 2197c478bd9Sstevel@tonic-gate } 2207c478bd9Sstevel@tonic-gate } 2217c478bd9Sstevel@tonic-gate if (dcf == -1) { 2227c478bd9Sstevel@tonic-gate /* Here if not a built-in caller function */ 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate /* We do locking (file and advisory) after open */ 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate /* 2277c478bd9Sstevel@tonic-gate * Open the line 2287c478bd9Sstevel@tonic-gate */ 2297c478bd9Sstevel@tonic-gate if (*dev[D_LINE] != '/') { 23061961e0fSrobinson (void) snprintf(dcname, sizeof (dcname), 23161961e0fSrobinson "/dev/%s", dev[D_LINE]); 2327c478bd9Sstevel@tonic-gate } else { 2337c478bd9Sstevel@tonic-gate (void) strcpy(dcname, dev[D_LINE]); 2347c478bd9Sstevel@tonic-gate } 2357c478bd9Sstevel@tonic-gate /* take care of the possible partial open fd */ 2367c478bd9Sstevel@tonic-gate (void) close(nullfd = open("/", O_RDONLY)); 2377c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 2387c478bd9Sstevel@tonic-gate (void) close(nullfd); 2397c478bd9Sstevel@tonic-gate DEBUG(1, "generic open timeout\n%s", ""); 2407c478bd9Sstevel@tonic-gate logent("generic open", "TIMEOUT"); 2417c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE; 2427c478bd9Sstevel@tonic-gate goto bad; 2437c478bd9Sstevel@tonic-gate } 2447c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 2457c478bd9Sstevel@tonic-gate (void) alarm(10); 2467c478bd9Sstevel@tonic-gate if (Modemctrl) { 2477c478bd9Sstevel@tonic-gate DEBUG(7, "opening with O_NDELAY set\n%s", ""); 2487c478bd9Sstevel@tonic-gate dcf = open(dcname, (O_RDWR | O_NDELAY)); 2497c478bd9Sstevel@tonic-gate saved_mode = O_RDWR | O_NDELAY; 2507c478bd9Sstevel@tonic-gate } else { 2517c478bd9Sstevel@tonic-gate dcf = open(dcname, O_RDWR); 2527c478bd9Sstevel@tonic-gate saved_mode = O_RDWR; 2537c478bd9Sstevel@tonic-gate } 25461961e0fSrobinson (void) strcpy(saved_dcname, dcname); 2557c478bd9Sstevel@tonic-gate (void) alarm(0); 2567c478bd9Sstevel@tonic-gate if (dcf < 0) { 2577c478bd9Sstevel@tonic-gate DEBUG(1, "generic open failed, errno = %d\n", errno); 2587c478bd9Sstevel@tonic-gate (void) close(nullfd); 2597c478bd9Sstevel@tonic-gate logent("generic open", "FAILED"); 2607c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE; 2617c478bd9Sstevel@tonic-gate goto bad; 2627c478bd9Sstevel@tonic-gate } 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate /* check locks BEFORE modifying the stream */ 2657c478bd9Sstevel@tonic-gate 2667c478bd9Sstevel@tonic-gate if (fd_mklock(dcf) != SUCCESS) { 2677c478bd9Sstevel@tonic-gate DEBUG(1, "failed to lock device %s\n", dcname); 2687c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE; 2697c478bd9Sstevel@tonic-gate goto bad; 2707c478bd9Sstevel@tonic-gate } 2717c478bd9Sstevel@tonic-gate 2727c478bd9Sstevel@tonic-gate if (Modemctrl) { 2737c478bd9Sstevel@tonic-gate DEBUG(7, "clear O_NDELAY\n%s", ""); 274e8031f0aSraf if (fcntl(dcf, F_SETFL, 275e8031f0aSraf (fcntl(dcf, F_GETFL, 0) & ~O_NDELAY)) < 0) { 27661961e0fSrobinson DEBUG(7, "clear O_NDELAY failed, errno %d\n", 27761961e0fSrobinson errno); 2787c478bd9Sstevel@tonic-gate Uerror = SS_DEVICE_FAILED; 2797c478bd9Sstevel@tonic-gate goto bad; 2807c478bd9Sstevel@tonic-gate } 2817c478bd9Sstevel@tonic-gate } 2827c478bd9Sstevel@tonic-gate } 2837c478bd9Sstevel@tonic-gate 2847c478bd9Sstevel@tonic-gate if ((*Setup)(MASTER, &dcf, &dcf)) { 2857c478bd9Sstevel@tonic-gate /* any device|system lock files we should remove? */ 2867c478bd9Sstevel@tonic-gate DEBUG(5, "MASTER Setup failed%s", ""); 2877c478bd9Sstevel@tonic-gate Uerror = SS_DEVICE_FAILED; 2887c478bd9Sstevel@tonic-gate goto bad; 2897c478bd9Sstevel@tonic-gate } 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate /* configure any requested streams modules */ 2927c478bd9Sstevel@tonic-gate if (!pop_push(dcf)) { 2937c478bd9Sstevel@tonic-gate DEBUG(5, "STREAMS module configuration failed%s\n", ""); 2947c478bd9Sstevel@tonic-gate Uerror = SS_DEVICE_FAILED; 2957c478bd9Sstevel@tonic-gate goto bad; 2967c478bd9Sstevel@tonic-gate } 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate /* save initial state of line in case script fails */ 2997c478bd9Sstevel@tonic-gate ret_orig = ioctl(dcf, TCGETA, &tty_orig); 3007c478bd9Sstevel@tonic-gate 3017c478bd9Sstevel@tonic-gate /* use sdev[] since dev[] is incremented for internal callers */ 3027c478bd9Sstevel@tonic-gate fixline(dcf, atoi(fdig(sdev[D_CLASS])), D_DIRECT); 3037c478bd9Sstevel@tonic-gate 3047c478bd9Sstevel@tonic-gate /* 3057c478bd9Sstevel@tonic-gate * Now loop through the remaining callers and chat 3067c478bd9Sstevel@tonic-gate * according to scripts in dialers file. 3077c478bd9Sstevel@tonic-gate */ 3087c478bd9Sstevel@tonic-gate for (; dev[D_CALLER] != NULL; dev += 2) { 30961961e0fSrobinson int w; 3107c478bd9Sstevel@tonic-gate /* 3117c478bd9Sstevel@tonic-gate * Scan Dialers file to find an entry 3127c478bd9Sstevel@tonic-gate */ 3137c478bd9Sstevel@tonic-gate if ((w = gdial(dev[D_CALLER], args, D_MAX)) < 1) { 3147c478bd9Sstevel@tonic-gate logent("generic call to gdial", "FAILED"); 3157c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE; 3167c478bd9Sstevel@tonic-gate goto bad; 3177c478bd9Sstevel@tonic-gate } 3187c478bd9Sstevel@tonic-gate if (w <= 2) /* do nothing - no chat */ 3197c478bd9Sstevel@tonic-gate break; 3207c478bd9Sstevel@tonic-gate /* 3217c478bd9Sstevel@tonic-gate * Translate the phone number 3227c478bd9Sstevel@tonic-gate */ 3237c478bd9Sstevel@tonic-gate if (dev[D_ARG] == NULL) { 3247c478bd9Sstevel@tonic-gate /* if NULL - assume no translation */ 32561961e0fSrobinson /* needed for for loop to mark the end */ 32661961e0fSrobinson dev[D_ARG+1] = NULL; 3277c478bd9Sstevel@tonic-gate dev[D_ARG] = "\\D"; 3287c478bd9Sstevel@tonic-gate } 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate phonecl = repphone(dev[D_ARG], flds[F_PHONE], args[1]); 3317c478bd9Sstevel@tonic-gate exphone(phonecl, phoneex); 3327c478bd9Sstevel@tonic-gate translate(args[1], phoneex); 3337c478bd9Sstevel@tonic-gate /* 3347c478bd9Sstevel@tonic-gate * Chat 3357c478bd9Sstevel@tonic-gate */ 3367c478bd9Sstevel@tonic-gate if (chat(w-2, &args[2], dcf, phonecl, phoneex) != SUCCESS) { 3377c478bd9Sstevel@tonic-gate CDEBUG(5, "\nCHAT gdial(%s) FAILED\n", dev[D_CALLER]); 3387c478bd9Sstevel@tonic-gate Uerror = SS_CHAT_FAILED; 3397c478bd9Sstevel@tonic-gate goto bad; 3407c478bd9Sstevel@tonic-gate } 3417c478bd9Sstevel@tonic-gate } 3427c478bd9Sstevel@tonic-gate /* 3437c478bd9Sstevel@tonic-gate * Success at last! 3447c478bd9Sstevel@tonic-gate */ 34561961e0fSrobinson (void) strcpy(Dc, sdev[D_LINE]); 3467c478bd9Sstevel@tonic-gate return (dcf); 3477c478bd9Sstevel@tonic-gate bad: 3487c478bd9Sstevel@tonic-gate if (dcf >= 0) { 3497c478bd9Sstevel@tonic-gate /* reset line settings if we got them in the beginning */ 3507c478bd9Sstevel@tonic-gate if (ret_orig == 0) 3517c478bd9Sstevel@tonic-gate (void) ioctl(dcf, TCSETAW, &tty_orig); 3527c478bd9Sstevel@tonic-gate fd_rmlock(dcf); 3537c478bd9Sstevel@tonic-gate (void) close(dcf); 3547c478bd9Sstevel@tonic-gate } 3557c478bd9Sstevel@tonic-gate /* restore vanilla unix interface */ 3567c478bd9Sstevel@tonic-gate (void) interface("UNIX"); 3577c478bd9Sstevel@tonic-gate return (FAIL); 3587c478bd9Sstevel@tonic-gate } 3597c478bd9Sstevel@tonic-gate 3607c478bd9Sstevel@tonic-gate /* 3617c478bd9Sstevel@tonic-gate * clear_hup() clear the hangup state of the given device 3627c478bd9Sstevel@tonic-gate */ 36361961e0fSrobinson static int 36461961e0fSrobinson clear_hup(int dcf) 3657c478bd9Sstevel@tonic-gate { 3667c478bd9Sstevel@tonic-gate int ndcf; 3677c478bd9Sstevel@tonic-gate if ((ndcf = open(saved_dcname, saved_mode)) < 0) { 3687c478bd9Sstevel@tonic-gate return (FAIL); 3697c478bd9Sstevel@tonic-gate } 3707c478bd9Sstevel@tonic-gate if (ndcf != dcf) { 37161961e0fSrobinson (void) close(ndcf); 3727c478bd9Sstevel@tonic-gate } 3737c478bd9Sstevel@tonic-gate return (SUCCESS); 3747c478bd9Sstevel@tonic-gate } 3757c478bd9Sstevel@tonic-gate 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate /* 3787c478bd9Sstevel@tonic-gate * translate the pairs of characters present in the first 3797c478bd9Sstevel@tonic-gate * string whenever the first of the pair appears in the second 3807c478bd9Sstevel@tonic-gate * string. 3817c478bd9Sstevel@tonic-gate */ 3827c478bd9Sstevel@tonic-gate static void 38361961e0fSrobinson translate(char *ttab, char *str) 3847c478bd9Sstevel@tonic-gate { 38561961e0fSrobinson char *s; 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate for (; *ttab && *(ttab+1); ttab += 2) 3887c478bd9Sstevel@tonic-gate for (s = str; *s; s++) 3897c478bd9Sstevel@tonic-gate if (*ttab == *s) 3907c478bd9Sstevel@tonic-gate *s = *(ttab+1); 3917c478bd9Sstevel@tonic-gate } 3927c478bd9Sstevel@tonic-gate 3937c478bd9Sstevel@tonic-gate #define MAXLINE 512 394*d67944fbSScott Rotondo 395*d67944fbSScott Rotondo static void dialreset(void); 396*d67944fbSScott Rotondo #ifndef SMALL 397*d67944fbSScott Rotondo static char *currdial(void); 398*d67944fbSScott Rotondo #endif 3997c478bd9Sstevel@tonic-gate /* 4007c478bd9Sstevel@tonic-gate * Get the information about the dialer. 4017c478bd9Sstevel@tonic-gate * gdial(type, arps, narps) 4027c478bd9Sstevel@tonic-gate * type -> type of dialer (e.g., penril) 4037c478bd9Sstevel@tonic-gate * arps -> array of pointers returned by gdial 4047c478bd9Sstevel@tonic-gate * narps -> number of elements in array returned by gdial 4057c478bd9Sstevel@tonic-gate * Return value: 4067c478bd9Sstevel@tonic-gate * -1 -> Can't open DIALERFILE 4077c478bd9Sstevel@tonic-gate * 0 -> requested type not found 4087c478bd9Sstevel@tonic-gate * >0 -> success - number of fields filled in 4097c478bd9Sstevel@tonic-gate */ 4107c478bd9Sstevel@tonic-gate static int 41161961e0fSrobinson gdial(char *type, char *arps[], int narps) 4127c478bd9Sstevel@tonic-gate { 4137c478bd9Sstevel@tonic-gate static char *info; /* dynamically allocated MAXLINE */ 4147c478bd9Sstevel@tonic-gate int na; 4157c478bd9Sstevel@tonic-gate 4167c478bd9Sstevel@tonic-gate DEBUG(2, "gdial(%s) called\n", type); 4177c478bd9Sstevel@tonic-gate if (info == NULL) { 41861961e0fSrobinson info = malloc(MAXLINE); 4197c478bd9Sstevel@tonic-gate if (info == NULL) { 4207c478bd9Sstevel@tonic-gate DEBUG(1, "malloc failed for info in gdial\n", 0); 4217c478bd9Sstevel@tonic-gate return (0); 4227c478bd9Sstevel@tonic-gate } 4237c478bd9Sstevel@tonic-gate } 4247c478bd9Sstevel@tonic-gate while (getdialline(info, MAXLINE)) { 4257c478bd9Sstevel@tonic-gate if ((info[0] == '#') || (info[0] == ' ') || 4267c478bd9Sstevel@tonic-gate (info[0] == '\t') || (info[0] == '\n')) 4277c478bd9Sstevel@tonic-gate continue; 4287c478bd9Sstevel@tonic-gate if ((na = getargs(info, arps, narps)) == 0) 4297c478bd9Sstevel@tonic-gate continue; 4307c478bd9Sstevel@tonic-gate if (EQUALS(arps[0], type)) { 4317c478bd9Sstevel@tonic-gate DEBUG(5, "Trying caller script '%s'", type); 4327c478bd9Sstevel@tonic-gate DEBUG(5, " from '%s'.\n", currdial()); 4337c478bd9Sstevel@tonic-gate dialreset(); 4347c478bd9Sstevel@tonic-gate bsfix(arps); 4357c478bd9Sstevel@tonic-gate return (na); 4367c478bd9Sstevel@tonic-gate } 4377c478bd9Sstevel@tonic-gate } 4387c478bd9Sstevel@tonic-gate DEBUG(1, "%s not found in Dialers file\n", type); 4397c478bd9Sstevel@tonic-gate dialreset(); 4407c478bd9Sstevel@tonic-gate return (0); 4417c478bd9Sstevel@tonic-gate } 4427c478bd9Sstevel@tonic-gate 4437c478bd9Sstevel@tonic-gate #ifdef TLI 4447c478bd9Sstevel@tonic-gate /* 4457c478bd9Sstevel@tonic-gate * 4467c478bd9Sstevel@tonic-gate * AT&T Transport Layer Interface 4477c478bd9Sstevel@tonic-gate * 4487c478bd9Sstevel@tonic-gate * expected in Devices 4497c478bd9Sstevel@tonic-gate * TLI line1 - - TLI 4507c478bd9Sstevel@tonic-gate * or 4517c478bd9Sstevel@tonic-gate * TLIS line1 - - TLIS 4527c478bd9Sstevel@tonic-gate * 4537c478bd9Sstevel@tonic-gate */ 4547c478bd9Sstevel@tonic-gate 4557c478bd9Sstevel@tonic-gate #include <tiuser.h> 4567c478bd9Sstevel@tonic-gate 45761961e0fSrobinson static void tfaillog(int fd, const char *s); 4587c478bd9Sstevel@tonic-gate 4597c478bd9Sstevel@tonic-gate #define CONNECT_ATTEMPTS 3 46061961e0fSrobinson #define TFREE(p, type) if ((p)) (void) t_free((char *)(p), (type)) 4617c478bd9Sstevel@tonic-gate 462*d67944fbSScott Rotondo static struct netbuf *stoa(char *, struct netbuf *); 4637c478bd9Sstevel@tonic-gate /* 4647c478bd9Sstevel@tonic-gate * returns fd to remote uucp daemon 4657c478bd9Sstevel@tonic-gate */ 4667c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 46761961e0fSrobinson static int 46861961e0fSrobinson tlicall(char *flds[], char *dev[]) 4697c478bd9Sstevel@tonic-gate { 4707c478bd9Sstevel@tonic-gate char addrbuf[ BUFSIZ ]; 4717c478bd9Sstevel@tonic-gate char devname[MAXNAMESIZE]; 4727c478bd9Sstevel@tonic-gate int fd; 47361961e0fSrobinson int i, j; 4747c478bd9Sstevel@tonic-gate struct t_bind *bind_ret = 0; 4757c478bd9Sstevel@tonic-gate struct t_info tinfo; 4767c478bd9Sstevel@tonic-gate struct t_call *sndcall = 0, *rcvcall = 0; 4777c478bd9Sstevel@tonic-gate 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate if (dev[D_LINE][0] != '/') { 4807c478bd9Sstevel@tonic-gate /* dev holds device name relative to /dev */ 48161961e0fSrobinson (void) snprintf(devname, sizeof (devname), 48261961e0fSrobinson "/dev/%s", dev[D_LINE]); 4837c478bd9Sstevel@tonic-gate } else { 4847c478bd9Sstevel@tonic-gate /* dev holds full path name of device */ 48561961e0fSrobinson (void) strcpy(devname, dev[D_LINE]); 4867c478bd9Sstevel@tonic-gate } 4877c478bd9Sstevel@tonic-gate /* gimme local transport endpoint */ 4887c478bd9Sstevel@tonic-gate errno = t_errno = 0; 4897c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 4907c478bd9Sstevel@tonic-gate DEBUG(1, "t_open timeout\n%s", ""); 4917c478bd9Sstevel@tonic-gate logent("t_open", "TIMEOUT"); 4927c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 4937c478bd9Sstevel@tonic-gate return (FAIL); 4947c478bd9Sstevel@tonic-gate } 4957c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 4967c478bd9Sstevel@tonic-gate (void) alarm(5); 4977c478bd9Sstevel@tonic-gate fd = t_open(devname, O_RDWR, &tinfo); 4987c478bd9Sstevel@tonic-gate (void) alarm(0); 4997c478bd9Sstevel@tonic-gate if (fd < 0) { 5007c478bd9Sstevel@tonic-gate tfaillog(fd, "t_open"); 5017c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 5027c478bd9Sstevel@tonic-gate return (FAIL); 5037c478bd9Sstevel@tonic-gate } 5047c478bd9Sstevel@tonic-gate if (fd_mklock(fd) != SUCCESS) { 5057c478bd9Sstevel@tonic-gate (void) t_close(fd); 5067c478bd9Sstevel@tonic-gate DEBUG(1, "tlicall: failed to lock device %s\n", devname); 5077c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE; 5087c478bd9Sstevel@tonic-gate return (FAIL); 5097c478bd9Sstevel@tonic-gate } 5107c478bd9Sstevel@tonic-gate 5117c478bd9Sstevel@tonic-gate /* allocate tli structures */ 5127c478bd9Sstevel@tonic-gate errno = t_errno = 0; 51361961e0fSrobinson /* LINTED pointer cast */ 51461961e0fSrobinson if ((bind_ret = (struct t_bind *)t_alloc(fd, T_BIND, T_ALL)) == NULL || 51561961e0fSrobinson /* LINTED pointer cast */ 51661961e0fSrobinson (sndcall = (struct t_call *)t_alloc(fd, T_CALL, T_ALL)) == NULL || 51761961e0fSrobinson /* LINTED pointer cast */ 51861961e0fSrobinson (rcvcall = (struct t_call *)t_alloc(fd, T_CALL, T_ALL)) == NULL) { 5197c478bd9Sstevel@tonic-gate tfaillog(fd, "t_alloc"); 52061961e0fSrobinson TFREE(bind_ret, T_BIND); 52161961e0fSrobinson TFREE(sndcall, T_CALL); 5227c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL); 5237c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 5247c478bd9Sstevel@tonic-gate return (FAIL); 5257c478bd9Sstevel@tonic-gate } 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate /* bind */ 5287c478bd9Sstevel@tonic-gate errno = t_errno = 0; 5297c478bd9Sstevel@tonic-gate if (t_bind(fd, (struct t_bind *)0, bind_ret) < 0) { 5307c478bd9Sstevel@tonic-gate tfaillog(fd, "t_bind"); 53161961e0fSrobinson TFREE(bind_ret, T_BIND); 53261961e0fSrobinson TFREE(sndcall, T_CALL); 5337c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL); 5347c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 5357c478bd9Sstevel@tonic-gate fd_rmlock(fd); 5367c478bd9Sstevel@tonic-gate (void) t_close(fd); 5377c478bd9Sstevel@tonic-gate return (FAIL); 5387c478bd9Sstevel@tonic-gate } 5397c478bd9Sstevel@tonic-gate DEBUG(5, "tlicall: bound to %s\n", bind_ret->addr.buf); 5407c478bd9Sstevel@tonic-gate 5417c478bd9Sstevel@tonic-gate /* 5427c478bd9Sstevel@tonic-gate * Prepare to connect. 5437c478bd9Sstevel@tonic-gate * 5447c478bd9Sstevel@tonic-gate * If address begins with "\x", "\X", "\o", or "\O", 5457c478bd9Sstevel@tonic-gate * assume is hexadecimal or octal address and use stoa() 5467c478bd9Sstevel@tonic-gate * to convert it. 5477c478bd9Sstevel@tonic-gate * 5487c478bd9Sstevel@tonic-gate * Else is usual uucico address -- only \N's left to process. 5497c478bd9Sstevel@tonic-gate * Walk thru connection address, changing \N's to NULLCHARs. 5507c478bd9Sstevel@tonic-gate * Note: If a NULLCHAR must be part of the connection address, 5517c478bd9Sstevel@tonic-gate * it must be overtly included in the address. One recommended 5527c478bd9Sstevel@tonic-gate * way is to do it in the Devices file, thusly: 5537c478bd9Sstevel@tonic-gate * Netname /dev/netport - - TLI \D\000 5547c478bd9Sstevel@tonic-gate * bsfix() turns \000 into \N and then the loop below makes it a 5557c478bd9Sstevel@tonic-gate * real, included-in-the-length null-byte. 5567c478bd9Sstevel@tonic-gate * 5577c478bd9Sstevel@tonic-gate * The DEBUG must print the strecpy'd address (so that 5587c478bd9Sstevel@tonic-gate * non-printables will have been replaced with C escapes). 5597c478bd9Sstevel@tonic-gate */ 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate DEBUG(5, "t_connect to addr \"%s\"\n", 5627c478bd9Sstevel@tonic-gate strecpy(addrbuf, dev[D_ARG], "\\")); 5637c478bd9Sstevel@tonic-gate 56461961e0fSrobinson if (dev[D_ARG][0] == '\\' && (dev[D_ARG][1] == 'x' || 56561961e0fSrobinson dev[D_ARG][1] == 'X' || dev[D_ARG][1] == 'o' || 56661961e0fSrobinson dev[D_ARG][1] == 'O')) { 56761961e0fSrobinson if (stoa(dev[D_ARG], &(sndcall->addr)) == NULL) { 5687c478bd9Sstevel@tonic-gate DEBUG(5, "tlicall: stoa failed\n%s", ""); 5697c478bd9Sstevel@tonic-gate logent("tlicall", "string-to-address failed"); 57061961e0fSrobinson TFREE(bind_ret, T_BIND); 57161961e0fSrobinson TFREE(sndcall, T_CALL); 5727c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL); 5737c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 5747c478bd9Sstevel@tonic-gate fd_rmlock(fd); 5757c478bd9Sstevel@tonic-gate (void) t_close(fd); 5767c478bd9Sstevel@tonic-gate return (FAIL); 5777c478bd9Sstevel@tonic-gate } 5787c478bd9Sstevel@tonic-gate } else { 5797c478bd9Sstevel@tonic-gate for (i = j = 0; i < BUFSIZ && dev[D_ARG][i] != NULLCHAR; 5807c478bd9Sstevel@tonic-gate ++i, ++j) { 5817c478bd9Sstevel@tonic-gate if (dev[D_ARG][i] == '\\' && dev[D_ARG][i+1] == 'N') { 5827c478bd9Sstevel@tonic-gate addrbuf[j] = NULLCHAR; 5837c478bd9Sstevel@tonic-gate ++i; 58461961e0fSrobinson } else { 5857c478bd9Sstevel@tonic-gate addrbuf[j] = dev[D_ARG][i]; 5867c478bd9Sstevel@tonic-gate } 5877c478bd9Sstevel@tonic-gate } 5887c478bd9Sstevel@tonic-gate sndcall->addr.buf = addrbuf; 5897c478bd9Sstevel@tonic-gate sndcall->addr.len = j; 5907c478bd9Sstevel@tonic-gate } 5917c478bd9Sstevel@tonic-gate 5927c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 5937c478bd9Sstevel@tonic-gate DEBUG(4, "timeout tlicall\n%s", ""); 5947c478bd9Sstevel@tonic-gate logent("tlicall", "TIMEOUT"); 59561961e0fSrobinson TFREE(bind_ret, T_BIND); 59661961e0fSrobinson TFREE(sndcall, T_CALL); 5977c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL); 5987c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 5997c478bd9Sstevel@tonic-gate fd_rmlock(fd); 6007c478bd9Sstevel@tonic-gate (void) t_close(fd); 6017c478bd9Sstevel@tonic-gate return (FAIL); 6027c478bd9Sstevel@tonic-gate } 6037c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 6047c478bd9Sstevel@tonic-gate (void) alarm(connecttime); 6057c478bd9Sstevel@tonic-gate 6067c478bd9Sstevel@tonic-gate /* connect to the service -- some listeners can't handle */ 6077c478bd9Sstevel@tonic-gate /* multiple connect requests, so try it a few times */ 6087c478bd9Sstevel@tonic-gate errno = t_errno = 0; 6097c478bd9Sstevel@tonic-gate for (i = 0; i < CONNECT_ATTEMPTS; ++i) { 6107c478bd9Sstevel@tonic-gate if (t_connect(fd, sndcall, rcvcall) == 0) 6117c478bd9Sstevel@tonic-gate break; 6127c478bd9Sstevel@tonic-gate if ((t_errno == TLOOK) && (t_look(fd) == T_DISCONNECT)) { 61361961e0fSrobinson (void) t_rcvdis(fd, NULL); 6147c478bd9Sstevel@tonic-gate (void) alarm(0); 6157c478bd9Sstevel@tonic-gate } else { 6167c478bd9Sstevel@tonic-gate (void) alarm(0); 6177c478bd9Sstevel@tonic-gate tfaillog(fd, "t_connect"); 61861961e0fSrobinson TFREE(bind_ret, T_BIND); 61961961e0fSrobinson TFREE(sndcall, T_CALL); 6207c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL); 6217c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 6227c478bd9Sstevel@tonic-gate fd_rmlock(fd); 6237c478bd9Sstevel@tonic-gate (void) t_close(fd); 6247c478bd9Sstevel@tonic-gate return (FAIL); 6257c478bd9Sstevel@tonic-gate } 6267c478bd9Sstevel@tonic-gate } 6277c478bd9Sstevel@tonic-gate (void) alarm(0); 62861961e0fSrobinson TFREE(bind_ret, T_BIND); 62961961e0fSrobinson TFREE(sndcall, T_CALL); 6307c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL); 6317c478bd9Sstevel@tonic-gate if (i == CONNECT_ATTEMPTS) { 6327c478bd9Sstevel@tonic-gate tfaillog(fd, "t_connect"); 6337c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 6347c478bd9Sstevel@tonic-gate fd_rmlock(fd); 6357c478bd9Sstevel@tonic-gate (void) t_close(fd); 6367c478bd9Sstevel@tonic-gate return (FAIL); 6377c478bd9Sstevel@tonic-gate } 6387c478bd9Sstevel@tonic-gate errno = t_errno = 0; 6397c478bd9Sstevel@tonic-gate (void) strcpy(Dc, dev[D_CALLER]); 6407c478bd9Sstevel@tonic-gate return (fd); 6417c478bd9Sstevel@tonic-gate } 6427c478bd9Sstevel@tonic-gate #endif /* TLI */ 643