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 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate #ident "%Z%%M% %I% %E% SMI" /* from SVR4 bnu:dial.c 1.3 */ 27*7c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/ 28*7c478bd9Sstevel@tonic-gate /*************************************************************** 29*7c478bd9Sstevel@tonic-gate * dial() returns an fd for an open tty-line connected to the 30*7c478bd9Sstevel@tonic-gate * specified remote. The caller should trap all ways to 31*7c478bd9Sstevel@tonic-gate * terminate, and call undial(). This will release the `lock' 32*7c478bd9Sstevel@tonic-gate * file and return the outgoing line to the system. This routine 33*7c478bd9Sstevel@tonic-gate * would prefer that the calling routine not use the `alarm()' 34*7c478bd9Sstevel@tonic-gate * system call, nor issue a `signal(SIGALRM, xxx)' call. 35*7c478bd9Sstevel@tonic-gate * If you must, then please save and restore the alarm times. 36*7c478bd9Sstevel@tonic-gate * The sleep() library routine is ok, though. 37*7c478bd9Sstevel@tonic-gate * 38*7c478bd9Sstevel@tonic-gate * #include <sys/types.h> 39*7c478bd9Sstevel@tonic-gate * #include <sys/stat.h> 40*7c478bd9Sstevel@tonic-gate * #include "dial.h" 41*7c478bd9Sstevel@tonic-gate * 42*7c478bd9Sstevel@tonic-gate * int dial(call); 43*7c478bd9Sstevel@tonic-gate * CALL call; 44*7c478bd9Sstevel@tonic-gate * 45*7c478bd9Sstevel@tonic-gate * void undial(rlfd); 46*7c478bd9Sstevel@tonic-gate * int rlfd; 47*7c478bd9Sstevel@tonic-gate * 48*7c478bd9Sstevel@tonic-gate * rlfd is the "remote-lne file descriptor" returned from dial. 49*7c478bd9Sstevel@tonic-gate * 50*7c478bd9Sstevel@tonic-gate * The CALL structure as (defined in dial.h): 51*7c478bd9Sstevel@tonic-gate * 52*7c478bd9Sstevel@tonic-gate * typedef struct { 53*7c478bd9Sstevel@tonic-gate * struct termio *attr; ptr to term attribute structure 54*7c478bd9Sstevel@tonic-gate * int baud; no longer used -- 55*7c478bd9Sstevel@tonic-gate * left in for backwards compatibility 56*7c478bd9Sstevel@tonic-gate * int speed; 212A modem: low=300, high=1200 57*7c478bd9Sstevel@tonic-gate * negative for "Any" speed 58*7c478bd9Sstevel@tonic-gate * char *line; device name for out-going line 59*7c478bd9Sstevel@tonic-gate * char *telno; ptr to tel-no digit string 60*7c478bd9Sstevel@tonic-gate * int modem no longer used -- 61*7c478bd9Sstevel@tonic-gate * left in for backwards compatibility 62*7c478bd9Sstevel@tonic-gate * char *device no longer used -- 63*7c478bd9Sstevel@tonic-gate * left in for backwards compatibility 64*7c478bd9Sstevel@tonic-gate * int dev_len no longer used -- 65*7c478bd9Sstevel@tonic-gate * left in for backwards compatibility 66*7c478bd9Sstevel@tonic-gate * } CALL; 67*7c478bd9Sstevel@tonic-gate * 68*7c478bd9Sstevel@tonic-gate * The error returns from dial are negative, in the range -1 69*7c478bd9Sstevel@tonic-gate * to -13, and their meanings are: 70*7c478bd9Sstevel@tonic-gate * 71*7c478bd9Sstevel@tonic-gate * INTRPT -1: interrupt occured 72*7c478bd9Sstevel@tonic-gate * D_HUNG -2: dialer hung (no return from write) 73*7c478bd9Sstevel@tonic-gate * NO_ANS -3: no answer (caller script failed) 74*7c478bd9Sstevel@tonic-gate * ILL_BD -4: illegal baud-rate 75*7c478bd9Sstevel@tonic-gate * A_PROB -5: acu problem (open() failure) 76*7c478bd9Sstevel@tonic-gate * L_PROB -6: line problem (open() failure) 77*7c478bd9Sstevel@tonic-gate * NO_Ldv -7: can't open Devices file 78*7c478bd9Sstevel@tonic-gate * DV_NT_A -8: specified device not available 79*7c478bd9Sstevel@tonic-gate * DV_NT_K -9: specified device not known 80*7c478bd9Sstevel@tonic-gate * NO_BD_A -10: no device available at requested baud-rate 81*7c478bd9Sstevel@tonic-gate * NO_BD_K -11: no device known at requested baud-rate 82*7c478bd9Sstevel@tonic-gate * DV_NT_E -12: requested speed does not match 83*7c478bd9Sstevel@tonic-gate * BAD_SYS -13: system not in Systems file 84*7c478bd9Sstevel@tonic-gate * 85*7c478bd9Sstevel@tonic-gate * Setting attributes in the termio structure indicated in 86*7c478bd9Sstevel@tonic-gate * the `attr' field of the CALL structure before passing the 87*7c478bd9Sstevel@tonic-gate * structure to dial(), will cause those attributes to be set 88*7c478bd9Sstevel@tonic-gate * before the connection is made. This can be important for 89*7c478bd9Sstevel@tonic-gate * some attributes such as parity and baud. 90*7c478bd9Sstevel@tonic-gate * 91*7c478bd9Sstevel@tonic-gate * With an error return (negative value), there will not be 92*7c478bd9Sstevel@tonic-gate * any `lock-file' entry, so no need to call undial(). 93*7c478bd9Sstevel@tonic-gate ***************************************************************/ 94*7c478bd9Sstevel@tonic-gate 95*7c478bd9Sstevel@tonic-gate #include <stdio.h> 96*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 97*7c478bd9Sstevel@tonic-gate #include <string.h> 98*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 99*7c478bd9Sstevel@tonic-gate #include <unistd.h> 100*7c478bd9Sstevel@tonic-gate #include <setjmp.h> 101*7c478bd9Sstevel@tonic-gate #include <sys/stat.h> 102*7c478bd9Sstevel@tonic-gate #include <sys/times.h> 103*7c478bd9Sstevel@tonic-gate #include <fcntl.h> 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate #include "dial.h" 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate #include "uucp.h" 108*7c478bd9Sstevel@tonic-gate #include "uucpdefs.c" 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate #include "callers.c" 111*7c478bd9Sstevel@tonic-gate #include "conn.c" 112*7c478bd9Sstevel@tonic-gate #include "getargs.c" 113*7c478bd9Sstevel@tonic-gate #include "interface.c" 114*7c478bd9Sstevel@tonic-gate #include "line.c" 115*7c478bd9Sstevel@tonic-gate #include "stoa.c" 116*7c478bd9Sstevel@tonic-gate #include "strecpy.c" 117*7c478bd9Sstevel@tonic-gate #include "strsave.c" 118*7c478bd9Sstevel@tonic-gate #include "sysfiles.c" 119*7c478bd9Sstevel@tonic-gate #include "ulockf.c" 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate #ifdef DATAKIT 122*7c478bd9Sstevel@tonic-gate #include "dkbreak.c" 123*7c478bd9Sstevel@tonic-gate #include "dkerr.c" 124*7c478bd9Sstevel@tonic-gate #include "dkdial.c" 125*7c478bd9Sstevel@tonic-gate #include "dkminor.c" 126*7c478bd9Sstevel@tonic-gate #include "dtnamer.c" 127*7c478bd9Sstevel@tonic-gate #endif 128*7c478bd9Sstevel@tonic-gate 129*7c478bd9Sstevel@tonic-gate static int 130*7c478bd9Sstevel@tonic-gate rlfd; /* fd for remote comm line */ 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate GLOBAL jmp_buf Sjbuf; /*needed by connection routines*/ 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate /*VARARGS*/ 135*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 136*7c478bd9Sstevel@tonic-gate static void 137*7c478bd9Sstevel@tonic-gate assert(s1,s2,i1,s3,i2) 138*7c478bd9Sstevel@tonic-gate char *s1, *s2, *s3; 139*7c478bd9Sstevel@tonic-gate int i1, i2; 140*7c478bd9Sstevel@tonic-gate {} /* for ASSERT in conn() */ 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 143*7c478bd9Sstevel@tonic-gate static void 144*7c478bd9Sstevel@tonic-gate logent(s1,s2) 145*7c478bd9Sstevel@tonic-gate char *s1, *s2; 146*7c478bd9Sstevel@tonic-gate {} /* so we can load unlockf() */ 147*7c478bd9Sstevel@tonic-gate 148*7c478bd9Sstevel@tonic-gate static void 149*7c478bd9Sstevel@tonic-gate cleanup(Cn) /*this is executed only in the parent process*/ 150*7c478bd9Sstevel@tonic-gate int Cn; /*fd for remote comm line */ 151*7c478bd9Sstevel@tonic-gate { 152*7c478bd9Sstevel@tonic-gate (void)restline(); 153*7c478bd9Sstevel@tonic-gate (void)setuid(Euid); 154*7c478bd9Sstevel@tonic-gate if(Cn > 0) { 155*7c478bd9Sstevel@tonic-gate (void) close(Cn); 156*7c478bd9Sstevel@tonic-gate } 157*7c478bd9Sstevel@tonic-gate 158*7c478bd9Sstevel@tonic-gate 159*7c478bd9Sstevel@tonic-gate rmlock((char*) NULL); /*uucp routine in ulockf.c*/ 160*7c478bd9Sstevel@tonic-gate return; /* code=negative for signal causing disconnect*/ 161*7c478bd9Sstevel@tonic-gate } 162*7c478bd9Sstevel@tonic-gate 163*7c478bd9Sstevel@tonic-gate int 164*7c478bd9Sstevel@tonic-gate dial(call) 165*7c478bd9Sstevel@tonic-gate CALL call; 166*7c478bd9Sstevel@tonic-gate { 167*7c478bd9Sstevel@tonic-gate char *alt[7]; 168*7c478bd9Sstevel@tonic-gate char speed[10]; /* character value of speed passed to dial */ 169*7c478bd9Sstevel@tonic-gate 170*7c478bd9Sstevel@tonic-gate /* set service so we know which Sysfiles entries to use, then */ 171*7c478bd9Sstevel@tonic-gate /* be sure can access Devices file(s). use "cu" entries ... */ 172*7c478bd9Sstevel@tonic-gate /* dial is more like cu than like uucico. */ 173*7c478bd9Sstevel@tonic-gate (void)strcpy(Progname,"cu"); 174*7c478bd9Sstevel@tonic-gate setservice(Progname); 175*7c478bd9Sstevel@tonic-gate if ( sysaccess(EACCESS_DEVICES) != 0 ) { 176*7c478bd9Sstevel@tonic-gate /* can't read Devices file(s) */ 177*7c478bd9Sstevel@tonic-gate return(NO_Ldv); 178*7c478bd9Sstevel@tonic-gate } 179*7c478bd9Sstevel@tonic-gate 180*7c478bd9Sstevel@tonic-gate if (call.attr != NULL) { 181*7c478bd9Sstevel@tonic-gate if ( call.attr->c_cflag & PARENB ) { 182*7c478bd9Sstevel@tonic-gate Evenflag = ((call.attr->c_cflag & PARODD) ? 0 : 1); 183*7c478bd9Sstevel@tonic-gate Oddflag = ((call.attr->c_cflag & PARODD) ? 1 : 0); 184*7c478bd9Sstevel@tonic-gate } 185*7c478bd9Sstevel@tonic-gate line_8bit = (call.attr->c_cflag & CS8 ? 1 : 0); 186*7c478bd9Sstevel@tonic-gate } 187*7c478bd9Sstevel@tonic-gate 188*7c478bd9Sstevel@tonic-gate if (call.speed <= 0) 189*7c478bd9Sstevel@tonic-gate strcpy(speed,"Any"); 190*7c478bd9Sstevel@tonic-gate else 191*7c478bd9Sstevel@tonic-gate sprintf(speed,"%d",call.speed); 192*7c478bd9Sstevel@tonic-gate 193*7c478bd9Sstevel@tonic-gate /* Determine whether contents of "telno" is a system name. */ 194*7c478bd9Sstevel@tonic-gate if ( (call.telno != NULL) && 195*7c478bd9Sstevel@tonic-gate (strlen(call.telno) != strspn(call.telno,"0123456789=-*#")) ) { 196*7c478bd9Sstevel@tonic-gate /* use conn() for system names */ 197*7c478bd9Sstevel@tonic-gate rlfd = conn(call.telno); 198*7c478bd9Sstevel@tonic-gate } else { 199*7c478bd9Sstevel@tonic-gate alt[F_NAME] = "dummy"; /* to replace the Systems file fields */ 200*7c478bd9Sstevel@tonic-gate alt[F_TIME] = "Any"; /* needed for getto(); [F_TYPE] and */ 201*7c478bd9Sstevel@tonic-gate alt[F_TYPE] = ""; /* [F_PHONE] assignment below */ 202*7c478bd9Sstevel@tonic-gate alt[F_CLASS] = speed; 203*7c478bd9Sstevel@tonic-gate alt[F_PHONE] = ""; 204*7c478bd9Sstevel@tonic-gate alt[F_LOGIN] = ""; 205*7c478bd9Sstevel@tonic-gate alt[6] = ""; 206*7c478bd9Sstevel@tonic-gate 207*7c478bd9Sstevel@tonic-gate if ( (call.telno != NULL) && (*call.telno != '\0') ) { 208*7c478bd9Sstevel@tonic-gate /* given a phone number, use an ACU */ 209*7c478bd9Sstevel@tonic-gate alt[F_PHONE] = call.telno; 210*7c478bd9Sstevel@tonic-gate alt[F_TYPE] = "ACU"; 211*7c478bd9Sstevel@tonic-gate } else { 212*7c478bd9Sstevel@tonic-gate /* otherwise, use a Direct connection */ 213*7c478bd9Sstevel@tonic-gate alt[F_TYPE] = "Direct"; 214*7c478bd9Sstevel@tonic-gate /* If device name starts with "/dev/", strip it off */ 215*7c478bd9Sstevel@tonic-gate /* since Devices file entries will also be stripped. */ 216*7c478bd9Sstevel@tonic-gate if ( (call.line != NULL) && 217*7c478bd9Sstevel@tonic-gate (strncmp(call.line, "/dev/", 5) == 0) ) 218*7c478bd9Sstevel@tonic-gate Myline = (call.line + 5); 219*7c478bd9Sstevel@tonic-gate else 220*7c478bd9Sstevel@tonic-gate Myline = call.line; 221*7c478bd9Sstevel@tonic-gate } 222*7c478bd9Sstevel@tonic-gate 223*7c478bd9Sstevel@tonic-gate #ifdef forfutureuse 224*7c478bd9Sstevel@tonic-gate if (call->class != NULL) 225*7c478bd9Sstevel@tonic-gate alt[F_TYPE] = call->class; 226*7c478bd9Sstevel@tonic-gate #endif 227*7c478bd9Sstevel@tonic-gate 228*7c478bd9Sstevel@tonic-gate 229*7c478bd9Sstevel@tonic-gate rlfd = getto(alt); 230*7c478bd9Sstevel@tonic-gate } 231*7c478bd9Sstevel@tonic-gate if (rlfd < 0) 232*7c478bd9Sstevel@tonic-gate switch (Uerror) { 233*7c478bd9Sstevel@tonic-gate case SS_NO_DEVICE: return(NO_BD_A); 234*7c478bd9Sstevel@tonic-gate case SS_DIAL_FAILED: return(D_HUNG); 235*7c478bd9Sstevel@tonic-gate case SS_LOCKED_DEVICE: return(DV_NT_A); 236*7c478bd9Sstevel@tonic-gate case SS_BADSYSTEM: return(BAD_SYS); 237*7c478bd9Sstevel@tonic-gate case SS_CANT_ACCESS_DEVICE: return(L_PROB); 238*7c478bd9Sstevel@tonic-gate case SS_CHAT_FAILED: return(NO_ANS); 239*7c478bd9Sstevel@tonic-gate default: return(-Uerror); 240*7c478bd9Sstevel@tonic-gate } 241*7c478bd9Sstevel@tonic-gate (void)savline(); 242*7c478bd9Sstevel@tonic-gate if ((call.attr) && ioctl(rlfd, TCSETA, call.attr) < 0) { 243*7c478bd9Sstevel@tonic-gate perror("stty for remote"); 244*7c478bd9Sstevel@tonic-gate return(L_PROB); 245*7c478bd9Sstevel@tonic-gate } 246*7c478bd9Sstevel@tonic-gate Euid = geteuid(); 247*7c478bd9Sstevel@tonic-gate if(setuid(getuid()) && setgid(getgid()) < 0) 248*7c478bd9Sstevel@tonic-gate undial(rlfd); 249*7c478bd9Sstevel@tonic-gate return(rlfd); 250*7c478bd9Sstevel@tonic-gate } 251*7c478bd9Sstevel@tonic-gate 252*7c478bd9Sstevel@tonic-gate /* 253*7c478bd9Sstevel@tonic-gate * undial(fd) 254*7c478bd9Sstevel@tonic-gate */ 255*7c478bd9Sstevel@tonic-gate void 256*7c478bd9Sstevel@tonic-gate undial(fd) 257*7c478bd9Sstevel@tonic-gate int fd; 258*7c478bd9Sstevel@tonic-gate { 259*7c478bd9Sstevel@tonic-gate sethup(fd); 260*7c478bd9Sstevel@tonic-gate sleep(2); 261*7c478bd9Sstevel@tonic-gate cleanup(fd); 262*7c478bd9Sstevel@tonic-gate } 263