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" /* SVr4.0 1.5 */ 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 <rpc/trace.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 rlfd; /* fd for remote comm line */ 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate GLOBAL jmp_buf Sjbuf; /* needed by connection routines */ 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate /* VARARGS */ 134*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 135*7c478bd9Sstevel@tonic-gate static void 136*7c478bd9Sstevel@tonic-gate assert(s1, s2, i1, s3, i2) 137*7c478bd9Sstevel@tonic-gate #if defined(__STDC__) 138*7c478bd9Sstevel@tonic-gate const char *s1, *s2, *s3; 139*7c478bd9Sstevel@tonic-gate #else 140*7c478bd9Sstevel@tonic-gate char *s1, *s2, *s3; 141*7c478bd9Sstevel@tonic-gate #endif 142*7c478bd9Sstevel@tonic-gate int i1, i2; 143*7c478bd9Sstevel@tonic-gate { /* for ASSERT in conn() */ 144*7c478bd9Sstevel@tonic-gate trace3(TR_assert, 0, i1, i2); 145*7c478bd9Sstevel@tonic-gate trace3(TR_assert, 1, i1, i2); 146*7c478bd9Sstevel@tonic-gate } 147*7c478bd9Sstevel@tonic-gate 148*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 149*7c478bd9Sstevel@tonic-gate static void 150*7c478bd9Sstevel@tonic-gate logent(s1, s2) 151*7c478bd9Sstevel@tonic-gate #if defined(__STDC__) 152*7c478bd9Sstevel@tonic-gate const char *s1, *s2; 153*7c478bd9Sstevel@tonic-gate #else 154*7c478bd9Sstevel@tonic-gate char *s1, *s2; 155*7c478bd9Sstevel@tonic-gate #endif 156*7c478bd9Sstevel@tonic-gate { /* so we can load unlockf() */ 157*7c478bd9Sstevel@tonic-gate trace1(TR_logent, 0); 158*7c478bd9Sstevel@tonic-gate trace1(TR_logent, 1); 159*7c478bd9Sstevel@tonic-gate } 160*7c478bd9Sstevel@tonic-gate 161*7c478bd9Sstevel@tonic-gate static void 162*7c478bd9Sstevel@tonic-gate cleanup(Cn) /* this is executed only in the parent process */ 163*7c478bd9Sstevel@tonic-gate int Cn; /* fd for remote comm line */ 164*7c478bd9Sstevel@tonic-gate { 165*7c478bd9Sstevel@tonic-gate 166*7c478bd9Sstevel@tonic-gate trace2(TR_cleanup, 0, Cn); 167*7c478bd9Sstevel@tonic-gate (void) restline(); 168*7c478bd9Sstevel@tonic-gate (void) setuid(Euid); 169*7c478bd9Sstevel@tonic-gate if (Cn > 0) 170*7c478bd9Sstevel@tonic-gate (void) close(Cn); 171*7c478bd9Sstevel@tonic-gate 172*7c478bd9Sstevel@tonic-gate 173*7c478bd9Sstevel@tonic-gate rmlock((char*) NULL); /* uucp routine in ulockf.c */ 174*7c478bd9Sstevel@tonic-gate trace1(TR_cleanup, 1); 175*7c478bd9Sstevel@tonic-gate return; /* code=negative for signal causing disconnect */ 176*7c478bd9Sstevel@tonic-gate } 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate int 179*7c478bd9Sstevel@tonic-gate dial(call) 180*7c478bd9Sstevel@tonic-gate CALL call; 181*7c478bd9Sstevel@tonic-gate { 182*7c478bd9Sstevel@tonic-gate char *alt[7]; 183*7c478bd9Sstevel@tonic-gate char speed[10]; /* character value of speed passed to dial */ 184*7c478bd9Sstevel@tonic-gate 185*7c478bd9Sstevel@tonic-gate /* set service so we know which Sysfiles entries to use, then */ 186*7c478bd9Sstevel@tonic-gate /* be sure can access Devices file(s). use "cu" entries ... */ 187*7c478bd9Sstevel@tonic-gate /* dial is more like cu than like uucico. */ 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate trace1(TR_dial, 0); 190*7c478bd9Sstevel@tonic-gate (void) strcpy(Progname, "cu"); 191*7c478bd9Sstevel@tonic-gate setservice(Progname); 192*7c478bd9Sstevel@tonic-gate if (sysaccess(EACCESS_DEVICES) != 0) { 193*7c478bd9Sstevel@tonic-gate /* can't read Devices file(s) */ 194*7c478bd9Sstevel@tonic-gate trace1(TR_dial, 1); 195*7c478bd9Sstevel@tonic-gate return (NO_Ldv); 196*7c478bd9Sstevel@tonic-gate } 197*7c478bd9Sstevel@tonic-gate 198*7c478bd9Sstevel@tonic-gate if (call.attr != NULL) { 199*7c478bd9Sstevel@tonic-gate if (call.attr->c_cflag & PARENB) { 200*7c478bd9Sstevel@tonic-gate Evenflag = ((call.attr->c_cflag & PARODD) ? 0 : 1); 201*7c478bd9Sstevel@tonic-gate Oddflag = ((call.attr->c_cflag & PARODD) ? 1 : 0); 202*7c478bd9Sstevel@tonic-gate } 203*7c478bd9Sstevel@tonic-gate line_8bit = (call.attr->c_cflag & CS8 ? 1 : 0); 204*7c478bd9Sstevel@tonic-gate } 205*7c478bd9Sstevel@tonic-gate 206*7c478bd9Sstevel@tonic-gate if (call.speed <= 0) 207*7c478bd9Sstevel@tonic-gate strcpy(speed, "Any"); 208*7c478bd9Sstevel@tonic-gate else 209*7c478bd9Sstevel@tonic-gate sprintf(speed, "%d", call.speed); 210*7c478bd9Sstevel@tonic-gate 211*7c478bd9Sstevel@tonic-gate /* Determine whether contents of "telno" is a system name. */ 212*7c478bd9Sstevel@tonic-gate if ((call.telno != NULL) && 213*7c478bd9Sstevel@tonic-gate (strlen(call.telno) != strspn(call.telno, "0123456789=-*#"))) { 214*7c478bd9Sstevel@tonic-gate /* use conn() for system names */ 215*7c478bd9Sstevel@tonic-gate rlfd = conn(call.telno); 216*7c478bd9Sstevel@tonic-gate } else { 217*7c478bd9Sstevel@tonic-gate alt[F_NAME] = "dummy"; /* to replace the Systems file fields */ 218*7c478bd9Sstevel@tonic-gate alt[F_TIME] = "Any"; /* needed for getto(); [F_TYPE] and */ 219*7c478bd9Sstevel@tonic-gate alt[F_TYPE] = ""; /* [F_PHONE] assignment below */ 220*7c478bd9Sstevel@tonic-gate alt[F_CLASS] = speed; 221*7c478bd9Sstevel@tonic-gate alt[F_PHONE] = ""; 222*7c478bd9Sstevel@tonic-gate alt[F_LOGIN] = ""; 223*7c478bd9Sstevel@tonic-gate alt[6] = ""; 224*7c478bd9Sstevel@tonic-gate 225*7c478bd9Sstevel@tonic-gate if ((call.telno != NULL) && (*call.telno != '\0')) { 226*7c478bd9Sstevel@tonic-gate /* given a phone number, use an ACU */ 227*7c478bd9Sstevel@tonic-gate alt[F_PHONE] = call.telno; 228*7c478bd9Sstevel@tonic-gate alt[F_TYPE] = "ACU"; 229*7c478bd9Sstevel@tonic-gate } else { 230*7c478bd9Sstevel@tonic-gate /* otherwise, use a Direct connection */ 231*7c478bd9Sstevel@tonic-gate alt[F_TYPE] = "Direct"; 232*7c478bd9Sstevel@tonic-gate /* If device name starts with "/dev/", strip it off */ 233*7c478bd9Sstevel@tonic-gate /* since Devices file entries will also be stripped. */ 234*7c478bd9Sstevel@tonic-gate if ((call.line != NULL) && 235*7c478bd9Sstevel@tonic-gate (strncmp(call.line, "/dev/", 5) == 0)) 236*7c478bd9Sstevel@tonic-gate Myline = (call.line + 5); 237*7c478bd9Sstevel@tonic-gate else 238*7c478bd9Sstevel@tonic-gate Myline = call.line; 239*7c478bd9Sstevel@tonic-gate } 240*7c478bd9Sstevel@tonic-gate 241*7c478bd9Sstevel@tonic-gate #ifdef forfutureuse 242*7c478bd9Sstevel@tonic-gate if (call->class != NULL) 243*7c478bd9Sstevel@tonic-gate alt[F_TYPE] = call->class; 244*7c478bd9Sstevel@tonic-gate #endif 245*7c478bd9Sstevel@tonic-gate 246*7c478bd9Sstevel@tonic-gate 247*7c478bd9Sstevel@tonic-gate rlfd = getto(alt); 248*7c478bd9Sstevel@tonic-gate } 249*7c478bd9Sstevel@tonic-gate if (rlfd < 0) 250*7c478bd9Sstevel@tonic-gate switch (Uerror) { 251*7c478bd9Sstevel@tonic-gate case SS_NO_DEVICE: 252*7c478bd9Sstevel@tonic-gate trace1(TR_dial, 1); 253*7c478bd9Sstevel@tonic-gate return (NO_BD_A); 254*7c478bd9Sstevel@tonic-gate case SS_DIAL_FAILED: 255*7c478bd9Sstevel@tonic-gate trace1(TR_dial, 1); 256*7c478bd9Sstevel@tonic-gate return (D_HUNG); 257*7c478bd9Sstevel@tonic-gate case SS_LOCKED_DEVICE: 258*7c478bd9Sstevel@tonic-gate trace1(TR_dial, 1); 259*7c478bd9Sstevel@tonic-gate return (DV_NT_A); 260*7c478bd9Sstevel@tonic-gate case SS_BADSYSTEM: 261*7c478bd9Sstevel@tonic-gate trace1(TR_dial, 1); 262*7c478bd9Sstevel@tonic-gate return (BAD_SYS); 263*7c478bd9Sstevel@tonic-gate case SS_CANT_ACCESS_DEVICE: 264*7c478bd9Sstevel@tonic-gate trace1(TR_dial, 1); 265*7c478bd9Sstevel@tonic-gate return (L_PROB); 266*7c478bd9Sstevel@tonic-gate case SS_CHAT_FAILED: 267*7c478bd9Sstevel@tonic-gate trace1(TR_dial, 1); 268*7c478bd9Sstevel@tonic-gate return (NO_ANS); 269*7c478bd9Sstevel@tonic-gate default: 270*7c478bd9Sstevel@tonic-gate trace1(TR_dial, 1); 271*7c478bd9Sstevel@tonic-gate return (-Uerror); 272*7c478bd9Sstevel@tonic-gate } 273*7c478bd9Sstevel@tonic-gate (void) savline(); 274*7c478bd9Sstevel@tonic-gate if ((call.attr) && ioctl(rlfd, TCSETA, call.attr) < 0) { 275*7c478bd9Sstevel@tonic-gate perror("stty for remote"); 276*7c478bd9Sstevel@tonic-gate trace1(TR_dial, 1); 277*7c478bd9Sstevel@tonic-gate return (L_PROB); 278*7c478bd9Sstevel@tonic-gate } 279*7c478bd9Sstevel@tonic-gate Euid = geteuid(); 280*7c478bd9Sstevel@tonic-gate if (setuid(getuid()) && setgid(getgid()) < 0) 281*7c478bd9Sstevel@tonic-gate undial(rlfd); 282*7c478bd9Sstevel@tonic-gate trace1(TR_dial, 1); 283*7c478bd9Sstevel@tonic-gate return (rlfd); 284*7c478bd9Sstevel@tonic-gate } 285*7c478bd9Sstevel@tonic-gate 286*7c478bd9Sstevel@tonic-gate /* 287*7c478bd9Sstevel@tonic-gate * undial(fd) 288*7c478bd9Sstevel@tonic-gate */ 289*7c478bd9Sstevel@tonic-gate void 290*7c478bd9Sstevel@tonic-gate undial(fd) 291*7c478bd9Sstevel@tonic-gate int fd; 292*7c478bd9Sstevel@tonic-gate { 293*7c478bd9Sstevel@tonic-gate trace2(TR_undial, 0, fd); 294*7c478bd9Sstevel@tonic-gate sethup(fd); 295*7c478bd9Sstevel@tonic-gate sleep(2); 296*7c478bd9Sstevel@tonic-gate cleanup(fd); 297*7c478bd9Sstevel@tonic-gate trace1(TR_undial, 1); 298*7c478bd9Sstevel@tonic-gate } 299