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