17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 2261961e0fSrobinson 2361961e0fSrobinson /* 24*e8031f0aSraf * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 2561961e0fSrobinson * Use is subject to license terms. 2661961e0fSrobinson */ 2761961e0fSrobinson 287c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 297c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 307c478bd9Sstevel@tonic-gate 3161961e0fSrobinson #pragma ident "%Z%%M% %I% %E% SMI" 327c478bd9Sstevel@tonic-gate 3361961e0fSrobinson /* 3461961e0fSrobinson * ************************************************************* 357c478bd9Sstevel@tonic-gate * dial() returns an fd for an open tty-line connected to the 367c478bd9Sstevel@tonic-gate * specified remote. The caller should trap all ways to 377c478bd9Sstevel@tonic-gate * terminate, and call undial(). This will release the `lock' 387c478bd9Sstevel@tonic-gate * file and return the outgoing line to the system. This routine 397c478bd9Sstevel@tonic-gate * would prefer that the calling routine not use the `alarm()' 407c478bd9Sstevel@tonic-gate * system call, nor issue a `signal(SIGALRM, xxx)' call. 417c478bd9Sstevel@tonic-gate * If you must, then please save and restore the alarm times. 427c478bd9Sstevel@tonic-gate * The sleep() library routine is ok, though. 437c478bd9Sstevel@tonic-gate * 447c478bd9Sstevel@tonic-gate * #include <sys/types.h> 457c478bd9Sstevel@tonic-gate * #include <sys/stat.h> 467c478bd9Sstevel@tonic-gate * #include "dial.h" 477c478bd9Sstevel@tonic-gate * 487c478bd9Sstevel@tonic-gate * int dial(call); 497c478bd9Sstevel@tonic-gate * CALL call; 507c478bd9Sstevel@tonic-gate * 517c478bd9Sstevel@tonic-gate * void undial(rlfd); 527c478bd9Sstevel@tonic-gate * int rlfd; 537c478bd9Sstevel@tonic-gate * 547c478bd9Sstevel@tonic-gate * rlfd is the "remote-lne file descriptor" returned from dial. 557c478bd9Sstevel@tonic-gate * 567c478bd9Sstevel@tonic-gate * The CALL structure as (defined in dial.h): 577c478bd9Sstevel@tonic-gate * 587c478bd9Sstevel@tonic-gate * typedef struct { 597c478bd9Sstevel@tonic-gate * struct termio *attr; ptr to term attribute structure 607c478bd9Sstevel@tonic-gate * int baud; no longer used -- 617c478bd9Sstevel@tonic-gate * left in for backwards compatibility 627c478bd9Sstevel@tonic-gate * int speed; 212A modem: low=300, high=1200 637c478bd9Sstevel@tonic-gate * negative for "Any" speed 647c478bd9Sstevel@tonic-gate * char *line; device name for out-going line 657c478bd9Sstevel@tonic-gate * char *telno; ptr to tel-no digit string 667c478bd9Sstevel@tonic-gate * int modem no longer used -- 677c478bd9Sstevel@tonic-gate * left in for backwards compatibility 687c478bd9Sstevel@tonic-gate * char *device no longer used -- 697c478bd9Sstevel@tonic-gate * left in for backwards compatibility 707c478bd9Sstevel@tonic-gate * int dev_len no longer used -- 717c478bd9Sstevel@tonic-gate * left in for backwards compatibility 727c478bd9Sstevel@tonic-gate * } CALL; 737c478bd9Sstevel@tonic-gate * 747c478bd9Sstevel@tonic-gate * The error returns from dial are negative, in the range -1 757c478bd9Sstevel@tonic-gate * to -13, and their meanings are: 767c478bd9Sstevel@tonic-gate * 777c478bd9Sstevel@tonic-gate * INTRPT -1: interrupt occured 787c478bd9Sstevel@tonic-gate * D_HUNG -2: dialer hung (no return from write) 797c478bd9Sstevel@tonic-gate * NO_ANS -3: no answer (caller script failed) 807c478bd9Sstevel@tonic-gate * ILL_BD -4: illegal baud-rate 817c478bd9Sstevel@tonic-gate * A_PROB -5: acu problem (open() failure) 827c478bd9Sstevel@tonic-gate * L_PROB -6: line problem (open() failure) 837c478bd9Sstevel@tonic-gate * NO_Ldv -7: can't open Devices file 847c478bd9Sstevel@tonic-gate * DV_NT_A -8: specified device not available 857c478bd9Sstevel@tonic-gate * DV_NT_K -9: specified device not known 8661961e0fSrobinson * NO_BD_A -10: no dev available at requested baud-rate 877c478bd9Sstevel@tonic-gate * NO_BD_K -11: no device known at requested baud-rate 887c478bd9Sstevel@tonic-gate * DV_NT_E -12: requested speed does not match 897c478bd9Sstevel@tonic-gate * BAD_SYS -13: system not in Systems file 907c478bd9Sstevel@tonic-gate * 917c478bd9Sstevel@tonic-gate * Setting attributes in the termio structure indicated in 927c478bd9Sstevel@tonic-gate * the `attr' field of the CALL structure before passing the 937c478bd9Sstevel@tonic-gate * structure to dial(), will cause those attributes to be set 947c478bd9Sstevel@tonic-gate * before the connection is made. This can be important for 957c478bd9Sstevel@tonic-gate * some attributes such as parity and baud. 967c478bd9Sstevel@tonic-gate * 977c478bd9Sstevel@tonic-gate * With an error return (negative value), there will not be 987c478bd9Sstevel@tonic-gate * any `lock-file' entry, so no need to call undial(). 9961961e0fSrobinson * ************************************************************* 10061961e0fSrobinson */ 1017c478bd9Sstevel@tonic-gate 102*e8031f0aSraf #include "mt.h" 103*e8031f0aSraf 1047c478bd9Sstevel@tonic-gate #include <stdio.h> 1057c478bd9Sstevel@tonic-gate #include <stdlib.h> 1067c478bd9Sstevel@tonic-gate #include <string.h> 1077c478bd9Sstevel@tonic-gate #include <sys/types.h> 1087c478bd9Sstevel@tonic-gate #include <unistd.h> 1097c478bd9Sstevel@tonic-gate #include <setjmp.h> 1107c478bd9Sstevel@tonic-gate #include <sys/stat.h> 1117c478bd9Sstevel@tonic-gate #include <sys/times.h> 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate #include "dial.h" 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate #include "uucp.h" 1167c478bd9Sstevel@tonic-gate #include "uucpdefs.c" 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate #include "callers.c" 1197c478bd9Sstevel@tonic-gate #include "conn.c" 1207c478bd9Sstevel@tonic-gate #include "getargs.c" 1217c478bd9Sstevel@tonic-gate #include "interface.c" 1227c478bd9Sstevel@tonic-gate #include "line.c" 1237c478bd9Sstevel@tonic-gate #include "stoa.c" 1247c478bd9Sstevel@tonic-gate #include "strecpy.c" 1257c478bd9Sstevel@tonic-gate #include "strsave.c" 1267c478bd9Sstevel@tonic-gate #include "sysfiles.c" 1277c478bd9Sstevel@tonic-gate #include "ulockf.c" 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate static int rlfd; /* fd for remote comm line */ 1307c478bd9Sstevel@tonic-gate 13161961e0fSrobinson static jmp_buf Sjbuf; /* needed by connection routines */ 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate /* VARARGS */ 1347c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1357c478bd9Sstevel@tonic-gate static void 13661961e0fSrobinson assert(const char *s1, const char *s2, int i1, const char *s3, int i2) 1377c478bd9Sstevel@tonic-gate { /* for ASSERT in conn() */ 1387c478bd9Sstevel@tonic-gate } 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1417c478bd9Sstevel@tonic-gate static void 14261961e0fSrobinson logent(const char *s1, const char *s2) 1437c478bd9Sstevel@tonic-gate { /* so we can load unlockf() */ 1447c478bd9Sstevel@tonic-gate } 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate static void 14761961e0fSrobinson cleanup(int Cn) /* this is executed only in the parent process */ 1487c478bd9Sstevel@tonic-gate { 1497c478bd9Sstevel@tonic-gate (void) restline(); 1507c478bd9Sstevel@tonic-gate (void) setuid(Euid); 1517c478bd9Sstevel@tonic-gate if (Cn > 0) 1527c478bd9Sstevel@tonic-gate (void) close(Cn); 1537c478bd9Sstevel@tonic-gate 15461961e0fSrobinson rmlock(NULL); /* uucp routine in ulockf.c */ 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate int 15861961e0fSrobinson dial(CALL call) 1597c478bd9Sstevel@tonic-gate { 1607c478bd9Sstevel@tonic-gate char *alt[7]; 1617c478bd9Sstevel@tonic-gate char speed[10]; /* character value of speed passed to dial */ 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate /* set service so we know which Sysfiles entries to use, then */ 1647c478bd9Sstevel@tonic-gate /* be sure can access Devices file(s). use "cu" entries ... */ 1657c478bd9Sstevel@tonic-gate /* dial is more like cu than like uucico. */ 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate (void) strcpy(Progname, "cu"); 1687c478bd9Sstevel@tonic-gate setservice(Progname); 16961961e0fSrobinson if (sysaccess(EACCESS_DEVICES) != 0) 1707c478bd9Sstevel@tonic-gate /* can't read Devices file(s) */ 1717c478bd9Sstevel@tonic-gate return (NO_Ldv); 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate if (call.attr != NULL) { 1747c478bd9Sstevel@tonic-gate if (call.attr->c_cflag & PARENB) { 1757c478bd9Sstevel@tonic-gate Evenflag = ((call.attr->c_cflag & PARODD) ? 0 : 1); 1767c478bd9Sstevel@tonic-gate Oddflag = ((call.attr->c_cflag & PARODD) ? 1 : 0); 1777c478bd9Sstevel@tonic-gate } 1787c478bd9Sstevel@tonic-gate line_8bit = (call.attr->c_cflag & CS8 ? 1 : 0); 1797c478bd9Sstevel@tonic-gate } 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate if (call.speed <= 0) 18261961e0fSrobinson (void) strcpy(speed, "Any"); 1837c478bd9Sstevel@tonic-gate else 18461961e0fSrobinson (void) sprintf(speed, "%d", call.speed); 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate /* Determine whether contents of "telno" is a system name. */ 1877c478bd9Sstevel@tonic-gate if ((call.telno != NULL) && 1887c478bd9Sstevel@tonic-gate (strlen(call.telno) != strspn(call.telno, "0123456789=-*#"))) { 1897c478bd9Sstevel@tonic-gate /* use conn() for system names */ 1907c478bd9Sstevel@tonic-gate rlfd = conn(call.telno); 1917c478bd9Sstevel@tonic-gate } else { 1927c478bd9Sstevel@tonic-gate alt[F_NAME] = "dummy"; /* to replace the Systems file fields */ 1937c478bd9Sstevel@tonic-gate alt[F_TIME] = "Any"; /* needed for getto(); [F_TYPE] and */ 1947c478bd9Sstevel@tonic-gate alt[F_TYPE] = ""; /* [F_PHONE] assignment below */ 1957c478bd9Sstevel@tonic-gate alt[F_CLASS] = speed; 1967c478bd9Sstevel@tonic-gate alt[F_PHONE] = ""; 1977c478bd9Sstevel@tonic-gate alt[F_LOGIN] = ""; 1987c478bd9Sstevel@tonic-gate alt[6] = ""; 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate if ((call.telno != NULL) && (*call.telno != '\0')) { 2017c478bd9Sstevel@tonic-gate /* given a phone number, use an ACU */ 2027c478bd9Sstevel@tonic-gate alt[F_PHONE] = call.telno; 2037c478bd9Sstevel@tonic-gate alt[F_TYPE] = "ACU"; 2047c478bd9Sstevel@tonic-gate } else { 2057c478bd9Sstevel@tonic-gate /* otherwise, use a Direct connection */ 2067c478bd9Sstevel@tonic-gate alt[F_TYPE] = "Direct"; 2077c478bd9Sstevel@tonic-gate /* If device name starts with "/dev/", strip it off */ 2087c478bd9Sstevel@tonic-gate /* since Devices file entries will also be stripped. */ 2097c478bd9Sstevel@tonic-gate if ((call.line != NULL) && 2107c478bd9Sstevel@tonic-gate (strncmp(call.line, "/dev/", 5) == 0)) 2117c478bd9Sstevel@tonic-gate Myline = (call.line + 5); 2127c478bd9Sstevel@tonic-gate else 2137c478bd9Sstevel@tonic-gate Myline = call.line; 2147c478bd9Sstevel@tonic-gate } 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate #ifdef forfutureuse 2177c478bd9Sstevel@tonic-gate if (call->class != NULL) 2187c478bd9Sstevel@tonic-gate alt[F_TYPE] = call->class; 2197c478bd9Sstevel@tonic-gate #endif 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate rlfd = getto(alt); 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate if (rlfd < 0) 2257c478bd9Sstevel@tonic-gate switch (Uerror) { 2267c478bd9Sstevel@tonic-gate case SS_NO_DEVICE: 2277c478bd9Sstevel@tonic-gate return (NO_BD_A); 2287c478bd9Sstevel@tonic-gate case SS_DIAL_FAILED: 2297c478bd9Sstevel@tonic-gate return (D_HUNG); 2307c478bd9Sstevel@tonic-gate case SS_LOCKED_DEVICE: 2317c478bd9Sstevel@tonic-gate return (DV_NT_A); 2327c478bd9Sstevel@tonic-gate case SS_BADSYSTEM: 2337c478bd9Sstevel@tonic-gate return (BAD_SYS); 2347c478bd9Sstevel@tonic-gate case SS_CANT_ACCESS_DEVICE: 2357c478bd9Sstevel@tonic-gate return (L_PROB); 2367c478bd9Sstevel@tonic-gate case SS_CHAT_FAILED: 2377c478bd9Sstevel@tonic-gate return (NO_ANS); 2387c478bd9Sstevel@tonic-gate default: 2397c478bd9Sstevel@tonic-gate return (-Uerror); 2407c478bd9Sstevel@tonic-gate } 2417c478bd9Sstevel@tonic-gate (void) savline(); 2427c478bd9Sstevel@tonic-gate if ((call.attr) && ioctl(rlfd, TCSETA, call.attr) < 0) { 2437c478bd9Sstevel@tonic-gate perror("stty for remote"); 2447c478bd9Sstevel@tonic-gate return (L_PROB); 2457c478bd9Sstevel@tonic-gate } 2467c478bd9Sstevel@tonic-gate Euid = geteuid(); 2477c478bd9Sstevel@tonic-gate if (setuid(getuid()) && setgid(getgid()) < 0) 2487c478bd9Sstevel@tonic-gate undial(rlfd); 2497c478bd9Sstevel@tonic-gate return (rlfd); 2507c478bd9Sstevel@tonic-gate } 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate /* 2537c478bd9Sstevel@tonic-gate * undial(fd) 2547c478bd9Sstevel@tonic-gate */ 2557c478bd9Sstevel@tonic-gate void 25661961e0fSrobinson undial(int fd) 2577c478bd9Sstevel@tonic-gate { 2587c478bd9Sstevel@tonic-gate sethup(fd); 25961961e0fSrobinson (void) sleep(2); 2607c478bd9Sstevel@tonic-gate cleanup(fd); 2617c478bd9Sstevel@tonic-gate } 262