xref: /titanic_44/usr/src/cmd/bnu/uucp.c (revision d67944fbe3fa0b31893a7116a09b0718eecf6078)
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
5*d67944fbSScott Rotondo  * Common Development and Distribution License (the "License").
6*d67944fbSScott 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  */
217c478bd9Sstevel@tonic-gate /*
22*d67944fbSScott Rotondo  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
26462be471Sceastha /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27462be471Sceastha /*	  All Rights Reserved  	*/
28462be471Sceastha 
297c478bd9Sstevel@tonic-gate #include "uucp.h"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * uucp
337c478bd9Sstevel@tonic-gate  * user id
347c478bd9Sstevel@tonic-gate  * make a copy in spool directory
357c478bd9Sstevel@tonic-gate  */
367c478bd9Sstevel@tonic-gate int Copy = 0;
377c478bd9Sstevel@tonic-gate static int _Transfer = 0;
387c478bd9Sstevel@tonic-gate char Nuser[32];
397c478bd9Sstevel@tonic-gate char *Ropt = " ";
407c478bd9Sstevel@tonic-gate char Optns[10];
417c478bd9Sstevel@tonic-gate char Uopts[BUFSIZ];
427c478bd9Sstevel@tonic-gate char Xopts[BUFSIZ];
437c478bd9Sstevel@tonic-gate char Sgrade[NAMESIZE];
447c478bd9Sstevel@tonic-gate int Mail = 0;
457c478bd9Sstevel@tonic-gate int Notify = 0;
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate void cleanup(), ruux(), usage();
487c478bd9Sstevel@tonic-gate int eaccess(), guinfo(), vergrd(), gwd(), ckexpf(), uidstat(), uidxcp(),
497c478bd9Sstevel@tonic-gate 	copy(), gtcfile();
507c478bd9Sstevel@tonic-gate void commitall(), wfabort(), mailst(), gename(), svcfile();
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate char	Sfile[MAXFULLNAME];
537c478bd9Sstevel@tonic-gate 
54462be471Sceastha int
main(argc,argv,envp)557c478bd9Sstevel@tonic-gate main(argc, argv, envp)
56462be471Sceastha int argc;
577c478bd9Sstevel@tonic-gate char *argv[];
587c478bd9Sstevel@tonic-gate char	**envp;
597c478bd9Sstevel@tonic-gate {
607c478bd9Sstevel@tonic-gate 	char *jid();
617c478bd9Sstevel@tonic-gate 	int	ret;
627c478bd9Sstevel@tonic-gate 	int	errors = 0;
637c478bd9Sstevel@tonic-gate 	char	*fopt, *sys2p;
647c478bd9Sstevel@tonic-gate 	char	sys1[MAXFULLNAME], sys2[MAXFULLNAME];
657c478bd9Sstevel@tonic-gate 	char	fwd1[MAXFULLNAME], fwd2[MAXFULLNAME];
667c478bd9Sstevel@tonic-gate 	char	file1[MAXFULLNAME], file2[MAXFULLNAME];
677c478bd9Sstevel@tonic-gate 	short	jflag = 0;	/* -j flag  Jobid printout */
687c478bd9Sstevel@tonic-gate 	extern int	split();
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate 	/* Set locale environment variables local definitions */
727c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
737c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
747c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"	/* Use this only if it wasn't */
757c478bd9Sstevel@tonic-gate #endif
767c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 	/* this fails in some versions, but it doesn't hurt */
797c478bd9Sstevel@tonic-gate 	Uid = getuid();
807c478bd9Sstevel@tonic-gate 	Euid = geteuid();
817c478bd9Sstevel@tonic-gate 	if (Uid == 0)
827c478bd9Sstevel@tonic-gate 		(void) setuid(UUCPUID);
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 	/* choose LOGFILE */
857c478bd9Sstevel@tonic-gate 	(void) strcpy(Logfile, LOGUUCP);
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 	Env = envp;
887c478bd9Sstevel@tonic-gate 	fopt = NULL;
897c478bd9Sstevel@tonic-gate 	(void) strcpy(Progname, "uucp");
907c478bd9Sstevel@tonic-gate 	Pchar = 'U';
917c478bd9Sstevel@tonic-gate 	*Uopts = NULLCHAR;
927c478bd9Sstevel@tonic-gate 	*Xopts = NULLCHAR;
937c478bd9Sstevel@tonic-gate 	*Sgrade = NULLCHAR;
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 	if (eaccess(GRADES, 0) != -1) {
967c478bd9Sstevel@tonic-gate 		Grade = 'A';
977c478bd9Sstevel@tonic-gate 		Sgrades = TRUE;
987c478bd9Sstevel@tonic-gate 		sprintf(Sgrade, "%s", "default");
997c478bd9Sstevel@tonic-gate 	}
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	/*
1027c478bd9Sstevel@tonic-gate 	 * find name of local system
1037c478bd9Sstevel@tonic-gate 	 */
1047c478bd9Sstevel@tonic-gate 	uucpname(Myname);
1057c478bd9Sstevel@tonic-gate 	Optns[0] = '-';
1067c478bd9Sstevel@tonic-gate 	Optns[1] = 'd';
1077c478bd9Sstevel@tonic-gate 	Optns[2] = 'c';
1087c478bd9Sstevel@tonic-gate 	Optns[3] = Nuser[0] = Sfile[0] = NULLCHAR;
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	/*
1117c478bd9Sstevel@tonic-gate 	 * find id of user who spawned command to
1127c478bd9Sstevel@tonic-gate 	 * determine
1137c478bd9Sstevel@tonic-gate 	 */
1147c478bd9Sstevel@tonic-gate 	(void) guinfo(Uid, User);
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 	/*
1177c478bd9Sstevel@tonic-gate 	 * create/append command log
1187c478bd9Sstevel@tonic-gate 	 */
1197c478bd9Sstevel@tonic-gate 	commandlog(argc,argv);
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 	while ((ret = getopt(argc, argv, "Ccdfg:jmn:rs:x:")) != EOF) {
1227c478bd9Sstevel@tonic-gate 		switch (ret) {
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 		/*
1257c478bd9Sstevel@tonic-gate 		 * make a copy of the file in the spool
1267c478bd9Sstevel@tonic-gate 		 * directory.
1277c478bd9Sstevel@tonic-gate 		 */
1287c478bd9Sstevel@tonic-gate 		case 'C':
1297c478bd9Sstevel@tonic-gate 			Copy = 1;
1307c478bd9Sstevel@tonic-gate 			Optns[2] = 'C';
1317c478bd9Sstevel@tonic-gate 			break;
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 		/*
1347c478bd9Sstevel@tonic-gate 		 * not used (default)
1357c478bd9Sstevel@tonic-gate 		 */
1367c478bd9Sstevel@tonic-gate 		case 'c':
1377c478bd9Sstevel@tonic-gate 			break;
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate 		/*
1407c478bd9Sstevel@tonic-gate 		 * not used (default)
1417c478bd9Sstevel@tonic-gate 		 */
1427c478bd9Sstevel@tonic-gate 		case 'd':
1437c478bd9Sstevel@tonic-gate 			break;
1447c478bd9Sstevel@tonic-gate 		case 'f':
1457c478bd9Sstevel@tonic-gate 			Optns[1] = 'f';
1467c478bd9Sstevel@tonic-gate 			break;
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 		/*
1497c478bd9Sstevel@tonic-gate 		 * set service grade
1507c478bd9Sstevel@tonic-gate 		 */
1517c478bd9Sstevel@tonic-gate 		case 'g':
1527c478bd9Sstevel@tonic-gate 			snprintf(Xopts, sizeof (Xopts), "-g%s", optarg);
1537c478bd9Sstevel@tonic-gate 			if (!Sgrades) {
1547c478bd9Sstevel@tonic-gate 				if (strlen(optarg) < (size_t)2 && isalnum(*optarg))
1557c478bd9Sstevel@tonic-gate 					Grade = *optarg;
1567c478bd9Sstevel@tonic-gate 				else {
1577c478bd9Sstevel@tonic-gate 					(void) fprintf(stderr, gettext("No"
1587c478bd9Sstevel@tonic-gate 					    " administrator defined service"
1597c478bd9Sstevel@tonic-gate 					    " grades available on this"
1607c478bd9Sstevel@tonic-gate 					    " machine.\n"));
1617c478bd9Sstevel@tonic-gate 					(void) fprintf(stderr, gettext("UUCP"
1627c478bd9Sstevel@tonic-gate 					    " service grades range from"
1637c478bd9Sstevel@tonic-gate 					    " [A-Z][a-z] only.\n"));
1647c478bd9Sstevel@tonic-gate 					cleanup(-1);
1657c478bd9Sstevel@tonic-gate 				}
1667c478bd9Sstevel@tonic-gate 			}
1677c478bd9Sstevel@tonic-gate 			else {
1687c478bd9Sstevel@tonic-gate 				(void) strncpy(Sgrade, optarg, NAMESIZE-1);
1697c478bd9Sstevel@tonic-gate 				Sgrade[NAMESIZE-1] = NULLCHAR;
1707c478bd9Sstevel@tonic-gate 				if (vergrd(Sgrade) != SUCCESS)
1717c478bd9Sstevel@tonic-gate 					cleanup(FAIL);
1727c478bd9Sstevel@tonic-gate 			}
1737c478bd9Sstevel@tonic-gate 			break;
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 		case 'j':	/* job id */
1767c478bd9Sstevel@tonic-gate 			jflag = 1;
1777c478bd9Sstevel@tonic-gate 			break;
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 		/*
1807c478bd9Sstevel@tonic-gate 		 * send notification to local user
1817c478bd9Sstevel@tonic-gate 		 */
1827c478bd9Sstevel@tonic-gate 		case 'm':
1837c478bd9Sstevel@tonic-gate 			Mail = 1;
1847c478bd9Sstevel@tonic-gate 			(void) strcat(Optns, "m");
1857c478bd9Sstevel@tonic-gate 			break;
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate 		/*
1887c478bd9Sstevel@tonic-gate 		 * send notification to user on remote
1897c478bd9Sstevel@tonic-gate 		 * if no user specified do not send notification
1907c478bd9Sstevel@tonic-gate 		 */
1917c478bd9Sstevel@tonic-gate 		case 'n':
1927c478bd9Sstevel@tonic-gate 			/*
1937c478bd9Sstevel@tonic-gate 			 * We should add "n" option to Optns only once,
1947c478bd9Sstevel@tonic-gate 			 * even if multiple -n option are passed to uucp
1957c478bd9Sstevel@tonic-gate 			 */
1967c478bd9Sstevel@tonic-gate 			if (!Notify) {
1977c478bd9Sstevel@tonic-gate 				(void) strlcat(Optns, "n", sizeof (Optns));
1987c478bd9Sstevel@tonic-gate 				Notify = 1;
1997c478bd9Sstevel@tonic-gate 			}
2007c478bd9Sstevel@tonic-gate 			(void) sprintf(Nuser, "%.8s", optarg);
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 			/*
2037c478bd9Sstevel@tonic-gate 			 * We do the copy multiple times when multiple
2047c478bd9Sstevel@tonic-gate 			 * -n options are specified, but
2057c478bd9Sstevel@tonic-gate 			 * only the last -n value is used.
2067c478bd9Sstevel@tonic-gate 	 		 */
2077c478bd9Sstevel@tonic-gate 			(void) snprintf(Uopts, sizeof (Uopts), "-n%s ", Nuser);
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate 			break;
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 		/*
2127c478bd9Sstevel@tonic-gate 		 * create JCL files but do not start uucico
2137c478bd9Sstevel@tonic-gate 		 */
2147c478bd9Sstevel@tonic-gate 		case 'r':
2157c478bd9Sstevel@tonic-gate 			Ropt = "-r";
2167c478bd9Sstevel@tonic-gate 			break;
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 		/*
2197c478bd9Sstevel@tonic-gate 		 * return status file
2207c478bd9Sstevel@tonic-gate 		 */
2217c478bd9Sstevel@tonic-gate 		case 's':
2227c478bd9Sstevel@tonic-gate 			fopt = optarg;
2237c478bd9Sstevel@tonic-gate 			/* "m" needed for compatability */
2247c478bd9Sstevel@tonic-gate 			(void) strcat(Optns, "mo");
2257c478bd9Sstevel@tonic-gate 			break;
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 		/*
2287c478bd9Sstevel@tonic-gate 		 * turn on debugging
2297c478bd9Sstevel@tonic-gate 		 */
2307c478bd9Sstevel@tonic-gate 		case 'x':
2317c478bd9Sstevel@tonic-gate 			Debug = atoi(optarg);
2327c478bd9Sstevel@tonic-gate 			if (Debug <= 0)
2337c478bd9Sstevel@tonic-gate 				Debug = 1;
2347c478bd9Sstevel@tonic-gate #ifdef SMALL
2357c478bd9Sstevel@tonic-gate 			fprintf(stderr, gettext("WARNING: uucp built with SMALL"
2367c478bd9Sstevel@tonic-gate 			    " flag defined -- no debug info available\n"));
2377c478bd9Sstevel@tonic-gate #endif /* SMALL */
2387c478bd9Sstevel@tonic-gate 			break;
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate 		default:
2417c478bd9Sstevel@tonic-gate 			usage();
2427c478bd9Sstevel@tonic-gate 			break;
2437c478bd9Sstevel@tonic-gate 		}
2447c478bd9Sstevel@tonic-gate 	}
2457c478bd9Sstevel@tonic-gate 	DEBUG(4, "\n\n** %s **\n", "START");
2467c478bd9Sstevel@tonic-gate 	gwd(Wrkdir);
2477c478bd9Sstevel@tonic-gate 	if (fopt) {
2487c478bd9Sstevel@tonic-gate 		if (*fopt != '/')
2497c478bd9Sstevel@tonic-gate 			(void) snprintf(Sfile, MAXFULLNAME, "%s/%s",
2507c478bd9Sstevel@tonic-gate 					Wrkdir, fopt);
2517c478bd9Sstevel@tonic-gate 		else
2527c478bd9Sstevel@tonic-gate 			(void) snprintf(Sfile, MAXFULLNAME, "%s", fopt);
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 	}
2557c478bd9Sstevel@tonic-gate 	else
2567c478bd9Sstevel@tonic-gate 		if (strlcpy(Sfile, "dummy", sizeof (Sfile)) >= sizeof (Sfile))
2577c478bd9Sstevel@tonic-gate 			return (2);
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	/*
2607c478bd9Sstevel@tonic-gate 	 * work in WORKSPACE directory
2617c478bd9Sstevel@tonic-gate 	 */
2627c478bd9Sstevel@tonic-gate 	ret = chdir(WORKSPACE);
2637c478bd9Sstevel@tonic-gate 	if (ret != 0) {
2647c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext("No work directory - %s -"
2657c478bd9Sstevel@tonic-gate 		    " get help\n"), WORKSPACE);
2667c478bd9Sstevel@tonic-gate 		cleanup(-12);
2677c478bd9Sstevel@tonic-gate 	}
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 	if (Nuser[0] == NULLCHAR)
2707c478bd9Sstevel@tonic-gate 		(void) strcpy(Nuser, User);
2717c478bd9Sstevel@tonic-gate 	(void) strcpy(Loginuser, User);
2727c478bd9Sstevel@tonic-gate 	DEBUG(4, "UID %ld, ", (long) Uid);
2737c478bd9Sstevel@tonic-gate 	DEBUG(4, "User %s\n", User);
2747c478bd9Sstevel@tonic-gate 	if (argc - optind < 2) {
2757c478bd9Sstevel@tonic-gate 		usage();
2767c478bd9Sstevel@tonic-gate 	}
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	/*
2797c478bd9Sstevel@tonic-gate 	 * set up "to" system and file names
2807c478bd9Sstevel@tonic-gate 	 */
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 	(void) split(argv[argc - 1], sys2, fwd2, file2);
2837c478bd9Sstevel@tonic-gate 	if (*sys2 != NULLCHAR) {
2847c478bd9Sstevel@tonic-gate 		(void) strncpy(Rmtname, sys2, MAXBASENAME);
2857c478bd9Sstevel@tonic-gate 		Rmtname[MAXBASENAME] = NULLCHAR;
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate 		/* get real Myname - it depends on who I'm calling--Rmtname */
2887c478bd9Sstevel@tonic-gate 		(void) mchFind(Rmtname);
2897c478bd9Sstevel@tonic-gate 		myName(Myname);
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate 		if (versys(sys2) != 0) {
2927c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
2937c478bd9Sstevel@tonic-gate 			    gettext("bad system: %s\n"), sys2);
2947c478bd9Sstevel@tonic-gate 			cleanup(-EX_NOHOST);
2957c478bd9Sstevel@tonic-gate 		}
2967c478bd9Sstevel@tonic-gate 	}
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate 	DEBUG(9, "sys2: %s, ", sys2);
2997c478bd9Sstevel@tonic-gate 	DEBUG(9, "fwd2: %s, ", fwd2);
3007c478bd9Sstevel@tonic-gate 	DEBUG(9, "file2: %s\n", file2);
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate 	/*
3037c478bd9Sstevel@tonic-gate 	 * if there are more than 2 argsc, file2 is a directory
3047c478bd9Sstevel@tonic-gate 	 */
3057c478bd9Sstevel@tonic-gate 	if (argc - optind > 2)
3067c478bd9Sstevel@tonic-gate 		(void) strcat(file2, "/");
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate 	/*
3097c478bd9Sstevel@tonic-gate 	 * do each from argument
3107c478bd9Sstevel@tonic-gate 	 */
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 	for ( ; optind < argc - 1; optind++) {
3137c478bd9Sstevel@tonic-gate 	    (void) split(argv[optind], sys1, fwd1, file1);
3147c478bd9Sstevel@tonic-gate 	    if (*sys1 != NULLCHAR) {
3157c478bd9Sstevel@tonic-gate 		if (versys(sys1) != 0) {
3167c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
3177c478bd9Sstevel@tonic-gate 			    gettext("bad system: %s\n"), sys1);
3187c478bd9Sstevel@tonic-gate 			cleanup(-EX_NOHOST);
3197c478bd9Sstevel@tonic-gate 		}
3207c478bd9Sstevel@tonic-gate 	    }
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate 	    /*  source files can have at most one ! */
3237c478bd9Sstevel@tonic-gate 	    if (*fwd1 != NULLCHAR) {
3247c478bd9Sstevel@tonic-gate 		/* syntax error */
3257c478bd9Sstevel@tonic-gate 	        (void) fprintf(stderr,
3267c478bd9Sstevel@tonic-gate 		    gettext("illegal  syntax %s\n"), argv[optind]);
3277c478bd9Sstevel@tonic-gate 	        exit(2);
3287c478bd9Sstevel@tonic-gate 	    }
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate 	    /*
3317c478bd9Sstevel@tonic-gate 	     * check for required remote expansion of file names -- generate
3327c478bd9Sstevel@tonic-gate 	     *	and execute a uux command
3337c478bd9Sstevel@tonic-gate 	     * e.g.
3347c478bd9Sstevel@tonic-gate 	     *		uucp   owl!~/dan/..  ~/dan/
3357c478bd9Sstevel@tonic-gate 	     *
3367c478bd9Sstevel@tonic-gate 	     * NOTE: The source file part must be full path name.
3377c478bd9Sstevel@tonic-gate 	     *  If ~ it will be expanded locally - it assumes the remote
3387c478bd9Sstevel@tonic-gate 	     *  names are the same.
3397c478bd9Sstevel@tonic-gate 	     */
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 	    if (*sys1 != NULLCHAR)
3427c478bd9Sstevel@tonic-gate 		if ((strchr(file1, '*') != NULL
3437c478bd9Sstevel@tonic-gate 		      || strchr(file1, '?') != NULL
3447c478bd9Sstevel@tonic-gate 		      || strchr(file1, '[') != NULL)) {
3457c478bd9Sstevel@tonic-gate 		        /* do a uux command */
3467c478bd9Sstevel@tonic-gate 		        if (ckexpf(file1) == FAIL)
3477c478bd9Sstevel@tonic-gate 			    exit(6);
3487c478bd9Sstevel@tonic-gate 			(void) strncpy(Rmtname, sys1, MAXBASENAME);
3497c478bd9Sstevel@tonic-gate 			Rmtname[MAXBASENAME] = NULLCHAR;
3507c478bd9Sstevel@tonic-gate 			/* get real Myname - it depends on who I'm calling--Rmtname */
3517c478bd9Sstevel@tonic-gate 			(void) mchFind(Rmtname);
3527c478bd9Sstevel@tonic-gate 			myName(Myname);
3537c478bd9Sstevel@tonic-gate 			if (*sys2 == NULLCHAR)
3547c478bd9Sstevel@tonic-gate 			    sys2p = Myname;
3557c478bd9Sstevel@tonic-gate 		        ruux(sys1, sys1, file1, sys2p, fwd2, file2);
3567c478bd9Sstevel@tonic-gate 		        continue;
3577c478bd9Sstevel@tonic-gate 		}
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate 	    /*
3607c478bd9Sstevel@tonic-gate 	     * check for forwarding -- generate and execute a uux command
3617c478bd9Sstevel@tonic-gate 	     * e.g.
3627c478bd9Sstevel@tonic-gate 	     *		uucp uucp.c raven!owl!~/dan/
3637c478bd9Sstevel@tonic-gate 	     */
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate 	    if (*fwd2 != NULLCHAR) {
3667c478bd9Sstevel@tonic-gate 	        ruux(sys2, sys1, file1, "", fwd2, file2);
3677c478bd9Sstevel@tonic-gate 	        continue;
3687c478bd9Sstevel@tonic-gate 	    }
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate 	    /*
3717c478bd9Sstevel@tonic-gate 	     * check for both source and destination on other systems --
3727c478bd9Sstevel@tonic-gate 	     *  generate and execute a uux command
3737c478bd9Sstevel@tonic-gate 	     */
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate 	    if (*sys1 != NULLCHAR )
3767c478bd9Sstevel@tonic-gate 		if ( (!EQUALS(Myname, sys1))
3777c478bd9Sstevel@tonic-gate 	    	  && *sys2 != NULLCHAR
3787c478bd9Sstevel@tonic-gate 	    	  && (!EQUALS(sys2, Myname)) ) {
3797c478bd9Sstevel@tonic-gate 		    ruux(sys2, sys1, file1, "", fwd2, file2);
3807c478bd9Sstevel@tonic-gate 	            continue;
3817c478bd9Sstevel@tonic-gate 	        }
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate 	    sys2p = sys2;
3857c478bd9Sstevel@tonic-gate 	    if (*sys1 == NULLCHAR) {
3867c478bd9Sstevel@tonic-gate 		if (*sys2 == NULLCHAR)
3877c478bd9Sstevel@tonic-gate 		    sys2p = Myname;
3887c478bd9Sstevel@tonic-gate 		(void) strcpy(sys1, Myname);
3897c478bd9Sstevel@tonic-gate 	    } else {
3907c478bd9Sstevel@tonic-gate 		(void) strncpy(Rmtname, sys1, MAXBASENAME);
3917c478bd9Sstevel@tonic-gate 		Rmtname[MAXBASENAME] = NULLCHAR;
3927c478bd9Sstevel@tonic-gate 		/* get real Myname - it depends on who I'm calling--Rmtname */
3937c478bd9Sstevel@tonic-gate 		(void) mchFind(Rmtname);
3947c478bd9Sstevel@tonic-gate 		myName(Myname);
3957c478bd9Sstevel@tonic-gate 		if (*sys2 == NULLCHAR)
3967c478bd9Sstevel@tonic-gate 		    sys2p = Myname;
3977c478bd9Sstevel@tonic-gate 	    }
3987c478bd9Sstevel@tonic-gate 
3997c478bd9Sstevel@tonic-gate 	    DEBUG(4, "sys1 - %s, ", sys1);
4007c478bd9Sstevel@tonic-gate 	    DEBUG(4, "file1 - %s, ", file1);
4017c478bd9Sstevel@tonic-gate 	    DEBUG(4, "Rmtname - %s\n", Rmtname);
4027c478bd9Sstevel@tonic-gate 	    if (copy(sys1, file1, sys2p, file2))
4037c478bd9Sstevel@tonic-gate 	    	errors++;
4047c478bd9Sstevel@tonic-gate 	}
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate 	/* move the work files to their proper places */
4077c478bd9Sstevel@tonic-gate 	commitall();
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate 	/*
4107c478bd9Sstevel@tonic-gate 	 * Wait for all background uux processes to finish so
4117c478bd9Sstevel@tonic-gate 	 * that our caller will know that we're done with all
4127c478bd9Sstevel@tonic-gate 	 * input files and it's safe to remove them.
4137c478bd9Sstevel@tonic-gate 	 */
4147c478bd9Sstevel@tonic-gate 	while (wait(NULL) != -1)
4157c478bd9Sstevel@tonic-gate 		;
4167c478bd9Sstevel@tonic-gate 
4177c478bd9Sstevel@tonic-gate 	/*
4187c478bd9Sstevel@tonic-gate 	 * do not spawn daemon if -r option specified
4197c478bd9Sstevel@tonic-gate 	 */
4207c478bd9Sstevel@tonic-gate 	if (*Ropt != '-') {
4217c478bd9Sstevel@tonic-gate #ifndef	V7
4227c478bd9Sstevel@tonic-gate 		long	limit;
4237c478bd9Sstevel@tonic-gate 		char	msg[100];
4247c478bd9Sstevel@tonic-gate 		limit = ulimit(1, (long) 0);
4257c478bd9Sstevel@tonic-gate 		if (limit < MINULIMIT)  {
4267c478bd9Sstevel@tonic-gate 			(void) sprintf(msg,
4277c478bd9Sstevel@tonic-gate 			    "ULIMIT (%ld) < MINULIMIT (%ld)", limit, MINULIMIT);
4287c478bd9Sstevel@tonic-gate 			logent(msg, "Low-ULIMIT");
4297c478bd9Sstevel@tonic-gate 		}
4307c478bd9Sstevel@tonic-gate 		else
4317c478bd9Sstevel@tonic-gate #endif
4327c478bd9Sstevel@tonic-gate 			xuucico(Rmtname);
4337c478bd9Sstevel@tonic-gate 	}
4347c478bd9Sstevel@tonic-gate 	if (jflag) {
4357c478bd9Sstevel@tonic-gate 		(void) strncpy(Jobid, jid(), NAMESIZE);
4367c478bd9Sstevel@tonic-gate 		printf("%s\n", Jobid);
4377c478bd9Sstevel@tonic-gate 	}
4387c478bd9Sstevel@tonic-gate 	cleanup(errors);
4397c478bd9Sstevel@tonic-gate 	/*NOTREACHED*/
440462be471Sceastha 	return (0);
4417c478bd9Sstevel@tonic-gate }
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate /*
4447c478bd9Sstevel@tonic-gate  * cleanup lock files before exiting
4457c478bd9Sstevel@tonic-gate  */
4467c478bd9Sstevel@tonic-gate void
cleanup(code)4477c478bd9Sstevel@tonic-gate cleanup(code)
448462be471Sceastha int	code;
4497c478bd9Sstevel@tonic-gate {
4507c478bd9Sstevel@tonic-gate 	static int first = 1;
4517c478bd9Sstevel@tonic-gate 
4527c478bd9Sstevel@tonic-gate 	if (first) {
4537c478bd9Sstevel@tonic-gate 		first = 0;
4547c478bd9Sstevel@tonic-gate 		rmlock(CNULL);
4557c478bd9Sstevel@tonic-gate 		if (code != 0)
4567c478bd9Sstevel@tonic-gate 			wfabort();  /* this may be extreme -- abort all work */
4577c478bd9Sstevel@tonic-gate 	}
4587c478bd9Sstevel@tonic-gate 	if (code < 0) {
4597c478bd9Sstevel@tonic-gate 	       (void) fprintf(stderr,
4607c478bd9Sstevel@tonic-gate 		   gettext("uucp failed completely (%d)\n"), (-code));
4617c478bd9Sstevel@tonic-gate 		exit(-code);
4627c478bd9Sstevel@tonic-gate 	}
4637c478bd9Sstevel@tonic-gate 	else if (code > 0) {
4647c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext(
4657c478bd9Sstevel@tonic-gate 		    "uucp failed partially: %d file(s) sent; %d error(s)\n"),
4667c478bd9Sstevel@tonic-gate 		 _Transfer, code);
4677c478bd9Sstevel@tonic-gate 		exit(code);
4687c478bd9Sstevel@tonic-gate 	}
4697c478bd9Sstevel@tonic-gate 	exit(code);
4707c478bd9Sstevel@tonic-gate }
4717c478bd9Sstevel@tonic-gate 
472*d67944fbSScott Rotondo static FILE *syscfile();
4737c478bd9Sstevel@tonic-gate /*
4747c478bd9Sstevel@tonic-gate  * generate copy files for s1!f1 -> s2!f2
4757c478bd9Sstevel@tonic-gate  *	Note: only one remote machine, other situations
4767c478bd9Sstevel@tonic-gate  *	have been taken care of in main.
4777c478bd9Sstevel@tonic-gate  * return:
4787c478bd9Sstevel@tonic-gate  *	0	-> success
4797c478bd9Sstevel@tonic-gate  * Non-zero     -> failure
4807c478bd9Sstevel@tonic-gate  */
4817c478bd9Sstevel@tonic-gate int
copy(s1,f1,s2,f2)4827c478bd9Sstevel@tonic-gate copy(s1, f1, s2, f2)
4837c478bd9Sstevel@tonic-gate char *s1, *f1, *s2, *f2;
4847c478bd9Sstevel@tonic-gate {
4857c478bd9Sstevel@tonic-gate 	FILE *cfp;
4867c478bd9Sstevel@tonic-gate 	struct stat stbuf, stbuf1;
4877c478bd9Sstevel@tonic-gate 	int type, statret;
4887c478bd9Sstevel@tonic-gate 	char dfile[NAMESIZE];
4897c478bd9Sstevel@tonic-gate 	char cfile[NAMESIZE];
4907c478bd9Sstevel@tonic-gate 	char command[10+(2*MAXFULLNAME)];
4917c478bd9Sstevel@tonic-gate 	char file1[MAXFULLNAME], file2[MAXFULLNAME];
4927c478bd9Sstevel@tonic-gate 	char msg[BUFSIZ];
4937c478bd9Sstevel@tonic-gate 
4947c478bd9Sstevel@tonic-gate 	type = 0;
4957c478bd9Sstevel@tonic-gate 	(void) strcpy(file1, f1);
4967c478bd9Sstevel@tonic-gate 	(void) strcpy(file2, f2);
4977c478bd9Sstevel@tonic-gate 	if (!EQUALS(s1, Myname))
4987c478bd9Sstevel@tonic-gate 		type = 1;
4997c478bd9Sstevel@tonic-gate 	if (!EQUALS(s2, Myname))
5007c478bd9Sstevel@tonic-gate 		type = 2;
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate 	DEBUG(4, "copy: file1=<%s> ", file1);
5037c478bd9Sstevel@tonic-gate 	DEBUG(4, "file2=<%s>\n", file2);
5047c478bd9Sstevel@tonic-gate 	switch (type) {
5057c478bd9Sstevel@tonic-gate 	case 0:
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate 		/*
5087c478bd9Sstevel@tonic-gate 		 * all work here
5097c478bd9Sstevel@tonic-gate 		 */
5107c478bd9Sstevel@tonic-gate 		DEBUG(4, "all work here %d\n", type);
5117c478bd9Sstevel@tonic-gate 
5127c478bd9Sstevel@tonic-gate 		/*
5137c478bd9Sstevel@tonic-gate 		 * check access control permissions
5147c478bd9Sstevel@tonic-gate 		 */
5157c478bd9Sstevel@tonic-gate 		if (ckexpf(file1))
5167c478bd9Sstevel@tonic-gate 			 return(-6);
5177c478bd9Sstevel@tonic-gate 		if (ckexpf(file2))
5187c478bd9Sstevel@tonic-gate 			 return(-7);
5197c478bd9Sstevel@tonic-gate 
5207c478bd9Sstevel@tonic-gate 		setuid(Uid);
5217c478bd9Sstevel@tonic-gate 		if (chkperm(file1, file2, strchr(Optns, 'd')) &&
5227c478bd9Sstevel@tonic-gate 		    (access(file2, W_OK) == -1)) {
5237c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext("permission denied\n"));
5247c478bd9Sstevel@tonic-gate 			cleanup(1);
5257c478bd9Sstevel@tonic-gate 		}
5267c478bd9Sstevel@tonic-gate 
5277c478bd9Sstevel@tonic-gate 		/*
5287c478bd9Sstevel@tonic-gate 		 * copy file locally
5297c478bd9Sstevel@tonic-gate 		 *
5307c478bd9Sstevel@tonic-gate 		 * Changed from uidxcp() to fic file made and owner
5317c478bd9Sstevel@tonic-gate 		 * being modified for existing files, and local file
5327c478bd9Sstevel@tonic-gate 		 * name expansion.
5337c478bd9Sstevel@tonic-gate 		 */
5347c478bd9Sstevel@tonic-gate 		DEBUG(2, "local copy: %s -> ", file1);
5357c478bd9Sstevel@tonic-gate 		DEBUG(2, "%s\n", file2);
5367c478bd9Sstevel@tonic-gate 
5377c478bd9Sstevel@tonic-gate 		sprintf(command, "cp %s %s", file1, file2);
5387c478bd9Sstevel@tonic-gate 		if ((cfp = popen(command, "r")) == NULL) {
5397c478bd9Sstevel@tonic-gate 			perror("popen");
5407c478bd9Sstevel@tonic-gate 			DEBUG(5, "popen failed - errno %d\n", errno);
5417c478bd9Sstevel@tonic-gate 			setuid(Euid);
5427c478bd9Sstevel@tonic-gate 			return (FAIL);
5437c478bd9Sstevel@tonic-gate 		}
5447c478bd9Sstevel@tonic-gate 		if (pclose(cfp) != 0) {
5457c478bd9Sstevel@tonic-gate 			DEBUG(5, "Copy failed - errno %d\n", errno);
5467c478bd9Sstevel@tonic-gate 			return (FAIL);
5477c478bd9Sstevel@tonic-gate 		}
5487c478bd9Sstevel@tonic-gate 		setuid(Euid);
5497c478bd9Sstevel@tonic-gate 
5507c478bd9Sstevel@tonic-gate 		/*
5517c478bd9Sstevel@tonic-gate 		 * if user specified -m, notify "local" user
5527c478bd9Sstevel@tonic-gate 		 */
5537c478bd9Sstevel@tonic-gate 		 if ( Mail ) {
5547c478bd9Sstevel@tonic-gate 		 	sprintf(msg,
5557c478bd9Sstevel@tonic-gate 		 	"REQUEST: %s!%s --> %s!%s (%s)\n(SYSTEM %s) copy succeeded\n",
5567c478bd9Sstevel@tonic-gate 		 	s1, file1, s2, file2, User, s2 );
5577c478bd9Sstevel@tonic-gate 		 	mailst(User, "copy succeeded", msg, "", "");
5587c478bd9Sstevel@tonic-gate 		}
5597c478bd9Sstevel@tonic-gate 		/*
5607c478bd9Sstevel@tonic-gate 		 * if user specified -n, notify "remote" user
5617c478bd9Sstevel@tonic-gate 		 */
5627c478bd9Sstevel@tonic-gate 		if ( Notify ) {
5637c478bd9Sstevel@tonic-gate 			sprintf(msg, "%s from %s!%s arrived\n",
5647c478bd9Sstevel@tonic-gate 				file2, s1, User );
5657c478bd9Sstevel@tonic-gate 			mailst(Nuser, msg, msg, "", "");
5667c478bd9Sstevel@tonic-gate 		}
5677c478bd9Sstevel@tonic-gate 		return(0);
5687c478bd9Sstevel@tonic-gate 	case 1:
5697c478bd9Sstevel@tonic-gate 
5707c478bd9Sstevel@tonic-gate 		/*
5717c478bd9Sstevel@tonic-gate 		 * receive file
5727c478bd9Sstevel@tonic-gate 		 */
5737c478bd9Sstevel@tonic-gate 		DEBUG(4, "receive file - %d\n", type);
5747c478bd9Sstevel@tonic-gate 
5757c478bd9Sstevel@tonic-gate 		/*
5767c478bd9Sstevel@tonic-gate 		 * expand source and destination file names
5777c478bd9Sstevel@tonic-gate 		 * and check access permissions
5787c478bd9Sstevel@tonic-gate 		 */
5797c478bd9Sstevel@tonic-gate 		if (file1[0] != '~')
5807c478bd9Sstevel@tonic-gate 			if (ckexpf(file1))
5817c478bd9Sstevel@tonic-gate 				 return(6);
5827c478bd9Sstevel@tonic-gate 		if (ckexpf(file2))
5837c478bd9Sstevel@tonic-gate 			 return(7);
5847c478bd9Sstevel@tonic-gate 
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate 		gename(DATAPRE, s2, Grade, dfile);
5877c478bd9Sstevel@tonic-gate 
5887c478bd9Sstevel@tonic-gate 		/*
5897c478bd9Sstevel@tonic-gate 		 * insert JCL card in file
5907c478bd9Sstevel@tonic-gate 		 */
5917c478bd9Sstevel@tonic-gate 		cfp = syscfile(cfile, s1);
5927c478bd9Sstevel@tonic-gate 		(void) fprintf(cfp,
5937c478bd9Sstevel@tonic-gate 	       	"R %s %s %s %s %s %o %s %s\n", file1, file2,
5947c478bd9Sstevel@tonic-gate 			User, Optns,
5957c478bd9Sstevel@tonic-gate 			*Sfile ? Sfile : "dummy",
5967c478bd9Sstevel@tonic-gate 			0777, Nuser, dfile);
5977c478bd9Sstevel@tonic-gate 		(void) fclose(cfp);
5987c478bd9Sstevel@tonic-gate 		(void) sprintf(msg, "%s!%s --> %s!%s", Rmtname, file1,
5997c478bd9Sstevel@tonic-gate 		    Myname, file2);
6007c478bd9Sstevel@tonic-gate 		logent(msg, "QUEUED");
6017c478bd9Sstevel@tonic-gate 		break;
6027c478bd9Sstevel@tonic-gate 	case 2:
6037c478bd9Sstevel@tonic-gate 
6047c478bd9Sstevel@tonic-gate 		/*
6057c478bd9Sstevel@tonic-gate 		 * send file
6067c478bd9Sstevel@tonic-gate 		 */
6077c478bd9Sstevel@tonic-gate 		if (ckexpf(file1))
6087c478bd9Sstevel@tonic-gate 			 return(6);
6097c478bd9Sstevel@tonic-gate 		/* XQTDIR hook enables 3rd party uux requests (cough) */
6107c478bd9Sstevel@tonic-gate 		DEBUG(4, "Workdir = <%s>\n", Wrkdir);
6117c478bd9Sstevel@tonic-gate 		if (file2[0] != '~' && !EQUALS(Wrkdir, XQTDIR))
6127c478bd9Sstevel@tonic-gate 			if (ckexpf(file2))
6137c478bd9Sstevel@tonic-gate 				 return(7);
6147c478bd9Sstevel@tonic-gate 		DEBUG(4, "send file - %d\n", type);
6157c478bd9Sstevel@tonic-gate 
6167c478bd9Sstevel@tonic-gate 		if (uidstat(file1, &stbuf) != 0) {
6177c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
6187c478bd9Sstevel@tonic-gate 			    gettext("can't get status for file %s\n"), file1);
6197c478bd9Sstevel@tonic-gate 			return(8);
6207c478bd9Sstevel@tonic-gate 		}
6217c478bd9Sstevel@tonic-gate 		if ((stbuf.st_mode & S_IFMT) == S_IFDIR) {
6227c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
6237c478bd9Sstevel@tonic-gate 			    gettext("directory name illegal - %s\n"), file1);
6247c478bd9Sstevel@tonic-gate 			return(9);
6257c478bd9Sstevel@tonic-gate 		}
6267c478bd9Sstevel@tonic-gate 		/* see if I can read this file as read uid, gid */
6277c478bd9Sstevel@tonic-gate 		if (access(file1, R_OK) != 0) {
6287c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
6297c478bd9Sstevel@tonic-gate 			    gettext("uucp can't read (%s) mode (%o)\n"),
6307c478bd9Sstevel@tonic-gate 			    file1, stbuf.st_mode&0777);
6317c478bd9Sstevel@tonic-gate 			return(3);
6327c478bd9Sstevel@tonic-gate 		}
6337c478bd9Sstevel@tonic-gate 
6347c478bd9Sstevel@tonic-gate 		/*
6357c478bd9Sstevel@tonic-gate 		 * make a copy of file in spool directory
6367c478bd9Sstevel@tonic-gate 		 */
6377c478bd9Sstevel@tonic-gate 
6387c478bd9Sstevel@tonic-gate 		gename(DATAPRE, s2, Grade, dfile);
6397c478bd9Sstevel@tonic-gate 
6407c478bd9Sstevel@tonic-gate 		if (Copy || !READANY(file1) ) {
6417c478bd9Sstevel@tonic-gate 
6427c478bd9Sstevel@tonic-gate 			if (uidxcp(file1, dfile))
6437c478bd9Sstevel@tonic-gate 			    return(5);
6447c478bd9Sstevel@tonic-gate 
6457c478bd9Sstevel@tonic-gate 			(void) chmod(dfile, DFILEMODE);
6467c478bd9Sstevel@tonic-gate 		}
6477c478bd9Sstevel@tonic-gate 
6487c478bd9Sstevel@tonic-gate 		cfp = syscfile(cfile, s2);
6497c478bd9Sstevel@tonic-gate 		(void) fprintf(cfp, "S %s %s %s %s %s %lo %s %s\n",
6507c478bd9Sstevel@tonic-gate 		    file1, file2, User, Optns, dfile,
6517c478bd9Sstevel@tonic-gate 		    (long) stbuf.st_mode & LEGALMODE, Nuser, Sfile);
6527c478bd9Sstevel@tonic-gate 		(void) fclose(cfp);
6537c478bd9Sstevel@tonic-gate 		(void) sprintf(msg, "%s!%s --> %s!%s", Myname, file1,
6547c478bd9Sstevel@tonic-gate 		    Rmtname, file2);
6557c478bd9Sstevel@tonic-gate 		logent(msg, "QUEUED");
6567c478bd9Sstevel@tonic-gate 		break;
6577c478bd9Sstevel@tonic-gate 	}
6587c478bd9Sstevel@tonic-gate 	_Transfer++;
6597c478bd9Sstevel@tonic-gate 	return(0);
6607c478bd9Sstevel@tonic-gate }
6617c478bd9Sstevel@tonic-gate 
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate /*
6647c478bd9Sstevel@tonic-gate  *	syscfile(file, sys)
6657c478bd9Sstevel@tonic-gate  *	char	*file, *sys;
6667c478bd9Sstevel@tonic-gate  *
6677c478bd9Sstevel@tonic-gate  *	get the cfile for system sys (creat if need be)
6687c478bd9Sstevel@tonic-gate  *	return stream pointer
6697c478bd9Sstevel@tonic-gate  *
6707c478bd9Sstevel@tonic-gate  *	returns
6717c478bd9Sstevel@tonic-gate  *		stream pointer to open cfile
6727c478bd9Sstevel@tonic-gate  *
6737c478bd9Sstevel@tonic-gate  */
6747c478bd9Sstevel@tonic-gate 
6757c478bd9Sstevel@tonic-gate static FILE	*
syscfile(file,sys)6767c478bd9Sstevel@tonic-gate syscfile(file, sys)
6777c478bd9Sstevel@tonic-gate char	*file, *sys;
6787c478bd9Sstevel@tonic-gate {
6797c478bd9Sstevel@tonic-gate 	FILE	*cfp;
6807c478bd9Sstevel@tonic-gate 
6817c478bd9Sstevel@tonic-gate 	if (gtcfile(file, sys) == FAIL) {
6827c478bd9Sstevel@tonic-gate 		gename(CMDPRE, sys, Grade, file);
6837c478bd9Sstevel@tonic-gate 		ASSERT(access(file, 0) != 0, Fl_EXISTS, file, errno);
6847c478bd9Sstevel@tonic-gate 		cfp = fdopen(creat(file, CFILEMODE), "w");
6857c478bd9Sstevel@tonic-gate 		svcfile(file, sys, Sgrade);
6867c478bd9Sstevel@tonic-gate 	} else
6877c478bd9Sstevel@tonic-gate 		cfp = fopen(file, "a");
6887c478bd9Sstevel@tonic-gate 	ASSERT(cfp != NULL, Ct_OPEN, file, errno);
6897c478bd9Sstevel@tonic-gate 	return(cfp);
6907c478bd9Sstevel@tonic-gate }
6917c478bd9Sstevel@tonic-gate 
6927c478bd9Sstevel@tonic-gate 
6937c478bd9Sstevel@tonic-gate /*
6947c478bd9Sstevel@tonic-gate  * generate and execute a uux command
6957c478bd9Sstevel@tonic-gate  */
6967c478bd9Sstevel@tonic-gate 
6977c478bd9Sstevel@tonic-gate void
ruux(rmt,sys1,file1,sys2,fwd2,file2)6987c478bd9Sstevel@tonic-gate ruux(rmt, sys1, file1, sys2, fwd2, file2)
6997c478bd9Sstevel@tonic-gate char *rmt, *sys1, *file1, *sys2, *fwd2, *file2;
7007c478bd9Sstevel@tonic-gate {
7017c478bd9Sstevel@tonic-gate     char cmd[BUFSIZ];
7027c478bd9Sstevel@tonic-gate     char xcmd[BUFSIZ];
7037c478bd9Sstevel@tonic-gate     char * xarg[6];
7047c478bd9Sstevel@tonic-gate     int narg = 0;
7057c478bd9Sstevel@tonic-gate     int i;
7067c478bd9Sstevel@tonic-gate 
7077c478bd9Sstevel@tonic-gate     /* get real Myname - it depends on who I'm calling--rmt */
7087c478bd9Sstevel@tonic-gate     (void) mchFind(rmt);
7097c478bd9Sstevel@tonic-gate     myName(Myname);
7107c478bd9Sstevel@tonic-gate 
7117c478bd9Sstevel@tonic-gate     xarg[narg++] = UUX;
7127c478bd9Sstevel@tonic-gate     xarg[narg++] = "-C";
7137c478bd9Sstevel@tonic-gate     if (*Xopts != NULLCHAR)
7147c478bd9Sstevel@tonic-gate 	xarg[narg++] = Xopts;
7157c478bd9Sstevel@tonic-gate     if (*Ropt  != ' ')
7167c478bd9Sstevel@tonic-gate 	xarg[narg++] = Ropt;
7177c478bd9Sstevel@tonic-gate 
7187c478bd9Sstevel@tonic-gate     (void) sprintf(cmd, "%s!uucp -C", rmt);
7197c478bd9Sstevel@tonic-gate 
7207c478bd9Sstevel@tonic-gate     if (*Uopts != NULLCHAR)
7217c478bd9Sstevel@tonic-gate 	(void) sprintf(cmd+strlen(cmd), " (%s) ", Uopts);
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate     if (*sys1 == NULLCHAR || EQUALS(sys1, Myname)) {
7247c478bd9Sstevel@tonic-gate         if (ckexpf(file1))
7257c478bd9Sstevel@tonic-gate   	    exit(6);
7267c478bd9Sstevel@tonic-gate 	(void) sprintf(cmd+strlen(cmd), " %s!%s ", sys1, file1);
7277c478bd9Sstevel@tonic-gate     }
7287c478bd9Sstevel@tonic-gate     else
7297c478bd9Sstevel@tonic-gate 	if (!EQUALS(rmt, sys1))
7307c478bd9Sstevel@tonic-gate 	    (void) sprintf(cmd+strlen(cmd), " (%s!%s) ", sys1, file1);
7317c478bd9Sstevel@tonic-gate 	else
7327c478bd9Sstevel@tonic-gate 	    (void) sprintf(cmd+strlen(cmd), " (%s) ", file1);
7337c478bd9Sstevel@tonic-gate 
7347c478bd9Sstevel@tonic-gate     if (*fwd2 != NULLCHAR) {
7357c478bd9Sstevel@tonic-gate 	if (*sys2 != NULLCHAR)
7367c478bd9Sstevel@tonic-gate 	    (void) sprintf(cmd+strlen(cmd),
7377c478bd9Sstevel@tonic-gate 		" (%s!%s!%s) ", sys2, fwd2, file2);
7387c478bd9Sstevel@tonic-gate 	else
7397c478bd9Sstevel@tonic-gate 	    (void) sprintf(cmd+strlen(cmd), " (%s!%s) ", fwd2, file2);
7407c478bd9Sstevel@tonic-gate     }
7417c478bd9Sstevel@tonic-gate     else {
7427c478bd9Sstevel@tonic-gate 	if (*sys2 == NULLCHAR || EQUALS(sys2, Myname))
7437c478bd9Sstevel@tonic-gate 	    if (ckexpf(file2))
7447c478bd9Sstevel@tonic-gate 		exit(7);
7457c478bd9Sstevel@tonic-gate 	(void) sprintf(cmd+strlen(cmd), " (%s!%s) ", sys2, file2);
7467c478bd9Sstevel@tonic-gate     }
7477c478bd9Sstevel@tonic-gate 
7487c478bd9Sstevel@tonic-gate     xarg[narg++] = cmd;
7497c478bd9Sstevel@tonic-gate     xarg[narg] = (char *) 0;
7507c478bd9Sstevel@tonic-gate 
7517c478bd9Sstevel@tonic-gate     xcmd[0] = NULLCHAR;
7527c478bd9Sstevel@tonic-gate     for (i=0; i < narg; i++) {
7537c478bd9Sstevel@tonic-gate 	strcat(xcmd, xarg[i]);
7547c478bd9Sstevel@tonic-gate 	strcat(xcmd, " ");
7557c478bd9Sstevel@tonic-gate     }
7567c478bd9Sstevel@tonic-gate     DEBUG(2, "cmd: %s\n", xcmd);
7577c478bd9Sstevel@tonic-gate     logent(xcmd, "QUEUED");
7587c478bd9Sstevel@tonic-gate 
7597c478bd9Sstevel@tonic-gate     if (fork() == 0) {
7607c478bd9Sstevel@tonic-gate 	ASSERT(setuid(getuid()) == 0, "setuid", "failed", 99);
7617c478bd9Sstevel@tonic-gate 	execv(UUX, xarg);
7627c478bd9Sstevel@tonic-gate 	exit(0);
7637c478bd9Sstevel@tonic-gate     }
7647c478bd9Sstevel@tonic-gate     return;
7657c478bd9Sstevel@tonic-gate }
7667c478bd9Sstevel@tonic-gate 
7677c478bd9Sstevel@tonic-gate void
usage()7687c478bd9Sstevel@tonic-gate usage()
7697c478bd9Sstevel@tonic-gate {
7707c478bd9Sstevel@tonic-gate 
7717c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext(
7727c478bd9Sstevel@tonic-gate 	"Usage:  %s [-c|-C] [-d|-f] [-g GRADE] [-jm] [-n USER]\\\n"
7737c478bd9Sstevel@tonic-gate 	"[-r] [-s FILE] [-x DEBUG_LEVEL] source-files destination-file\n"),
7747c478bd9Sstevel@tonic-gate 	Progname);
7757c478bd9Sstevel@tonic-gate 	cleanup(-2);
7767c478bd9Sstevel@tonic-gate }
777