xref: /illumos-gate/usr/src/cmd/bnu/uucico.c (revision 55fea89d)
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
5d67944fbSScott Rotondo  * Common Development and Distribution License (the "License").
6d67944fbSScott Rotondo  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21052519c2SGarrett D'Amore /*
22052519c2SGarrett D'Amore  * Copyright 2014 Garrett D'Amore
23052519c2SGarrett D'Amore  */
247c478bd9Sstevel@tonic-gate /*
25d67944fbSScott Rotondo  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
267c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
307c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate  * uucp file transfer program:
367c478bd9Sstevel@tonic-gate  * to place a call to a remote machine, login, and
377c478bd9Sstevel@tonic-gate  * copy files between the two machines.
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate */
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * Added check to limit the total number of uucicos as defined
427c478bd9Sstevel@tonic-gate  * in the Limits file.
437c478bd9Sstevel@tonic-gate  *
447c478bd9Sstevel@tonic-gate  * Added -f flag to "force execution", ignoring the limit on the
457c478bd9Sstevel@tonic-gate  * number of uucicos. This will be used when invoking uucico from
467c478bd9Sstevel@tonic-gate  * Uutry.
477c478bd9Sstevel@tonic-gate */
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #include "uucp.h"
507c478bd9Sstevel@tonic-gate #include "log.h"
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #ifndef	V7
537c478bd9Sstevel@tonic-gate #include <sys/mkdev.h>
547c478bd9Sstevel@tonic-gate #endif /* V7 */
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #ifdef TLI
577c478bd9Sstevel@tonic-gate #include	<sys/tiuser.h>
587c478bd9Sstevel@tonic-gate #endif /* TLI */
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate jmp_buf Sjbuf;
617c478bd9Sstevel@tonic-gate extern unsigned msgtime;
627c478bd9Sstevel@tonic-gate char	uuxqtarg[MAXBASENAME] = {'\0'};
637c478bd9Sstevel@tonic-gate int	uuxqtflag = 0;
6420af54a8SToomas Soome int	Dologin = 0;
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate extern int	(*Setup)(), (*Teardown)();	/* defined in interface.c */
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate #define USAGE	"Usage: %s [-x NUM] [-r [0|1]] -s SYSTEM -u USERID -d SPOOL -i INTERFACE [-f]\n"
697c478bd9Sstevel@tonic-gate extern void closedem();
707c478bd9Sstevel@tonic-gate void cleanup(), cleanTM();
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate extern int sysaccess(), guinfo(), eaccess(), countProcs(), interface(),
737c478bd9Sstevel@tonic-gate 	savline(), omsg(), restline(), imsg(), callok(), gnxseq(),
747c478bd9Sstevel@tonic-gate 	cmtseq(), conn(), startup(), cntrl();
757c478bd9Sstevel@tonic-gate extern void setuucp(), fixline(), gename(), ulkseq(), pfEndfile();
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate #ifdef	NOSTRANGERS
787c478bd9Sstevel@tonic-gate static void checkrmt();		/* See if we want to talk to remote. */
797c478bd9Sstevel@tonic-gate #endif /* NOSTRANGERS */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate extern char *Mytype;
827c478bd9Sstevel@tonic-gate 
83d67944fbSScott Rotondo static char *pskip();
84d67944fbSScott Rotondo 
85462be471Sceastha int
main(argc,argv,envp)867c478bd9Sstevel@tonic-gate main(argc, argv, envp)
87462be471Sceastha int argc;
887c478bd9Sstevel@tonic-gate char *argv[];
897c478bd9Sstevel@tonic-gate char **envp;
907c478bd9Sstevel@tonic-gate {
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	extern void intrEXIT(), onintr(), timeout();
937c478bd9Sstevel@tonic-gate 	extern void setservice();
947c478bd9Sstevel@tonic-gate #ifndef ATTSVR3
957c478bd9Sstevel@tonic-gate 	void setTZ();
967c478bd9Sstevel@tonic-gate #endif /* ATTSVR3 */
977c478bd9Sstevel@tonic-gate 	int ret, seq, exitcode;
987c478bd9Sstevel@tonic-gate 	char file[NAMESIZE];
997c478bd9Sstevel@tonic-gate 	char msg[BUFSIZ], *p, *q;
1007c478bd9Sstevel@tonic-gate 	char xflag[6];	/* -xN N is single digit */
1017c478bd9Sstevel@tonic-gate 	char *ttyn;
1027c478bd9Sstevel@tonic-gate 	char *iface;	/* interface name	*/
1037c478bd9Sstevel@tonic-gate 	char	cb[128];
1047c478bd9Sstevel@tonic-gate 	time_t	ts, tconv;
1057c478bd9Sstevel@tonic-gate 	char lockname[MAXFULLNAME];
1067c478bd9Sstevel@tonic-gate 	struct limits limitval;
1077c478bd9Sstevel@tonic-gate 	int maxnumb;
1087c478bd9Sstevel@tonic-gate 	int force = 0;	/* set to force execution, ignoring uucico limit */
1097c478bd9Sstevel@tonic-gate 	char gradedir[2*NAMESIZE];
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 	/* Set locale environment variables local definitions */
1127c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
1137c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
1147c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"	/* Use this only if it wasn't */
1157c478bd9Sstevel@tonic-gate #endif
1167c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	Ulimit = ulimit(1,0L);
1197c478bd9Sstevel@tonic-gate 	Uid = getuid();
1207c478bd9Sstevel@tonic-gate 	Euid = geteuid();	/* this should be UUCPUID */
1217c478bd9Sstevel@tonic-gate 	if (Uid == 0)
1227c478bd9Sstevel@tonic-gate 	    setuid(UUCPUID);
1237c478bd9Sstevel@tonic-gate 	Env = envp;
1247c478bd9Sstevel@tonic-gate 	Role = SLAVE;
1257c478bd9Sstevel@tonic-gate 	strcpy(Logfile, LOGCICO);
1267c478bd9Sstevel@tonic-gate 	*Rmtname = NULLCHAR;
1277c478bd9Sstevel@tonic-gate 	Ifn = Ofn = -1;		/* must be set before signal handlers */
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 	closedem();
1307c478bd9Sstevel@tonic-gate 	time(&Nstat.t_qtime);
1317c478bd9Sstevel@tonic-gate 	tconv = Nstat.t_start = Nstat.t_qtime;
1327c478bd9Sstevel@tonic-gate 	strcpy(Progname, "uucico");
1337c478bd9Sstevel@tonic-gate 	setservice(Progname);
1347c478bd9Sstevel@tonic-gate 	ret = sysaccess(EACCESS_SYSTEMS);
1357c478bd9Sstevel@tonic-gate 	ASSERT(ret == 0, Ct_OPEN, "Systems", ret);
1367c478bd9Sstevel@tonic-gate 	ret = sysaccess(EACCESS_DEVICES);
1377c478bd9Sstevel@tonic-gate 	ASSERT(ret == 0, Ct_OPEN, "Devices", ret);
1387c478bd9Sstevel@tonic-gate 	ret = sysaccess(EACCESS_DIALERS);
1397c478bd9Sstevel@tonic-gate 	ASSERT(ret == 0, Ct_OPEN, "Dialers", ret);
1407c478bd9Sstevel@tonic-gate 	Pchar = 'C';
1417c478bd9Sstevel@tonic-gate 	(void) signal(SIGILL, intrEXIT);
1427c478bd9Sstevel@tonic-gate 	(void) signal(SIGTRAP, intrEXIT);
1437c478bd9Sstevel@tonic-gate 	(void) signal(SIGIOT, intrEXIT);
1447c478bd9Sstevel@tonic-gate 	(void) signal(SIGEMT, intrEXIT);
1457c478bd9Sstevel@tonic-gate 	(void) signal(SIGFPE, intrEXIT);
1467c478bd9Sstevel@tonic-gate 	(void) signal(SIGBUS, intrEXIT);
1477c478bd9Sstevel@tonic-gate 	(void) signal(SIGSEGV, intrEXIT);
1487c478bd9Sstevel@tonic-gate 	(void) signal(SIGSYS, intrEXIT);
1497c478bd9Sstevel@tonic-gate 	if (signal(SIGPIPE, SIG_IGN) != SIG_IGN)	/* This for sockets */
1507c478bd9Sstevel@tonic-gate 		(void) signal(SIGPIPE, intrEXIT);
1517c478bd9Sstevel@tonic-gate 	(void) signal(SIGINT, onintr);
1527c478bd9Sstevel@tonic-gate 	(void) signal(SIGHUP, onintr);
1537c478bd9Sstevel@tonic-gate 	(void) signal(SIGQUIT, onintr);
1547c478bd9Sstevel@tonic-gate 	(void) signal(SIGTERM, onintr);
1557c478bd9Sstevel@tonic-gate #ifdef SIGUSR1
1567c478bd9Sstevel@tonic-gate 	(void) signal(SIGUSR1, SIG_IGN);
1577c478bd9Sstevel@tonic-gate #endif
1587c478bd9Sstevel@tonic-gate #ifdef SIGUSR2
1597c478bd9Sstevel@tonic-gate 	(void) signal(SIGUSR2, SIG_IGN);
1607c478bd9Sstevel@tonic-gate #endif
1617c478bd9Sstevel@tonic-gate #ifdef BSD4_2
1627c478bd9Sstevel@tonic-gate 	(void) sigsetmask(sigblock(0) & ~(1 << (SIGALRM - 1)));
1637c478bd9Sstevel@tonic-gate #endif /*BSD4_2*/
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 	pfInit();
1667c478bd9Sstevel@tonic-gate 	scInit("xfer");
1677c478bd9Sstevel@tonic-gate 	ret = guinfo(Euid, User);
1687c478bd9Sstevel@tonic-gate 	ASSERT(ret == 0, "BAD UID ", "", ret);
1697c478bd9Sstevel@tonic-gate 	strncpy(Uucp, User, NAMESIZE);
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 	setuucp(User);
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate 	*xflag = NULLCHAR;
1747c478bd9Sstevel@tonic-gate 	iface = "UNIX";
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 	while ((ret = getopt(argc, argv, "fd:c:r:s:x:u:i:")) != EOF) {
1777c478bd9Sstevel@tonic-gate 		switch (ret) {
1787c478bd9Sstevel@tonic-gate 		case 'd':
1797c478bd9Sstevel@tonic-gate 			if ( eaccess(optarg, 01) != 0 ) {
1807c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext("%s: cannot"
1817c478bd9Sstevel@tonic-gate 				    " access spool directory %s\n"),
1827c478bd9Sstevel@tonic-gate 					Progname, optarg);
1837c478bd9Sstevel@tonic-gate 				exit(1);
1847c478bd9Sstevel@tonic-gate 			}
1857c478bd9Sstevel@tonic-gate 			Spool = optarg;
1867c478bd9Sstevel@tonic-gate 			break;
1877c478bd9Sstevel@tonic-gate 		case 'c':
1887c478bd9Sstevel@tonic-gate 			Mytype = optarg;
1897c478bd9Sstevel@tonic-gate 			break;
1907c478bd9Sstevel@tonic-gate 		case 'f':
1917c478bd9Sstevel@tonic-gate 			++force;
1927c478bd9Sstevel@tonic-gate 			break;
1937c478bd9Sstevel@tonic-gate 		case 'r':
1947c478bd9Sstevel@tonic-gate 			if ( (Role = atoi(optarg)) != MASTER && Role != SLAVE ) {
1957c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext("%s: bad value"
1967c478bd9Sstevel@tonic-gate 				    " '%s' for -r argument\n" USAGE),
1977c478bd9Sstevel@tonic-gate 					Progname, optarg, Progname);
1987c478bd9Sstevel@tonic-gate 				exit(1);
1997c478bd9Sstevel@tonic-gate 			}
2007c478bd9Sstevel@tonic-gate 			break;
2017c478bd9Sstevel@tonic-gate 		case 's':
2027c478bd9Sstevel@tonic-gate 			strncpy(Rmtname, optarg, MAXFULLNAME-1);
2037c478bd9Sstevel@tonic-gate 			if (versys(Rmtname)) {
2047c478bd9Sstevel@tonic-gate 			    (void) fprintf(stderr,
2057c478bd9Sstevel@tonic-gate 				gettext("%s: %s not in Systems file\n"),
2067c478bd9Sstevel@tonic-gate 				Progname, optarg);
2077c478bd9Sstevel@tonic-gate 			    cleanup(101);
2087c478bd9Sstevel@tonic-gate 			}
2097c478bd9Sstevel@tonic-gate 			/* set args for possible xuuxqt call */
2107c478bd9Sstevel@tonic-gate 			strcpy(uuxqtarg, Rmtname);
2117c478bd9Sstevel@tonic-gate 			/* if versys put a longer name in, truncate it again */
2127c478bd9Sstevel@tonic-gate 			Rmtname[MAXBASENAME] = '\0';
2137c478bd9Sstevel@tonic-gate 			break;
2147c478bd9Sstevel@tonic-gate 		case 'x':
2157c478bd9Sstevel@tonic-gate 			Debug = atoi(optarg);
2167c478bd9Sstevel@tonic-gate 			if (Debug <= 0)
2177c478bd9Sstevel@tonic-gate 				Debug = 1;
2187c478bd9Sstevel@tonic-gate 			if (Debug > 9)
2197c478bd9Sstevel@tonic-gate 				Debug = 9;
2207c478bd9Sstevel@tonic-gate 			(void) sprintf(xflag, "-x%d", Debug);
2217c478bd9Sstevel@tonic-gate 			break;
2227c478bd9Sstevel@tonic-gate 		case 'u':
2237c478bd9Sstevel@tonic-gate 			DEBUG(4, "Loginuser %s specified\n", optarg);
2247c478bd9Sstevel@tonic-gate 			strncpy(Loginuser, optarg, NAMESIZE);
2257c478bd9Sstevel@tonic-gate 			Loginuser[NAMESIZE - 1] = NULLCHAR;
2267c478bd9Sstevel@tonic-gate 			break;
2277c478bd9Sstevel@tonic-gate 		case 'i':
2287c478bd9Sstevel@tonic-gate 			/*	interface type		*/
2297c478bd9Sstevel@tonic-gate 			iface = optarg;
2307c478bd9Sstevel@tonic-gate 			break;
2317c478bd9Sstevel@tonic-gate 		default:
2327c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(USAGE), Progname);
2337c478bd9Sstevel@tonic-gate 			exit(1);
2347c478bd9Sstevel@tonic-gate 		}
2357c478bd9Sstevel@tonic-gate 	}
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate 	if (Role == MASTER || *Loginuser == NULLCHAR) {
2387c478bd9Sstevel@tonic-gate 	    ret = guinfo(Uid, Loginuser);
2397c478bd9Sstevel@tonic-gate 	    ASSERT(ret == 0, "BAD LOGIN_UID ", "", ret);
2407c478bd9Sstevel@tonic-gate 	}
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 	/* limit the total number of uucicos */
2437c478bd9Sstevel@tonic-gate 	if (force) {
2447c478bd9Sstevel@tonic-gate 	    DEBUG(4, "force flag set (ignoring uucico limit)\n%s", "");
2457c478bd9Sstevel@tonic-gate 	} else if (scanlimit("uucico", &limitval) == FAIL) {
2467c478bd9Sstevel@tonic-gate 	    DEBUG(1, "No limits for uucico in %s\n", LIMITS);
2477c478bd9Sstevel@tonic-gate 	} else {
2487c478bd9Sstevel@tonic-gate 	    maxnumb = limitval.totalmax;
2497c478bd9Sstevel@tonic-gate 	    if (maxnumb < 0) {
2507c478bd9Sstevel@tonic-gate 		DEBUG(4, "Non-positive limit for uucico in %s\n", LIMITS);
2517c478bd9Sstevel@tonic-gate 		DEBUG(1, "No limits for uucico\n%s", "");
2527c478bd9Sstevel@tonic-gate 	    } else {
2537c478bd9Sstevel@tonic-gate 		DEBUG(4, "Uucico limit %d -- ", maxnumb);
2547c478bd9Sstevel@tonic-gate 		(void) sprintf(lockname, "%s.", LOCKPRE);
2557c478bd9Sstevel@tonic-gate 		if (countProcs(lockname, (maxnumb-1)) == FALSE) {
2567c478bd9Sstevel@tonic-gate 			DEBUG(4, "exiting\n%s", "");
2577c478bd9Sstevel@tonic-gate 			cleanup(101);
2587c478bd9Sstevel@tonic-gate 		}
2597c478bd9Sstevel@tonic-gate 		DEBUG(4, "continuing\n%s", "");
2607c478bd9Sstevel@tonic-gate 	    }
2617c478bd9Sstevel@tonic-gate 	}
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate 	pfStrtConn((Role == MASTER) ? 'M' : 'S');
2647c478bd9Sstevel@tonic-gate 	if (Role == MASTER) {
2657c478bd9Sstevel@tonic-gate 	    if (*Rmtname == NULLCHAR) {
2667c478bd9Sstevel@tonic-gate 		DEBUG(5, "No -s specified\n%s" , "");
2677c478bd9Sstevel@tonic-gate 		cleanup(101);
2687c478bd9Sstevel@tonic-gate 	    }
2697c478bd9Sstevel@tonic-gate 	    /* get Myname - it depends on who I'm calling--Rmtname */
2707c478bd9Sstevel@tonic-gate 	    (void) mchFind(Rmtname);
2717c478bd9Sstevel@tonic-gate 	    myName(Myname);
2727c478bd9Sstevel@tonic-gate 	    if (EQUALSN(Rmtname, Myname, MAXBASENAME)) {
2737c478bd9Sstevel@tonic-gate 		DEBUG(5, "This system specified: -sMyname: %s, ", Myname);
2747c478bd9Sstevel@tonic-gate 		cleanup(101);
2757c478bd9Sstevel@tonic-gate 	    }
2767c478bd9Sstevel@tonic-gate 	    acInit("xfer");
2777c478bd9Sstevel@tonic-gate 	}
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 	ASSERT(chdir(Spool) == 0, Ct_CHDIR, Spool, errno);
2807c478bd9Sstevel@tonic-gate 	strcpy(Wrkdir, Spool);
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 	scReqsys((Role == MASTER) ? Myname : Rmtname); /* log requestor system */
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 	if (Role == SLAVE) {
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate #ifndef ATTSVR3
2877c478bd9Sstevel@tonic-gate 		setTZ();
2887c478bd9Sstevel@tonic-gate #endif /* ATTSVR3 */
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 		if (freopen(RMTDEBUG, "a", stderr) == 0) {
2917c478bd9Sstevel@tonic-gate 			errent(Ct_OPEN, RMTDEBUG, errno, __FILE__, __LINE__);
2927c478bd9Sstevel@tonic-gate 			freopen("/dev/null", "w", stderr);
2937c478bd9Sstevel@tonic-gate 		}
2947c478bd9Sstevel@tonic-gate 		if ( interface(iface) ) {
2957c478bd9Sstevel@tonic-gate 			(void)fprintf(stderr,
2967c478bd9Sstevel@tonic-gate 			"%s: invalid interface %s\n", Progname, iface);
2977c478bd9Sstevel@tonic-gate 			cleanup(101);
2987c478bd9Sstevel@tonic-gate 		}
2997c478bd9Sstevel@tonic-gate 		/*master setup will be called from processdev()*/
3007c478bd9Sstevel@tonic-gate 		if ( (*Setup)( Role, &Ifn, &Ofn ) ) {
3017c478bd9Sstevel@tonic-gate 			DEBUG(5, "SLAVE Setup failed%s", "");
3027c478bd9Sstevel@tonic-gate 			cleanup(101);
3037c478bd9Sstevel@tonic-gate 		}
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate 		/*
3067c478bd9Sstevel@tonic-gate 		 * initial handshake
3077c478bd9Sstevel@tonic-gate 		 */
3087c478bd9Sstevel@tonic-gate 		(void) savline();
3097c478bd9Sstevel@tonic-gate 		fixline(Ifn, 0, D_ACU);
3107c478bd9Sstevel@tonic-gate 		/* get MyName - use logFind to check PERMISSIONS file */
3117c478bd9Sstevel@tonic-gate 		(void) logFind(Loginuser, "");
3127c478bd9Sstevel@tonic-gate 		myName(Myname);
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate 		DEBUG(4,"cico.c: Myname - %s\n",Myname);
3157c478bd9Sstevel@tonic-gate 		DEBUG(4,"cico.c: Loginuser - %s\n",Loginuser);
3167c478bd9Sstevel@tonic-gate 		fflush(stderr);
3177c478bd9Sstevel@tonic-gate 		Nstat.t_scall = times(&Nstat.t_tga);
3187c478bd9Sstevel@tonic-gate 		(void) sprintf(msg, "here=%s", Myname);
3197c478bd9Sstevel@tonic-gate 		omsg('S', msg, Ofn);
3207c478bd9Sstevel@tonic-gate 		(void) signal(SIGALRM, timeout);
3217c478bd9Sstevel@tonic-gate 		(void) alarm(msgtime); /* give slow machines a second chance */
3227c478bd9Sstevel@tonic-gate 		if (setjmp(Sjbuf)) {
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 			/*
3257c478bd9Sstevel@tonic-gate 			 * timed out
3267c478bd9Sstevel@tonic-gate 			 */
3277c478bd9Sstevel@tonic-gate 			(void) restline();
3287c478bd9Sstevel@tonic-gate 			rmlock(CNULL);
3297c478bd9Sstevel@tonic-gate 			exit(0);
3307c478bd9Sstevel@tonic-gate 		}
3317c478bd9Sstevel@tonic-gate 		for (;;) {
3327c478bd9Sstevel@tonic-gate 			ret = imsg(msg, Ifn);
3337c478bd9Sstevel@tonic-gate 			if (ret != 0) {
3347c478bd9Sstevel@tonic-gate 				(void) alarm(0);
3357c478bd9Sstevel@tonic-gate 				(void) restline();
3367c478bd9Sstevel@tonic-gate 				rmlock(CNULL);
3377c478bd9Sstevel@tonic-gate 				exit(0);
3387c478bd9Sstevel@tonic-gate 			}
3397c478bd9Sstevel@tonic-gate 			if (msg[0] == 'S')
3407c478bd9Sstevel@tonic-gate 				break;
3417c478bd9Sstevel@tonic-gate 		}
3427c478bd9Sstevel@tonic-gate 		Nstat.t_ecall = times(&Nstat.t_tga);
3437c478bd9Sstevel@tonic-gate 		(void) alarm(0);
3447c478bd9Sstevel@tonic-gate 		q = &msg[1];
3457c478bd9Sstevel@tonic-gate 		p = pskip(q);
3467c478bd9Sstevel@tonic-gate 		strncpy(Rmtname, q, MAXBASENAME);
3477c478bd9Sstevel@tonic-gate 		Rmtname[MAXBASENAME] = '\0';
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate 		seq = 0;
3507c478bd9Sstevel@tonic-gate 		while (p && *p == '-') {
3517c478bd9Sstevel@tonic-gate 			q = pskip(p);
3527c478bd9Sstevel@tonic-gate 			switch(*(++p)) {
3537c478bd9Sstevel@tonic-gate 			case 'x':
3547c478bd9Sstevel@tonic-gate 				Debug = atoi(++p);
3557c478bd9Sstevel@tonic-gate 				if (Debug <= 0)
3567c478bd9Sstevel@tonic-gate 					Debug = 1;
3577c478bd9Sstevel@tonic-gate 				(void) sprintf(xflag, "-x%d", Debug);
3587c478bd9Sstevel@tonic-gate 				break;
3597c478bd9Sstevel@tonic-gate 			case 'Q':
3607c478bd9Sstevel@tonic-gate 				seq = atoi(++p);
3617c478bd9Sstevel@tonic-gate 				if (seq < 0)
3627c478bd9Sstevel@tonic-gate 					seq = 0;
3637c478bd9Sstevel@tonic-gate 				break;
3647c478bd9Sstevel@tonic-gate #ifdef MAXGRADE
3657c478bd9Sstevel@tonic-gate 			case 'v':	/* version -- -vname=val or -vname */
3667c478bd9Sstevel@tonic-gate 				if (strncmp(++p, "grade=", 6) == 0 &&
3677c478bd9Sstevel@tonic-gate 				    isalnum(p[6]))
3687c478bd9Sstevel@tonic-gate 					MaxGrade = p[6];
3697c478bd9Sstevel@tonic-gate 				break;
3707c478bd9Sstevel@tonic-gate #endif /* MAXGRADE */
3717c478bd9Sstevel@tonic-gate 			case 'R':
3727c478bd9Sstevel@tonic-gate 				Restart++;
3737c478bd9Sstevel@tonic-gate 				p++;
3747c478bd9Sstevel@tonic-gate 				break;
3757c478bd9Sstevel@tonic-gate 			case 'U':
3767c478bd9Sstevel@tonic-gate 				SizeCheck++;
3777c478bd9Sstevel@tonic-gate 				RemUlimit = strtol(++p, (char **) NULL,0);
3787c478bd9Sstevel@tonic-gate 				break;
3797c478bd9Sstevel@tonic-gate 			default:
3807c478bd9Sstevel@tonic-gate 				break;
3817c478bd9Sstevel@tonic-gate 			}
3827c478bd9Sstevel@tonic-gate 			p = q;
3837c478bd9Sstevel@tonic-gate 		}
3847c478bd9Sstevel@tonic-gate 		DEBUG(4, "sys-%s\n", Rmtname);
3857c478bd9Sstevel@tonic-gate 		if (strpbrk(Rmtname, Shchar) != NULL) {
3867c478bd9Sstevel@tonic-gate 			DEBUG(4, "Bad remote system name '%s'\n", Rmtname);
3877c478bd9Sstevel@tonic-gate 			logent(Rmtname, "BAD REMOTE SYSTEM NAME");
3887c478bd9Sstevel@tonic-gate 			omsg('R', "Bad remote system name", Ofn);
3897c478bd9Sstevel@tonic-gate 			cleanup(101);
3907c478bd9Sstevel@tonic-gate 		}
3917c478bd9Sstevel@tonic-gate 		if (Restart)
3927c478bd9Sstevel@tonic-gate 		    CDEBUG(1,"Checkpoint Restart enabled\n%s", "");
3937c478bd9Sstevel@tonic-gate 
3947c478bd9Sstevel@tonic-gate #ifdef NOSTRANGERS
3957c478bd9Sstevel@tonic-gate 		checkrmt();	/* Do we know the remote system. */
3967c478bd9Sstevel@tonic-gate #else
3977c478bd9Sstevel@tonic-gate 		(void) versys(Rmtname);	/* in case the real name is longer */
3987c478bd9Sstevel@tonic-gate #endif /* NOSTRANGERS */
399*55fea89dSDan Cross 
4007c478bd9Sstevel@tonic-gate 		(void) sprintf(lockname, "%ld", (long) getpid());
4017c478bd9Sstevel@tonic-gate 		if (umlock(LOCKPRE, lockname)) {
4027c478bd9Sstevel@tonic-gate 			omsg('R', "LCK", Ofn);
4037c478bd9Sstevel@tonic-gate 			cleanup(101);
4047c478bd9Sstevel@tonic-gate 		}
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate 		/* validate login using PERMISSIONS file */
4077c478bd9Sstevel@tonic-gate 		if (logFind(Loginuser, Rmtname) == FAIL) {
4087c478bd9Sstevel@tonic-gate 			scWrite(); /* log security violation */
4097c478bd9Sstevel@tonic-gate 			Uerror = SS_BAD_LOG_MCH;
4107c478bd9Sstevel@tonic-gate 			logent(UERRORTEXT, "FAILED");
4117c478bd9Sstevel@tonic-gate 			systat(Rmtname, SS_BAD_LOG_MCH, UERRORTEXT,
4127c478bd9Sstevel@tonic-gate 			    Retrytime);
4137c478bd9Sstevel@tonic-gate 			omsg('R', "LOGIN", Ofn);
4147c478bd9Sstevel@tonic-gate 			cleanup(101);
4157c478bd9Sstevel@tonic-gate 		}
4167c478bd9Sstevel@tonic-gate 
4177c478bd9Sstevel@tonic-gate 		ret = callBack();
4187c478bd9Sstevel@tonic-gate 		DEBUG(4,"return from callcheck: %s",ret ? "TRUE" : "FALSE");
4197c478bd9Sstevel@tonic-gate 		if (ret==TRUE) {
4207c478bd9Sstevel@tonic-gate 			(void) signal(SIGINT, SIG_IGN);
4217c478bd9Sstevel@tonic-gate 			(void) signal(SIGHUP, SIG_IGN);
4227c478bd9Sstevel@tonic-gate 			omsg('R', "CB", Ofn);
4237c478bd9Sstevel@tonic-gate 			logent("CALLBACK", "REQUIRED");
4247c478bd9Sstevel@tonic-gate 			/*
4257c478bd9Sstevel@tonic-gate 			 * set up for call back
4267c478bd9Sstevel@tonic-gate 			 */
4277c478bd9Sstevel@tonic-gate 			chremdir(Rmtname);
4287c478bd9Sstevel@tonic-gate 			(void) sprintf(file, "%s/%c", Rmtname, D_QUEUE);
4297c478bd9Sstevel@tonic-gate 			chremdir(file);
4307c478bd9Sstevel@tonic-gate 			gename(CMDPRE, Rmtname, 'C', file);
4317c478bd9Sstevel@tonic-gate 			(void) close(creat(file, CFILEMODE));
4327c478bd9Sstevel@tonic-gate 			if (callok(Rmtname) == SS_CALLBACK_LOOP) {
4337c478bd9Sstevel@tonic-gate 			    systat(Rmtname, SS_CALLBACK_LOOP, "CALL BACK - LOOP", Retrytime);
4347c478bd9Sstevel@tonic-gate 			} else {
4357c478bd9Sstevel@tonic-gate 			    systat(Rmtname, SS_CALLBACK, "CALL BACK", Retrytime);
4367c478bd9Sstevel@tonic-gate 			    xuucico(Rmtname);
4377c478bd9Sstevel@tonic-gate 			}
4387c478bd9Sstevel@tonic-gate 			cleanup(101);
4397c478bd9Sstevel@tonic-gate 		}
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate 		if (callok(Rmtname) == SS_SEQBAD) {
4427c478bd9Sstevel@tonic-gate 			Uerror = SS_SEQBAD;
4437c478bd9Sstevel@tonic-gate 			logent(UERRORTEXT, "PREVIOUS");
4447c478bd9Sstevel@tonic-gate 			omsg('R', "BADSEQ", Ofn);
4457c478bd9Sstevel@tonic-gate 			cleanup(101);
4467c478bd9Sstevel@tonic-gate 		}
4477c478bd9Sstevel@tonic-gate 
4487c478bd9Sstevel@tonic-gate 		if (gnxseq(Rmtname) == seq) {
4497c478bd9Sstevel@tonic-gate 			if (Restart) {
4507c478bd9Sstevel@tonic-gate 			    if (SizeCheck)
4517c478bd9Sstevel@tonic-gate 				(void) sprintf (msg, "OK -R -U0x%lx %s",
4527c478bd9Sstevel@tonic-gate 					Ulimit, xflag);
4537c478bd9Sstevel@tonic-gate 			    else
4547c478bd9Sstevel@tonic-gate 				(void) sprintf (msg, "OK -R %s", xflag);
4557c478bd9Sstevel@tonic-gate 			    omsg('R', msg, Ofn);
4567c478bd9Sstevel@tonic-gate 			} else
4577c478bd9Sstevel@tonic-gate 			    omsg('R', "OK", Ofn);
4587c478bd9Sstevel@tonic-gate 			(void) cmtseq();
4597c478bd9Sstevel@tonic-gate 		} else {
4607c478bd9Sstevel@tonic-gate 			Uerror = SS_SEQBAD;
4617c478bd9Sstevel@tonic-gate 			systat(Rmtname, SS_SEQBAD, UERRORTEXT, Retrytime);
4627c478bd9Sstevel@tonic-gate 			logent(UERRORTEXT, "HANDSHAKE FAILED");
4637c478bd9Sstevel@tonic-gate 			ulkseq();
4647c478bd9Sstevel@tonic-gate 			omsg('R', "BADSEQ", Ofn);
4657c478bd9Sstevel@tonic-gate 			cleanup(101);
4667c478bd9Sstevel@tonic-gate 		}
4677c478bd9Sstevel@tonic-gate 		ttyn = ttyname(Ifn);
4687c478bd9Sstevel@tonic-gate 		if (ttyn != CNULL && *ttyn != NULLCHAR) {
4697c478bd9Sstevel@tonic-gate 			struct stat ttysbuf;
4707c478bd9Sstevel@tonic-gate 			if ( fstat(Ifn,&ttysbuf) == 0 )
4717c478bd9Sstevel@tonic-gate 				Dev_mode = ttysbuf.st_mode;
4727c478bd9Sstevel@tonic-gate 			else
4737c478bd9Sstevel@tonic-gate 				Dev_mode = R_DEVICEMODE;
4747c478bd9Sstevel@tonic-gate 			if ( EQUALSN(ttyn,"/dev/",5) )
4757c478bd9Sstevel@tonic-gate 			    strcpy(Dc, ttyn+5);
4767c478bd9Sstevel@tonic-gate 			else
4777c478bd9Sstevel@tonic-gate 			    strcpy(Dc, ttyn);
4787c478bd9Sstevel@tonic-gate 			chmod(ttyn, S_DEVICEMODE);
4797c478bd9Sstevel@tonic-gate 		} else
4807c478bd9Sstevel@tonic-gate 			strcpy(Dc, "notty");
4817c478bd9Sstevel@tonic-gate 		/* set args for possible xuuxqt call */
4827c478bd9Sstevel@tonic-gate 		strcpy(uuxqtarg, Rmtname);
4837c478bd9Sstevel@tonic-gate 	}
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate 	strcpy(User, Uucp);
4867c478bd9Sstevel@tonic-gate /*
4877c478bd9Sstevel@tonic-gate  *  Ensure reasonable ulimit (MINULIMIT)
4887c478bd9Sstevel@tonic-gate  */
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate #ifndef	V7
4917c478bd9Sstevel@tonic-gate 	{
4927c478bd9Sstevel@tonic-gate 	long 	minulimit;
4937c478bd9Sstevel@tonic-gate 	minulimit = ulimit(1, (long) 0);
4947c478bd9Sstevel@tonic-gate 	ASSERT(minulimit >= MINULIMIT, "ULIMIT TOO SMALL",
4957c478bd9Sstevel@tonic-gate 	    Loginuser, (int) minulimit);
4967c478bd9Sstevel@tonic-gate 	}
4977c478bd9Sstevel@tonic-gate #endif
4987c478bd9Sstevel@tonic-gate 	if (Role == MASTER && callok(Rmtname) != 0) {
4997c478bd9Sstevel@tonic-gate 		logent("SYSTEM STATUS", "CAN NOT CALL");
5007c478bd9Sstevel@tonic-gate 		cleanup(101);
5017c478bd9Sstevel@tonic-gate 	}
5027c478bd9Sstevel@tonic-gate 
5037c478bd9Sstevel@tonic-gate 	chremdir(Rmtname);
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate 	(void) strcpy(Wrkdir, RemSpool);
5067c478bd9Sstevel@tonic-gate 	if (Role == MASTER) {
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate 		/*
5097c478bd9Sstevel@tonic-gate 		 * master part
5107c478bd9Sstevel@tonic-gate 		 */
5117c478bd9Sstevel@tonic-gate 		(void) signal(SIGINT, SIG_IGN);
5127c478bd9Sstevel@tonic-gate 		(void) signal(SIGHUP, SIG_IGN);
5137c478bd9Sstevel@tonic-gate 		(void) signal(SIGQUIT, SIG_IGN);
5147c478bd9Sstevel@tonic-gate 		if (Ifn != -1 && Role == MASTER) {
5157c478bd9Sstevel@tonic-gate 			(void) (*Write)(Ofn, EOTMSG, strlen(EOTMSG));
5167c478bd9Sstevel@tonic-gate 			(void) close(Ofn);
5177c478bd9Sstevel@tonic-gate 			(void) close(Ifn);
5187c478bd9Sstevel@tonic-gate 			Ifn = Ofn = -1;
5197c478bd9Sstevel@tonic-gate 			rmlock(CNULL);
5207c478bd9Sstevel@tonic-gate 			sleep(3);
5217c478bd9Sstevel@tonic-gate 		}
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate 		/*
5247c478bd9Sstevel@tonic-gate 		 * Find the highest priority job grade that has
5257c478bd9Sstevel@tonic-gate 		 * jobs to do. This is needed to form the lock name.
5267c478bd9Sstevel@tonic-gate 		 */
5277c478bd9Sstevel@tonic-gate 
5287c478bd9Sstevel@tonic-gate 		findgrade(RemSpool, JobGrade);
5297c478bd9Sstevel@tonic-gate 		DEBUG(4, "Job grade to process - %s\n", JobGrade);
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate 		/*
5327c478bd9Sstevel@tonic-gate 		 * Lock the job grade if there is one to process.
5337c478bd9Sstevel@tonic-gate 		 */
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate 		if (*JobGrade != NULLCHAR) {
5367c478bd9Sstevel@tonic-gate 			(void) sprintf(gradedir, "%s/%s", Rmtname, JobGrade);
5377c478bd9Sstevel@tonic-gate 			chremdir(gradedir);
5387c478bd9Sstevel@tonic-gate 
5397c478bd9Sstevel@tonic-gate 			(void) sprintf(lockname, "%.*s.%s", SYSNSIZE, Rmtname, JobGrade);
5407c478bd9Sstevel@tonic-gate 			(void) sprintf(msg, "call to %s - process job grade %s ",
5417c478bd9Sstevel@tonic-gate 			    Rmtname, JobGrade);
5427c478bd9Sstevel@tonic-gate 			if (umlock(LOCKPRE, lockname) != 0) {
5437c478bd9Sstevel@tonic-gate 				logent(msg, "LOCKED");
5447c478bd9Sstevel@tonic-gate 				CDEBUG(1, "Currently Talking With %s\n",
5457c478bd9Sstevel@tonic-gate 				    Rmtname);
5467c478bd9Sstevel@tonic-gate  				cleanup(100);
5477c478bd9Sstevel@tonic-gate 			}
5487c478bd9Sstevel@tonic-gate 		} else {
5497c478bd9Sstevel@tonic-gate 			(void) sprintf(msg, "call to %s - no work", Rmtname);
5507c478bd9Sstevel@tonic-gate 		}
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate 		Nstat.t_scall = times(&Nstat.t_tga);
5537c478bd9Sstevel@tonic-gate 		Ofn = Ifn = conn(Rmtname);
5547c478bd9Sstevel@tonic-gate 		Nstat.t_ecall = times(&Nstat.t_tga);
5557c478bd9Sstevel@tonic-gate 		if (Ofn < 0) {
5567c478bd9Sstevel@tonic-gate 			delock(LOCKPRE, lockname);
5577c478bd9Sstevel@tonic-gate 			logent(UERRORTEXT, "CONN FAILED");
5587c478bd9Sstevel@tonic-gate 			systat(Rmtname, Uerror, UERRORTEXT, Retrytime);
5597c478bd9Sstevel@tonic-gate 			cleanup(101);
5607c478bd9Sstevel@tonic-gate 		} else {
5617c478bd9Sstevel@tonic-gate 			logent(msg, "SUCCEEDED");
5627c478bd9Sstevel@tonic-gate 			ttyn = ttyname(Ifn);
5637c478bd9Sstevel@tonic-gate 			if (ttyn != CNULL && *ttyn != NULLCHAR) {
5647c478bd9Sstevel@tonic-gate 				struct stat ttysbuf;
5657c478bd9Sstevel@tonic-gate 				if ( fstat(Ifn,&ttysbuf) == 0 )
5667c478bd9Sstevel@tonic-gate 					Dev_mode = ttysbuf.st_mode;
5677c478bd9Sstevel@tonic-gate 				else
5687c478bd9Sstevel@tonic-gate 					Dev_mode = R_DEVICEMODE;
5697c478bd9Sstevel@tonic-gate 				chmod(ttyn, M_DEVICEMODE);
5707c478bd9Sstevel@tonic-gate 			}
5717c478bd9Sstevel@tonic-gate 		}
572*55fea89dSDan Cross 
5737c478bd9Sstevel@tonic-gate 		if (setjmp(Sjbuf)) {
5747c478bd9Sstevel@tonic-gate 			delock(LOCKPRE, lockname);
5757c478bd9Sstevel@tonic-gate 			Uerror = SS_LOGIN_FAILED;
5767c478bd9Sstevel@tonic-gate 			logent(Rmtname, UERRORTEXT);
5777c478bd9Sstevel@tonic-gate 			systat(Rmtname, SS_LOGIN_FAILED,
5787c478bd9Sstevel@tonic-gate 			    UERRORTEXT, Retrytime);
5797c478bd9Sstevel@tonic-gate 			DEBUG(4, "%s - failed\n", UERRORTEXT);
5807c478bd9Sstevel@tonic-gate 			cleanup(101);
5817c478bd9Sstevel@tonic-gate 		}
5827c478bd9Sstevel@tonic-gate 		(void) signal(SIGALRM, timeout);
5837c478bd9Sstevel@tonic-gate 		/* give slow guys lots of time to thrash */
5847c478bd9Sstevel@tonic-gate 		(void) alarm(2 * msgtime);
5857c478bd9Sstevel@tonic-gate 		for (;;) {
5867c478bd9Sstevel@tonic-gate 			ret = imsg(msg, Ifn);
5877c478bd9Sstevel@tonic-gate 			if (ret != 0) {
5887c478bd9Sstevel@tonic-gate 				continue; /* try again */
5897c478bd9Sstevel@tonic-gate 			}
5907c478bd9Sstevel@tonic-gate 			if (msg[0] == 'S')
5917c478bd9Sstevel@tonic-gate 				break;
5927c478bd9Sstevel@tonic-gate 		}
5937c478bd9Sstevel@tonic-gate 		(void) alarm(0);
5947c478bd9Sstevel@tonic-gate 		if(EQUALSN("here=", &msg[1], 5)){
5957c478bd9Sstevel@tonic-gate 			/* This may be a problem, we check up to MAXBASENAME
5967c478bd9Sstevel@tonic-gate 			 * characters now. The old comment was:
5977c478bd9Sstevel@tonic-gate 			 * this is a problem.  We'd like to compare with an
5987c478bd9Sstevel@tonic-gate 			 * untruncated Rmtname but we fear incompatability.
5997c478bd9Sstevel@tonic-gate 			 * So we'll look at most 6 chars (at most).
6007c478bd9Sstevel@tonic-gate 			 */
6017c478bd9Sstevel@tonic-gate 			(void) pskip(&msg[6]);
6027c478bd9Sstevel@tonic-gate 			if (!EQUALSN(&msg[6], Rmtname, MAXBASENAME)) {
6037c478bd9Sstevel@tonic-gate 				delock(LOCKPRE, lockname);
6047c478bd9Sstevel@tonic-gate 				Uerror = SS_WRONG_MCH;
6057c478bd9Sstevel@tonic-gate 				logent(&msg[6], UERRORTEXT);
6067c478bd9Sstevel@tonic-gate 				systat(Rmtname, SS_WRONG_MCH, UERRORTEXT,
6077c478bd9Sstevel@tonic-gate 				     Retrytime);
6087c478bd9Sstevel@tonic-gate 				DEBUG(4, "%s - failed\n", UERRORTEXT);
6097c478bd9Sstevel@tonic-gate 				cleanup(101);
6107c478bd9Sstevel@tonic-gate 			}
6117c478bd9Sstevel@tonic-gate 		}
6127c478bd9Sstevel@tonic-gate 		CDEBUG(1,"Login Successful: System=%s\n",&msg[6]);
6137c478bd9Sstevel@tonic-gate 		seq = gnxseq(Rmtname);
6147c478bd9Sstevel@tonic-gate 		(void) sprintf(msg, "%s -Q%d -R -U0x%lx %s",
6157c478bd9Sstevel@tonic-gate 			Myname, seq, Ulimit, xflag);
6167c478bd9Sstevel@tonic-gate #ifdef MAXGRADE
6177c478bd9Sstevel@tonic-gate 		if (MaxGrade != NULLCHAR) {
6187c478bd9Sstevel@tonic-gate 			p = strchr(msg, NULLCHAR);
6197c478bd9Sstevel@tonic-gate 			sprintf(p, " -vgrade=%c", MaxGrade);
6207c478bd9Sstevel@tonic-gate 		}
6217c478bd9Sstevel@tonic-gate #endif /* MAXGRADE */
6227c478bd9Sstevel@tonic-gate 		omsg('S', msg, Ofn);
6237c478bd9Sstevel@tonic-gate 		(void) alarm(msgtime);	/* give slow guys some thrash time */
6247c478bd9Sstevel@tonic-gate 		for (;;) {
6257c478bd9Sstevel@tonic-gate 			ret = imsg(msg, Ifn);
6267c478bd9Sstevel@tonic-gate 			DEBUG(4, "msg-%s\n", msg);
6277c478bd9Sstevel@tonic-gate 			if (ret != 0) {
6287c478bd9Sstevel@tonic-gate 				(void) alarm(0);
6297c478bd9Sstevel@tonic-gate 				delock(LOCKPRE, lockname);
6307c478bd9Sstevel@tonic-gate 				ulkseq();
6317c478bd9Sstevel@tonic-gate 				cleanup(101);
6327c478bd9Sstevel@tonic-gate 			}
6337c478bd9Sstevel@tonic-gate 			if (msg[0] == 'R')
6347c478bd9Sstevel@tonic-gate 				break;
6357c478bd9Sstevel@tonic-gate 		}
6367c478bd9Sstevel@tonic-gate 		(void) alarm(0);
6377c478bd9Sstevel@tonic-gate 
6387c478bd9Sstevel@tonic-gate 		/*  check for rejects from remote */
6397c478bd9Sstevel@tonic-gate 		Uerror = 0;
640*55fea89dSDan Cross 		if (EQUALS(&msg[1], "LCK"))
6417c478bd9Sstevel@tonic-gate 			Uerror = SS_RLOCKED;
6427c478bd9Sstevel@tonic-gate 		else if (EQUALS(&msg[1], "LOGIN"))
6437c478bd9Sstevel@tonic-gate 			Uerror = SS_RLOGIN;
6447c478bd9Sstevel@tonic-gate 		else if (EQUALS(&msg[1], "CB"))
6457c478bd9Sstevel@tonic-gate 			Uerror = (callBack() ? SS_CALLBACK_LOOP : SS_CALLBACK);
6467c478bd9Sstevel@tonic-gate 		else if (EQUALS(&msg[1], "You are unknown to me"))
6477c478bd9Sstevel@tonic-gate 			Uerror = SS_RUNKNOWN;
6487c478bd9Sstevel@tonic-gate 		else if (EQUALS(&msg[1], "BADSEQ"))
6497c478bd9Sstevel@tonic-gate 			Uerror = SS_SEQBAD;
6507c478bd9Sstevel@tonic-gate 		else if (!EQUALSN(&msg[1], "OK", 2))
6517c478bd9Sstevel@tonic-gate 			Uerror = SS_UNKNOWN_RESPONSE;
6527c478bd9Sstevel@tonic-gate 		if (Uerror)  {
6537c478bd9Sstevel@tonic-gate 			delock(LOCKPRE, lockname);
6547c478bd9Sstevel@tonic-gate 			systat(Rmtname, Uerror, UERRORTEXT, Retrytime);
6557c478bd9Sstevel@tonic-gate 			logent(UERRORTEXT, "HANDSHAKE FAILED");
6567c478bd9Sstevel@tonic-gate 			CDEBUG(1, "HANDSHAKE FAILED: %s\n", UERRORTEXT);
6577c478bd9Sstevel@tonic-gate 			ulkseq();
6587c478bd9Sstevel@tonic-gate 			cleanup(101);
6597c478bd9Sstevel@tonic-gate 		}
6607c478bd9Sstevel@tonic-gate 		(void) cmtseq();
6617c478bd9Sstevel@tonic-gate 
6627c478bd9Sstevel@tonic-gate 		/*
6637c478bd9Sstevel@tonic-gate 		 * See if we have any additional parameters on the OK
6647c478bd9Sstevel@tonic-gate 		 */
6657c478bd9Sstevel@tonic-gate 
6667c478bd9Sstevel@tonic-gate 		if (strlen(&msg[3])) {
6677c478bd9Sstevel@tonic-gate 			p = pskip(&msg[3]);
6687c478bd9Sstevel@tonic-gate 			while (p && *p == '-') {
6697c478bd9Sstevel@tonic-gate 				q = pskip(p);
6707c478bd9Sstevel@tonic-gate 				switch(*(++p)) {
6717c478bd9Sstevel@tonic-gate 				case 'R':
6727c478bd9Sstevel@tonic-gate 					Restart++;
6737c478bd9Sstevel@tonic-gate 					p++;
6747c478bd9Sstevel@tonic-gate 					break;
6757c478bd9Sstevel@tonic-gate 				case 'U':
6767c478bd9Sstevel@tonic-gate 					SizeCheck++;
6777c478bd9Sstevel@tonic-gate 					RemUlimit = strtol(++p, (char **) NULL, 0);
6787c478bd9Sstevel@tonic-gate 					break;
6797c478bd9Sstevel@tonic-gate 				case 'x':
6807c478bd9Sstevel@tonic-gate 					if (!Debug) {
6817c478bd9Sstevel@tonic-gate 						Debug = atoi(++p);
6827c478bd9Sstevel@tonic-gate 						if (Debug <= 0)
6837c478bd9Sstevel@tonic-gate 							Debug = 1;
6847c478bd9Sstevel@tonic-gate 					}
6857c478bd9Sstevel@tonic-gate 					break;
6867c478bd9Sstevel@tonic-gate 				default:
6877c478bd9Sstevel@tonic-gate 					break;
6887c478bd9Sstevel@tonic-gate 				}
6897c478bd9Sstevel@tonic-gate 				p = q;
6907c478bd9Sstevel@tonic-gate 			}
6917c478bd9Sstevel@tonic-gate 		}
6927c478bd9Sstevel@tonic-gate 
6937c478bd9Sstevel@tonic-gate 	}
6947c478bd9Sstevel@tonic-gate 	DEBUG(4, " Rmtname %s, ", Rmtname);
6957c478bd9Sstevel@tonic-gate 	DEBUG(4, " Restart %s, ", (Restart ? "YES" : "NO"));
6967c478bd9Sstevel@tonic-gate 	DEBUG(4, "Role %s,  ", Role ? "MASTER" : "SLAVE");
6977c478bd9Sstevel@tonic-gate 	DEBUG(4, "Ifn - %d, ", Ifn);
6987c478bd9Sstevel@tonic-gate 	DEBUG(4, "Loginuser - %s\n", Loginuser);
6997c478bd9Sstevel@tonic-gate 
7007c478bd9Sstevel@tonic-gate 	/* alarm/setjmp added here due to experience with uucico
7017c478bd9Sstevel@tonic-gate 	 * hanging for hours in imsg().
7027c478bd9Sstevel@tonic-gate 	 */
7037c478bd9Sstevel@tonic-gate 	if (setjmp(Sjbuf)) {
7047c478bd9Sstevel@tonic-gate 		delock(LOCKPRE, lockname);
7057c478bd9Sstevel@tonic-gate 		logent("startup", "TIMEOUT");
7067c478bd9Sstevel@tonic-gate 		DEBUG(4, "%s - timeout\n", "startup");
7077c478bd9Sstevel@tonic-gate 		cleanup(101);
7087c478bd9Sstevel@tonic-gate 	}
7097c478bd9Sstevel@tonic-gate 	(void) alarm(MAXSTART);
7107c478bd9Sstevel@tonic-gate 	ret = startup();
7117c478bd9Sstevel@tonic-gate 	(void) alarm(0);
7127c478bd9Sstevel@tonic-gate 
7137c478bd9Sstevel@tonic-gate 	if (ret != SUCCESS) {
7147c478bd9Sstevel@tonic-gate 		delock(LOCKPRE, lockname);
7157c478bd9Sstevel@tonic-gate 		logent("startup", "FAILED");
7167c478bd9Sstevel@tonic-gate 		Uerror = SS_STARTUP;
7177c478bd9Sstevel@tonic-gate 		CDEBUG(1, "%s\n", UERRORTEXT);
7187c478bd9Sstevel@tonic-gate 		systat(Rmtname, Uerror, UERRORTEXT, Retrytime);
7197c478bd9Sstevel@tonic-gate 		exitcode = 101;
7207c478bd9Sstevel@tonic-gate 	} else {
7217c478bd9Sstevel@tonic-gate 		pfConnected(Rmtname, Dc);
7227c478bd9Sstevel@tonic-gate 		acConnected(Rmtname, Dc);
7237c478bd9Sstevel@tonic-gate 		logent("startup", "OK");
7247c478bd9Sstevel@tonic-gate 		systat(Rmtname, SS_INPROGRESS, UTEXT(SS_INPROGRESS),Retrytime);
7257c478bd9Sstevel@tonic-gate 		Nstat.t_sftp = times(&Nstat.t_tga);
7267c478bd9Sstevel@tonic-gate 
7277c478bd9Sstevel@tonic-gate 		exitcode = cntrl();
7287c478bd9Sstevel@tonic-gate 		Nstat.t_eftp = times(&Nstat.t_tga);
7297c478bd9Sstevel@tonic-gate 		DEBUG(4, "cntrl - %d\n", exitcode);
7307c478bd9Sstevel@tonic-gate 		(void) signal(SIGINT, SIG_IGN);
7317c478bd9Sstevel@tonic-gate 		(void) signal(SIGHUP, SIG_IGN);
7327c478bd9Sstevel@tonic-gate 		(void) signal(SIGALRM, timeout);
7337c478bd9Sstevel@tonic-gate 
7347c478bd9Sstevel@tonic-gate 		if (exitcode == 0) {
7357c478bd9Sstevel@tonic-gate 			(void) time(&ts);
7367c478bd9Sstevel@tonic-gate 			(void) sprintf(cb, "conversation complete %s %ld",
7377c478bd9Sstevel@tonic-gate 				Dc, ts - tconv);
7387c478bd9Sstevel@tonic-gate 			logent(cb, "OK");
7397c478bd9Sstevel@tonic-gate 			systat(Rmtname, SS_OK, UTEXT(SS_OK), Retrytime);
7407c478bd9Sstevel@tonic-gate 
7417c478bd9Sstevel@tonic-gate 		} else {
7427c478bd9Sstevel@tonic-gate 			logent("conversation complete", "FAILED");
7437c478bd9Sstevel@tonic-gate 			systat(Rmtname, SS_CONVERSATION,
7447c478bd9Sstevel@tonic-gate 			    UTEXT(SS_CONVERSATION), Retrytime);
7457c478bd9Sstevel@tonic-gate 		}
7467c478bd9Sstevel@tonic-gate 		(void) alarm(msgtime);	/* give slow guys some thrash time */
7477c478bd9Sstevel@tonic-gate 		omsg('O', "OOOOO", Ofn);
7487c478bd9Sstevel@tonic-gate 		CDEBUG(4, "send OO %d,", ret);
7497c478bd9Sstevel@tonic-gate 		if (!setjmp(Sjbuf)) {
7507c478bd9Sstevel@tonic-gate 			for (;;) {
7517c478bd9Sstevel@tonic-gate 				omsg('O', "OOOOO", Ofn);
7527c478bd9Sstevel@tonic-gate 				ret = imsg(msg, Ifn);
7537c478bd9Sstevel@tonic-gate 				if (ret != 0)
7547c478bd9Sstevel@tonic-gate 					break;
7557c478bd9Sstevel@tonic-gate 				if (msg[0] == 'O')
7567c478bd9Sstevel@tonic-gate 					break;
7577c478bd9Sstevel@tonic-gate 			}
7587c478bd9Sstevel@tonic-gate 		}
7597c478bd9Sstevel@tonic-gate 		(void) alarm(0);
7607c478bd9Sstevel@tonic-gate 	}
7617c478bd9Sstevel@tonic-gate 	cleanup(exitcode);
7627c478bd9Sstevel@tonic-gate 	/*NOTREACHED*/
763462be471Sceastha 	return (0);
7647c478bd9Sstevel@tonic-gate }
7657c478bd9Sstevel@tonic-gate 
7667c478bd9Sstevel@tonic-gate /*
7677c478bd9Sstevel@tonic-gate  * clean and exit with "code" status
7687c478bd9Sstevel@tonic-gate  */
7697c478bd9Sstevel@tonic-gate void
cleanup(code)7707c478bd9Sstevel@tonic-gate cleanup(code)
771462be471Sceastha int code;
7727c478bd9Sstevel@tonic-gate {
7737c478bd9Sstevel@tonic-gate 	(void) signal(SIGINT, SIG_IGN);
7747c478bd9Sstevel@tonic-gate 	(void) signal(SIGHUP, SIG_IGN);
7757c478bd9Sstevel@tonic-gate 	rmlock(CNULL);
7767c478bd9Sstevel@tonic-gate 	closedem();
7777c478bd9Sstevel@tonic-gate 	alarm(msgtime);		/* Start timer in case closes hang. */
7787c478bd9Sstevel@tonic-gate 	if (setjmp(Sjbuf) == 0)
7797c478bd9Sstevel@tonic-gate 		(*Teardown)( Role, Ifn, Ofn );
7807c478bd9Sstevel@tonic-gate 	alarm(0);			/* Turn off timer. */
7817c478bd9Sstevel@tonic-gate 	DEBUG(4, "exit code %d\n", code);
782*55fea89dSDan Cross 	CDEBUG(1, "Conversation Complete: Status %s\n\n",
7837c478bd9Sstevel@tonic-gate 	    code ? "FAILED" : "SUCCEEDED");
7847c478bd9Sstevel@tonic-gate 
7857c478bd9Sstevel@tonic-gate 	cleanTM();
7867c478bd9Sstevel@tonic-gate 	if ((code == 0) && (uuxqtflag == 1))
7877c478bd9Sstevel@tonic-gate 		xuuxqt(uuxqtarg);
7887c478bd9Sstevel@tonic-gate 	exit(code);
7897c478bd9Sstevel@tonic-gate }
7907c478bd9Sstevel@tonic-gate 
7917c478bd9Sstevel@tonic-gate short TM_cnt = 0;
7927c478bd9Sstevel@tonic-gate char TM_name[MAXNAMESIZE];
7937c478bd9Sstevel@tonic-gate 
7947c478bd9Sstevel@tonic-gate void
cleanTM()7957c478bd9Sstevel@tonic-gate cleanTM()
7967c478bd9Sstevel@tonic-gate {
797462be471Sceastha 	int i;
7987c478bd9Sstevel@tonic-gate 	char tm_name[MAXNAMESIZE];
7997c478bd9Sstevel@tonic-gate 
8007c478bd9Sstevel@tonic-gate 	DEBUG(7,"TM_cnt: %d\n",TM_cnt);
8017c478bd9Sstevel@tonic-gate 	for(i=0; i < TM_cnt; i++) {
8027c478bd9Sstevel@tonic-gate 		(void) sprintf(tm_name, "%s.%3.3d", TM_name, i);
8037c478bd9Sstevel@tonic-gate 		DEBUG(7, "tm_name: %s\n", tm_name);
8047c478bd9Sstevel@tonic-gate 		unlink(tm_name);
8057c478bd9Sstevel@tonic-gate 	}
8067c478bd9Sstevel@tonic-gate 	return;
8077c478bd9Sstevel@tonic-gate }
8087c478bd9Sstevel@tonic-gate 
8097c478bd9Sstevel@tonic-gate void
TMname(file,pnum)8107c478bd9Sstevel@tonic-gate TMname(file, pnum)
8117c478bd9Sstevel@tonic-gate char *file;
8127c478bd9Sstevel@tonic-gate pid_t pnum;
8137c478bd9Sstevel@tonic-gate {
8147c478bd9Sstevel@tonic-gate 
8157c478bd9Sstevel@tonic-gate 	(void) sprintf(file, "%s/TM.%.5ld.%.3d", RemSpool, (long) pnum, TM_cnt);
8167c478bd9Sstevel@tonic-gate 	if (TM_cnt == 0)
8177c478bd9Sstevel@tonic-gate 	    (void) sprintf(TM_name, "%s/TM.%.5ld", RemSpool, (long) pnum);
8187c478bd9Sstevel@tonic-gate 	DEBUG(7, "TMname(%s)\n", file);
8197c478bd9Sstevel@tonic-gate 	TM_cnt++;
8207c478bd9Sstevel@tonic-gate 	return;
8217c478bd9Sstevel@tonic-gate }
8227c478bd9Sstevel@tonic-gate 
8237c478bd9Sstevel@tonic-gate /*
8247c478bd9Sstevel@tonic-gate  * intrrupt - remove locks and exit
8257c478bd9Sstevel@tonic-gate  */
8267c478bd9Sstevel@tonic-gate void
onintr(inter)8277c478bd9Sstevel@tonic-gate onintr(inter)
828462be471Sceastha int inter;
8297c478bd9Sstevel@tonic-gate {
8307c478bd9Sstevel@tonic-gate 	char str[30];
8317c478bd9Sstevel@tonic-gate 	/* I'm putting a test for zero here because I saw it happen
8327c478bd9Sstevel@tonic-gate 	 * and don't know how or why, but it seemed to then loop
8337c478bd9Sstevel@tonic-gate 	 * here for ever?
8347c478bd9Sstevel@tonic-gate 	 */
8357c478bd9Sstevel@tonic-gate 	if (inter == 0)
8367c478bd9Sstevel@tonic-gate 	    exit(99);
8377c478bd9Sstevel@tonic-gate 	(void) signal(inter, SIG_IGN);
8387c478bd9Sstevel@tonic-gate 	(void) sprintf(str, "SIGNAL %d", inter);
8397c478bd9Sstevel@tonic-gate 	logent(str, "CAUGHT");
8407c478bd9Sstevel@tonic-gate 	pfEndfile("PARTIAL FILE");
8417c478bd9Sstevel@tonic-gate 	acEnd(PARTIAL); /*stop collecting accounting log */
8427c478bd9Sstevel@tonic-gate 	cleanup(inter);
8437c478bd9Sstevel@tonic-gate }
8447c478bd9Sstevel@tonic-gate 
8457c478bd9Sstevel@tonic-gate void
intrEXIT(inter)8467c478bd9Sstevel@tonic-gate intrEXIT(inter)
8477c478bd9Sstevel@tonic-gate int inter;
8487c478bd9Sstevel@tonic-gate {
8497c478bd9Sstevel@tonic-gate 	char	cb[20];
8507c478bd9Sstevel@tonic-gate 
8517c478bd9Sstevel@tonic-gate 	(void) sprintf(cb, "SIGNAL %d", inter);
8527c478bd9Sstevel@tonic-gate 	logent("INTREXIT", cb);
8537c478bd9Sstevel@tonic-gate 	(void) signal(SIGIOT, SIG_DFL);
8547c478bd9Sstevel@tonic-gate 	(void) signal(SIGILL, SIG_DFL);
8557c478bd9Sstevel@tonic-gate 	rmlock(CNULL);
8567c478bd9Sstevel@tonic-gate 	closedem();
8577c478bd9Sstevel@tonic-gate 	(void) setuid(Uid);
8587c478bd9Sstevel@tonic-gate 	abort();
8597c478bd9Sstevel@tonic-gate }
8607c478bd9Sstevel@tonic-gate 
8617c478bd9Sstevel@tonic-gate /*
8627c478bd9Sstevel@tonic-gate  * catch SIGALRM routine
8637c478bd9Sstevel@tonic-gate  */
8647c478bd9Sstevel@tonic-gate void
timeout()8657c478bd9Sstevel@tonic-gate timeout()
8667c478bd9Sstevel@tonic-gate {
8677c478bd9Sstevel@tonic-gate 	longjmp(Sjbuf, 1);
8687c478bd9Sstevel@tonic-gate }
8697c478bd9Sstevel@tonic-gate 
8707c478bd9Sstevel@tonic-gate /* skip to next field */
8717c478bd9Sstevel@tonic-gate static char *
pskip(p)8727c478bd9Sstevel@tonic-gate pskip(p)
873462be471Sceastha char *p;
8747c478bd9Sstevel@tonic-gate {
8757c478bd9Sstevel@tonic-gate 	if ((p = strchr(p, ' ')) != CNULL)
8767c478bd9Sstevel@tonic-gate 		do
8777c478bd9Sstevel@tonic-gate 			*p++ = NULLCHAR;
8787c478bd9Sstevel@tonic-gate 		while (*p == ' ');
8797c478bd9Sstevel@tonic-gate 	return(p);
8807c478bd9Sstevel@tonic-gate }
8817c478bd9Sstevel@tonic-gate 
8827c478bd9Sstevel@tonic-gate void
closedem()8837c478bd9Sstevel@tonic-gate closedem()
8847c478bd9Sstevel@tonic-gate {
885462be471Sceastha 	int i, maxfiles;
8867c478bd9Sstevel@tonic-gate 
8877c478bd9Sstevel@tonic-gate #ifdef ATTSVR3
8887c478bd9Sstevel@tonic-gate 	maxfiles = ulimit(4,0);
8897c478bd9Sstevel@tonic-gate #else /* !ATTSVR3 */
8907c478bd9Sstevel@tonic-gate #ifdef BSD4_2
8917c478bd9Sstevel@tonic-gate 	maxfiles = getdtablesize();
8927c478bd9Sstevel@tonic-gate #else /* BSD4_2 */
8937c478bd9Sstevel@tonic-gate 	maxfiles = _NFILE;
8947c478bd9Sstevel@tonic-gate #endif /* BSD4_2 */
8957c478bd9Sstevel@tonic-gate #endif /* ATTSVR3 */
8967c478bd9Sstevel@tonic-gate 
8977c478bd9Sstevel@tonic-gate 	for (  i = 3; i < maxfiles; i++ )
8987c478bd9Sstevel@tonic-gate 		if ( i != Ifn && i != Ofn && i != fileno(stderr) )
8997c478bd9Sstevel@tonic-gate 			(void) close(i);
9007c478bd9Sstevel@tonic-gate 	return;
9017c478bd9Sstevel@tonic-gate }
9027c478bd9Sstevel@tonic-gate 
9037c478bd9Sstevel@tonic-gate #ifndef ATTSVR3
9047c478bd9Sstevel@tonic-gate 
9057c478bd9Sstevel@tonic-gate /*
9067c478bd9Sstevel@tonic-gate  *	setTZ()
9077c478bd9Sstevel@tonic-gate  *
9087c478bd9Sstevel@tonic-gate  *	if login "shell" is uucico (i.e., Role == SLAVE), must set
9097c478bd9Sstevel@tonic-gate  *	timezone env variable TZ.  otherwise will default to EST.
9107c478bd9Sstevel@tonic-gate  */
9117c478bd9Sstevel@tonic-gate 
9127c478bd9Sstevel@tonic-gate #define	LINELEN	81
9137c478bd9Sstevel@tonic-gate 
9147c478bd9Sstevel@tonic-gate void
setTZ()9157c478bd9Sstevel@tonic-gate setTZ()
9167c478bd9Sstevel@tonic-gate {
9177c478bd9Sstevel@tonic-gate 	static char	buf[LINELEN], *bp;
9187c478bd9Sstevel@tonic-gate 	extern char	*fgets();
9197c478bd9Sstevel@tonic-gate 	FILE		*tzfp;
9207c478bd9Sstevel@tonic-gate 	extern FILE	*fopen();
921462be471Sceastha 	int		i;
9227c478bd9Sstevel@tonic-gate 	extern int	fclose(), strncmp();
9237c478bd9Sstevel@tonic-gate 
924052519c2SGarrett D'Amore 	if ( (tzfp = fopen("/etc/default/init","r")) == (FILE *)NULL )
9257c478bd9Sstevel@tonic-gate 		return;
9267c478bd9Sstevel@tonic-gate 	while ( (bp = fgets(buf,LINELEN,tzfp)) != (char *)NULL ) {
9277c478bd9Sstevel@tonic-gate 		while ( isspace(*bp) )
9287c478bd9Sstevel@tonic-gate 			++bp;
9297c478bd9Sstevel@tonic-gate 		if ( strncmp(bp, "TZ=", 3) == 0 ) {
9307c478bd9Sstevel@tonic-gate 			for ( i = strlen(bp) - 1; i > 0 && isspace(*(bp+i)); --i )
9317c478bd9Sstevel@tonic-gate 				*(bp+i) = '\0';
9327c478bd9Sstevel@tonic-gate 			putenv(bp);
9337c478bd9Sstevel@tonic-gate 			(void)fclose(tzfp);
9347c478bd9Sstevel@tonic-gate 			return;
9357c478bd9Sstevel@tonic-gate 		}
9367c478bd9Sstevel@tonic-gate 	}
9377c478bd9Sstevel@tonic-gate 	(void)fclose(tzfp);
9387c478bd9Sstevel@tonic-gate 	return;
9397c478bd9Sstevel@tonic-gate }
9407c478bd9Sstevel@tonic-gate #endif /* ATTSVR3 */
9417c478bd9Sstevel@tonic-gate 
9427c478bd9Sstevel@tonic-gate #ifdef NOSTRANGERS
9437c478bd9Sstevel@tonic-gate /*
9447c478bd9Sstevel@tonic-gate * Function:	checkrmt
9457c478bd9Sstevel@tonic-gate *
9467c478bd9Sstevel@tonic-gate * If NOSTRANGERS is defined, see if the remote system is in our systems
9477c478bd9Sstevel@tonic-gate * file.  If it is not, execute NOSTRANGERS and then reject the call.
9487c478bd9Sstevel@tonic-gate */
9497c478bd9Sstevel@tonic-gate 
9507c478bd9Sstevel@tonic-gate static void
checkrmt()9517c478bd9Sstevel@tonic-gate checkrmt ()
9527c478bd9Sstevel@tonic-gate 
9537c478bd9Sstevel@tonic-gate {
9547c478bd9Sstevel@tonic-gate 	char **	eVarPtr;	/* Pointer to environment variable. */
9557c478bd9Sstevel@tonic-gate 	char	msgbuf[BUFSIZ];	/* Place to build messages. */
9567c478bd9Sstevel@tonic-gate 	pid_t	procid;		/* ID of Nostranger process. */
9577c478bd9Sstevel@tonic-gate 	static char * safePath = PATH;
9587c478bd9Sstevel@tonic-gate 	int	status;		/* Exit status of child. */
9597c478bd9Sstevel@tonic-gate 	pid_t	waitrv;		/* Return value from wait system call. */
9607c478bd9Sstevel@tonic-gate 
9617c478bd9Sstevel@tonic-gate 	/* here's the place to look the remote system up in the Systems file.
962*55fea89dSDan Cross 	 * If the command NOSTRANGERS is executable and
9637c478bd9Sstevel@tonic-gate 	 * If they're not in my file then hang up */
9647c478bd9Sstevel@tonic-gate 
9657c478bd9Sstevel@tonic-gate 	if (versys(Rmtname) && (access(NOSTRANGERS, 1) == 0)) {
9667c478bd9Sstevel@tonic-gate 		sprintf(msgbuf, "Invoking %s for %%s\n", NOSTRANGERS);
9677c478bd9Sstevel@tonic-gate 		DEBUG(4, msgbuf, Rmtname);
9687c478bd9Sstevel@tonic-gate 
9697c478bd9Sstevel@tonic-gate 		/*
9707c478bd9Sstevel@tonic-gate 		* Ignore hangup in case remote goes away before we can
9717c478bd9Sstevel@tonic-gate 		* finish logging.
9727c478bd9Sstevel@tonic-gate 		*/
9737c478bd9Sstevel@tonic-gate 
9747c478bd9Sstevel@tonic-gate 		(void) signal(SIGHUP, SIG_IGN);
9757c478bd9Sstevel@tonic-gate 		omsg('R', "You are unknown to me", Ofn);
9767c478bd9Sstevel@tonic-gate 		scWrite(); /* log unknown remote system */
9777c478bd9Sstevel@tonic-gate 		procid = fork();
9787c478bd9Sstevel@tonic-gate 		if ( procid == 0 ) {
9797c478bd9Sstevel@tonic-gate 			/*
9807c478bd9Sstevel@tonic-gate 			* Before execing the no strangers program, there is
9817c478bd9Sstevel@tonic-gate 			* a security aspect to consider.  If NOSTRANGERS is
9827c478bd9Sstevel@tonic-gate 			* not a full path name, then the PATH environment
9837c478bd9Sstevel@tonic-gate 			* variable will provide places to look for the file.
9847c478bd9Sstevel@tonic-gate 			* To be safe, we will set the PATH environment
9857c478bd9Sstevel@tonic-gate 			* variable before we do the exec.
9867c478bd9Sstevel@tonic-gate 			*/
9877c478bd9Sstevel@tonic-gate 
9887c478bd9Sstevel@tonic-gate 			/* Find PATH in current environment and change it. */
9897c478bd9Sstevel@tonic-gate 
9907c478bd9Sstevel@tonic-gate 			for (eVarPtr = Env; *eVarPtr != CNULL; eVarPtr++) {
9917c478bd9Sstevel@tonic-gate 				if (PREFIX("PATH=", *eVarPtr))
9927c478bd9Sstevel@tonic-gate 					*eVarPtr = safePath;
9937c478bd9Sstevel@tonic-gate 			}
9947c478bd9Sstevel@tonic-gate 			execlp( NOSTRANGERS, "stranger", Rmtname, (char *) 0);
9957c478bd9Sstevel@tonic-gate 			sprintf(msgbuf, "Execlp of %s failed with errno=%%d\n",
9967c478bd9Sstevel@tonic-gate 				NOSTRANGERS);
9977c478bd9Sstevel@tonic-gate 			DEBUG(4, msgbuf, errno);
9987c478bd9Sstevel@tonic-gate 			perror(gettext("cico.c: execlp NOSTRANGERS failed"));
9997c478bd9Sstevel@tonic-gate 			cleanup(errno);
10007c478bd9Sstevel@tonic-gate 		} else if (procid < 0) {
10017c478bd9Sstevel@tonic-gate 			perror(gettext("cico.c: execlp NOSTRANGERS failed"));
10027c478bd9Sstevel@tonic-gate 			cleanup(errno);
10037c478bd9Sstevel@tonic-gate 		} else {
10047c478bd9Sstevel@tonic-gate 			while ((waitrv = wait(&status)) != procid)
10057c478bd9Sstevel@tonic-gate 				if (waitrv == -1 && errno != EINTR)
10067c478bd9Sstevel@tonic-gate 					cleanup(errno);
10077c478bd9Sstevel@tonic-gate 			sprintf(msgbuf, "%s exit status was %%#x\n",
10087c478bd9Sstevel@tonic-gate 				NOSTRANGERS);
10097c478bd9Sstevel@tonic-gate 			DEBUG(4, msgbuf, status);
10107c478bd9Sstevel@tonic-gate 		}
10117c478bd9Sstevel@tonic-gate 		cleanup(101);
10127c478bd9Sstevel@tonic-gate 	}
10137c478bd9Sstevel@tonic-gate }
10147c478bd9Sstevel@tonic-gate #endif /* NOSTRANGERS */
1015