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 /*
3261961e0fSrobinson * *************************************************************
337c478bd9Sstevel@tonic-gate * dial() returns an fd for an open tty-line connected to the
347c478bd9Sstevel@tonic-gate * specified remote. The caller should trap all ways to
357c478bd9Sstevel@tonic-gate * terminate, and call undial(). This will release the `lock'
367c478bd9Sstevel@tonic-gate * file and return the outgoing line to the system. This routine
377c478bd9Sstevel@tonic-gate * would prefer that the calling routine not use the `alarm()'
387c478bd9Sstevel@tonic-gate * system call, nor issue a `signal(SIGALRM, xxx)' call.
397c478bd9Sstevel@tonic-gate * If you must, then please save and restore the alarm times.
407c478bd9Sstevel@tonic-gate * The sleep() library routine is ok, though.
417c478bd9Sstevel@tonic-gate *
427c478bd9Sstevel@tonic-gate * #include <sys/types.h>
437c478bd9Sstevel@tonic-gate * #include <sys/stat.h>
447c478bd9Sstevel@tonic-gate * #include "dial.h"
457c478bd9Sstevel@tonic-gate *
467c478bd9Sstevel@tonic-gate * int dial(call);
477c478bd9Sstevel@tonic-gate * CALL call;
487c478bd9Sstevel@tonic-gate *
497c478bd9Sstevel@tonic-gate * void undial(rlfd);
507c478bd9Sstevel@tonic-gate * int rlfd;
517c478bd9Sstevel@tonic-gate *
527c478bd9Sstevel@tonic-gate * rlfd is the "remote-lne file descriptor" returned from dial.
537c478bd9Sstevel@tonic-gate *
547c478bd9Sstevel@tonic-gate * The CALL structure as (defined in dial.h):
557c478bd9Sstevel@tonic-gate *
567c478bd9Sstevel@tonic-gate * typedef struct {
577c478bd9Sstevel@tonic-gate * struct termio *attr; ptr to term attribute structure
587c478bd9Sstevel@tonic-gate * int baud; no longer used --
597c478bd9Sstevel@tonic-gate * left in for backwards compatibility
607c478bd9Sstevel@tonic-gate * int speed; 212A modem: low=300, high=1200
617c478bd9Sstevel@tonic-gate * negative for "Any" speed
627c478bd9Sstevel@tonic-gate * char *line; device name for out-going line
637c478bd9Sstevel@tonic-gate * char *telno; ptr to tel-no digit string
647c478bd9Sstevel@tonic-gate * int modem no longer used --
657c478bd9Sstevel@tonic-gate * left in for backwards compatibility
667c478bd9Sstevel@tonic-gate * char *device no longer used --
677c478bd9Sstevel@tonic-gate * left in for backwards compatibility
687c478bd9Sstevel@tonic-gate * int dev_len no longer used --
697c478bd9Sstevel@tonic-gate * left in for backwards compatibility
707c478bd9Sstevel@tonic-gate * } CALL;
717c478bd9Sstevel@tonic-gate *
727c478bd9Sstevel@tonic-gate * The error returns from dial are negative, in the range -1
737c478bd9Sstevel@tonic-gate * to -13, and their meanings are:
747c478bd9Sstevel@tonic-gate *
757c478bd9Sstevel@tonic-gate * INTRPT -1: interrupt occured
767c478bd9Sstevel@tonic-gate * D_HUNG -2: dialer hung (no return from write)
777c478bd9Sstevel@tonic-gate * NO_ANS -3: no answer (caller script failed)
787c478bd9Sstevel@tonic-gate * ILL_BD -4: illegal baud-rate
797c478bd9Sstevel@tonic-gate * A_PROB -5: acu problem (open() failure)
807c478bd9Sstevel@tonic-gate * L_PROB -6: line problem (open() failure)
817c478bd9Sstevel@tonic-gate * NO_Ldv -7: can't open Devices file
827c478bd9Sstevel@tonic-gate * DV_NT_A -8: specified device not available
837c478bd9Sstevel@tonic-gate * DV_NT_K -9: specified device not known
8461961e0fSrobinson * NO_BD_A -10: no dev available at requested baud-rate
857c478bd9Sstevel@tonic-gate * NO_BD_K -11: no device known at requested baud-rate
867c478bd9Sstevel@tonic-gate * DV_NT_E -12: requested speed does not match
877c478bd9Sstevel@tonic-gate * BAD_SYS -13: system not in Systems file
887c478bd9Sstevel@tonic-gate *
897c478bd9Sstevel@tonic-gate * Setting attributes in the termio structure indicated in
907c478bd9Sstevel@tonic-gate * the `attr' field of the CALL structure before passing the
917c478bd9Sstevel@tonic-gate * structure to dial(), will cause those attributes to be set
927c478bd9Sstevel@tonic-gate * before the connection is made. This can be important for
937c478bd9Sstevel@tonic-gate * some attributes such as parity and baud.
947c478bd9Sstevel@tonic-gate *
957c478bd9Sstevel@tonic-gate * With an error return (negative value), there will not be
967c478bd9Sstevel@tonic-gate * any `lock-file' entry, so no need to call undial().
9761961e0fSrobinson * *************************************************************
9861961e0fSrobinson */
997c478bd9Sstevel@tonic-gate
100*e8031f0aSraf #include "mt.h"
101*e8031f0aSraf
1027c478bd9Sstevel@tonic-gate #include <stdio.h>
1037c478bd9Sstevel@tonic-gate #include <stdlib.h>
1047c478bd9Sstevel@tonic-gate #include <string.h>
1057c478bd9Sstevel@tonic-gate #include <sys/types.h>
1067c478bd9Sstevel@tonic-gate #include <unistd.h>
1077c478bd9Sstevel@tonic-gate #include <setjmp.h>
1087c478bd9Sstevel@tonic-gate #include <sys/stat.h>
1097c478bd9Sstevel@tonic-gate #include <sys/times.h>
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate #include "dial.h"
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate #include "uucp.h"
1147c478bd9Sstevel@tonic-gate #include "uucpdefs.c"
1157c478bd9Sstevel@tonic-gate
1167c478bd9Sstevel@tonic-gate #include "callers.c"
1177c478bd9Sstevel@tonic-gate #include "conn.c"
1187c478bd9Sstevel@tonic-gate #include "getargs.c"
1197c478bd9Sstevel@tonic-gate #include "interface.c"
1207c478bd9Sstevel@tonic-gate #include "line.c"
1217c478bd9Sstevel@tonic-gate #include "stoa.c"
1227c478bd9Sstevel@tonic-gate #include "strecpy.c"
1237c478bd9Sstevel@tonic-gate #include "strsave.c"
1247c478bd9Sstevel@tonic-gate #include "sysfiles.c"
1257c478bd9Sstevel@tonic-gate #include "ulockf.c"
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate static int rlfd; /* fd for remote comm line */
1287c478bd9Sstevel@tonic-gate
12961961e0fSrobinson static jmp_buf Sjbuf; /* needed by connection routines */
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate /* VARARGS */
1327c478bd9Sstevel@tonic-gate /* ARGSUSED */
1337c478bd9Sstevel@tonic-gate static void
assert(const char * s1,const char * s2,int i1,const char * s3,int i2)13461961e0fSrobinson assert(const char *s1, const char *s2, int i1, const char *s3, int i2)
1357c478bd9Sstevel@tonic-gate { /* for ASSERT in conn() */
1367c478bd9Sstevel@tonic-gate }
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate /* ARGSUSED */
1397c478bd9Sstevel@tonic-gate static void
logent(const char * s1,const char * s2)14061961e0fSrobinson logent(const char *s1, const char *s2)
1417c478bd9Sstevel@tonic-gate { /* so we can load unlockf() */
1427c478bd9Sstevel@tonic-gate }
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate static void
cleanup(int Cn)14561961e0fSrobinson cleanup(int Cn) /* this is executed only in the parent process */
1467c478bd9Sstevel@tonic-gate {
1477c478bd9Sstevel@tonic-gate (void) restline();
1487c478bd9Sstevel@tonic-gate (void) setuid(Euid);
1497c478bd9Sstevel@tonic-gate if (Cn > 0)
1507c478bd9Sstevel@tonic-gate (void) close(Cn);
1517c478bd9Sstevel@tonic-gate
15261961e0fSrobinson rmlock(NULL); /* uucp routine in ulockf.c */
1537c478bd9Sstevel@tonic-gate }
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate int
dial(CALL call)15661961e0fSrobinson dial(CALL call)
1577c478bd9Sstevel@tonic-gate {
1587c478bd9Sstevel@tonic-gate char *alt[7];
1597c478bd9Sstevel@tonic-gate char speed[10]; /* character value of speed passed to dial */
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate /* set service so we know which Sysfiles entries to use, then */
1627c478bd9Sstevel@tonic-gate /* be sure can access Devices file(s). use "cu" entries ... */
1637c478bd9Sstevel@tonic-gate /* dial is more like cu than like uucico. */
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate (void) strcpy(Progname, "cu");
1667c478bd9Sstevel@tonic-gate setservice(Progname);
16761961e0fSrobinson if (sysaccess(EACCESS_DEVICES) != 0)
1687c478bd9Sstevel@tonic-gate /* can't read Devices file(s) */
1697c478bd9Sstevel@tonic-gate return (NO_Ldv);
1707c478bd9Sstevel@tonic-gate
1717c478bd9Sstevel@tonic-gate if (call.attr != NULL) {
1727c478bd9Sstevel@tonic-gate if (call.attr->c_cflag & PARENB) {
1737c478bd9Sstevel@tonic-gate Evenflag = ((call.attr->c_cflag & PARODD) ? 0 : 1);
1747c478bd9Sstevel@tonic-gate Oddflag = ((call.attr->c_cflag & PARODD) ? 1 : 0);
1757c478bd9Sstevel@tonic-gate }
1767c478bd9Sstevel@tonic-gate line_8bit = (call.attr->c_cflag & CS8 ? 1 : 0);
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate if (call.speed <= 0)
18061961e0fSrobinson (void) strcpy(speed, "Any");
1817c478bd9Sstevel@tonic-gate else
18261961e0fSrobinson (void) sprintf(speed, "%d", call.speed);
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate /* Determine whether contents of "telno" is a system name. */
1857c478bd9Sstevel@tonic-gate if ((call.telno != NULL) &&
1867c478bd9Sstevel@tonic-gate (strlen(call.telno) != strspn(call.telno, "0123456789=-*#"))) {
1877c478bd9Sstevel@tonic-gate /* use conn() for system names */
1887c478bd9Sstevel@tonic-gate rlfd = conn(call.telno);
1897c478bd9Sstevel@tonic-gate } else {
1907c478bd9Sstevel@tonic-gate alt[F_NAME] = "dummy"; /* to replace the Systems file fields */
1917c478bd9Sstevel@tonic-gate alt[F_TIME] = "Any"; /* needed for getto(); [F_TYPE] and */
1927c478bd9Sstevel@tonic-gate alt[F_TYPE] = ""; /* [F_PHONE] assignment below */
1937c478bd9Sstevel@tonic-gate alt[F_CLASS] = speed;
1947c478bd9Sstevel@tonic-gate alt[F_PHONE] = "";
1957c478bd9Sstevel@tonic-gate alt[F_LOGIN] = "";
1967c478bd9Sstevel@tonic-gate alt[6] = "";
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate if ((call.telno != NULL) && (*call.telno != '\0')) {
1997c478bd9Sstevel@tonic-gate /* given a phone number, use an ACU */
2007c478bd9Sstevel@tonic-gate alt[F_PHONE] = call.telno;
2017c478bd9Sstevel@tonic-gate alt[F_TYPE] = "ACU";
2027c478bd9Sstevel@tonic-gate } else {
2037c478bd9Sstevel@tonic-gate /* otherwise, use a Direct connection */
2047c478bd9Sstevel@tonic-gate alt[F_TYPE] = "Direct";
2057c478bd9Sstevel@tonic-gate /* If device name starts with "/dev/", strip it off */
2067c478bd9Sstevel@tonic-gate /* since Devices file entries will also be stripped. */
2077c478bd9Sstevel@tonic-gate if ((call.line != NULL) &&
2087c478bd9Sstevel@tonic-gate (strncmp(call.line, "/dev/", 5) == 0))
2097c478bd9Sstevel@tonic-gate Myline = (call.line + 5);
2107c478bd9Sstevel@tonic-gate else
2117c478bd9Sstevel@tonic-gate Myline = call.line;
2127c478bd9Sstevel@tonic-gate }
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gate #ifdef forfutureuse
2157c478bd9Sstevel@tonic-gate if (call->class != NULL)
2167c478bd9Sstevel@tonic-gate alt[F_TYPE] = call->class;
2177c478bd9Sstevel@tonic-gate #endif
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate rlfd = getto(alt);
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate if (rlfd < 0)
2237c478bd9Sstevel@tonic-gate switch (Uerror) {
2247c478bd9Sstevel@tonic-gate case SS_NO_DEVICE:
2257c478bd9Sstevel@tonic-gate return (NO_BD_A);
2267c478bd9Sstevel@tonic-gate case SS_DIAL_FAILED:
2277c478bd9Sstevel@tonic-gate return (D_HUNG);
2287c478bd9Sstevel@tonic-gate case SS_LOCKED_DEVICE:
2297c478bd9Sstevel@tonic-gate return (DV_NT_A);
2307c478bd9Sstevel@tonic-gate case SS_BADSYSTEM:
2317c478bd9Sstevel@tonic-gate return (BAD_SYS);
2327c478bd9Sstevel@tonic-gate case SS_CANT_ACCESS_DEVICE:
2337c478bd9Sstevel@tonic-gate return (L_PROB);
2347c478bd9Sstevel@tonic-gate case SS_CHAT_FAILED:
2357c478bd9Sstevel@tonic-gate return (NO_ANS);
2367c478bd9Sstevel@tonic-gate default:
2377c478bd9Sstevel@tonic-gate return (-Uerror);
2387c478bd9Sstevel@tonic-gate }
2397c478bd9Sstevel@tonic-gate (void) savline();
2407c478bd9Sstevel@tonic-gate if ((call.attr) && ioctl(rlfd, TCSETA, call.attr) < 0) {
2417c478bd9Sstevel@tonic-gate perror("stty for remote");
2427c478bd9Sstevel@tonic-gate return (L_PROB);
2437c478bd9Sstevel@tonic-gate }
2447c478bd9Sstevel@tonic-gate Euid = geteuid();
2457c478bd9Sstevel@tonic-gate if (setuid(getuid()) && setgid(getgid()) < 0)
2467c478bd9Sstevel@tonic-gate undial(rlfd);
2477c478bd9Sstevel@tonic-gate return (rlfd);
2487c478bd9Sstevel@tonic-gate }
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate /*
2517c478bd9Sstevel@tonic-gate * undial(fd)
2527c478bd9Sstevel@tonic-gate */
2537c478bd9Sstevel@tonic-gate void
undial(int fd)25461961e0fSrobinson undial(int fd)
2557c478bd9Sstevel@tonic-gate {
2567c478bd9Sstevel@tonic-gate sethup(fd);
25761961e0fSrobinson (void) sleep(2);
2587c478bd9Sstevel@tonic-gate cleanup(fd);
2597c478bd9Sstevel@tonic-gate }
260