1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 1996 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate #include "uucp.h" 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #if defined(BSD4_2) || defined(ATTSVR4) 37*7c478bd9Sstevel@tonic-gate #include <netdb.h> 38*7c478bd9Sstevel@tonic-gate #include <netinet/in.h> 39*7c478bd9Sstevel@tonic-gate #include <sys/socket.h> 40*7c478bd9Sstevel@tonic-gate #endif 41*7c478bd9Sstevel@tonic-gate #ifdef UNET 42*7c478bd9Sstevel@tonic-gate #include "UNET/unetio.h" 43*7c478bd9Sstevel@tonic-gate #include "UNET/tcp.h" 44*7c478bd9Sstevel@tonic-gate #endif 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate EXTERN void alarmtr(); 48*7c478bd9Sstevel@tonic-gate EXTERN jmp_buf Sjbuf; 49*7c478bd9Sstevel@tonic-gate EXTERN char *fdig(), *strecpy(); 50*7c478bd9Sstevel@tonic-gate EXTERN int interface(); 51*7c478bd9Sstevel@tonic-gate EXTERN int fd_mklock(), fd_cklock(), chat(), getdialline(); 52*7c478bd9Sstevel@tonic-gate EXTERN void fixline(), fd_rmlock(); 53*7c478bd9Sstevel@tonic-gate static void translate(); 54*7c478bd9Sstevel@tonic-gate static int gdial(); 55*7c478bd9Sstevel@tonic-gate EXTERN int Modemctrl; 56*7c478bd9Sstevel@tonic-gate EXTERN unsigned connecttime; 57*7c478bd9Sstevel@tonic-gate EXTERN int (*Setup)(); 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate /* 60*7c478bd9Sstevel@tonic-gate * to add a new caller: 61*7c478bd9Sstevel@tonic-gate * declare the function that knows how to call on the device, 62*7c478bd9Sstevel@tonic-gate * add a line to the callers table giving the name of the device 63*7c478bd9Sstevel@tonic-gate * (from Devices file) and the name of the function 64*7c478bd9Sstevel@tonic-gate * add the function to the end of this file 65*7c478bd9Sstevel@tonic-gate */ 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate #ifdef DIAL801 68*7c478bd9Sstevel@tonic-gate EXTERN int dial801(); 69*7c478bd9Sstevel@tonic-gate EXTERN int open801(); 70*7c478bd9Sstevel@tonic-gate #endif 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate #ifdef DATAKIT 73*7c478bd9Sstevel@tonic-gate EXTERN int dkcall(); 74*7c478bd9Sstevel@tonic-gate #endif /* DATAKIT */ 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate #ifdef V8 77*7c478bd9Sstevel@tonic-gate int Dialout(); 78*7c478bd9Sstevel@tonic-gate #endif 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate #ifdef TCP 81*7c478bd9Sstevel@tonic-gate int unetcall(); 82*7c478bd9Sstevel@tonic-gate int tcpcall(); 83*7c478bd9Sstevel@tonic-gate #endif /* TCP */ 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate #ifdef SYTEK 86*7c478bd9Sstevel@tonic-gate int sytcall(); 87*7c478bd9Sstevel@tonic-gate #endif /* SYTEK */ 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate #ifdef TLI 90*7c478bd9Sstevel@tonic-gate EXTERN int tlicall(); 91*7c478bd9Sstevel@tonic-gate #endif /* TLI */ 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate static struct caller Caller[] = { 94*7c478bd9Sstevel@tonic-gate 95*7c478bd9Sstevel@tonic-gate #ifdef DIAL801 96*7c478bd9Sstevel@tonic-gate {"801", dial801}, 97*7c478bd9Sstevel@tonic-gate {"212", dial801}, 98*7c478bd9Sstevel@tonic-gate #endif /* DIAL801 */ 99*7c478bd9Sstevel@tonic-gate 100*7c478bd9Sstevel@tonic-gate #ifdef V8 101*7c478bd9Sstevel@tonic-gate {"Dialout", Dialout}, /* ditto but using dialout(III) */ 102*7c478bd9Sstevel@tonic-gate #endif 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate #ifdef TCP 105*7c478bd9Sstevel@tonic-gate #if defined(BSD4_2) || defined(ATTSVR4) 106*7c478bd9Sstevel@tonic-gate {"TCP", tcpcall}, /* 4.2BSD sockets */ 107*7c478bd9Sstevel@tonic-gate #else /* !BSD4_2 */ 108*7c478bd9Sstevel@tonic-gate #ifdef UNET 109*7c478bd9Sstevel@tonic-gate {"TCP", unetcall}, /* 3com implementation of tcp */ 110*7c478bd9Sstevel@tonic-gate {"Unetserver", unetcall}, 111*7c478bd9Sstevel@tonic-gate #endif /* UNET */ 112*7c478bd9Sstevel@tonic-gate #endif /* BSD4_2 || ATTSVR4 */ 113*7c478bd9Sstevel@tonic-gate #endif /* TCP */ 114*7c478bd9Sstevel@tonic-gate 115*7c478bd9Sstevel@tonic-gate #ifdef DATAKIT 116*7c478bd9Sstevel@tonic-gate {"DK", dkcall}, /* standard AT&T DATAKIT VCS caller */ 117*7c478bd9Sstevel@tonic-gate #endif /* DATAKIT */ 118*7c478bd9Sstevel@tonic-gate 119*7c478bd9Sstevel@tonic-gate #ifdef SYTEK 120*7c478bd9Sstevel@tonic-gate {"Sytek", sytcall}, /* untested but should work */ 121*7c478bd9Sstevel@tonic-gate #endif /* SYTEK */ 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate #ifdef TLI 124*7c478bd9Sstevel@tonic-gate {"TLI", tlicall}, /* AT&T Transport Layer Interface */ 125*7c478bd9Sstevel@tonic-gate #ifdef TLIS 126*7c478bd9Sstevel@tonic-gate {"TLIS", tlicall}, /* AT&T Transport Layer Interface */ 127*7c478bd9Sstevel@tonic-gate #endif /* TLIS */ 128*7c478bd9Sstevel@tonic-gate #endif /* TLI */ 129*7c478bd9Sstevel@tonic-gate 130*7c478bd9Sstevel@tonic-gate {NULL, NULL} /* this line must be last */ 131*7c478bd9Sstevel@tonic-gate }; 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate /* 134*7c478bd9Sstevel@tonic-gate * exphone - expand phone number for given prefix and number 135*7c478bd9Sstevel@tonic-gate * 136*7c478bd9Sstevel@tonic-gate * return code - none 137*7c478bd9Sstevel@tonic-gate */ 138*7c478bd9Sstevel@tonic-gate 139*7c478bd9Sstevel@tonic-gate static void 140*7c478bd9Sstevel@tonic-gate exphone(in, out) 141*7c478bd9Sstevel@tonic-gate char *in, *out; 142*7c478bd9Sstevel@tonic-gate { 143*7c478bd9Sstevel@tonic-gate FILE *fn; 144*7c478bd9Sstevel@tonic-gate char pre[MAXPH], npart[MAXPH], tpre[MAXPH], p[MAXPH]; 145*7c478bd9Sstevel@tonic-gate char buf[BUFSIZ]; 146*7c478bd9Sstevel@tonic-gate char *s1; 147*7c478bd9Sstevel@tonic-gate 148*7c478bd9Sstevel@tonic-gate if (!isalpha(*in)) { 149*7c478bd9Sstevel@tonic-gate (void) strcpy(out, in); 150*7c478bd9Sstevel@tonic-gate return; 151*7c478bd9Sstevel@tonic-gate } 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate s1=pre; 154*7c478bd9Sstevel@tonic-gate while (isalpha(*in)) 155*7c478bd9Sstevel@tonic-gate *s1++ = *in++; 156*7c478bd9Sstevel@tonic-gate *s1 = NULLCHAR; 157*7c478bd9Sstevel@tonic-gate s1 = npart; 158*7c478bd9Sstevel@tonic-gate while (*in != NULLCHAR) 159*7c478bd9Sstevel@tonic-gate *s1++ = *in++; 160*7c478bd9Sstevel@tonic-gate *s1 = NULLCHAR; 161*7c478bd9Sstevel@tonic-gate 162*7c478bd9Sstevel@tonic-gate tpre[0] = NULLCHAR; 163*7c478bd9Sstevel@tonic-gate fn = fopen(DIALCODES, "r"); 164*7c478bd9Sstevel@tonic-gate if (fn != NULL) { 165*7c478bd9Sstevel@tonic-gate while (fgets(buf, BUFSIZ, fn)) { 166*7c478bd9Sstevel@tonic-gate if ( sscanf(buf, "%s%s", p, tpre) < 1) 167*7c478bd9Sstevel@tonic-gate continue; 168*7c478bd9Sstevel@tonic-gate if (EQUALS(p, pre)) 169*7c478bd9Sstevel@tonic-gate break; 170*7c478bd9Sstevel@tonic-gate tpre[0] = NULLCHAR; 171*7c478bd9Sstevel@tonic-gate } 172*7c478bd9Sstevel@tonic-gate fclose(fn); 173*7c478bd9Sstevel@tonic-gate } 174*7c478bd9Sstevel@tonic-gate 175*7c478bd9Sstevel@tonic-gate (void) strcpy(out, tpre); 176*7c478bd9Sstevel@tonic-gate (void) strcat(out, npart); 177*7c478bd9Sstevel@tonic-gate return; 178*7c478bd9Sstevel@tonic-gate } 179*7c478bd9Sstevel@tonic-gate 180*7c478bd9Sstevel@tonic-gate /* 181*7c478bd9Sstevel@tonic-gate * repphone - Replace \D and \T sequences in arg with phone 182*7c478bd9Sstevel@tonic-gate * expanding and translating as appropriate. 183*7c478bd9Sstevel@tonic-gate */ 184*7c478bd9Sstevel@tonic-gate static char * 185*7c478bd9Sstevel@tonic-gate repphone(arg, phone, trstr) 186*7c478bd9Sstevel@tonic-gate register char *arg, *phone, *trstr; 187*7c478bd9Sstevel@tonic-gate { 188*7c478bd9Sstevel@tonic-gate static char pbuf[2*(MAXPH+2)]; 189*7c478bd9Sstevel@tonic-gate register char *fp, *tp; 190*7c478bd9Sstevel@tonic-gate 191*7c478bd9Sstevel@tonic-gate for (tp=pbuf; *arg; arg++) { 192*7c478bd9Sstevel@tonic-gate if (*arg != '\\') { 193*7c478bd9Sstevel@tonic-gate *tp++ = *arg; 194*7c478bd9Sstevel@tonic-gate continue; 195*7c478bd9Sstevel@tonic-gate } else { 196*7c478bd9Sstevel@tonic-gate switch (*(arg+1)) { 197*7c478bd9Sstevel@tonic-gate case 'T': 198*7c478bd9Sstevel@tonic-gate exphone(phone, tp); 199*7c478bd9Sstevel@tonic-gate translate(trstr, tp); 200*7c478bd9Sstevel@tonic-gate for(; *tp; tp++) 201*7c478bd9Sstevel@tonic-gate ; 202*7c478bd9Sstevel@tonic-gate arg++; 203*7c478bd9Sstevel@tonic-gate break; 204*7c478bd9Sstevel@tonic-gate case 'D': 205*7c478bd9Sstevel@tonic-gate for(fp=phone; *tp = *fp++; tp++) 206*7c478bd9Sstevel@tonic-gate ; 207*7c478bd9Sstevel@tonic-gate arg++; 208*7c478bd9Sstevel@tonic-gate break; 209*7c478bd9Sstevel@tonic-gate default: 210*7c478bd9Sstevel@tonic-gate *tp++ = *arg; 211*7c478bd9Sstevel@tonic-gate break; 212*7c478bd9Sstevel@tonic-gate } 213*7c478bd9Sstevel@tonic-gate } 214*7c478bd9Sstevel@tonic-gate } 215*7c478bd9Sstevel@tonic-gate *tp = '\0'; 216*7c478bd9Sstevel@tonic-gate return(pbuf); 217*7c478bd9Sstevel@tonic-gate } 218*7c478bd9Sstevel@tonic-gate 219*7c478bd9Sstevel@tonic-gate static u_int saved_mode; 220*7c478bd9Sstevel@tonic-gate static char saved_dcname[20]; 221*7c478bd9Sstevel@tonic-gate 222*7c478bd9Sstevel@tonic-gate /* 223*7c478bd9Sstevel@tonic-gate * processdev - Process a line from the Devices file 224*7c478bd9Sstevel@tonic-gate * 225*7c478bd9Sstevel@tonic-gate * return codes: 226*7c478bd9Sstevel@tonic-gate * file descriptor - succeeded 227*7c478bd9Sstevel@tonic-gate * FAIL - failed 228*7c478bd9Sstevel@tonic-gate */ 229*7c478bd9Sstevel@tonic-gate GLOBAL int 230*7c478bd9Sstevel@tonic-gate processdev(flds, dev) 231*7c478bd9Sstevel@tonic-gate register char *flds[], *dev[]; 232*7c478bd9Sstevel@tonic-gate { 233*7c478bd9Sstevel@tonic-gate int dcf = -1; 234*7c478bd9Sstevel@tonic-gate register struct caller *ca; 235*7c478bd9Sstevel@tonic-gate char *args[D_MAX+1], dcname[20]; 236*7c478bd9Sstevel@tonic-gate register char **sdev; 237*7c478bd9Sstevel@tonic-gate EXTERN int pop_push(); 238*7c478bd9Sstevel@tonic-gate EXTERN void setdevcfg(); 239*7c478bd9Sstevel@tonic-gate register nullfd; 240*7c478bd9Sstevel@tonic-gate char *phonecl; /* clear phone string */ 241*7c478bd9Sstevel@tonic-gate char phoneex[2*(MAXPH+2)]; /* expanded phone string */ 242*7c478bd9Sstevel@tonic-gate EXTERN void ttygenbrk(); 243*7c478bd9Sstevel@tonic-gate struct termio tty_orig; 244*7c478bd9Sstevel@tonic-gate int ret_orig = -1; 245*7c478bd9Sstevel@tonic-gate 246*7c478bd9Sstevel@tonic-gate sdev = dev; 247*7c478bd9Sstevel@tonic-gate /* set up default "break" routine */ 248*7c478bd9Sstevel@tonic-gate genbrk = ttygenbrk; 249*7c478bd9Sstevel@tonic-gate 250*7c478bd9Sstevel@tonic-gate /* initialize Devconfig info */ 251*7c478bd9Sstevel@tonic-gate DEBUG(5, "processdev: calling setdevcfg(%s, ", Progname); 252*7c478bd9Sstevel@tonic-gate DEBUG(5, "%s)\n", flds[F_TYPE]); 253*7c478bd9Sstevel@tonic-gate setdevcfg(Progname, flds[F_TYPE]); 254*7c478bd9Sstevel@tonic-gate 255*7c478bd9Sstevel@tonic-gate for (ca = Caller; ca->CA_type != NULL; ca++) { 256*7c478bd9Sstevel@tonic-gate /* This will find built-in caller functions */ 257*7c478bd9Sstevel@tonic-gate if (EQUALS(ca->CA_type, dev[D_CALLER])) { 258*7c478bd9Sstevel@tonic-gate DEBUG(5, "Internal caller type %s\n", dev[D_CALLER]); 259*7c478bd9Sstevel@tonic-gate if (dev[D_ARG] == NULL) { 260*7c478bd9Sstevel@tonic-gate /* if NULL - assume translate */ 261*7c478bd9Sstevel@tonic-gate dev[D_ARG+1] = NULL; /* needed for for loop later to mark the end */ 262*7c478bd9Sstevel@tonic-gate dev[D_ARG] = "\\T"; 263*7c478bd9Sstevel@tonic-gate } 264*7c478bd9Sstevel@tonic-gate dev[D_ARG] = repphone(dev[D_ARG], flds[F_PHONE], ""); 265*7c478bd9Sstevel@tonic-gate if ((dcf = (*(ca->CA_caller))(flds, dev)) < 0) 266*7c478bd9Sstevel@tonic-gate return(dcf) ; 267*7c478bd9Sstevel@tonic-gate if ( interface( ca->CA_type ) ) { 268*7c478bd9Sstevel@tonic-gate DEBUG(5, "interface(%s) failed", ca->CA_type); 269*7c478bd9Sstevel@tonic-gate Uerror = SS_DEVICE_FAILED; 270*7c478bd9Sstevel@tonic-gate /* restore vanilla unix interface */ 271*7c478bd9Sstevel@tonic-gate (void)interface("UNIX"); 272*7c478bd9Sstevel@tonic-gate return(FAIL); 273*7c478bd9Sstevel@tonic-gate } 274*7c478bd9Sstevel@tonic-gate dev += 2; /* Skip to next CALLER and ARG */ 275*7c478bd9Sstevel@tonic-gate break; 276*7c478bd9Sstevel@tonic-gate } 277*7c478bd9Sstevel@tonic-gate } 278*7c478bd9Sstevel@tonic-gate if (dcf == -1) { 279*7c478bd9Sstevel@tonic-gate /* Here if not a built-in caller function */ 280*7c478bd9Sstevel@tonic-gate 281*7c478bd9Sstevel@tonic-gate /* We do locking (file and advisory) after open */ 282*7c478bd9Sstevel@tonic-gate 283*7c478bd9Sstevel@tonic-gate /* 284*7c478bd9Sstevel@tonic-gate * Open the line 285*7c478bd9Sstevel@tonic-gate */ 286*7c478bd9Sstevel@tonic-gate if ( *dev[D_LINE] != '/' ) { 287*7c478bd9Sstevel@tonic-gate (void) sprintf(dcname, "/dev/%s", dev[D_LINE]); 288*7c478bd9Sstevel@tonic-gate } else { 289*7c478bd9Sstevel@tonic-gate (void) strcpy(dcname, dev[D_LINE] ); 290*7c478bd9Sstevel@tonic-gate } 291*7c478bd9Sstevel@tonic-gate /* take care of the possible partial open fd */ 292*7c478bd9Sstevel@tonic-gate (void) close(nullfd = open("/", O_RDONLY)); 293*7c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 294*7c478bd9Sstevel@tonic-gate (void) close(nullfd); 295*7c478bd9Sstevel@tonic-gate DEBUG(1, "generic open timeout\n%s", ""); 296*7c478bd9Sstevel@tonic-gate logent("generic open", "TIMEOUT"); 297*7c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE; 298*7c478bd9Sstevel@tonic-gate goto bad; 299*7c478bd9Sstevel@tonic-gate } 300*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 301*7c478bd9Sstevel@tonic-gate (void) alarm(10); 302*7c478bd9Sstevel@tonic-gate if ( Modemctrl ) { 303*7c478bd9Sstevel@tonic-gate DEBUG(7, "opening with O_NDELAY set\n%s", ""); 304*7c478bd9Sstevel@tonic-gate dcf = open(dcname, (O_RDWR | O_NDELAY) ); 305*7c478bd9Sstevel@tonic-gate saved_mode = O_RDWR | O_NDELAY; 306*7c478bd9Sstevel@tonic-gate } else { 307*7c478bd9Sstevel@tonic-gate dcf = open(dcname, O_RDWR ); 308*7c478bd9Sstevel@tonic-gate saved_mode = O_RDWR; 309*7c478bd9Sstevel@tonic-gate } 310*7c478bd9Sstevel@tonic-gate strcpy(saved_dcname, dcname); 311*7c478bd9Sstevel@tonic-gate (void) alarm(0); 312*7c478bd9Sstevel@tonic-gate if (dcf < 0) { 313*7c478bd9Sstevel@tonic-gate DEBUG(1, "generic open failed, errno = %d\n", errno); 314*7c478bd9Sstevel@tonic-gate (void) close(nullfd); 315*7c478bd9Sstevel@tonic-gate logent("generic open", "FAILED"); 316*7c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE; 317*7c478bd9Sstevel@tonic-gate goto bad; 318*7c478bd9Sstevel@tonic-gate } 319*7c478bd9Sstevel@tonic-gate 320*7c478bd9Sstevel@tonic-gate /* check locks BEFORE modifying the stream */ 321*7c478bd9Sstevel@tonic-gate 322*7c478bd9Sstevel@tonic-gate if ( fd_mklock(dcf) != SUCCESS ) { 323*7c478bd9Sstevel@tonic-gate DEBUG(1, "failed to lock device %s\n", dcname); 324*7c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE; 325*7c478bd9Sstevel@tonic-gate goto bad; 326*7c478bd9Sstevel@tonic-gate } 327*7c478bd9Sstevel@tonic-gate 328*7c478bd9Sstevel@tonic-gate if ( Modemctrl ) { 329*7c478bd9Sstevel@tonic-gate DEBUG(7, "clear O_NDELAY\n%s", ""); 330*7c478bd9Sstevel@tonic-gate if ( fcntl(dcf, F_SETFL, 331*7c478bd9Sstevel@tonic-gate (fcntl(dcf, F_GETFL, 0) & ~O_NDELAY)) < 0 ) { 332*7c478bd9Sstevel@tonic-gate DEBUG( 7, "clear O_NDELAY failed, errno %d\n", errno); 333*7c478bd9Sstevel@tonic-gate Uerror = SS_DEVICE_FAILED; 334*7c478bd9Sstevel@tonic-gate goto bad; 335*7c478bd9Sstevel@tonic-gate } 336*7c478bd9Sstevel@tonic-gate } 337*7c478bd9Sstevel@tonic-gate } 338*7c478bd9Sstevel@tonic-gate 339*7c478bd9Sstevel@tonic-gate if ( (*Setup)( MASTER, &dcf, &dcf ) ) { 340*7c478bd9Sstevel@tonic-gate /* any device|system lock files we should remove? */ 341*7c478bd9Sstevel@tonic-gate DEBUG(5, "MASTER Setup failed%s", ""); 342*7c478bd9Sstevel@tonic-gate Uerror = SS_DEVICE_FAILED; 343*7c478bd9Sstevel@tonic-gate goto bad; 344*7c478bd9Sstevel@tonic-gate } 345*7c478bd9Sstevel@tonic-gate 346*7c478bd9Sstevel@tonic-gate /* configure any requested streams modules */ 347*7c478bd9Sstevel@tonic-gate if ( !pop_push(dcf) ) { 348*7c478bd9Sstevel@tonic-gate DEBUG(5, "STREAMS module configuration failed%s\n",""); 349*7c478bd9Sstevel@tonic-gate Uerror = SS_DEVICE_FAILED; 350*7c478bd9Sstevel@tonic-gate goto bad; 351*7c478bd9Sstevel@tonic-gate } 352*7c478bd9Sstevel@tonic-gate 353*7c478bd9Sstevel@tonic-gate /* save initial state of line in case script fails */ 354*7c478bd9Sstevel@tonic-gate ret_orig = ioctl(dcf, TCGETA, &tty_orig); 355*7c478bd9Sstevel@tonic-gate 356*7c478bd9Sstevel@tonic-gate /* use sdev[] since dev[] is incremented for internal callers */ 357*7c478bd9Sstevel@tonic-gate fixline(dcf, atoi(fdig(sdev[D_CLASS])), D_DIRECT); 358*7c478bd9Sstevel@tonic-gate 359*7c478bd9Sstevel@tonic-gate /* 360*7c478bd9Sstevel@tonic-gate * Now loop through the remaining callers and chat 361*7c478bd9Sstevel@tonic-gate * according to scripts in dialers file. 362*7c478bd9Sstevel@tonic-gate */ 363*7c478bd9Sstevel@tonic-gate for (; dev[D_CALLER] != NULL; dev += 2) { 364*7c478bd9Sstevel@tonic-gate register int w; 365*7c478bd9Sstevel@tonic-gate /* 366*7c478bd9Sstevel@tonic-gate * Scan Dialers file to find an entry 367*7c478bd9Sstevel@tonic-gate */ 368*7c478bd9Sstevel@tonic-gate if ((w = gdial(dev[D_CALLER], args, D_MAX)) < 1) { 369*7c478bd9Sstevel@tonic-gate logent("generic call to gdial", "FAILED"); 370*7c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE; 371*7c478bd9Sstevel@tonic-gate goto bad; 372*7c478bd9Sstevel@tonic-gate } 373*7c478bd9Sstevel@tonic-gate if (w <= 2) /* do nothing - no chat */ 374*7c478bd9Sstevel@tonic-gate break; 375*7c478bd9Sstevel@tonic-gate /* 376*7c478bd9Sstevel@tonic-gate * Translate the phone number 377*7c478bd9Sstevel@tonic-gate */ 378*7c478bd9Sstevel@tonic-gate if (dev[D_ARG] == NULL) { 379*7c478bd9Sstevel@tonic-gate /* if NULL - assume no translation */ 380*7c478bd9Sstevel@tonic-gate dev[D_ARG+1] = NULL; /* needed for for loop to mark the end */ 381*7c478bd9Sstevel@tonic-gate dev[D_ARG] = "\\D"; 382*7c478bd9Sstevel@tonic-gate } 383*7c478bd9Sstevel@tonic-gate 384*7c478bd9Sstevel@tonic-gate phonecl = repphone(dev[D_ARG], flds[F_PHONE], args[1]); 385*7c478bd9Sstevel@tonic-gate exphone(phonecl, phoneex); 386*7c478bd9Sstevel@tonic-gate translate(args[1], phoneex); 387*7c478bd9Sstevel@tonic-gate /* 388*7c478bd9Sstevel@tonic-gate * Chat 389*7c478bd9Sstevel@tonic-gate */ 390*7c478bd9Sstevel@tonic-gate if (chat(w-2, &args[2], dcf, phonecl, phoneex) != SUCCESS) { 391*7c478bd9Sstevel@tonic-gate CDEBUG(5, "\nCHAT gdial(%s) FAILED\n", dev[D_CALLER]); 392*7c478bd9Sstevel@tonic-gate Uerror = SS_CHAT_FAILED; 393*7c478bd9Sstevel@tonic-gate goto bad; 394*7c478bd9Sstevel@tonic-gate } 395*7c478bd9Sstevel@tonic-gate } 396*7c478bd9Sstevel@tonic-gate /* 397*7c478bd9Sstevel@tonic-gate * Success at last! 398*7c478bd9Sstevel@tonic-gate */ 399*7c478bd9Sstevel@tonic-gate strcpy(Dc, sdev[D_LINE]); 400*7c478bd9Sstevel@tonic-gate return(dcf); 401*7c478bd9Sstevel@tonic-gate bad: 402*7c478bd9Sstevel@tonic-gate if ( dcf >= 0 ) { 403*7c478bd9Sstevel@tonic-gate /* reset line settings if we got them in the beginning */ 404*7c478bd9Sstevel@tonic-gate if ( ret_orig == 0 ) 405*7c478bd9Sstevel@tonic-gate (void) ioctl(dcf, TCSETAW, &tty_orig); 406*7c478bd9Sstevel@tonic-gate fd_rmlock(dcf); 407*7c478bd9Sstevel@tonic-gate (void)close(dcf); 408*7c478bd9Sstevel@tonic-gate } 409*7c478bd9Sstevel@tonic-gate /* restore vanilla unix interface */ 410*7c478bd9Sstevel@tonic-gate (void)interface("UNIX"); 411*7c478bd9Sstevel@tonic-gate return(FAIL); 412*7c478bd9Sstevel@tonic-gate } 413*7c478bd9Sstevel@tonic-gate 414*7c478bd9Sstevel@tonic-gate /* 415*7c478bd9Sstevel@tonic-gate * clear_hup() clear the hangup state of the given device 416*7c478bd9Sstevel@tonic-gate */ 417*7c478bd9Sstevel@tonic-gate GLOBAL int 418*7c478bd9Sstevel@tonic-gate clear_hup(dcf) 419*7c478bd9Sstevel@tonic-gate int dcf; 420*7c478bd9Sstevel@tonic-gate { 421*7c478bd9Sstevel@tonic-gate int ndcf; 422*7c478bd9Sstevel@tonic-gate if ((ndcf = open(saved_dcname, saved_mode)) < 0) { 423*7c478bd9Sstevel@tonic-gate return (FAIL); 424*7c478bd9Sstevel@tonic-gate } 425*7c478bd9Sstevel@tonic-gate if (ndcf != dcf) { 426*7c478bd9Sstevel@tonic-gate close(ndcf); 427*7c478bd9Sstevel@tonic-gate } 428*7c478bd9Sstevel@tonic-gate return (SUCCESS); 429*7c478bd9Sstevel@tonic-gate } 430*7c478bd9Sstevel@tonic-gate 431*7c478bd9Sstevel@tonic-gate 432*7c478bd9Sstevel@tonic-gate /* 433*7c478bd9Sstevel@tonic-gate * translate the pairs of characters present in the first 434*7c478bd9Sstevel@tonic-gate * string whenever the first of the pair appears in the second 435*7c478bd9Sstevel@tonic-gate * string. 436*7c478bd9Sstevel@tonic-gate */ 437*7c478bd9Sstevel@tonic-gate static void 438*7c478bd9Sstevel@tonic-gate translate(ttab, str) 439*7c478bd9Sstevel@tonic-gate register char *ttab, *str; 440*7c478bd9Sstevel@tonic-gate { 441*7c478bd9Sstevel@tonic-gate register char *s; 442*7c478bd9Sstevel@tonic-gate 443*7c478bd9Sstevel@tonic-gate for(;*ttab && *(ttab+1); ttab += 2) 444*7c478bd9Sstevel@tonic-gate for(s=str;*s;s++) 445*7c478bd9Sstevel@tonic-gate if(*ttab == *s) 446*7c478bd9Sstevel@tonic-gate *s = *(ttab+1); 447*7c478bd9Sstevel@tonic-gate return; 448*7c478bd9Sstevel@tonic-gate } 449*7c478bd9Sstevel@tonic-gate 450*7c478bd9Sstevel@tonic-gate #define MAXLINE 512 451*7c478bd9Sstevel@tonic-gate /* 452*7c478bd9Sstevel@tonic-gate * Get the information about the dialer. 453*7c478bd9Sstevel@tonic-gate * gdial(type, arps, narps) 454*7c478bd9Sstevel@tonic-gate * type -> type of dialer (e.g., penril) 455*7c478bd9Sstevel@tonic-gate * arps -> array of pointers returned by gdial 456*7c478bd9Sstevel@tonic-gate * narps -> number of elements in array returned by gdial 457*7c478bd9Sstevel@tonic-gate * Return value: 458*7c478bd9Sstevel@tonic-gate * -1 -> Can't open DIALERFILE 459*7c478bd9Sstevel@tonic-gate * 0 -> requested type not found 460*7c478bd9Sstevel@tonic-gate * >0 -> success - number of fields filled in 461*7c478bd9Sstevel@tonic-gate */ 462*7c478bd9Sstevel@tonic-gate static int 463*7c478bd9Sstevel@tonic-gate gdial(type, arps, narps) 464*7c478bd9Sstevel@tonic-gate register char *type, *arps[]; 465*7c478bd9Sstevel@tonic-gate register int narps; 466*7c478bd9Sstevel@tonic-gate { 467*7c478bd9Sstevel@tonic-gate static char info[MAXLINE]; 468*7c478bd9Sstevel@tonic-gate register na; 469*7c478bd9Sstevel@tonic-gate EXTERN void dialreset(); 470*7c478bd9Sstevel@tonic-gate EXTERN char * currdial(); 471*7c478bd9Sstevel@tonic-gate 472*7c478bd9Sstevel@tonic-gate DEBUG(2, "gdial(%s) called\n", type); 473*7c478bd9Sstevel@tonic-gate while (getdialline(info, sizeof(info))) { 474*7c478bd9Sstevel@tonic-gate if ((info[0] == '#') || (info[0] == ' ') || 475*7c478bd9Sstevel@tonic-gate (info[0] == '\t') || (info[0] == '\n')) 476*7c478bd9Sstevel@tonic-gate continue; 477*7c478bd9Sstevel@tonic-gate if ((na = getargs(info, arps, narps)) == 0) 478*7c478bd9Sstevel@tonic-gate continue; 479*7c478bd9Sstevel@tonic-gate if (EQUALS(arps[0], type)) { 480*7c478bd9Sstevel@tonic-gate DEBUG(5, "Trying caller script '%s'", type); 481*7c478bd9Sstevel@tonic-gate DEBUG(5, " from '%s'.\n", currdial()); 482*7c478bd9Sstevel@tonic-gate dialreset(); 483*7c478bd9Sstevel@tonic-gate bsfix(arps); 484*7c478bd9Sstevel@tonic-gate return(na); 485*7c478bd9Sstevel@tonic-gate } 486*7c478bd9Sstevel@tonic-gate } 487*7c478bd9Sstevel@tonic-gate DEBUG(1, "%s not found in Dialers file\n", type); 488*7c478bd9Sstevel@tonic-gate dialreset(); 489*7c478bd9Sstevel@tonic-gate return(0); 490*7c478bd9Sstevel@tonic-gate } 491*7c478bd9Sstevel@tonic-gate 492*7c478bd9Sstevel@tonic-gate 493*7c478bd9Sstevel@tonic-gate #ifdef DATAKIT 494*7c478bd9Sstevel@tonic-gate 495*7c478bd9Sstevel@tonic-gate /* 496*7c478bd9Sstevel@tonic-gate * dkcall(flds, dev) make a DATAKIT VCS connection 497*7c478bd9Sstevel@tonic-gate * DATAKIT VCS is a trademark of AT&T 498*7c478bd9Sstevel@tonic-gate * 499*7c478bd9Sstevel@tonic-gate * return codes: 500*7c478bd9Sstevel@tonic-gate * >0 - file number - ok 501*7c478bd9Sstevel@tonic-gate * FAIL - failed 502*7c478bd9Sstevel@tonic-gate */ 503*7c478bd9Sstevel@tonic-gate 504*7c478bd9Sstevel@tonic-gate #include "dk.h" 505*7c478bd9Sstevel@tonic-gate EXTERN int dkdial(); 506*7c478bd9Sstevel@tonic-gate 507*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 508*7c478bd9Sstevel@tonic-gate GLOBAL int 509*7c478bd9Sstevel@tonic-gate dkcall(flds, dev) 510*7c478bd9Sstevel@tonic-gate char *flds[], *dev[]; 511*7c478bd9Sstevel@tonic-gate { 512*7c478bd9Sstevel@tonic-gate register fd; 513*7c478bd9Sstevel@tonic-gate #ifdef V8 514*7c478bd9Sstevel@tonic-gate extern int cdkp_ld; 515*7c478bd9Sstevel@tonic-gate #endif 516*7c478bd9Sstevel@tonic-gate 517*7c478bd9Sstevel@tonic-gate char dialstring[64]; 518*7c478bd9Sstevel@tonic-gate EXTERN void dkbreak(); 519*7c478bd9Sstevel@tonic-gate 520*7c478bd9Sstevel@tonic-gate strcpy(dialstring, dev[D_ARG]); 521*7c478bd9Sstevel@tonic-gate DEBUG(4, "dkcall(%s)\n", dialstring); 522*7c478bd9Sstevel@tonic-gate 523*7c478bd9Sstevel@tonic-gate 524*7c478bd9Sstevel@tonic-gate #ifdef V8 525*7c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 526*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 527*7c478bd9Sstevel@tonic-gate return(FAIL); 528*7c478bd9Sstevel@tonic-gate } 529*7c478bd9Sstevel@tonic-gate 530*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 531*7c478bd9Sstevel@tonic-gate (void) alarm(connecttime); 532*7c478bd9Sstevel@tonic-gate DEBUG(4, "tdkdial(%s", flds[F_PHONE]); 533*7c478bd9Sstevel@tonic-gate DEBUG(4, ", %d)\n", atoi(dev[D_CLASS])); 534*7c478bd9Sstevel@tonic-gate if ((fd = tdkdial(flds[F_PHONE], atoi(dev[D_CLASS]))) >= 0) 535*7c478bd9Sstevel@tonic-gate if (dkproto(fd, cdkp_ld) < 0) 536*7c478bd9Sstevel@tonic-gate { 537*7c478bd9Sstevel@tonic-gate close(fd); 538*7c478bd9Sstevel@tonic-gate fd = -1; 539*7c478bd9Sstevel@tonic-gate } 540*7c478bd9Sstevel@tonic-gate (void) alarm(0); 541*7c478bd9Sstevel@tonic-gate #else 542*7c478bd9Sstevel@tonic-gate fd = dkdial(dialstring); 543*7c478bd9Sstevel@tonic-gate #endif 544*7c478bd9Sstevel@tonic-gate 545*7c478bd9Sstevel@tonic-gate (void) strcpy(Dc, "DK"); 546*7c478bd9Sstevel@tonic-gate if (fd < 0) { 547*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 548*7c478bd9Sstevel@tonic-gate return(FAIL); 549*7c478bd9Sstevel@tonic-gate } 550*7c478bd9Sstevel@tonic-gate else { 551*7c478bd9Sstevel@tonic-gate genbrk = dkbreak; 552*7c478bd9Sstevel@tonic-gate return(fd); 553*7c478bd9Sstevel@tonic-gate } 554*7c478bd9Sstevel@tonic-gate } 555*7c478bd9Sstevel@tonic-gate 556*7c478bd9Sstevel@tonic-gate #endif /* DATAKIT */ 557*7c478bd9Sstevel@tonic-gate 558*7c478bd9Sstevel@tonic-gate #ifdef TCP 559*7c478bd9Sstevel@tonic-gate 560*7c478bd9Sstevel@tonic-gate /* 561*7c478bd9Sstevel@tonic-gate * tcpcall(flds, dev) make ethernet/socket connection 562*7c478bd9Sstevel@tonic-gate * 563*7c478bd9Sstevel@tonic-gate * return codes: 564*7c478bd9Sstevel@tonic-gate * >0 - file number - ok 565*7c478bd9Sstevel@tonic-gate * FAIL - failed 566*7c478bd9Sstevel@tonic-gate */ 567*7c478bd9Sstevel@tonic-gate 568*7c478bd9Sstevel@tonic-gate #if !(defined(BSD4_2) || defined(ATTSVR4)) 569*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 570*7c478bd9Sstevel@tonic-gate GLOBAL int 571*7c478bd9Sstevel@tonic-gate tcpcall(flds, dev) 572*7c478bd9Sstevel@tonic-gate char *flds[], *dev[]; 573*7c478bd9Sstevel@tonic-gate { 574*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 575*7c478bd9Sstevel@tonic-gate return(FAIL); 576*7c478bd9Sstevel@tonic-gate } 577*7c478bd9Sstevel@tonic-gate #else /* BSD4_2 */ 578*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 579*7c478bd9Sstevel@tonic-gate GLOBAL int 580*7c478bd9Sstevel@tonic-gate tcpcall(flds, dev) 581*7c478bd9Sstevel@tonic-gate char *flds[], *dev[]; 582*7c478bd9Sstevel@tonic-gate { 583*7c478bd9Sstevel@tonic-gate int ret; 584*7c478bd9Sstevel@tonic-gate short port; 585*7c478bd9Sstevel@tonic-gate extern int sys_nerr; 586*7c478bd9Sstevel@tonic-gate extern char *sys_errlist[]; 587*7c478bd9Sstevel@tonic-gate struct servent *sp; 588*7c478bd9Sstevel@tonic-gate struct hostent *hp; 589*7c478bd9Sstevel@tonic-gate struct sockaddr_in sin; 590*7c478bd9Sstevel@tonic-gate 591*7c478bd9Sstevel@tonic-gate if (EQUALS(flds[F_CLASS], "-")) { 592*7c478bd9Sstevel@tonic-gate /* 593*7c478bd9Sstevel@tonic-gate * Use standard UUCP port number. 594*7c478bd9Sstevel@tonic-gate */ 595*7c478bd9Sstevel@tonic-gate sp = getservbyname("uucp", "tcp"); 596*7c478bd9Sstevel@tonic-gate endservent(); 597*7c478bd9Sstevel@tonic-gate ASSERT(sp != NULL, "No uucp service number", 0, 0); 598*7c478bd9Sstevel@tonic-gate port = sp->s_port; 599*7c478bd9Sstevel@tonic-gate } else { 600*7c478bd9Sstevel@tonic-gate /* 601*7c478bd9Sstevel@tonic-gate * Systems file specifies a port number. 602*7c478bd9Sstevel@tonic-gate */ 603*7c478bd9Sstevel@tonic-gate sp = getservbyname(flds[F_CLASS], "tcp"); 604*7c478bd9Sstevel@tonic-gate endservent(); 605*7c478bd9Sstevel@tonic-gate if (sp == NULL) { 606*7c478bd9Sstevel@tonic-gate port = htons(atoi(flds[F_CLASS])); 607*7c478bd9Sstevel@tonic-gate if (port == 0) { 608*7c478bd9Sstevel@tonic-gate logent("tcpopen", "unknown port number"); 609*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 610*7c478bd9Sstevel@tonic-gate return(FAIL); 611*7c478bd9Sstevel@tonic-gate } 612*7c478bd9Sstevel@tonic-gate } else 613*7c478bd9Sstevel@tonic-gate port = sp->s_port; 614*7c478bd9Sstevel@tonic-gate } 615*7c478bd9Sstevel@tonic-gate if (EQUALS(flds[F_PHONE], "-")) { 616*7c478bd9Sstevel@tonic-gate /* 617*7c478bd9Sstevel@tonic-gate * Use UUCP name as host name. 618*7c478bd9Sstevel@tonic-gate */ 619*7c478bd9Sstevel@tonic-gate hp = gethostbyname(flds[F_NAME]); 620*7c478bd9Sstevel@tonic-gate } else { 621*7c478bd9Sstevel@tonic-gate /* 622*7c478bd9Sstevel@tonic-gate * Systems file specifies a host name different from the UUCP 623*7c478bd9Sstevel@tonic-gate * host name. 624*7c478bd9Sstevel@tonic-gate */ 625*7c478bd9Sstevel@tonic-gate hp = gethostbyname(flds[F_PHONE]); 626*7c478bd9Sstevel@tonic-gate } 627*7c478bd9Sstevel@tonic-gate endhostent(); 628*7c478bd9Sstevel@tonic-gate if (hp == NULL) { 629*7c478bd9Sstevel@tonic-gate logent("tcpopen", "no such host"); 630*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 631*7c478bd9Sstevel@tonic-gate return(FAIL); 632*7c478bd9Sstevel@tonic-gate } 633*7c478bd9Sstevel@tonic-gate DEBUG(4, "tcpdial host %s, ", hp->h_name); 634*7c478bd9Sstevel@tonic-gate DEBUG(4, "port %d\n", ntohs(port)); 635*7c478bd9Sstevel@tonic-gate 636*7c478bd9Sstevel@tonic-gate ret = socket(AF_INET, SOCK_STREAM, 0); 637*7c478bd9Sstevel@tonic-gate if (ret < 0) { 638*7c478bd9Sstevel@tonic-gate if (errno < sys_nerr) { 639*7c478bd9Sstevel@tonic-gate DEBUG(5, "no socket: %s\n", sys_errlist[errno]); 640*7c478bd9Sstevel@tonic-gate logent("no socket", sys_errlist[errno]); 641*7c478bd9Sstevel@tonic-gate } 642*7c478bd9Sstevel@tonic-gate else { 643*7c478bd9Sstevel@tonic-gate DEBUG(5, "no socket, errno %d\n", errno); 644*7c478bd9Sstevel@tonic-gate logent("tcpopen", "NO SOCKET"); 645*7c478bd9Sstevel@tonic-gate } 646*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 647*7c478bd9Sstevel@tonic-gate return(FAIL); 648*7c478bd9Sstevel@tonic-gate } 649*7c478bd9Sstevel@tonic-gate sin.sin_family = hp->h_addrtype; 650*7c478bd9Sstevel@tonic-gate #ifdef BSD4_2 651*7c478bd9Sstevel@tonic-gate bcopy(hp->h_addr, (caddr_t)&sin.sin_addr, hp->h_length); 652*7c478bd9Sstevel@tonic-gate #else 653*7c478bd9Sstevel@tonic-gate memcpy((caddr_t)&sin.sin_addr, hp->h_addr, hp->h_length); 654*7c478bd9Sstevel@tonic-gate #endif 655*7c478bd9Sstevel@tonic-gate sin.sin_port = port; 656*7c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 657*7c478bd9Sstevel@tonic-gate DEBUG(4, "timeout tcpopen\n%s", ""); 658*7c478bd9Sstevel@tonic-gate logent("tcpopen", "TIMEOUT"); 659*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 660*7c478bd9Sstevel@tonic-gate return(FAIL); 661*7c478bd9Sstevel@tonic-gate } 662*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 663*7c478bd9Sstevel@tonic-gate (void) alarm(connecttime); 664*7c478bd9Sstevel@tonic-gate DEBUG(7, "family: %d\n", sin.sin_family); 665*7c478bd9Sstevel@tonic-gate DEBUG(7, "port: %d\n", sin.sin_port); 666*7c478bd9Sstevel@tonic-gate DEBUG(7, "addr: %08x\n",*((int *) &sin.sin_addr)); 667*7c478bd9Sstevel@tonic-gate if (connect(ret, (struct sockaddr *)&sin, sizeof (sin)) < 0) { 668*7c478bd9Sstevel@tonic-gate (void) alarm(0); 669*7c478bd9Sstevel@tonic-gate (void) close(ret); 670*7c478bd9Sstevel@tonic-gate if (errno < sys_nerr) { 671*7c478bd9Sstevel@tonic-gate DEBUG(5, "connect failed: %s\n", sys_errlist[errno]); 672*7c478bd9Sstevel@tonic-gate logent("connect failed", sys_errlist[errno]); 673*7c478bd9Sstevel@tonic-gate } 674*7c478bd9Sstevel@tonic-gate else { 675*7c478bd9Sstevel@tonic-gate DEBUG(5, "connect failed, errno %d\n", errno); 676*7c478bd9Sstevel@tonic-gate logent("tcpopen", "CONNECT FAILED"); 677*7c478bd9Sstevel@tonic-gate } 678*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 679*7c478bd9Sstevel@tonic-gate return(FAIL); 680*7c478bd9Sstevel@tonic-gate } 681*7c478bd9Sstevel@tonic-gate (void) signal(SIGPIPE, SIG_IGN); /* watch out for broken ipc link...*/ 682*7c478bd9Sstevel@tonic-gate (void) alarm(0); 683*7c478bd9Sstevel@tonic-gate (void) strcpy(Dc, "IPC"); 684*7c478bd9Sstevel@tonic-gate return(ret); 685*7c478bd9Sstevel@tonic-gate } 686*7c478bd9Sstevel@tonic-gate 687*7c478bd9Sstevel@tonic-gate #endif /* BSD4_2 */ 688*7c478bd9Sstevel@tonic-gate 689*7c478bd9Sstevel@tonic-gate /* 690*7c478bd9Sstevel@tonic-gate * unetcall(flds, dev) make ethernet connection 691*7c478bd9Sstevel@tonic-gate * 692*7c478bd9Sstevel@tonic-gate * return codes: 693*7c478bd9Sstevel@tonic-gate * >0 - file number - ok 694*7c478bd9Sstevel@tonic-gate * FAIL - failed 695*7c478bd9Sstevel@tonic-gate */ 696*7c478bd9Sstevel@tonic-gate 697*7c478bd9Sstevel@tonic-gate #ifndef UNET 698*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 699*7c478bd9Sstevel@tonic-gate GLOBAL int 700*7c478bd9Sstevel@tonic-gate unetcall(flds, dev) 701*7c478bd9Sstevel@tonic-gate char *flds[], *dev[]; 702*7c478bd9Sstevel@tonic-gate { 703*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 704*7c478bd9Sstevel@tonic-gate return(FAIL); 705*7c478bd9Sstevel@tonic-gate } 706*7c478bd9Sstevel@tonic-gate #else /* UNET */ 707*7c478bd9Sstevel@tonic-gate GLOBAL int 708*7c478bd9Sstevel@tonic-gate unetcall(flds, dev) 709*7c478bd9Sstevel@tonic-gate char *flds[], *dev[]; 710*7c478bd9Sstevel@tonic-gate { 711*7c478bd9Sstevel@tonic-gate int ret; 712*7c478bd9Sstevel@tonic-gate int port; 713*7c478bd9Sstevel@tonic-gate 714*7c478bd9Sstevel@tonic-gate port = atoi(dev[D_ARG]); 715*7c478bd9Sstevel@tonic-gate DEBUG(4, "unetdial host %s, ", flds[F_PHONE]); 716*7c478bd9Sstevel@tonic-gate DEBUG(4, "port %d\n", port); 717*7c478bd9Sstevel@tonic-gate (void) alarm(connecttime); 718*7c478bd9Sstevel@tonic-gate ret = tcpopen(flds[F_PHONE], port, 0, TO_ACTIVE, "rw"); 719*7c478bd9Sstevel@tonic-gate (void) alarm(0); 720*7c478bd9Sstevel@tonic-gate endhnent(); 721*7c478bd9Sstevel@tonic-gate if (ret < 0) { 722*7c478bd9Sstevel@tonic-gate DEBUG(5, "tcpopen failed: errno %d\n", errno); 723*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 724*7c478bd9Sstevel@tonic-gate return(FAIL); 725*7c478bd9Sstevel@tonic-gate } 726*7c478bd9Sstevel@tonic-gate (void) strcpy(Dc, "UNET"); 727*7c478bd9Sstevel@tonic-gate return(ret); 728*7c478bd9Sstevel@tonic-gate } 729*7c478bd9Sstevel@tonic-gate #endif /* UNET */ 730*7c478bd9Sstevel@tonic-gate 731*7c478bd9Sstevel@tonic-gate #endif /* TCP */ 732*7c478bd9Sstevel@tonic-gate 733*7c478bd9Sstevel@tonic-gate #ifdef SYTEK 734*7c478bd9Sstevel@tonic-gate 735*7c478bd9Sstevel@tonic-gate /* 736*7c478bd9Sstevel@tonic-gate * sytcall(flds, dev) make a sytek connection 737*7c478bd9Sstevel@tonic-gate * 738*7c478bd9Sstevel@tonic-gate * return codes: 739*7c478bd9Sstevel@tonic-gate * >0 - file number - ok 740*7c478bd9Sstevel@tonic-gate * FAIL - failed 741*7c478bd9Sstevel@tonic-gate */ 742*7c478bd9Sstevel@tonic-gate 743*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 744*7c478bd9Sstevel@tonic-gate GLOBAL int 745*7c478bd9Sstevel@tonic-gate sytcall(flds, dev) 746*7c478bd9Sstevel@tonic-gate char *flds[], *dev[]; 747*7c478bd9Sstevel@tonic-gate { 748*7c478bd9Sstevel@tonic-gate int dcr, dcr2, nullfd, ret; 749*7c478bd9Sstevel@tonic-gate char dcname[20], command[BUFSIZ]; 750*7c478bd9Sstevel@tonic-gate 751*7c478bd9Sstevel@tonic-gate (void) sprintf(dcname, "/dev/%s", dev[D_LINE]); 752*7c478bd9Sstevel@tonic-gate DEBUG(4, "dc - %s, ", dcname); 753*7c478bd9Sstevel@tonic-gate dcr = open(dcname, O_WRONLY|O_NDELAY); 754*7c478bd9Sstevel@tonic-gate if (dcr < 0) { 755*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 756*7c478bd9Sstevel@tonic-gate DEBUG(4, "OPEN FAILED %s\n", dcname); 757*7c478bd9Sstevel@tonic-gate return(FAIL); 758*7c478bd9Sstevel@tonic-gate } 759*7c478bd9Sstevel@tonic-gate if ( fd_mklock(dcr) != SUCCESS ) { 760*7c478bd9Sstevel@tonic-gate (void)close(dcr); 761*7c478bd9Sstevel@tonic-gate DEBUG(1, "failed to lock device %s\n", dcname); 762*7c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE; 763*7c478bd9Sstevel@tonic-gate return(FAIL); 764*7c478bd9Sstevel@tonic-gate } 765*7c478bd9Sstevel@tonic-gate 766*7c478bd9Sstevel@tonic-gate sytfixline(dcr, atoi(fdig(dev[D_CLASS])), D_DIRECT); 767*7c478bd9Sstevel@tonic-gate (void) sleep(2); 768*7c478bd9Sstevel@tonic-gate DEBUG(4, "Calling Sytek unit %s\n", dev[D_ARG]); 769*7c478bd9Sstevel@tonic-gate (void) sprintf(command,"\r\rcall %s\r", dev[D_ARG]); 770*7c478bd9Sstevel@tonic-gate ret = (*Write)(dcr, command, strlen(command)); 771*7c478bd9Sstevel@tonic-gate (void) sleep(1); 772*7c478bd9Sstevel@tonic-gate DEBUG(4, "COM1 return = %d\n", ret); 773*7c478bd9Sstevel@tonic-gate sytfix2line(dcr); 774*7c478bd9Sstevel@tonic-gate (void) close(nullfd = open("/", O_RDONLY)); 775*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 776*7c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 777*7c478bd9Sstevel@tonic-gate DEBUG(4, "timeout sytek open\n%s", ""); 778*7c478bd9Sstevel@tonic-gate (void) close(nullfd); 779*7c478bd9Sstevel@tonic-gate (void) close(dcr2); 780*7c478bd9Sstevel@tonic-gate fd_rmlock(dcr); 781*7c478bd9Sstevel@tonic-gate (void) close(dcr); 782*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 783*7c478bd9Sstevel@tonic-gate return(FAIL); 784*7c478bd9Sstevel@tonic-gate } 785*7c478bd9Sstevel@tonic-gate (void) alarm(10); 786*7c478bd9Sstevel@tonic-gate dcr2 = open(dcname,O_RDWR); 787*7c478bd9Sstevel@tonic-gate (void) alarm(0); 788*7c478bd9Sstevel@tonic-gate fd_rmlock(dcr); 789*7c478bd9Sstevel@tonic-gate (void) close(dcr); 790*7c478bd9Sstevel@tonic-gate if (dcr2 < 0) { 791*7c478bd9Sstevel@tonic-gate DEBUG(4, "OPEN 2 FAILED %s\n", dcname); 792*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 793*7c478bd9Sstevel@tonic-gate (void) close(nullfd); /* kernel might think dc2 is open */ 794*7c478bd9Sstevel@tonic-gate return(FAIL); 795*7c478bd9Sstevel@tonic-gate } 796*7c478bd9Sstevel@tonic-gate if ( fd_mklock(dcr2) != SUCCESS ) { 797*7c478bd9Sstevel@tonic-gate (void)close(dcr2); 798*7c478bd9Sstevel@tonic-gate DEBUG(1, "failed to lock device %s\n", dcname); 799*7c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE; 800*7c478bd9Sstevel@tonic-gate return(FAIL); 801*7c478bd9Sstevel@tonic-gate return(dcr2); 802*7c478bd9Sstevel@tonic-gate } 803*7c478bd9Sstevel@tonic-gate 804*7c478bd9Sstevel@tonic-gate #endif /* SYTEK */ 805*7c478bd9Sstevel@tonic-gate 806*7c478bd9Sstevel@tonic-gate #ifdef DIAL801 807*7c478bd9Sstevel@tonic-gate 808*7c478bd9Sstevel@tonic-gate /* 809*7c478bd9Sstevel@tonic-gate * dial801(flds, dev) dial remote machine on 801/801 810*7c478bd9Sstevel@tonic-gate * char *flds[], *dev[]; 811*7c478bd9Sstevel@tonic-gate * 812*7c478bd9Sstevel@tonic-gate * return codes: 813*7c478bd9Sstevel@tonic-gate * file descriptor - succeeded 814*7c478bd9Sstevel@tonic-gate * FAIL - failed 815*7c478bd9Sstevel@tonic-gate * 816*7c478bd9Sstevel@tonic-gate * unfortunately, open801() is different for usg and non-usg 817*7c478bd9Sstevel@tonic-gate */ 818*7c478bd9Sstevel@tonic-gate 819*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 820*7c478bd9Sstevel@tonic-gate GLOBAL int 821*7c478bd9Sstevel@tonic-gate dial801(flds, dev) 822*7c478bd9Sstevel@tonic-gate char *flds[], *dev[]; 823*7c478bd9Sstevel@tonic-gate { 824*7c478bd9Sstevel@tonic-gate char dcname[20], dnname[20], phone[MAXPH+2]; 825*7c478bd9Sstevel@tonic-gate int dcf = -1, speed; 826*7c478bd9Sstevel@tonic-gate 827*7c478bd9Sstevel@tonic-gate (void) sprintf(dnname, "/dev/%s", dev[D_CALLDEV]); 828*7c478bd9Sstevel@tonic-gate (void) sprintf(phone, "%s%s", dev[D_ARG] , ACULAST); 829*7c478bd9Sstevel@tonic-gate (void) sprintf(dcname, "/dev/%s", dev[D_LINE]); 830*7c478bd9Sstevel@tonic-gate CDEBUG(1, "Use Port %s, ", dcname); 831*7c478bd9Sstevel@tonic-gate DEBUG(4, "acu - %s, ", dnname); 832*7c478bd9Sstevel@tonic-gate VERBOSE("Trying modem - %s, ", dcname); /* for cu */ 833*7c478bd9Sstevel@tonic-gate VERBOSE("acu - %s, ", dnname); /* for cu */ 834*7c478bd9Sstevel@tonic-gate if(getuid()==0 || GRPCHK(getgid())) { 835*7c478bd9Sstevel@tonic-gate CDEBUG(1, "Phone Number %s\n", phone); 836*7c478bd9Sstevel@tonic-gate /* In cu, only give out the phone number to trusted people. */ 837*7c478bd9Sstevel@tonic-gate VERBOSE("calling %s: ", phone); /* for cu */ 838*7c478bd9Sstevel@tonic-gate } 839*7c478bd9Sstevel@tonic-gate speed = atoi(fdig(dev[D_CLASS])); 840*7c478bd9Sstevel@tonic-gate dcf = open801(dcname, dnname, phone, speed); 841*7c478bd9Sstevel@tonic-gate if (dcf >= 0) { 842*7c478bd9Sstevel@tonic-gate if ( fd_mklock(dcf) != SUCCESS ) { 843*7c478bd9Sstevel@tonic-gate (void) close(dcf); 844*7c478bd9Sstevel@tonic-gate DEBUG(5, "fd_mklock line %s failed\n", dev[D_LINE]); 845*7c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE; 846*7c478bd9Sstevel@tonic-gate return(FAIL); 847*7c478bd9Sstevel@tonic-gate } 848*7c478bd9Sstevel@tonic-gate fixline(dcf, speed, D_ACU); 849*7c478bd9Sstevel@tonic-gate (void) strcpy(Dc, dev[D_LINE]); /* for later unlock() */ 850*7c478bd9Sstevel@tonic-gate VERBOSE("SUCCEEDED\n%s", ""); 851*7c478bd9Sstevel@tonic-gate } else { 852*7c478bd9Sstevel@tonic-gate VERBOSE("FAILED\n%s", ""); 853*7c478bd9Sstevel@tonic-gate } 854*7c478bd9Sstevel@tonic-gate return(dcf); 855*7c478bd9Sstevel@tonic-gate } 856*7c478bd9Sstevel@tonic-gate 857*7c478bd9Sstevel@tonic-gate 858*7c478bd9Sstevel@tonic-gate #ifndef ATTSV 859*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 860*7c478bd9Sstevel@tonic-gate GLOBAL int 861*7c478bd9Sstevel@tonic-gate open801(dcname, dnname, phone, speed) 862*7c478bd9Sstevel@tonic-gate char *dcname, *dnname, *phone; 863*7c478bd9Sstevel@tonic-gate { 864*7c478bd9Sstevel@tonic-gate int nw, lt, dcf = -1, nullfd, dnf = -1; 865*7c478bd9Sstevel@tonic-gate pid_t w_ret, pid = -1; 866*7c478bd9Sstevel@tonic-gate unsigned timelim; 867*7c478bd9Sstevel@tonic-gate 868*7c478bd9Sstevel@tonic-gate if ((dnf = open(dnname, O_WRONLY)) < 0) { 869*7c478bd9Sstevel@tonic-gate DEBUG(5, "can't open %s\n", dnname); 870*7c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE; 871*7c478bd9Sstevel@tonic-gate return(FAIL); 872*7c478bd9Sstevel@tonic-gate } 873*7c478bd9Sstevel@tonic-gate DEBUG(5, "%s is open\n", dnname); 874*7c478bd9Sstevel@tonic-gate 875*7c478bd9Sstevel@tonic-gate (void) close(nullfd = open("/dev/null", O_RDONLY));/* partial open hack */ 876*7c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 877*7c478bd9Sstevel@tonic-gate DEBUG(4, "timeout modem open\n%s", ""); 878*7c478bd9Sstevel@tonic-gate (void) close(nullfd); 879*7c478bd9Sstevel@tonic-gate (void) close(dcf); 880*7c478bd9Sstevel@tonic-gate (void) close(dnf); 881*7c478bd9Sstevel@tonic-gate logent("801 open", "TIMEOUT"); 882*7c478bd9Sstevel@tonic-gate if (pid > 0) { 883*7c478bd9Sstevel@tonic-gate kill(pid, 9); 884*7c478bd9Sstevel@tonic-gate wait((int *) 0); 885*7c478bd9Sstevel@tonic-gate } 886*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 887*7c478bd9Sstevel@tonic-gate return(FAIL); 888*7c478bd9Sstevel@tonic-gate } 889*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 890*7c478bd9Sstevel@tonic-gate timelim = 5 * strlen(phone); 891*7c478bd9Sstevel@tonic-gate (void) alarm(timelim < connecttime ? connecttime : timelim); 892*7c478bd9Sstevel@tonic-gate if ((pid = fork()) == 0) { 893*7c478bd9Sstevel@tonic-gate sleep(2); 894*7c478bd9Sstevel@tonic-gate nw = (*Write)(dnf, phone, lt = strlen(phone)); 895*7c478bd9Sstevel@tonic-gate if (nw != lt) { 896*7c478bd9Sstevel@tonic-gate DEBUG(4, "ACU write error %d\n", errno); 897*7c478bd9Sstevel@tonic-gate logent("ACU write", "FAILED"); 898*7c478bd9Sstevel@tonic-gate exit(1); 899*7c478bd9Sstevel@tonic-gate } 900*7c478bd9Sstevel@tonic-gate DEBUG(4, "ACU write ok\n%s", ""); 901*7c478bd9Sstevel@tonic-gate exit(0); 902*7c478bd9Sstevel@tonic-gate } 903*7c478bd9Sstevel@tonic-gate /* open line - will return on carrier */ 904*7c478bd9Sstevel@tonic-gate dcf = open(dcname, O_RDWR); 905*7c478bd9Sstevel@tonic-gate 906*7c478bd9Sstevel@tonic-gate DEBUG(4, "dcf is %d\n", dcf); 907*7c478bd9Sstevel@tonic-gate if (dcf < 0) { /* handle like a timeout */ 908*7c478bd9Sstevel@tonic-gate (void) alarm(0); 909*7c478bd9Sstevel@tonic-gate longjmp(Sjbuf, 1); 910*7c478bd9Sstevel@tonic-gate } 911*7c478bd9Sstevel@tonic-gate 912*7c478bd9Sstevel@tonic-gate /* modem is open */ 913*7c478bd9Sstevel@tonic-gate while ((w_ret = wait(<)) != pid) 914*7c478bd9Sstevel@tonic-gate if (w_ret == -1 && errno != EINTR) { 915*7c478bd9Sstevel@tonic-gate DEBUG(4, "Wait failed errno=%d\n", errno); 916*7c478bd9Sstevel@tonic-gate (void) close(dcf); 917*7c478bd9Sstevel@tonic-gate (void) close(dnf); 918*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 919*7c478bd9Sstevel@tonic-gate return(FAIL); 920*7c478bd9Sstevel@tonic-gate } 921*7c478bd9Sstevel@tonic-gate (void) alarm(0); 922*7c478bd9Sstevel@tonic-gate 923*7c478bd9Sstevel@tonic-gate (void) close(dnf); /* no reason to keep the 801 open */ 924*7c478bd9Sstevel@tonic-gate if (lt != 0) { 925*7c478bd9Sstevel@tonic-gate DEBUG(4, "Fork Stat %o\n", lt); 926*7c478bd9Sstevel@tonic-gate (void) close(dcf); 927*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 928*7c478bd9Sstevel@tonic-gate return(FAIL); 929*7c478bd9Sstevel@tonic-gate } 930*7c478bd9Sstevel@tonic-gate return(dcf); 931*7c478bd9Sstevel@tonic-gate } 932*7c478bd9Sstevel@tonic-gate 933*7c478bd9Sstevel@tonic-gate #else /* ATTSV */ 934*7c478bd9Sstevel@tonic-gate 935*7c478bd9Sstevel@tonic-gate GLOBAL int 936*7c478bd9Sstevel@tonic-gate open801(dcname, dnname, phone, speed) 937*7c478bd9Sstevel@tonic-gate char *dcname, *dnname, *phone; 938*7c478bd9Sstevel@tonic-gate { 939*7c478bd9Sstevel@tonic-gate int nw, lt, dcf = -1, nullfd, dnf = -1, ret; 940*7c478bd9Sstevel@tonic-gate unsigned timelim; 941*7c478bd9Sstevel@tonic-gate 942*7c478bd9Sstevel@tonic-gate (void) close(nullfd = open("/", O_RDONLY)); /* partial open hack */ 943*7c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 944*7c478bd9Sstevel@tonic-gate DEBUG(4, "DN write %s\n", "timeout"); 945*7c478bd9Sstevel@tonic-gate (void) close(dnf); 946*7c478bd9Sstevel@tonic-gate (void) close(dcf); 947*7c478bd9Sstevel@tonic-gate (void) close(nullfd); 948*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 949*7c478bd9Sstevel@tonic-gate return(FAIL); 950*7c478bd9Sstevel@tonic-gate } 951*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 952*7c478bd9Sstevel@tonic-gate timelim = 5 * strlen(phone); 953*7c478bd9Sstevel@tonic-gate (void) alarm(timelim < connecttime ? connecttime : timelim); 954*7c478bd9Sstevel@tonic-gate 955*7c478bd9Sstevel@tonic-gate if ((dnf = open(dnname, O_WRONLY)) < 0 ) { 956*7c478bd9Sstevel@tonic-gate DEBUG(5, "can't open %s\n", dnname); 957*7c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE; 958*7c478bd9Sstevel@tonic-gate return(FAIL); 959*7c478bd9Sstevel@tonic-gate } 960*7c478bd9Sstevel@tonic-gate DEBUG(5, "%s is open\n", dnname); 961*7c478bd9Sstevel@tonic-gate if ( fd_mklock(dnf) != SUCCESS ) { 962*7c478bd9Sstevel@tonic-gate (void)close(dnf); 963*7c478bd9Sstevel@tonic-gate DEBUG(1, "failed to lock device %s\n", dnname); 964*7c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE; 965*7c478bd9Sstevel@tonic-gate } 966*7c478bd9Sstevel@tonic-gate if ( (dcf = open(dcname, O_RDWR | O_NDELAY)) < 0 ) { 967*7c478bd9Sstevel@tonic-gate DEBUG(5, "can't open %s\n", dcname); 968*7c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE; 969*7c478bd9Sstevel@tonic-gate return(FAIL); 970*7c478bd9Sstevel@tonic-gate } 971*7c478bd9Sstevel@tonic-gate if ( fd_mklock(dcf) != SUCCESS ) { 972*7c478bd9Sstevel@tonic-gate (void)close(dcf); 973*7c478bd9Sstevel@tonic-gate DEBUG(1, "failed to lock device %s\n", dcname); 974*7c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE; 975*7c478bd9Sstevel@tonic-gate return(FAIL); 976*7c478bd9Sstevel@tonic-gate } 977*7c478bd9Sstevel@tonic-gate 978*7c478bd9Sstevel@tonic-gate DEBUG(4, "dcf is %d\n", dcf); 979*7c478bd9Sstevel@tonic-gate fixline(dcf, speed, D_ACU); 980*7c478bd9Sstevel@tonic-gate nw = (*Write)(dnf, phone, lt = strlen(phone)); 981*7c478bd9Sstevel@tonic-gate if (nw != lt) { 982*7c478bd9Sstevel@tonic-gate (void) alarm(0); 983*7c478bd9Sstevel@tonic-gate DEBUG(4, "ACU write error %d\n", errno); 984*7c478bd9Sstevel@tonic-gate (void) close(dnf); 985*7c478bd9Sstevel@tonic-gate (void) close(dcf); 986*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 987*7c478bd9Sstevel@tonic-gate return(FAIL); 988*7c478bd9Sstevel@tonic-gate } else 989*7c478bd9Sstevel@tonic-gate DEBUG(4, "ACU write ok\n%s", ""); 990*7c478bd9Sstevel@tonic-gate 991*7c478bd9Sstevel@tonic-gate (void) close(dnf); 992*7c478bd9Sstevel@tonic-gate (void) close(nullfd = open("/", O_RDONLY)); /* partial open hack */ 993*7c478bd9Sstevel@tonic-gate ret = open(dcname, O_RDWR); /* wait for carrier */ 994*7c478bd9Sstevel@tonic-gate (void) alarm(0); 995*7c478bd9Sstevel@tonic-gate (void) close(ret); /* close 2nd modem open() */ 996*7c478bd9Sstevel@tonic-gate if (ret < 0) { /* open() interrupted by alarm */ 997*7c478bd9Sstevel@tonic-gate DEBUG(4, "Line open %s\n", "failed"); 998*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 999*7c478bd9Sstevel@tonic-gate (void) close(nullfd); /* close partially opened modem */ 1000*7c478bd9Sstevel@tonic-gate return(FAIL); 1001*7c478bd9Sstevel@tonic-gate } 1002*7c478bd9Sstevel@tonic-gate (void) fcntl(dcf,F_SETFL, fcntl(dcf, F_GETFL, 0) & ~O_NDELAY); 1003*7c478bd9Sstevel@tonic-gate return(dcf); 1004*7c478bd9Sstevel@tonic-gate } 1005*7c478bd9Sstevel@tonic-gate #endif /* ATTSV */ 1006*7c478bd9Sstevel@tonic-gate 1007*7c478bd9Sstevel@tonic-gate #endif /* DIAL801 */ 1008*7c478bd9Sstevel@tonic-gate 1009*7c478bd9Sstevel@tonic-gate #ifdef V8 1010*7c478bd9Sstevel@tonic-gate GLOBAL int 1011*7c478bd9Sstevel@tonic-gate Dialout(flds) 1012*7c478bd9Sstevel@tonic-gate char *flds[]; 1013*7c478bd9Sstevel@tonic-gate { 1014*7c478bd9Sstevel@tonic-gate int fd; 1015*7c478bd9Sstevel@tonic-gate char phone[MAXPH+2]; 1016*7c478bd9Sstevel@tonic-gate 1017*7c478bd9Sstevel@tonic-gate exphone(flds[F_PHONE], phone); 1018*7c478bd9Sstevel@tonic-gate 1019*7c478bd9Sstevel@tonic-gate DEBUG(4, "call dialout(%s", phone); 1020*7c478bd9Sstevel@tonic-gate DEBUG(4, ", %s)\n", dev[D_CLASS]); 1021*7c478bd9Sstevel@tonic-gate fd = dialout(phone, dev[D_CLASS]); 1022*7c478bd9Sstevel@tonic-gate if (fd == -1) 1023*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 1024*7c478bd9Sstevel@tonic-gate if (fd == -3) 1025*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 1026*7c478bd9Sstevel@tonic-gate if (fd == -9) 1027*7c478bd9Sstevel@tonic-gate Uerror = SS_DEVICE_FAILED; 1028*7c478bd9Sstevel@tonic-gate 1029*7c478bd9Sstevel@tonic-gate (void) strcpy(Dc, "Dialout"); 1030*7c478bd9Sstevel@tonic-gate 1031*7c478bd9Sstevel@tonic-gate return(fd); 1032*7c478bd9Sstevel@tonic-gate } 1033*7c478bd9Sstevel@tonic-gate #endif /* V8 */ 1034*7c478bd9Sstevel@tonic-gate 1035*7c478bd9Sstevel@tonic-gate #ifdef TLI 1036*7c478bd9Sstevel@tonic-gate /* 1037*7c478bd9Sstevel@tonic-gate * 1038*7c478bd9Sstevel@tonic-gate * AT&T Transport Layer Interface 1039*7c478bd9Sstevel@tonic-gate * 1040*7c478bd9Sstevel@tonic-gate * expected in Devices 1041*7c478bd9Sstevel@tonic-gate * TLI line1 - - TLI 1042*7c478bd9Sstevel@tonic-gate * or 1043*7c478bd9Sstevel@tonic-gate * TLIS line1 - - TLIS 1044*7c478bd9Sstevel@tonic-gate * 1045*7c478bd9Sstevel@tonic-gate */ 1046*7c478bd9Sstevel@tonic-gate 1047*7c478bd9Sstevel@tonic-gate #include <sys/tiuser.h> 1048*7c478bd9Sstevel@tonic-gate 1049*7c478bd9Sstevel@tonic-gate EXTERN void tfaillog(); 1050*7c478bd9Sstevel@tonic-gate 1051*7c478bd9Sstevel@tonic-gate char *t_alloc(); 1052*7c478bd9Sstevel@tonic-gate int t_bind(), t_close(), t_connect(), t_free(), t_look(), t_open(), t_rcvdis(); 1053*7c478bd9Sstevel@tonic-gate 1054*7c478bd9Sstevel@tonic-gate #define CONNECT_ATTEMPTS 3 1055*7c478bd9Sstevel@tonic-gate #define TFREE(p, type) if ((p)) t_free((char *)(p), (type)) 1056*7c478bd9Sstevel@tonic-gate 1057*7c478bd9Sstevel@tonic-gate /* 1058*7c478bd9Sstevel@tonic-gate * returns fd to remote uucp daemon 1059*7c478bd9Sstevel@tonic-gate */ 1060*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1061*7c478bd9Sstevel@tonic-gate GLOBAL int 1062*7c478bd9Sstevel@tonic-gate tlicall(flds, dev) 1063*7c478bd9Sstevel@tonic-gate char *flds[]; 1064*7c478bd9Sstevel@tonic-gate char *dev[]; 1065*7c478bd9Sstevel@tonic-gate { 1066*7c478bd9Sstevel@tonic-gate char addrbuf[ BUFSIZ ]; 1067*7c478bd9Sstevel@tonic-gate char devname[MAXNAMESIZE]; 1068*7c478bd9Sstevel@tonic-gate int fd; 1069*7c478bd9Sstevel@tonic-gate register int i, j; 1070*7c478bd9Sstevel@tonic-gate struct t_bind *bind_ret = 0; 1071*7c478bd9Sstevel@tonic-gate struct t_info tinfo; 1072*7c478bd9Sstevel@tonic-gate struct t_call *sndcall = 0, *rcvcall = 0; 1073*7c478bd9Sstevel@tonic-gate extern int t_errno; 1074*7c478bd9Sstevel@tonic-gate 1075*7c478bd9Sstevel@tonic-gate EXTERN struct netbuf *stoa(); 1076*7c478bd9Sstevel@tonic-gate 1077*7c478bd9Sstevel@tonic-gate if ( dev[D_LINE][0] != '/' ) { 1078*7c478bd9Sstevel@tonic-gate /* dev holds device name relative to /dev */ 1079*7c478bd9Sstevel@tonic-gate sprintf(devname, "/dev/%s", dev[D_LINE]); 1080*7c478bd9Sstevel@tonic-gate } else { 1081*7c478bd9Sstevel@tonic-gate /* dev holds full path name of device */ 1082*7c478bd9Sstevel@tonic-gate strcpy(devname, dev[D_LINE]); 1083*7c478bd9Sstevel@tonic-gate } 1084*7c478bd9Sstevel@tonic-gate /* gimme local transport endpoint */ 1085*7c478bd9Sstevel@tonic-gate errno = t_errno = 0; 1086*7c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 1087*7c478bd9Sstevel@tonic-gate DEBUG(1, "t_open timeout\n%s", ""); 1088*7c478bd9Sstevel@tonic-gate logent("t_open", "TIMEOUT"); 1089*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 1090*7c478bd9Sstevel@tonic-gate return(FAIL); 1091*7c478bd9Sstevel@tonic-gate } 1092*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 1093*7c478bd9Sstevel@tonic-gate (void) alarm(5); 1094*7c478bd9Sstevel@tonic-gate fd = t_open(devname, O_RDWR, &tinfo); 1095*7c478bd9Sstevel@tonic-gate (void) alarm(0); 1096*7c478bd9Sstevel@tonic-gate if (fd < 0) { 1097*7c478bd9Sstevel@tonic-gate tfaillog(fd, "t_open" ); 1098*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 1099*7c478bd9Sstevel@tonic-gate return(FAIL); 1100*7c478bd9Sstevel@tonic-gate } 1101*7c478bd9Sstevel@tonic-gate if ( fd_mklock(fd) != SUCCESS ) { 1102*7c478bd9Sstevel@tonic-gate (void)t_close(fd); 1103*7c478bd9Sstevel@tonic-gate DEBUG(1, "tlicall: failed to lock device %s\n", devname); 1104*7c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE; 1105*7c478bd9Sstevel@tonic-gate return(FAIL); 1106*7c478bd9Sstevel@tonic-gate } 1107*7c478bd9Sstevel@tonic-gate 1108*7c478bd9Sstevel@tonic-gate /* allocate tli structures */ 1109*7c478bd9Sstevel@tonic-gate errno = t_errno = 0; 1110*7c478bd9Sstevel@tonic-gate if ( (bind_ret = (struct t_bind *)t_alloc(fd, T_BIND, T_ALL)) == 1111*7c478bd9Sstevel@tonic-gate (struct t_bind *)NULL 1112*7c478bd9Sstevel@tonic-gate || (sndcall = (struct t_call *)t_alloc(fd, T_CALL, T_ALL)) == 1113*7c478bd9Sstevel@tonic-gate (struct t_call *)NULL 1114*7c478bd9Sstevel@tonic-gate || (rcvcall = (struct t_call *)t_alloc(fd, T_CALL, T_ALL)) == 1115*7c478bd9Sstevel@tonic-gate (struct t_call *)NULL ) { 1116*7c478bd9Sstevel@tonic-gate tfaillog(fd, "t_alloc" ); 1117*7c478bd9Sstevel@tonic-gate TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL); 1118*7c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL); 1119*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 1120*7c478bd9Sstevel@tonic-gate return(FAIL); 1121*7c478bd9Sstevel@tonic-gate } 1122*7c478bd9Sstevel@tonic-gate 1123*7c478bd9Sstevel@tonic-gate /* bind */ 1124*7c478bd9Sstevel@tonic-gate errno = t_errno = 0; 1125*7c478bd9Sstevel@tonic-gate if (t_bind(fd, (struct t_bind *) 0, bind_ret ) < 0) { 1126*7c478bd9Sstevel@tonic-gate tfaillog(fd, "t_bind" ); 1127*7c478bd9Sstevel@tonic-gate TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL); 1128*7c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL); 1129*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 1130*7c478bd9Sstevel@tonic-gate fd_rmlock(fd); 1131*7c478bd9Sstevel@tonic-gate (void) t_close(fd); 1132*7c478bd9Sstevel@tonic-gate return(FAIL); 1133*7c478bd9Sstevel@tonic-gate } 1134*7c478bd9Sstevel@tonic-gate DEBUG(5, "tlicall: bound to %s\n", bind_ret->addr.buf); 1135*7c478bd9Sstevel@tonic-gate 1136*7c478bd9Sstevel@tonic-gate /* 1137*7c478bd9Sstevel@tonic-gate * Prepare to connect. 1138*7c478bd9Sstevel@tonic-gate * 1139*7c478bd9Sstevel@tonic-gate * If address begins with "\x", "\X", "\o", or "\O", 1140*7c478bd9Sstevel@tonic-gate * assume is hexadecimal or octal address and use stoa() 1141*7c478bd9Sstevel@tonic-gate * to convert it. 1142*7c478bd9Sstevel@tonic-gate * 1143*7c478bd9Sstevel@tonic-gate * Else is usual uucico address -- only \N's left to process. 1144*7c478bd9Sstevel@tonic-gate * Walk thru connection address, changing \N's to NULLCHARs. 1145*7c478bd9Sstevel@tonic-gate * Note: If a NULLCHAR must be part of the connection address, 1146*7c478bd9Sstevel@tonic-gate * it must be overtly included in the address. One recommended 1147*7c478bd9Sstevel@tonic-gate * way is to do it in the Devices file, thusly: 1148*7c478bd9Sstevel@tonic-gate * Netname /dev/netport - - TLI \D\000 1149*7c478bd9Sstevel@tonic-gate * bsfix() turns \000 into \N and then the loop below makes it a 1150*7c478bd9Sstevel@tonic-gate * real, included-in-the-length null-byte. 1151*7c478bd9Sstevel@tonic-gate * 1152*7c478bd9Sstevel@tonic-gate * The DEBUG must print the strecpy'd address (so that 1153*7c478bd9Sstevel@tonic-gate * non-printables will have been replaced with C escapes). 1154*7c478bd9Sstevel@tonic-gate */ 1155*7c478bd9Sstevel@tonic-gate 1156*7c478bd9Sstevel@tonic-gate DEBUG(5, "t_connect to addr \"%s\"\n", 1157*7c478bd9Sstevel@tonic-gate strecpy( addrbuf, dev[D_ARG], "\\" ) ); 1158*7c478bd9Sstevel@tonic-gate 1159*7c478bd9Sstevel@tonic-gate if ( dev[D_ARG][0] == '\\' && 1160*7c478bd9Sstevel@tonic-gate ( dev[D_ARG][1] == 'x' || dev[D_ARG][1] == 'X' 1161*7c478bd9Sstevel@tonic-gate || dev[D_ARG][1] == 'o' || dev[D_ARG][1] == 'O' ) ) { 1162*7c478bd9Sstevel@tonic-gate if ( stoa(dev[D_ARG], &(sndcall->addr)) == (struct netbuf *)NULL ) { 1163*7c478bd9Sstevel@tonic-gate DEBUG(5, "tlicall: stoa failed\n%s", ""); 1164*7c478bd9Sstevel@tonic-gate logent("tlicall", "string-to-address failed"); 1165*7c478bd9Sstevel@tonic-gate TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL); 1166*7c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL); 1167*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 1168*7c478bd9Sstevel@tonic-gate fd_rmlock(fd); 1169*7c478bd9Sstevel@tonic-gate (void) t_close(fd); 1170*7c478bd9Sstevel@tonic-gate return(FAIL); 1171*7c478bd9Sstevel@tonic-gate } 1172*7c478bd9Sstevel@tonic-gate } else { 1173*7c478bd9Sstevel@tonic-gate for( i = j = 0; i < BUFSIZ && dev[D_ARG][i] != NULLCHAR; 1174*7c478bd9Sstevel@tonic-gate ++i, ++j ) { 1175*7c478bd9Sstevel@tonic-gate if( dev[D_ARG][i] == '\\' && dev[D_ARG][i+1] == 'N' ) { 1176*7c478bd9Sstevel@tonic-gate addrbuf[j] = NULLCHAR; 1177*7c478bd9Sstevel@tonic-gate ++i; 1178*7c478bd9Sstevel@tonic-gate } 1179*7c478bd9Sstevel@tonic-gate else { 1180*7c478bd9Sstevel@tonic-gate addrbuf[j] = dev[D_ARG][i]; 1181*7c478bd9Sstevel@tonic-gate } 1182*7c478bd9Sstevel@tonic-gate } 1183*7c478bd9Sstevel@tonic-gate sndcall->addr.buf = addrbuf; 1184*7c478bd9Sstevel@tonic-gate sndcall->addr.len = j; 1185*7c478bd9Sstevel@tonic-gate } 1186*7c478bd9Sstevel@tonic-gate 1187*7c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 1188*7c478bd9Sstevel@tonic-gate DEBUG(4, "timeout tlicall\n%s", ""); 1189*7c478bd9Sstevel@tonic-gate logent("tlicall", "TIMEOUT"); 1190*7c478bd9Sstevel@tonic-gate TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL); 1191*7c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL); 1192*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 1193*7c478bd9Sstevel@tonic-gate fd_rmlock(fd); 1194*7c478bd9Sstevel@tonic-gate (void) t_close(fd); 1195*7c478bd9Sstevel@tonic-gate return(FAIL); 1196*7c478bd9Sstevel@tonic-gate } 1197*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 1198*7c478bd9Sstevel@tonic-gate (void) alarm(connecttime); 1199*7c478bd9Sstevel@tonic-gate 1200*7c478bd9Sstevel@tonic-gate /* connect to the service -- some listeners can't handle */ 1201*7c478bd9Sstevel@tonic-gate /* multiple connect requests, so try it a few times */ 1202*7c478bd9Sstevel@tonic-gate errno = t_errno = 0; 1203*7c478bd9Sstevel@tonic-gate for ( i = 0; i < CONNECT_ATTEMPTS; ++i ) { 1204*7c478bd9Sstevel@tonic-gate if (t_connect(fd, sndcall, rcvcall) == 0) 1205*7c478bd9Sstevel@tonic-gate break; 1206*7c478bd9Sstevel@tonic-gate if ( (t_errno == TLOOK) && (t_look(fd) == T_DISCONNECT)) { 1207*7c478bd9Sstevel@tonic-gate t_rcvdis(fd,NULL); 1208*7c478bd9Sstevel@tonic-gate (void) alarm(0); 1209*7c478bd9Sstevel@tonic-gate } else { 1210*7c478bd9Sstevel@tonic-gate (void) alarm(0); 1211*7c478bd9Sstevel@tonic-gate tfaillog(fd, "t_connect"); 1212*7c478bd9Sstevel@tonic-gate TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL); 1213*7c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL); 1214*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 1215*7c478bd9Sstevel@tonic-gate fd_rmlock(fd); 1216*7c478bd9Sstevel@tonic-gate (void) t_close(fd); 1217*7c478bd9Sstevel@tonic-gate return(FAIL); 1218*7c478bd9Sstevel@tonic-gate } 1219*7c478bd9Sstevel@tonic-gate } 1220*7c478bd9Sstevel@tonic-gate (void) alarm(0); 1221*7c478bd9Sstevel@tonic-gate TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL); 1222*7c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL); 1223*7c478bd9Sstevel@tonic-gate if ( i == CONNECT_ATTEMPTS ) { 1224*7c478bd9Sstevel@tonic-gate tfaillog(fd, "t_connect"); 1225*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 1226*7c478bd9Sstevel@tonic-gate fd_rmlock(fd); 1227*7c478bd9Sstevel@tonic-gate (void) t_close(fd); 1228*7c478bd9Sstevel@tonic-gate return(FAIL); 1229*7c478bd9Sstevel@tonic-gate } 1230*7c478bd9Sstevel@tonic-gate errno = t_errno = 0; 1231*7c478bd9Sstevel@tonic-gate (void) strcpy(Dc, dev[D_CALLER]); 1232*7c478bd9Sstevel@tonic-gate return(fd); 1233*7c478bd9Sstevel@tonic-gate } 1234*7c478bd9Sstevel@tonic-gate #endif /* TLI */ 1235