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
267c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
277c478bd9Sstevel@tonic-gate /* All Rights Reserved */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate #include "uucp.h"
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate #define SHORTBUF 64
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate #define NOSYSPART 0
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate #define GENSEND(f, a, b, c) {\
377c478bd9Sstevel@tonic-gate ASSERT(fprintf(f, "S %s %s %s -%s %s 0666 %s %s\n", a, b, User, _Statop?"o":"", c, User, _Sfile) >= 0, Ct_WRITE, "", errno);\
387c478bd9Sstevel@tonic-gate }
397c478bd9Sstevel@tonic-gate #define GENRCV(f, a, b) {\
407c478bd9Sstevel@tonic-gate char tbuf[SHORTBUF]; \
417c478bd9Sstevel@tonic-gate gename (DATAPRE, xsys, 'Z', tbuf); \
427c478bd9Sstevel@tonic-gate ASSERT(fprintf(f, "R %s %s %s - %s 0666 %s %s\n", a, b, User, _Sfile, User, tbuf) \
437c478bd9Sstevel@tonic-gate >= 0, Ct_WRITE, "", errno);\
447c478bd9Sstevel@tonic-gate }
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate #define STRNCPY(str1, str2) { \
477c478bd9Sstevel@tonic-gate (void) strncpy(str1, str2, (sizeof(str1) - 1)); \
487c478bd9Sstevel@tonic-gate str1[sizeof(str1) - 1] = '\0'; \
497c478bd9Sstevel@tonic-gate }
507c478bd9Sstevel@tonic-gate #define STRNCAT(str1, str2) { \
517c478bd9Sstevel@tonic-gate (void) strncat(str1, str2, \
527c478bd9Sstevel@tonic-gate (sizeof(str1) - 1 - strlen(str1))); \
537c478bd9Sstevel@tonic-gate }
547c478bd9Sstevel@tonic-gate #define APPCMD(p) {STRNCAT(cmd, p); STRNCAT(cmd, " ");}
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate static char _Sfile[MAXFULLNAME];
577c478bd9Sstevel@tonic-gate static int _Statop;
587c478bd9Sstevel@tonic-gate char Sgrade[NAMESIZE];
597c478bd9Sstevel@tonic-gate void cleanup();
607c478bd9Sstevel@tonic-gate static void usage();
61*d67944fbSScott Rotondo static void onintr();
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate * uux
657c478bd9Sstevel@tonic-gate */
66462be471Sceastha int
main(argc,argv,envp)677c478bd9Sstevel@tonic-gate main(argc, argv, envp)
68462be471Sceastha int argc;
697c478bd9Sstevel@tonic-gate char *argv[];
707c478bd9Sstevel@tonic-gate char *envp[];
717c478bd9Sstevel@tonic-gate {
727c478bd9Sstevel@tonic-gate char *jid();
737c478bd9Sstevel@tonic-gate FILE *fprx = NULL, *fpc = NULL, *fpd = NULL, *fp = NULL;
747c478bd9Sstevel@tonic-gate int cfileUsed = 0; /* >0 if commands put in C. file flag */
757c478bd9Sstevel@tonic-gate int cflag = 0; /* if > 0 make local copy of files to be sent */
767c478bd9Sstevel@tonic-gate int nflag = 0; /* if != 0, do not request error notification */
777c478bd9Sstevel@tonic-gate int zflag = 0; /* if != 0, request success notification */
787c478bd9Sstevel@tonic-gate int pipein = 0;
797c478bd9Sstevel@tonic-gate int startjob = 1;
807c478bd9Sstevel@tonic-gate short jflag = 0; /* -j flag output Jobid */
817c478bd9Sstevel@tonic-gate int bringback = 0; /* return stdin to invoker on error */
827c478bd9Sstevel@tonic-gate int ret, i;
837c478bd9Sstevel@tonic-gate char *getprm();
847c478bd9Sstevel@tonic-gate char redir = '\0'; /* X_STDIN, X_STDOUT, X_STDERR as approprite */
857c478bd9Sstevel@tonic-gate char command = TRUE;
867c478bd9Sstevel@tonic-gate char cfile[NAMESIZE]; /* send commands for files from here */
877c478bd9Sstevel@tonic-gate char dfile[NAMESIZE]; /* used for all data files from here */
887c478bd9Sstevel@tonic-gate char rxfile[NAMESIZE]; /* file for X_ commands */
897c478bd9Sstevel@tonic-gate char tfile[NAMESIZE]; /* temporary file name */
907c478bd9Sstevel@tonic-gate char t2file[NAMESIZE]; /* temporary file name */
917c478bd9Sstevel@tonic-gate char buf[BUFSIZ];
927c478bd9Sstevel@tonic-gate char inargs[BUFSIZ];
937c478bd9Sstevel@tonic-gate char cmd[BUFSIZ];
947c478bd9Sstevel@tonic-gate char *ap;
957c478bd9Sstevel@tonic-gate char prm[BUFSIZ];
967c478bd9Sstevel@tonic-gate char syspart[MAXFULLNAME], rest[BUFSIZ];
977c478bd9Sstevel@tonic-gate char xsys[MAXFULLNAME];
987c478bd9Sstevel@tonic-gate char *fopt = NULL;
997c478bd9Sstevel@tonic-gate char *retaddr = NULL;
1007c478bd9Sstevel@tonic-gate struct stat stbuf;
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate /* Set locale environment variables local definitions */
1037c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
1047c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
1057c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */
1067c478bd9Sstevel@tonic-gate #endif
1077c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate /* we want this to run as uucp, even if the kernel doesn't */
1107c478bd9Sstevel@tonic-gate Uid = getuid();
1117c478bd9Sstevel@tonic-gate Euid = geteuid(); /* this should be UUCPUID */
1127c478bd9Sstevel@tonic-gate if (Uid == 0)
1137c478bd9Sstevel@tonic-gate setuid(UUCPUID);
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate /* init environment for fork-exec */
1167c478bd9Sstevel@tonic-gate Env = envp;
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gate /* choose LOGFILE */
1197c478bd9Sstevel@tonic-gate STRNCPY(Logfile, LOGUUX);
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate /*
1227c478bd9Sstevel@tonic-gate * determine local system name
1237c478bd9Sstevel@tonic-gate */
1247c478bd9Sstevel@tonic-gate (void) strcpy(Progname, "uux");
1257c478bd9Sstevel@tonic-gate Pchar = 'X';
1267c478bd9Sstevel@tonic-gate (void) signal(SIGILL, onintr);
1277c478bd9Sstevel@tonic-gate (void) signal(SIGTRAP, onintr);
1287c478bd9Sstevel@tonic-gate (void) signal(SIGIOT, onintr);
1297c478bd9Sstevel@tonic-gate (void) signal(SIGEMT, onintr);
1307c478bd9Sstevel@tonic-gate (void) signal(SIGFPE, onintr);
1317c478bd9Sstevel@tonic-gate (void) signal(SIGBUS, onintr);
1327c478bd9Sstevel@tonic-gate (void) signal(SIGSEGV, onintr);
1337c478bd9Sstevel@tonic-gate (void) signal(SIGSYS, onintr);
1347c478bd9Sstevel@tonic-gate (void) signal(SIGTERM, SIG_IGN);
1357c478bd9Sstevel@tonic-gate uucpname(Myname);
1367c478bd9Sstevel@tonic-gate Ofn = 1;
1377c478bd9Sstevel@tonic-gate Ifn = 0;
1387c478bd9Sstevel@tonic-gate *_Sfile = '\0';
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate /*
1417c478bd9Sstevel@tonic-gate * determine id of user starting remote
1427c478bd9Sstevel@tonic-gate * execution
1437c478bd9Sstevel@tonic-gate */
1447c478bd9Sstevel@tonic-gate guinfo(Uid, User);
1457c478bd9Sstevel@tonic-gate STRNCPY(Loginuser,User);
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate *Sgrade = NULLCHAR;
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate /*
1507c478bd9Sstevel@tonic-gate * this is a check to see if we are using the administrator
1517c478bd9Sstevel@tonic-gate * defined service grade. The GRADES file will determine if
1527c478bd9Sstevel@tonic-gate * we are. If so then setup the default grade variables.
1537c478bd9Sstevel@tonic-gate */
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate if (eaccess(GRADES, 04) != -1) {
1567c478bd9Sstevel@tonic-gate Grade = 'A';
1577c478bd9Sstevel@tonic-gate Sgrades = TRUE;
1587c478bd9Sstevel@tonic-gate STRNCPY(Sgrade, "default");
1597c478bd9Sstevel@tonic-gate }
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate /*
1627c478bd9Sstevel@tonic-gate * create/append command log
1637c478bd9Sstevel@tonic-gate */
1647c478bd9Sstevel@tonic-gate commandlog(argc,argv);
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gate /*
1677c478bd9Sstevel@tonic-gate * since getopt() can't handle the pipe input option '-';
1687c478bd9Sstevel@tonic-gate * change it to "-p"
1697c478bd9Sstevel@tonic-gate */
1707c478bd9Sstevel@tonic-gate for (i=1; i<argc && *argv[i] == '-'; i++)
1717c478bd9Sstevel@tonic-gate if (EQUALS(argv[i], "-"))
1727c478bd9Sstevel@tonic-gate argv[i] = "-p";
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate while ((i = getopt(argc, argv, "a:bcCjg:nprs:x:z")) != EOF) {
1757c478bd9Sstevel@tonic-gate switch(i){
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate /*
1787c478bd9Sstevel@tonic-gate * use this name in the U line
1797c478bd9Sstevel@tonic-gate */
1807c478bd9Sstevel@tonic-gate case 'a':
1817c478bd9Sstevel@tonic-gate retaddr = optarg;
1827c478bd9Sstevel@tonic-gate break;
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate /*
1857c478bd9Sstevel@tonic-gate * if return code non-zero, return command's input
1867c478bd9Sstevel@tonic-gate */
1877c478bd9Sstevel@tonic-gate case 'b':
1887c478bd9Sstevel@tonic-gate bringback = 1;
1897c478bd9Sstevel@tonic-gate break;
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate /* do not make local copies of files to be sent (default) */
1927c478bd9Sstevel@tonic-gate case 'c':
1937c478bd9Sstevel@tonic-gate cflag = 0;
1947c478bd9Sstevel@tonic-gate break;
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate /* make local copies of files to be sent */
1977c478bd9Sstevel@tonic-gate case 'C':
1987c478bd9Sstevel@tonic-gate cflag = 1;
1997c478bd9Sstevel@tonic-gate break;
2007c478bd9Sstevel@tonic-gate
2017c478bd9Sstevel@tonic-gate /*
2027c478bd9Sstevel@tonic-gate * set priority of request
2037c478bd9Sstevel@tonic-gate */
2047c478bd9Sstevel@tonic-gate case 'g':
2057c478bd9Sstevel@tonic-gate if (!Sgrades) {
2067c478bd9Sstevel@tonic-gate if (strlen(optarg) < (size_t) 2 && isalnum(*optarg))
2077c478bd9Sstevel@tonic-gate Grade = *optarg;
2087c478bd9Sstevel@tonic-gate else {
2097c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("No"
2107c478bd9Sstevel@tonic-gate " administrator defined service"
2117c478bd9Sstevel@tonic-gate " grades available on this"
2127c478bd9Sstevel@tonic-gate " machine.\n"));
2137c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("UUCP"
2147c478bd9Sstevel@tonic-gate " service grades range from"
2157c478bd9Sstevel@tonic-gate " [A-Z][a-z] only.\n"));
2167c478bd9Sstevel@tonic-gate cleanup(-1);
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate }
2197c478bd9Sstevel@tonic-gate else {
2207c478bd9Sstevel@tonic-gate STRNCPY(Sgrade, optarg);
2217c478bd9Sstevel@tonic-gate if (vergrd(Sgrade) != SUCCESS)
2227c478bd9Sstevel@tonic-gate cleanup(FAIL);
2237c478bd9Sstevel@tonic-gate }
2247c478bd9Sstevel@tonic-gate break;
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate case 'j': /* job id */
2287c478bd9Sstevel@tonic-gate jflag = 1;
2297c478bd9Sstevel@tonic-gate break;
2307c478bd9Sstevel@tonic-gate
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate /*
2337c478bd9Sstevel@tonic-gate * do not send failure notification to user
2347c478bd9Sstevel@tonic-gate */
2357c478bd9Sstevel@tonic-gate case 'n':
2367c478bd9Sstevel@tonic-gate nflag++;
2377c478bd9Sstevel@tonic-gate break;
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate /*
2407c478bd9Sstevel@tonic-gate * send success notification to user
2417c478bd9Sstevel@tonic-gate */
2427c478bd9Sstevel@tonic-gate case 'z':
2437c478bd9Sstevel@tonic-gate zflag++;
2447c478bd9Sstevel@tonic-gate break;
2457c478bd9Sstevel@tonic-gate
2467c478bd9Sstevel@tonic-gate /*
2477c478bd9Sstevel@tonic-gate * -p or - option specifies input from pipe
2487c478bd9Sstevel@tonic-gate */
2497c478bd9Sstevel@tonic-gate case 'p':
2507c478bd9Sstevel@tonic-gate pipein = 1;
2517c478bd9Sstevel@tonic-gate break;
2527c478bd9Sstevel@tonic-gate
2537c478bd9Sstevel@tonic-gate /*
2547c478bd9Sstevel@tonic-gate * do not start transfer
2557c478bd9Sstevel@tonic-gate */
2567c478bd9Sstevel@tonic-gate case 'r':
2577c478bd9Sstevel@tonic-gate startjob = 0;
2587c478bd9Sstevel@tonic-gate break;
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gate case 's':
2617c478bd9Sstevel@tonic-gate fopt = optarg;
2627c478bd9Sstevel@tonic-gate _Statop++;
2637c478bd9Sstevel@tonic-gate break;
2647c478bd9Sstevel@tonic-gate
2657c478bd9Sstevel@tonic-gate /*
2667c478bd9Sstevel@tonic-gate * debugging level
2677c478bd9Sstevel@tonic-gate */
2687c478bd9Sstevel@tonic-gate case 'x':
2697c478bd9Sstevel@tonic-gate Debug = atoi(optarg);
2707c478bd9Sstevel@tonic-gate if (Debug <= 0)
2717c478bd9Sstevel@tonic-gate Debug = 1;
2727c478bd9Sstevel@tonic-gate break;
2737c478bd9Sstevel@tonic-gate
2747c478bd9Sstevel@tonic-gate default:
2757c478bd9Sstevel@tonic-gate usage();
2767c478bd9Sstevel@tonic-gate }
2777c478bd9Sstevel@tonic-gate }
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate DEBUG(4, "\n\n** %s **\n", "START");
2807c478bd9Sstevel@tonic-gate
2817c478bd9Sstevel@tonic-gate if( optind >= argc )
2827c478bd9Sstevel@tonic-gate usage();
2837c478bd9Sstevel@tonic-gate
2847c478bd9Sstevel@tonic-gate /*
2857c478bd9Sstevel@tonic-gate * copy arguments into a buffer for later
2867c478bd9Sstevel@tonic-gate * processing
2877c478bd9Sstevel@tonic-gate */
2887c478bd9Sstevel@tonic-gate inargs[0] = '\0';
2897c478bd9Sstevel@tonic-gate for (; optind < argc; optind++) {
2907c478bd9Sstevel@tonic-gate DEBUG(4, "arg - %s:", argv[optind]);
2917c478bd9Sstevel@tonic-gate STRNCAT(inargs, " ");
2927c478bd9Sstevel@tonic-gate STRNCAT(inargs, argv[optind]);
2937c478bd9Sstevel@tonic-gate }
2947c478bd9Sstevel@tonic-gate
2957c478bd9Sstevel@tonic-gate /*
2967c478bd9Sstevel@tonic-gate * get working directory and change
2977c478bd9Sstevel@tonic-gate * to spool directory
2987c478bd9Sstevel@tonic-gate */
2997c478bd9Sstevel@tonic-gate DEBUG(4, "arg - %s\n", inargs);
3007c478bd9Sstevel@tonic-gate gwd(Wrkdir);
3017c478bd9Sstevel@tonic-gate if(fopt){
3027c478bd9Sstevel@tonic-gate if(*fopt != '/') {
3037c478bd9Sstevel@tonic-gate (void) snprintf(_Sfile, (sizeof(_Sfile) - 1),
3047c478bd9Sstevel@tonic-gate "%s/%s", Wrkdir, fopt);
3057c478bd9Sstevel@tonic-gate _Sfile[sizeof(_Sfile) - 1] = '\0';
3067c478bd9Sstevel@tonic-gate }
3077c478bd9Sstevel@tonic-gate else {
3087c478bd9Sstevel@tonic-gate (void) snprintf(_Sfile, (sizeof(_Sfile) - 1),
3097c478bd9Sstevel@tonic-gate "%s", fopt);
3107c478bd9Sstevel@tonic-gate _Sfile[sizeof(_Sfile) - 1] = '\0';
3117c478bd9Sstevel@tonic-gate }
3127c478bd9Sstevel@tonic-gate }
3137c478bd9Sstevel@tonic-gate else
3147c478bd9Sstevel@tonic-gate strcpy(_Sfile, "dummy");
3157c478bd9Sstevel@tonic-gate
3167c478bd9Sstevel@tonic-gate if (chdir(WORKSPACE) != 0) {
3177c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
3187c478bd9Sstevel@tonic-gate gettext("No spool directory - %s - get help\n"), WORKSPACE);
3197c478bd9Sstevel@tonic-gate cleanup(EX_OSERR);
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate /*
3227c478bd9Sstevel@tonic-gate * find remote system name
3237c478bd9Sstevel@tonic-gate * remote name is first to know that
3247c478bd9Sstevel@tonic-gate * is not > or <
3257c478bd9Sstevel@tonic-gate */
3267c478bd9Sstevel@tonic-gate ap = inargs;
3277c478bd9Sstevel@tonic-gate xsys[0] = '\0';
3287c478bd9Sstevel@tonic-gate while ((ap = getprm(ap, (char *)NULL, prm)) != NULL) {
3297c478bd9Sstevel@tonic-gate if (prm[0] == '>' || prm[0] == '<') {
3307c478bd9Sstevel@tonic-gate ap = getprm(ap, (char *)NULL, prm);
3317c478bd9Sstevel@tonic-gate continue;
3327c478bd9Sstevel@tonic-gate }
3337c478bd9Sstevel@tonic-gate
3347c478bd9Sstevel@tonic-gate /*
3357c478bd9Sstevel@tonic-gate * split name into system name
3367c478bd9Sstevel@tonic-gate * and command name
3377c478bd9Sstevel@tonic-gate */
3387c478bd9Sstevel@tonic-gate (void) split(prm, xsys, CNULL, rest);
3397c478bd9Sstevel@tonic-gate break;
3407c478bd9Sstevel@tonic-gate }
3417c478bd9Sstevel@tonic-gate if (xsys[0] == '\0')
3427c478bd9Sstevel@tonic-gate STRNCPY(xsys, Myname);
3437c478bd9Sstevel@tonic-gate STRNCPY(Rmtname, xsys);
3447c478bd9Sstevel@tonic-gate DEBUG(4, "xsys %s\n", xsys);
3457c478bd9Sstevel@tonic-gate
3467c478bd9Sstevel@tonic-gate /* get real Myname - it depends on who I'm calling--Rmtname */
3477c478bd9Sstevel@tonic-gate (void) mchFind(Rmtname);
3487c478bd9Sstevel@tonic-gate myName(Myname);
3497c478bd9Sstevel@tonic-gate
3507c478bd9Sstevel@tonic-gate /*
3517c478bd9Sstevel@tonic-gate * check to see if system name is valid
3527c478bd9Sstevel@tonic-gate */
3537c478bd9Sstevel@tonic-gate if (versys(xsys) != 0) {
3547c478bd9Sstevel@tonic-gate /*
3557c478bd9Sstevel@tonic-gate * bad system name
3567c478bd9Sstevel@tonic-gate */
3577c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("bad system name: %s\n"), xsys);
3587c478bd9Sstevel@tonic-gate if (fprx != NULL)
3597c478bd9Sstevel@tonic-gate (void) fclose(fprx);
3607c478bd9Sstevel@tonic-gate if (fpc != NULL)
3617c478bd9Sstevel@tonic-gate (void) fclose(fpc);
3627c478bd9Sstevel@tonic-gate cleanup(EX_NOHOST);
3637c478bd9Sstevel@tonic-gate }
3647c478bd9Sstevel@tonic-gate
3657c478bd9Sstevel@tonic-gate DEBUG(6, "User %s\n", User);
3667c478bd9Sstevel@tonic-gate if (retaddr == NULL)
3677c478bd9Sstevel@tonic-gate retaddr = User;
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate /*
3707c478bd9Sstevel@tonic-gate * initialize command buffer
3717c478bd9Sstevel@tonic-gate */
3727c478bd9Sstevel@tonic-gate *cmd = '\0';
3737c478bd9Sstevel@tonic-gate
3747c478bd9Sstevel@tonic-gate /*
3757c478bd9Sstevel@tonic-gate * generate JCL files to work from
3767c478bd9Sstevel@tonic-gate */
3777c478bd9Sstevel@tonic-gate
3787c478bd9Sstevel@tonic-gate /*
3797c478bd9Sstevel@tonic-gate * fpc is the C. file for the local site.
3807c478bd9Sstevel@tonic-gate * collect commands into cfile.
3817c478bd9Sstevel@tonic-gate * commit if not empty (at end).
3827c478bd9Sstevel@tonic-gate *
3837c478bd9Sstevel@tonic-gate * the appropriate C. file.
3847c478bd9Sstevel@tonic-gate */
3857c478bd9Sstevel@tonic-gate gename(CMDPRE, xsys, Grade, cfile);
3867c478bd9Sstevel@tonic-gate DEBUG(9, "cfile = %s\n", cfile);
3877c478bd9Sstevel@tonic-gate ASSERT(access(cfile, 0) != 0, Fl_EXISTS, cfile, errno);
3887c478bd9Sstevel@tonic-gate fpc = fdopen(ret = creat(cfile, CFILEMODE), "w");
3897c478bd9Sstevel@tonic-gate ASSERT(ret >= 0 && fpc != NULL, Ct_OPEN, cfile, errno);
3907c478bd9Sstevel@tonic-gate setbuf(fpc, CNULL);
3917c478bd9Sstevel@tonic-gate
3927c478bd9Sstevel@tonic-gate /* set Jobid -- C.jobid */
3937c478bd9Sstevel@tonic-gate STRNCPY(Jobid, BASENAME(cfile, '.'));
3947c478bd9Sstevel@tonic-gate
3957c478bd9Sstevel@tonic-gate /*
3967c478bd9Sstevel@tonic-gate * rxfile is the X. file for the job, fprx is its stream ptr.
3977c478bd9Sstevel@tonic-gate * if the command is to be executed locally, rxfile becomes
3987c478bd9Sstevel@tonic-gate * a local X. file, otherwise we send it as a D. file to the
3997c478bd9Sstevel@tonic-gate * remote site.
4007c478bd9Sstevel@tonic-gate */
4017c478bd9Sstevel@tonic-gate
4027c478bd9Sstevel@tonic-gate gename(DATAPRE, xsys, 'X', rxfile);
4037c478bd9Sstevel@tonic-gate DEBUG(9, "rxfile = %s\n", rxfile);
4047c478bd9Sstevel@tonic-gate ASSERT(access(rxfile, 0) != 0, Fl_EXISTS, rxfile, errno);
4057c478bd9Sstevel@tonic-gate fprx = fdopen(ret = creat(rxfile, DFILEMODE), "w");
4067c478bd9Sstevel@tonic-gate ASSERT(ret >= 0 && fprx != NULL, Ct_WRITE, rxfile, errno);
4077c478bd9Sstevel@tonic-gate setbuf(fprx, CNULL);
4087c478bd9Sstevel@tonic-gate clearerr(fprx);
4097c478bd9Sstevel@tonic-gate
4107c478bd9Sstevel@tonic-gate (void) fprintf(fprx,"%c %s %s\n", X_USER, User, Myname);
4117c478bd9Sstevel@tonic-gate if (zflag) {
4127c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c return status on success\n",
4137c478bd9Sstevel@tonic-gate X_COMMENT);
4147c478bd9Sstevel@tonic-gate (void) fprintf(fprx,"%c\n", X_SENDZERO);
4157c478bd9Sstevel@tonic-gate }
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gate if (nflag) {
4187c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c don't return status on failure\n",
4197c478bd9Sstevel@tonic-gate X_COMMENT);
4207c478bd9Sstevel@tonic-gate (void) fprintf(fprx,"%c\n", X_SENDNOTHING);
4217c478bd9Sstevel@tonic-gate } else {
4227c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c return status on failure\n",
4237c478bd9Sstevel@tonic-gate X_COMMENT);
4247c478bd9Sstevel@tonic-gate fprintf(fprx,"%c\n", X_NONZERO);
4257c478bd9Sstevel@tonic-gate }
4267c478bd9Sstevel@tonic-gate
4277c478bd9Sstevel@tonic-gate if (bringback) {
4287c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c return input on abnormal exit\n",
4297c478bd9Sstevel@tonic-gate X_COMMENT);
4307c478bd9Sstevel@tonic-gate (void) fprintf(fprx,"%c\n", X_BRINGBACK);
4317c478bd9Sstevel@tonic-gate }
4327c478bd9Sstevel@tonic-gate
4337c478bd9Sstevel@tonic-gate if (_Statop)
4347c478bd9Sstevel@tonic-gate (void) fprintf(fprx,"%c %s\n", X_MAILF, _Sfile);
4357c478bd9Sstevel@tonic-gate
4367c478bd9Sstevel@tonic-gate if (retaddr != NULL) {
4377c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c return address for status or input return\n",
4387c478bd9Sstevel@tonic-gate X_COMMENT);
4397c478bd9Sstevel@tonic-gate (void) fprintf(fprx,"%c %s\n", X_RETADDR, retaddr);
4407c478bd9Sstevel@tonic-gate }
4417c478bd9Sstevel@tonic-gate
4427c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c job id for status reporting\n", X_COMMENT);
4437c478bd9Sstevel@tonic-gate (void) fprintf(fprx,"%c %s\n", X_JOBID, Jobid);
4447c478bd9Sstevel@tonic-gate
4457c478bd9Sstevel@tonic-gate /*
4467c478bd9Sstevel@tonic-gate * create a JCL file to spool pipe input into
4477c478bd9Sstevel@tonic-gate */
4487c478bd9Sstevel@tonic-gate if (pipein) {
4497c478bd9Sstevel@tonic-gate /*
4507c478bd9Sstevel@tonic-gate * fpd is the D. file into which we now read
4517c478bd9Sstevel@tonic-gate * input from stdin
4527c478bd9Sstevel@tonic-gate */
4537c478bd9Sstevel@tonic-gate
4547c478bd9Sstevel@tonic-gate gename(DATAPRE, Myname, 'B', dfile);
4557c478bd9Sstevel@tonic-gate
4567c478bd9Sstevel@tonic-gate ASSERT(access(dfile, 0) != 0, Fl_EXISTS, dfile, errno);
4577c478bd9Sstevel@tonic-gate fpd = fdopen(ret = creat(dfile, DFILEMODE), "w");
4587c478bd9Sstevel@tonic-gate ASSERT(ret >= 0 && fpd != NULL, Ct_OPEN, dfile, errno);
4597c478bd9Sstevel@tonic-gate
4607c478bd9Sstevel@tonic-gate /*
4617c478bd9Sstevel@tonic-gate * read pipe to EOF
4627c478bd9Sstevel@tonic-gate */
4637c478bd9Sstevel@tonic-gate while (!feof(stdin)) {
4647c478bd9Sstevel@tonic-gate ret = fread(buf, 1, BUFSIZ, stdin);
4657c478bd9Sstevel@tonic-gate ASSERT(fwrite(buf, 1, ret, fpd) == ret, Ct_WRITE,
4667c478bd9Sstevel@tonic-gate dfile, errno);
4677c478bd9Sstevel@tonic-gate }
4687c478bd9Sstevel@tonic-gate ASSERT(fflush(fpd) != EOF && ferror(fpd) == 0, Ct_WRITE, dfile, errno);
4697c478bd9Sstevel@tonic-gate (void) fclose(fpd);
4707c478bd9Sstevel@tonic-gate
4717c478bd9Sstevel@tonic-gate /*
4727c478bd9Sstevel@tonic-gate * if command is to be executed on remote
4737c478bd9Sstevel@tonic-gate * create extra JCL
4747c478bd9Sstevel@tonic-gate */
4757c478bd9Sstevel@tonic-gate if (!EQUALSN(Myname, xsys, MAXBASENAME)) {
4767c478bd9Sstevel@tonic-gate GENSEND(fpc, dfile, dfile, dfile);
4777c478bd9Sstevel@tonic-gate }
4787c478bd9Sstevel@tonic-gate
4797c478bd9Sstevel@tonic-gate /*
4807c478bd9Sstevel@tonic-gate * create file for X_ commands
4817c478bd9Sstevel@tonic-gate */
4827c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s\n", X_RQDFILE, dfile);
4837c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s\n", X_STDIN, dfile);
4847c478bd9Sstevel@tonic-gate
4857c478bd9Sstevel@tonic-gate if (EQUALS(Myname, xsys))
4867c478bd9Sstevel@tonic-gate wfcommit(dfile, dfile, xsys);
4877c478bd9Sstevel@tonic-gate
4887c478bd9Sstevel@tonic-gate }
4897c478bd9Sstevel@tonic-gate /*
4907c478bd9Sstevel@tonic-gate * parse command
4917c478bd9Sstevel@tonic-gate */
4927c478bd9Sstevel@tonic-gate ap = inargs;
4937c478bd9Sstevel@tonic-gate while ((ap = getprm(ap, (char *)NULL, prm)) != NULL) {
4947c478bd9Sstevel@tonic-gate DEBUG(4, "prm - %s\n", prm);
4957c478bd9Sstevel@tonic-gate
4967c478bd9Sstevel@tonic-gate /*
4977c478bd9Sstevel@tonic-gate * redirection of I/O
4987c478bd9Sstevel@tonic-gate */
4997c478bd9Sstevel@tonic-gate if ( prm[0] == '<' ) {
5007c478bd9Sstevel@tonic-gate if (prm[1] == '<') {
5017c478bd9Sstevel@tonic-gate fprintf(stderr,
5027c478bd9Sstevel@tonic-gate gettext("'<<' may not be used in command\n"));
5037c478bd9Sstevel@tonic-gate cleanup(EX_USAGE);
5047c478bd9Sstevel@tonic-gate }
5057c478bd9Sstevel@tonic-gate redir = X_STDIN;
5067c478bd9Sstevel@tonic-gate continue;
5077c478bd9Sstevel@tonic-gate }
5087c478bd9Sstevel@tonic-gate if ( prm[0] == '>' ) {
5097c478bd9Sstevel@tonic-gate if (prm[1] == '>') {
5107c478bd9Sstevel@tonic-gate fprintf(stderr,
5117c478bd9Sstevel@tonic-gate gettext("'>>' may not be used in command\n"));
5127c478bd9Sstevel@tonic-gate cleanup(EX_USAGE);
5137c478bd9Sstevel@tonic-gate }
5147c478bd9Sstevel@tonic-gate if (prm[1] == '|') {
5157c478bd9Sstevel@tonic-gate fprintf(stderr,
5167c478bd9Sstevel@tonic-gate gettext("'>|' may not be used in command\n"));
5177c478bd9Sstevel@tonic-gate cleanup(EX_USAGE);
5187c478bd9Sstevel@tonic-gate }
5197c478bd9Sstevel@tonic-gate if (prm[1] == '&') {
5207c478bd9Sstevel@tonic-gate fprintf(stderr,
5217c478bd9Sstevel@tonic-gate gettext("'>&' may not be used in command\n"));
5227c478bd9Sstevel@tonic-gate cleanup(EX_USAGE);
5237c478bd9Sstevel@tonic-gate }
5247c478bd9Sstevel@tonic-gate redir = X_STDOUT;
5257c478bd9Sstevel@tonic-gate continue;
5267c478bd9Sstevel@tonic-gate }
5277c478bd9Sstevel@tonic-gate if ( EQUALS(prm, "2>") ) {
5287c478bd9Sstevel@tonic-gate redir = X_STDERR;
5297c478bd9Sstevel@tonic-gate continue;
5307c478bd9Sstevel@tonic-gate }
5317c478bd9Sstevel@tonic-gate
5327c478bd9Sstevel@tonic-gate /*
5337c478bd9Sstevel@tonic-gate * some terminator
5347c478bd9Sstevel@tonic-gate */
5357c478bd9Sstevel@tonic-gate if ( prm[0] == '|' || prm[0] == '^'
5367c478bd9Sstevel@tonic-gate || prm[0] == '&' || prm[0] == ';') {
5377c478bd9Sstevel@tonic-gate if (*cmd != '\0') /* not 1st thing on line */
5387c478bd9Sstevel@tonic-gate APPCMD(prm);
5397c478bd9Sstevel@tonic-gate command = TRUE;
5407c478bd9Sstevel@tonic-gate continue;
5417c478bd9Sstevel@tonic-gate }
5427c478bd9Sstevel@tonic-gate
5437c478bd9Sstevel@tonic-gate /*
5447c478bd9Sstevel@tonic-gate * process command or file or option
5457c478bd9Sstevel@tonic-gate * break out system and file name and
5467c478bd9Sstevel@tonic-gate * use default if necessary
5477c478bd9Sstevel@tonic-gate */
5487c478bd9Sstevel@tonic-gate ret = split(prm, syspart, CNULL, rest);
5497c478bd9Sstevel@tonic-gate DEBUG(4, "syspart -> %s, ", syspart);
5507c478bd9Sstevel@tonic-gate DEBUG(4, "rest -> %s, ", rest);
5517c478bd9Sstevel@tonic-gate DEBUG(4, "ret -> %d\n", ret);
5527c478bd9Sstevel@tonic-gate
5537c478bd9Sstevel@tonic-gate if (command && redir == '\0') {
5547c478bd9Sstevel@tonic-gate /*
5557c478bd9Sstevel@tonic-gate * command
5567c478bd9Sstevel@tonic-gate */
5577c478bd9Sstevel@tonic-gate APPCMD(rest);
5587c478bd9Sstevel@tonic-gate command = FALSE;
5597c478bd9Sstevel@tonic-gate continue;
5607c478bd9Sstevel@tonic-gate }
5617c478bd9Sstevel@tonic-gate
5627c478bd9Sstevel@tonic-gate if (syspart[0] == '\0') {
5637c478bd9Sstevel@tonic-gate STRNCPY(syspart, Myname);
5647c478bd9Sstevel@tonic-gate DEBUG(6, "syspart -> %s\n", syspart);
5657c478bd9Sstevel@tonic-gate } else if (versys(syspart) != 0) {
5667c478bd9Sstevel@tonic-gate /*
5677c478bd9Sstevel@tonic-gate * bad system name
5687c478bd9Sstevel@tonic-gate */
5697c478bd9Sstevel@tonic-gate fprintf(stderr,
5707c478bd9Sstevel@tonic-gate gettext("bad system name: %s\n"), syspart);
5717c478bd9Sstevel@tonic-gate if (fprx != NULL)
5727c478bd9Sstevel@tonic-gate (void) fclose(fprx);
5737c478bd9Sstevel@tonic-gate if (fpc != NULL)
5747c478bd9Sstevel@tonic-gate (void) fclose(fpc);
5757c478bd9Sstevel@tonic-gate cleanup(EX_NOHOST);
5767c478bd9Sstevel@tonic-gate }
5777c478bd9Sstevel@tonic-gate
5787c478bd9Sstevel@tonic-gate /*
5797c478bd9Sstevel@tonic-gate * process file or option
5807c478bd9Sstevel@tonic-gate */
5817c478bd9Sstevel@tonic-gate
5827c478bd9Sstevel@tonic-gate /*
5837c478bd9Sstevel@tonic-gate * process file argument
5847c478bd9Sstevel@tonic-gate * expand filename and create JCL card for
5857c478bd9Sstevel@tonic-gate * redirected output
5867c478bd9Sstevel@tonic-gate * e.g., X file sys
5877c478bd9Sstevel@tonic-gate */
5887c478bd9Sstevel@tonic-gate if ((redir == X_STDOUT) || (redir == X_STDERR)) {
5897c478bd9Sstevel@tonic-gate if (rest[0] != '~')
5907c478bd9Sstevel@tonic-gate if (ckexpf(rest))
5917c478bd9Sstevel@tonic-gate cleanup(EX_OSERR);
5927c478bd9Sstevel@tonic-gate ASSERT(fprintf(fprx, "%c %s %s\n", redir, rest,
5937c478bd9Sstevel@tonic-gate syspart) >= 0, Ct_WRITE, rxfile, errno);
5947c478bd9Sstevel@tonic-gate redir = '\0';
5957c478bd9Sstevel@tonic-gate continue;
5967c478bd9Sstevel@tonic-gate }
5977c478bd9Sstevel@tonic-gate
5987c478bd9Sstevel@tonic-gate /*
5997c478bd9Sstevel@tonic-gate * if no system specified, then being
6007c478bd9Sstevel@tonic-gate * processed locally
6017c478bd9Sstevel@tonic-gate */
6027c478bd9Sstevel@tonic-gate if (ret == NOSYSPART && redir == '\0') {
6037c478bd9Sstevel@tonic-gate
6047c478bd9Sstevel@tonic-gate /*
6057c478bd9Sstevel@tonic-gate * option
6067c478bd9Sstevel@tonic-gate */
6077c478bd9Sstevel@tonic-gate APPCMD(rest);
6087c478bd9Sstevel@tonic-gate continue;
6097c478bd9Sstevel@tonic-gate }
6107c478bd9Sstevel@tonic-gate
6117c478bd9Sstevel@tonic-gate
6127c478bd9Sstevel@tonic-gate /* local xeqn + local file (!x !f) */
6137c478bd9Sstevel@tonic-gate if ((EQUALSN(xsys, Myname, MAXBASENAME))
6147c478bd9Sstevel@tonic-gate && (EQUALSN(xsys, syspart, MAXBASENAME))) {
6157c478bd9Sstevel@tonic-gate /*
6167c478bd9Sstevel@tonic-gate * create JCL card
6177c478bd9Sstevel@tonic-gate */
6187c478bd9Sstevel@tonic-gate if (ckexpf(rest))
6197c478bd9Sstevel@tonic-gate cleanup(EX_OSERR);
6207c478bd9Sstevel@tonic-gate /*
6217c478bd9Sstevel@tonic-gate * JCL card for local input
6227c478bd9Sstevel@tonic-gate * e.g., I file
6237c478bd9Sstevel@tonic-gate */
6247c478bd9Sstevel@tonic-gate if (redir == X_STDIN) {
6257c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s\n", X_STDIN, rest);
6267c478bd9Sstevel@tonic-gate } else
6277c478bd9Sstevel@tonic-gate APPCMD(rest);
6287c478bd9Sstevel@tonic-gate ASSERT(fprx != NULL, Ct_WRITE, rxfile, errno);
6297c478bd9Sstevel@tonic-gate redir = '\0';
6307c478bd9Sstevel@tonic-gate continue;
6317c478bd9Sstevel@tonic-gate }
6327c478bd9Sstevel@tonic-gate
6337c478bd9Sstevel@tonic-gate /* remote xeqn + local file (sys!x !f) */
6347c478bd9Sstevel@tonic-gate if (EQUALSN(syspart, Myname, MAXBASENAME)) {
6357c478bd9Sstevel@tonic-gate /*
6367c478bd9Sstevel@tonic-gate * check access to local file
6377c478bd9Sstevel@tonic-gate * if cflag is set, copy to spool directory
6387c478bd9Sstevel@tonic-gate * otherwise, just mention it in the X. file
6397c478bd9Sstevel@tonic-gate */
6407c478bd9Sstevel@tonic-gate if (ckexpf(rest))
6417c478bd9Sstevel@tonic-gate cleanup(EX_OSERR);
6427c478bd9Sstevel@tonic-gate DEBUG(4, "rest %s\n", rest);
6437c478bd9Sstevel@tonic-gate
6447c478bd9Sstevel@tonic-gate /* see if I can read this file as read uid, gid */
6457c478bd9Sstevel@tonic-gate if (uidstat(rest, &stbuf) != 0) {
6467c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
6477c478bd9Sstevel@tonic-gate gettext("can't get file status %s\n"), rest);
6487c478bd9Sstevel@tonic-gate cleanup(EX_OSERR);
6497c478bd9Sstevel@tonic-gate }
6507c478bd9Sstevel@tonic-gate /* XXX - doesn't check group list */
6517c478bd9Sstevel@tonic-gate if ( !(stbuf.st_mode & ANYREAD)
6527c478bd9Sstevel@tonic-gate && !(stbuf.st_uid == Uid && stbuf.st_mode & 0400)
6537c478bd9Sstevel@tonic-gate && !(stbuf.st_gid ==getgid() && stbuf.st_mode & 0040)
6547c478bd9Sstevel@tonic-gate ) {
6557c478bd9Sstevel@tonic-gate fprintf(stderr,
6567c478bd9Sstevel@tonic-gate gettext("permission denied %s\n"), rest);
6577c478bd9Sstevel@tonic-gate cleanup(EX_CANTCREAT);
6587c478bd9Sstevel@tonic-gate }
6597c478bd9Sstevel@tonic-gate
6607c478bd9Sstevel@tonic-gate /* D. file for sending local file */
6617c478bd9Sstevel@tonic-gate gename(DATAPRE, xsys, 'A', dfile);
6627c478bd9Sstevel@tonic-gate
6637c478bd9Sstevel@tonic-gate if (cflag || !(stbuf.st_mode & ANYREAD)) {
6647c478bd9Sstevel@tonic-gate /* make local copy */
6657c478bd9Sstevel@tonic-gate if (uidxcp(rest, dfile) != 0) {
6667c478bd9Sstevel@tonic-gate fprintf(stderr,
6677c478bd9Sstevel@tonic-gate gettext("can't copy %s\n"), rest);
6687c478bd9Sstevel@tonic-gate cleanup(EX_CANTCREAT);
6697c478bd9Sstevel@tonic-gate }
6707c478bd9Sstevel@tonic-gate (void) chmod(dfile, DFILEMODE);
6717c478bd9Sstevel@tonic-gate /* generate 'send' entry in command file */
6727c478bd9Sstevel@tonic-gate GENSEND(fpc, rest, dfile, dfile);
6737c478bd9Sstevel@tonic-gate } else /* don't make local copy */
6747c478bd9Sstevel@tonic-gate GENSEND(fpc, rest, dfile, dfile);
6757c478bd9Sstevel@tonic-gate
6767c478bd9Sstevel@tonic-gate /*
6777c478bd9Sstevel@tonic-gate * JCL cards for redirected input in X. file,
6787c478bd9Sstevel@tonic-gate * e.g.
6797c478bd9Sstevel@tonic-gate * I D.xxx
6807c478bd9Sstevel@tonic-gate * F D.xxx
6817c478bd9Sstevel@tonic-gate */
6827c478bd9Sstevel@tonic-gate if (redir == X_STDIN) {
6837c478bd9Sstevel@tonic-gate /*
6847c478bd9Sstevel@tonic-gate * don't bother making a X_RQDFILE line that
6857c478bd9Sstevel@tonic-gate * renames stdin on the remote side, since the
6867c478bd9Sstevel@tonic-gate * remote command can't know its name anyway
6877c478bd9Sstevel@tonic-gate */
6887c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s\n", X_STDIN, dfile);
6897c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s\n", X_RQDFILE, dfile);
6907c478bd9Sstevel@tonic-gate } else {
6917c478bd9Sstevel@tonic-gate APPCMD(BASENAME(rest, '/'));;
6927c478bd9Sstevel@tonic-gate /*
6937c478bd9Sstevel@tonic-gate * generate X. JCL card that specifies
6947c478bd9Sstevel@tonic-gate * F file
6957c478bd9Sstevel@tonic-gate */
6967c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s %s\n", X_RQDFILE,
6977c478bd9Sstevel@tonic-gate dfile, BASENAME(rest, '/'));
6987c478bd9Sstevel@tonic-gate }
6997c478bd9Sstevel@tonic-gate redir = '\0';
7007c478bd9Sstevel@tonic-gate
7017c478bd9Sstevel@tonic-gate continue;
7027c478bd9Sstevel@tonic-gate }
7037c478bd9Sstevel@tonic-gate
7047c478bd9Sstevel@tonic-gate /* local xeqn + remote file (!x sys!f ) */
7057c478bd9Sstevel@tonic-gate if (EQUALS(Myname, xsys)) {
7067c478bd9Sstevel@tonic-gate /*
7077c478bd9Sstevel@tonic-gate * expand receive file name
7087c478bd9Sstevel@tonic-gate */
7097c478bd9Sstevel@tonic-gate if (ckexpf(rest))
7107c478bd9Sstevel@tonic-gate cleanup(EX_OSERR);
7117c478bd9Sstevel@tonic-gate /*
7127c478bd9Sstevel@tonic-gate * strategy:
7137c478bd9Sstevel@tonic-gate * request rest from syspart. when it arrives,
7147c478bd9Sstevel@tonic-gate * we can run the command.
7157c478bd9Sstevel@tonic-gate *
7167c478bd9Sstevel@tonic-gate * tfile is command file for receive from remote.
7177c478bd9Sstevel@tonic-gate * we defer commiting until later so
7187c478bd9Sstevel@tonic-gate * that only one C. file is created per site.
7197c478bd9Sstevel@tonic-gate *
7207c478bd9Sstevel@tonic-gate * dfile is name of data file to receive into;
7217c478bd9Sstevel@tonic-gate * we don't use it, just name it.
7227c478bd9Sstevel@tonic-gate *
7237c478bd9Sstevel@tonic-gate * once the data file arrives from syspart.
7247c478bd9Sstevel@tonic-gate * arrange so that in the X. file (fprx), rest is
7257c478bd9Sstevel@tonic-gate * required and named appropriately. this
7267c478bd9Sstevel@tonic-gate * necessitates local access to SPOOL/syspart, which
7277c478bd9Sstevel@tonic-gate * is handled by a hook in uuxqt that allows files
7287c478bd9Sstevel@tonic-gate * in SPOOL/syspart to be renamed on the F line.
7297c478bd9Sstevel@tonic-gate *
7307c478bd9Sstevel@tonic-gate * pictorially:
7317c478bd9Sstevel@tonic-gate *
7327c478bd9Sstevel@tonic-gate * ===== syspart/C.syspart.... ===== (tfile)
7337c478bd9Sstevel@tonic-gate * R rest D.syspart... (dfile)
7347c478bd9Sstevel@tonic-gate *
7357c478bd9Sstevel@tonic-gate *
7367c478bd9Sstevel@tonic-gate * ===== local/X.local... ===== (fprx)
7377c478bd9Sstevel@tonic-gate * F SPOOL/syspart/D.syspart... rest (dfile)
7387c478bd9Sstevel@tonic-gate *
7397c478bd9Sstevel@tonic-gate *
7407c478bd9Sstevel@tonic-gate */
7417c478bd9Sstevel@tonic-gate if (gtcfile(tfile, syspart) != SUCCESS) {
7427c478bd9Sstevel@tonic-gate gename(CMDPRE, syspart, 'R', tfile);
7437c478bd9Sstevel@tonic-gate
7447c478bd9Sstevel@tonic-gate ASSERT(access(tfile, 0) != 0,
7457c478bd9Sstevel@tonic-gate Fl_EXISTS, tfile, errno);
7467c478bd9Sstevel@tonic-gate svcfile(tfile, syspart, Sgrade);
7477c478bd9Sstevel@tonic-gate (void) close(creat(tfile, CFILEMODE));
7487c478bd9Sstevel@tonic-gate }
7497c478bd9Sstevel@tonic-gate fp = fopen(tfile, "a");
7507c478bd9Sstevel@tonic-gate ASSERT(fp != NULL, Ct_OPEN, tfile, errno);
7517c478bd9Sstevel@tonic-gate setbuf(fp, CNULL);
7527c478bd9Sstevel@tonic-gate gename(DATAPRE, syspart, 'R', dfile);
7537c478bd9Sstevel@tonic-gate
7547c478bd9Sstevel@tonic-gate /* prepare JCL card to receive file */
7557c478bd9Sstevel@tonic-gate GENRCV(fp, rest, dfile);
7567c478bd9Sstevel@tonic-gate ASSERT(fflush(fp) != EOF && ferror(fp) == 0, Ct_WRITE, dfile, errno);
7577c478bd9Sstevel@tonic-gate (void) fclose(fp);
7587c478bd9Sstevel@tonic-gate if (rest[0] != '~')
7597c478bd9Sstevel@tonic-gate if (ckexpf(rest))
7607c478bd9Sstevel@tonic-gate cleanup(EX_OSERR);
7617c478bd9Sstevel@tonic-gate
7627c478bd9Sstevel@tonic-gate /*
7637c478bd9Sstevel@tonic-gate * generate receive entries
7647c478bd9Sstevel@tonic-gate */
7657c478bd9Sstevel@tonic-gate if (redir == X_STDIN) {
7667c478bd9Sstevel@tonic-gate (void) fprintf(fprx,
7677c478bd9Sstevel@tonic-gate "%c %s/%s/%s\n", X_RQDFILE, Spool,
7687c478bd9Sstevel@tonic-gate syspart, dfile);
7697c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s\n", X_STDIN, dfile);
7707c478bd9Sstevel@tonic-gate } else {
7717c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s/%s/%s %s\n",
7727c478bd9Sstevel@tonic-gate X_RQDFILE, Spool, syspart, dfile,
7737c478bd9Sstevel@tonic-gate BASENAME(rest, '/'));
7747c478bd9Sstevel@tonic-gate APPCMD(BASENAME(rest, '/'));
7757c478bd9Sstevel@tonic-gate }
7767c478bd9Sstevel@tonic-gate
7777c478bd9Sstevel@tonic-gate redir = '\0';
7787c478bd9Sstevel@tonic-gate continue;
7797c478bd9Sstevel@tonic-gate }
7807c478bd9Sstevel@tonic-gate
7817c478bd9Sstevel@tonic-gate /* remote xeqn/file, different remotes (xsys!cmd syspart!rest) */
7827c478bd9Sstevel@tonic-gate if (!EQUALS(syspart, xsys)) {
7837c478bd9Sstevel@tonic-gate /*
7847c478bd9Sstevel@tonic-gate * strategy:
7857c478bd9Sstevel@tonic-gate * request rest from syspart.
7867c478bd9Sstevel@tonic-gate *
7877c478bd9Sstevel@tonic-gate * set up a local X. file that will send rest to xsys,
7887c478bd9Sstevel@tonic-gate * once it arrives from syspart.
7897c478bd9Sstevel@tonic-gate *
7907c478bd9Sstevel@tonic-gate * arrange so that in the xsys D. file (fated to become
7917c478bd9Sstevel@tonic-gate * an X. file on xsys), rest is required and named.
7927c478bd9Sstevel@tonic-gate *
7937c478bd9Sstevel@tonic-gate * pictorially:
7947c478bd9Sstevel@tonic-gate *
7957c478bd9Sstevel@tonic-gate * ===== syspart/C.syspart.... ===== (tfile)
7967c478bd9Sstevel@tonic-gate * R rest D.syspart... (dfile)
7977c478bd9Sstevel@tonic-gate *
7987c478bd9Sstevel@tonic-gate *
7997c478bd9Sstevel@tonic-gate * ===== local/X.local... ===== (t2file)
8007c478bd9Sstevel@tonic-gate * F Spool/syspart/D.syspart... rest (dfile)
8017c478bd9Sstevel@tonic-gate * C uucp -C rest D.syspart... (dfile)
8027c478bd9Sstevel@tonic-gate *
8037c478bd9Sstevel@tonic-gate * ===== xsys/D.xsysG.... (fprx)
8047c478bd9Sstevel@tonic-gate * F D.syspart... rest (dfile)
8057c478bd9Sstevel@tonic-gate * or, in the case of redir == '<'
8067c478bd9Sstevel@tonic-gate * F D.syspart... (dfile)
8077c478bd9Sstevel@tonic-gate * I D.syspart... (dfile)
8087c478bd9Sstevel@tonic-gate *
8097c478bd9Sstevel@tonic-gate * while we do push rest around a bunch,
8107c478bd9Sstevel@tonic-gate * we use the protection scheme to good effect.
8117c478bd9Sstevel@tonic-gate *
8127c478bd9Sstevel@tonic-gate * we must rely on uucp's treatment of requests
8137c478bd9Sstevel@tonic-gate * from XQTDIR to get the data file to the right
8147c478bd9Sstevel@tonic-gate * place ultimately.
8157c478bd9Sstevel@tonic-gate */
8167c478bd9Sstevel@tonic-gate
8177c478bd9Sstevel@tonic-gate /* build (or append to) C.syspart... */
8187c478bd9Sstevel@tonic-gate if (gtcfile(tfile, syspart) != SUCCESS) {
8197c478bd9Sstevel@tonic-gate gename(CMDPRE, syspart, 'R', tfile);
8207c478bd9Sstevel@tonic-gate
8217c478bd9Sstevel@tonic-gate ASSERT(access(tfile, 0) != 0,
8227c478bd9Sstevel@tonic-gate Fl_EXISTS, tfile, errno);
8237c478bd9Sstevel@tonic-gate svcfile(tfile, syspart, Sgrade);
8247c478bd9Sstevel@tonic-gate (void) close(creat(tfile, CFILEMODE));
8257c478bd9Sstevel@tonic-gate }
8267c478bd9Sstevel@tonic-gate fp = fopen(tfile, "a");
8277c478bd9Sstevel@tonic-gate ASSERT(fp != NULL, Ct_OPEN, tfile, errno);
8287c478bd9Sstevel@tonic-gate setbuf(fp, CNULL);
8297c478bd9Sstevel@tonic-gate gename(DATAPRE, syspart, 'R', dfile);
8307c478bd9Sstevel@tonic-gate GENRCV(fp, rest, dfile);
8317c478bd9Sstevel@tonic-gate ASSERT(fflush(fp) != EOF && ferror(fp) == 0, Ct_WRITE, dfile, errno);
8327c478bd9Sstevel@tonic-gate (void) fclose(fp);
8337c478bd9Sstevel@tonic-gate
8347c478bd9Sstevel@tonic-gate /* build local/X.localG... */
8357c478bd9Sstevel@tonic-gate /* name might collide with rxfile; no real danger */
8367c478bd9Sstevel@tonic-gate gename(XQTPRE, Myname, Grade, t2file);
8377c478bd9Sstevel@tonic-gate ASSERT(access(t2file, 0)!=0, Fl_EXISTS, t2file, errno);
8387c478bd9Sstevel@tonic-gate (void) close(creat(t2file, CFILEMODE));
8397c478bd9Sstevel@tonic-gate fp = fopen(t2file, "w");
8407c478bd9Sstevel@tonic-gate ASSERT(fp != NULL, Ct_OPEN, t2file, errno);
8417c478bd9Sstevel@tonic-gate setbuf(fp, CNULL);
8427c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%c third party request, job id\n",
8437c478bd9Sstevel@tonic-gate X_COMMENT);
8447c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%c %s\n", X_JOBID, Jobid);
8457c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%c %s/%s/%s %s\n", X_RQDFILE,
8467c478bd9Sstevel@tonic-gate Spool, syspart, dfile, BASENAME(rest, '/'));
8477c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%c uucp -C %s %s!%s\n",
8487c478bd9Sstevel@tonic-gate X_CMD, BASENAME(rest, '/'), xsys, dfile);
8497c478bd9Sstevel@tonic-gate ASSERT(fflush(fp) != EOF && ferror(fp) == 0, Ct_WRITE, t2file, errno);
8507c478bd9Sstevel@tonic-gate (void) fclose(fp);
8517c478bd9Sstevel@tonic-gate
8527c478bd9Sstevel@tonic-gate /* put t2file where uuxqt can get at it */
8537c478bd9Sstevel@tonic-gate wfcommit(t2file, t2file, Myname);
8547c478bd9Sstevel@tonic-gate
8557c478bd9Sstevel@tonic-gate /* generate xsys/X.sysG... cards */
8567c478bd9Sstevel@tonic-gate if (redir == X_STDIN) {
8577c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s\n",
8587c478bd9Sstevel@tonic-gate X_RQDFILE, dfile);
8597c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s\n", X_STDIN, dfile);
8607c478bd9Sstevel@tonic-gate } else {
8617c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s %s\n", X_RQDFILE,
8627c478bd9Sstevel@tonic-gate dfile, BASENAME(rest, '/'));
8637c478bd9Sstevel@tonic-gate APPCMD(BASENAME(rest, '/'));
8647c478bd9Sstevel@tonic-gate }
8657c478bd9Sstevel@tonic-gate redir = '\0';
8667c478bd9Sstevel@tonic-gate continue;
8677c478bd9Sstevel@tonic-gate }
8687c478bd9Sstevel@tonic-gate
8697c478bd9Sstevel@tonic-gate /* remote xeqn + remote file, same remote (sys!x sys!f) */
8707c478bd9Sstevel@tonic-gate if (rest[0] != '~') /* expand '~' on remote */
8717c478bd9Sstevel@tonic-gate if (ckexpf(rest))
8727c478bd9Sstevel@tonic-gate cleanup(EX_OSERR);
8737c478bd9Sstevel@tonic-gate if (redir == X_STDIN) {
8747c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s\n", X_STDIN, rest);
8757c478bd9Sstevel@tonic-gate }
8767c478bd9Sstevel@tonic-gate else
8777c478bd9Sstevel@tonic-gate APPCMD(rest);
8787c478bd9Sstevel@tonic-gate redir = '\0';
8797c478bd9Sstevel@tonic-gate continue;
8807c478bd9Sstevel@tonic-gate
8817c478bd9Sstevel@tonic-gate }
8827c478bd9Sstevel@tonic-gate
8837c478bd9Sstevel@tonic-gate /*
8847c478bd9Sstevel@tonic-gate * place command to be executed in JCL file
8857c478bd9Sstevel@tonic-gate */
8867c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s\n", X_CMD, cmd);
8877c478bd9Sstevel@tonic-gate ASSERT(fflush(fprx) != EOF && ferror(fprx) == 0, Ct_WRITE, rxfile, errno);
8887c478bd9Sstevel@tonic-gate (void) fclose(fprx); /* rxfile is ready for commit */
8897c478bd9Sstevel@tonic-gate logent(cmd, "QUEUED");
8907c478bd9Sstevel@tonic-gate
8917c478bd9Sstevel@tonic-gate gename(XQTPRE, Myname, Grade, tfile);
8927c478bd9Sstevel@tonic-gate if (EQUALS(xsys, Myname)) {
8937c478bd9Sstevel@tonic-gate /* local xeqn -- use X_ file here */
8947c478bd9Sstevel@tonic-gate /* this use of the X_ file can not collide with the earlier one */
8957c478bd9Sstevel@tonic-gate wfcommit(rxfile, tfile, xsys);
8967c478bd9Sstevel@tonic-gate
8977c478bd9Sstevel@tonic-gate /*
8987c478bd9Sstevel@tonic-gate * see if -r option requested JCL to be queued only
8997c478bd9Sstevel@tonic-gate */
9007c478bd9Sstevel@tonic-gate if (startjob)
9017c478bd9Sstevel@tonic-gate xuuxqt(Myname);
9027c478bd9Sstevel@tonic-gate } else {
9037c478bd9Sstevel@tonic-gate /* remote xeqn -- send rxfile to remote */
9047c478bd9Sstevel@tonic-gate /* put it in a place where cico can get at it */
9057c478bd9Sstevel@tonic-gate /* X_ file name might collide with an earlier use, */
9067c478bd9Sstevel@tonic-gate /* but that one lives locally, while this one gets shipped */
9077c478bd9Sstevel@tonic-gate
9087c478bd9Sstevel@tonic-gate GENSEND(fpc, rxfile, tfile, rxfile);
9097c478bd9Sstevel@tonic-gate }
9107c478bd9Sstevel@tonic-gate
9117c478bd9Sstevel@tonic-gate cfileUsed = (ftell(fpc) != 0L); /* was cfile used? */
9127c478bd9Sstevel@tonic-gate ASSERT(fflush(fpc) != EOF && ferror(fpc) == 0, Ct_WRITE, cfile, errno);
9137c478bd9Sstevel@tonic-gate (void) fclose(fpc);
9147c478bd9Sstevel@tonic-gate
9157c478bd9Sstevel@tonic-gate /* commit C. files for remote receive */
9167c478bd9Sstevel@tonic-gate
9177c478bd9Sstevel@tonic-gate commitall();
9187c478bd9Sstevel@tonic-gate
9197c478bd9Sstevel@tonic-gate /*
9207c478bd9Sstevel@tonic-gate * has any command been placed in command JCL file
9217c478bd9Sstevel@tonic-gate */
9227c478bd9Sstevel@tonic-gate if (cfileUsed) {
9237c478bd9Sstevel@tonic-gate
9247c478bd9Sstevel@tonic-gate svcfile(cfile, xsys, Sgrade);
9257c478bd9Sstevel@tonic-gate commitall();
9267c478bd9Sstevel@tonic-gate
9277c478bd9Sstevel@tonic-gate /*
9287c478bd9Sstevel@tonic-gate * see if -r option requested JCL to be queued only
9297c478bd9Sstevel@tonic-gate */
9307c478bd9Sstevel@tonic-gate if (startjob)
9317c478bd9Sstevel@tonic-gate xuucico(xsys);
9327c478bd9Sstevel@tonic-gate } else
9337c478bd9Sstevel@tonic-gate unlink(cfile);
9347c478bd9Sstevel@tonic-gate
9357c478bd9Sstevel@tonic-gate if (jflag) { /* print Jobid */
9367c478bd9Sstevel@tonic-gate STRNCPY(Jobid, jid());
9377c478bd9Sstevel@tonic-gate printf("%s\n", Jobid);
9387c478bd9Sstevel@tonic-gate }
9397c478bd9Sstevel@tonic-gate
9407c478bd9Sstevel@tonic-gate cleanup(0);
9417c478bd9Sstevel@tonic-gate /* NOTREACHED */
942462be471Sceastha return (0);
9437c478bd9Sstevel@tonic-gate }
9447c478bd9Sstevel@tonic-gate
9457c478bd9Sstevel@tonic-gate
9467c478bd9Sstevel@tonic-gate /*
9477c478bd9Sstevel@tonic-gate * cleanup and unlink if error
9487c478bd9Sstevel@tonic-gate * code -> exit code
9497c478bd9Sstevel@tonic-gate * return:
9507c478bd9Sstevel@tonic-gate * none
9517c478bd9Sstevel@tonic-gate */
9527c478bd9Sstevel@tonic-gate void
cleanup(code)9537c478bd9Sstevel@tonic-gate cleanup(code)
954462be471Sceastha int code;
9557c478bd9Sstevel@tonic-gate {
9567c478bd9Sstevel@tonic-gate static int first = 1;
9577c478bd9Sstevel@tonic-gate
9587c478bd9Sstevel@tonic-gate /* prevent recursion on errors */
9597c478bd9Sstevel@tonic-gate if (first) {
9607c478bd9Sstevel@tonic-gate first = 0;
9617c478bd9Sstevel@tonic-gate rmlock(CNULL);
9627c478bd9Sstevel@tonic-gate if (code) {
9637c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("uux failed ( %d )\n"), code);
9647c478bd9Sstevel@tonic-gate wfabort();
9657c478bd9Sstevel@tonic-gate }
9667c478bd9Sstevel@tonic-gate }
9677c478bd9Sstevel@tonic-gate DEBUG(1, "exit code %d\n", code);
9687c478bd9Sstevel@tonic-gate if (code < 0)
9697c478bd9Sstevel@tonic-gate exit(-code);
9707c478bd9Sstevel@tonic-gate else
9717c478bd9Sstevel@tonic-gate exit(code);
9727c478bd9Sstevel@tonic-gate }
9737c478bd9Sstevel@tonic-gate
9747c478bd9Sstevel@tonic-gate /*
9757c478bd9Sstevel@tonic-gate * catch signal then cleanup and exit
9767c478bd9Sstevel@tonic-gate */
9777c478bd9Sstevel@tonic-gate static void
onintr(inter)9787c478bd9Sstevel@tonic-gate onintr(inter)
979462be471Sceastha int inter;
9807c478bd9Sstevel@tonic-gate {
9817c478bd9Sstevel@tonic-gate char str[30];
9827c478bd9Sstevel@tonic-gate (void) signal(inter, SIG_IGN);
9837c478bd9Sstevel@tonic-gate (void) sprintf(str, "XSIGNAL %d", inter);
9847c478bd9Sstevel@tonic-gate logent(str, "XCAUGHT");
9857c478bd9Sstevel@tonic-gate cleanup(EX_TEMPFAIL);
9867c478bd9Sstevel@tonic-gate }
9877c478bd9Sstevel@tonic-gate
9887c478bd9Sstevel@tonic-gate
9897c478bd9Sstevel@tonic-gate static void
usage()9907c478bd9Sstevel@tonic-gate usage()
9917c478bd9Sstevel@tonic-gate {
9927c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Usage: %s [-bcCjnprz] [-a NAME]"
9937c478bd9Sstevel@tonic-gate " [-g GRADE] [-s FILE] [-x NUM] command-string\n"), Progname);
9947c478bd9Sstevel@tonic-gate exit(EX_USAGE);
9957c478bd9Sstevel@tonic-gate }
996