1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 1998 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #include "uucp.h" 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #define SHORTBUF 64 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #define NOSYSPART 0 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate #define GENSEND(f, a, b, c) {\ 40*7c478bd9Sstevel@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);\ 41*7c478bd9Sstevel@tonic-gate } 42*7c478bd9Sstevel@tonic-gate #define GENRCV(f, a, b) {\ 43*7c478bd9Sstevel@tonic-gate char tbuf[SHORTBUF]; \ 44*7c478bd9Sstevel@tonic-gate gename (DATAPRE, xsys, 'Z', tbuf); \ 45*7c478bd9Sstevel@tonic-gate ASSERT(fprintf(f, "R %s %s %s - %s 0666 %s %s\n", a, b, User, _Sfile, User, tbuf) \ 46*7c478bd9Sstevel@tonic-gate >= 0, Ct_WRITE, "", errno);\ 47*7c478bd9Sstevel@tonic-gate } 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate #define STRNCPY(str1, str2) { \ 50*7c478bd9Sstevel@tonic-gate (void) strncpy(str1, str2, (sizeof(str1) - 1)); \ 51*7c478bd9Sstevel@tonic-gate str1[sizeof(str1) - 1] = '\0'; \ 52*7c478bd9Sstevel@tonic-gate } 53*7c478bd9Sstevel@tonic-gate #define STRNCAT(str1, str2) { \ 54*7c478bd9Sstevel@tonic-gate (void) strncat(str1, str2, \ 55*7c478bd9Sstevel@tonic-gate (sizeof(str1) - 1 - strlen(str1))); \ 56*7c478bd9Sstevel@tonic-gate } 57*7c478bd9Sstevel@tonic-gate #define APPCMD(p) {STRNCAT(cmd, p); STRNCAT(cmd, " ");} 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate static char _Sfile[MAXFULLNAME]; 60*7c478bd9Sstevel@tonic-gate static int _Statop; 61*7c478bd9Sstevel@tonic-gate char Sgrade[NAMESIZE]; 62*7c478bd9Sstevel@tonic-gate void cleanup(); 63*7c478bd9Sstevel@tonic-gate static void usage(); 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate /* 66*7c478bd9Sstevel@tonic-gate * uux 67*7c478bd9Sstevel@tonic-gate */ 68*7c478bd9Sstevel@tonic-gate main(argc, argv, envp) 69*7c478bd9Sstevel@tonic-gate char *argv[]; 70*7c478bd9Sstevel@tonic-gate char *envp[]; 71*7c478bd9Sstevel@tonic-gate { 72*7c478bd9Sstevel@tonic-gate char *jid(); 73*7c478bd9Sstevel@tonic-gate FILE *fprx = NULL, *fpc = NULL, *fpd = NULL, *fp = NULL; 74*7c478bd9Sstevel@tonic-gate static void onintr(); 75*7c478bd9Sstevel@tonic-gate int cfileUsed = 0; /* >0 if commands put in C. file flag */ 76*7c478bd9Sstevel@tonic-gate int cflag = 0; /* if > 0 make local copy of files to be sent */ 77*7c478bd9Sstevel@tonic-gate int nflag = 0; /* if != 0, do not request error notification */ 78*7c478bd9Sstevel@tonic-gate int zflag = 0; /* if != 0, request success notification */ 79*7c478bd9Sstevel@tonic-gate int pipein = 0; 80*7c478bd9Sstevel@tonic-gate int startjob = 1; 81*7c478bd9Sstevel@tonic-gate short jflag = 0; /* -j flag output Jobid */ 82*7c478bd9Sstevel@tonic-gate int bringback = 0; /* return stdin to invoker on error */ 83*7c478bd9Sstevel@tonic-gate int ret, i; 84*7c478bd9Sstevel@tonic-gate char *getprm(); 85*7c478bd9Sstevel@tonic-gate char redir = '\0'; /* X_STDIN, X_STDOUT, X_STDERR as approprite */ 86*7c478bd9Sstevel@tonic-gate char command = TRUE; 87*7c478bd9Sstevel@tonic-gate char cfile[NAMESIZE]; /* send commands for files from here */ 88*7c478bd9Sstevel@tonic-gate char dfile[NAMESIZE]; /* used for all data files from here */ 89*7c478bd9Sstevel@tonic-gate char rxfile[NAMESIZE]; /* file for X_ commands */ 90*7c478bd9Sstevel@tonic-gate char tfile[NAMESIZE]; /* temporary file name */ 91*7c478bd9Sstevel@tonic-gate char t2file[NAMESIZE]; /* temporary file name */ 92*7c478bd9Sstevel@tonic-gate char buf[BUFSIZ]; 93*7c478bd9Sstevel@tonic-gate char inargs[BUFSIZ]; 94*7c478bd9Sstevel@tonic-gate char cmd[BUFSIZ]; 95*7c478bd9Sstevel@tonic-gate char *ap; 96*7c478bd9Sstevel@tonic-gate char prm[BUFSIZ]; 97*7c478bd9Sstevel@tonic-gate char syspart[MAXFULLNAME], rest[BUFSIZ]; 98*7c478bd9Sstevel@tonic-gate char xsys[MAXFULLNAME]; 99*7c478bd9Sstevel@tonic-gate char *fopt = NULL; 100*7c478bd9Sstevel@tonic-gate char *retaddr = NULL; 101*7c478bd9Sstevel@tonic-gate struct stat stbuf; 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate /* Set locale environment variables local definitions */ 104*7c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 105*7c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ 106*7c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */ 107*7c478bd9Sstevel@tonic-gate #endif 108*7c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate /* we want this to run as uucp, even if the kernel doesn't */ 111*7c478bd9Sstevel@tonic-gate Uid = getuid(); 112*7c478bd9Sstevel@tonic-gate Euid = geteuid(); /* this should be UUCPUID */ 113*7c478bd9Sstevel@tonic-gate if (Uid == 0) 114*7c478bd9Sstevel@tonic-gate setuid(UUCPUID); 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate /* init environment for fork-exec */ 117*7c478bd9Sstevel@tonic-gate Env = envp; 118*7c478bd9Sstevel@tonic-gate 119*7c478bd9Sstevel@tonic-gate /* choose LOGFILE */ 120*7c478bd9Sstevel@tonic-gate STRNCPY(Logfile, LOGUUX); 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate /* 123*7c478bd9Sstevel@tonic-gate * determine local system name 124*7c478bd9Sstevel@tonic-gate */ 125*7c478bd9Sstevel@tonic-gate (void) strcpy(Progname, "uux"); 126*7c478bd9Sstevel@tonic-gate Pchar = 'X'; 127*7c478bd9Sstevel@tonic-gate (void) signal(SIGILL, onintr); 128*7c478bd9Sstevel@tonic-gate (void) signal(SIGTRAP, onintr); 129*7c478bd9Sstevel@tonic-gate (void) signal(SIGIOT, onintr); 130*7c478bd9Sstevel@tonic-gate (void) signal(SIGEMT, onintr); 131*7c478bd9Sstevel@tonic-gate (void) signal(SIGFPE, onintr); 132*7c478bd9Sstevel@tonic-gate (void) signal(SIGBUS, onintr); 133*7c478bd9Sstevel@tonic-gate (void) signal(SIGSEGV, onintr); 134*7c478bd9Sstevel@tonic-gate (void) signal(SIGSYS, onintr); 135*7c478bd9Sstevel@tonic-gate (void) signal(SIGTERM, SIG_IGN); 136*7c478bd9Sstevel@tonic-gate uucpname(Myname); 137*7c478bd9Sstevel@tonic-gate Ofn = 1; 138*7c478bd9Sstevel@tonic-gate Ifn = 0; 139*7c478bd9Sstevel@tonic-gate *_Sfile = '\0'; 140*7c478bd9Sstevel@tonic-gate 141*7c478bd9Sstevel@tonic-gate /* 142*7c478bd9Sstevel@tonic-gate * determine id of user starting remote 143*7c478bd9Sstevel@tonic-gate * execution 144*7c478bd9Sstevel@tonic-gate */ 145*7c478bd9Sstevel@tonic-gate guinfo(Uid, User); 146*7c478bd9Sstevel@tonic-gate STRNCPY(Loginuser,User); 147*7c478bd9Sstevel@tonic-gate 148*7c478bd9Sstevel@tonic-gate *Sgrade = NULLCHAR; 149*7c478bd9Sstevel@tonic-gate 150*7c478bd9Sstevel@tonic-gate /* 151*7c478bd9Sstevel@tonic-gate * this is a check to see if we are using the administrator 152*7c478bd9Sstevel@tonic-gate * defined service grade. The GRADES file will determine if 153*7c478bd9Sstevel@tonic-gate * we are. If so then setup the default grade variables. 154*7c478bd9Sstevel@tonic-gate */ 155*7c478bd9Sstevel@tonic-gate 156*7c478bd9Sstevel@tonic-gate if (eaccess(GRADES, 04) != -1) { 157*7c478bd9Sstevel@tonic-gate Grade = 'A'; 158*7c478bd9Sstevel@tonic-gate Sgrades = TRUE; 159*7c478bd9Sstevel@tonic-gate STRNCPY(Sgrade, "default"); 160*7c478bd9Sstevel@tonic-gate } 161*7c478bd9Sstevel@tonic-gate 162*7c478bd9Sstevel@tonic-gate /* 163*7c478bd9Sstevel@tonic-gate * create/append command log 164*7c478bd9Sstevel@tonic-gate */ 165*7c478bd9Sstevel@tonic-gate commandlog(argc,argv); 166*7c478bd9Sstevel@tonic-gate 167*7c478bd9Sstevel@tonic-gate /* 168*7c478bd9Sstevel@tonic-gate * since getopt() can't handle the pipe input option '-'; 169*7c478bd9Sstevel@tonic-gate * change it to "-p" 170*7c478bd9Sstevel@tonic-gate */ 171*7c478bd9Sstevel@tonic-gate for (i=1; i<argc && *argv[i] == '-'; i++) 172*7c478bd9Sstevel@tonic-gate if (EQUALS(argv[i], "-")) 173*7c478bd9Sstevel@tonic-gate argv[i] = "-p"; 174*7c478bd9Sstevel@tonic-gate 175*7c478bd9Sstevel@tonic-gate while ((i = getopt(argc, argv, "a:bcCjg:nprs:x:z")) != EOF) { 176*7c478bd9Sstevel@tonic-gate switch(i){ 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate /* 179*7c478bd9Sstevel@tonic-gate * use this name in the U line 180*7c478bd9Sstevel@tonic-gate */ 181*7c478bd9Sstevel@tonic-gate case 'a': 182*7c478bd9Sstevel@tonic-gate retaddr = optarg; 183*7c478bd9Sstevel@tonic-gate break; 184*7c478bd9Sstevel@tonic-gate 185*7c478bd9Sstevel@tonic-gate /* 186*7c478bd9Sstevel@tonic-gate * if return code non-zero, return command's input 187*7c478bd9Sstevel@tonic-gate */ 188*7c478bd9Sstevel@tonic-gate case 'b': 189*7c478bd9Sstevel@tonic-gate bringback = 1; 190*7c478bd9Sstevel@tonic-gate break; 191*7c478bd9Sstevel@tonic-gate 192*7c478bd9Sstevel@tonic-gate /* do not make local copies of files to be sent (default) */ 193*7c478bd9Sstevel@tonic-gate case 'c': 194*7c478bd9Sstevel@tonic-gate cflag = 0; 195*7c478bd9Sstevel@tonic-gate break; 196*7c478bd9Sstevel@tonic-gate 197*7c478bd9Sstevel@tonic-gate /* make local copies of files to be sent */ 198*7c478bd9Sstevel@tonic-gate case 'C': 199*7c478bd9Sstevel@tonic-gate cflag = 1; 200*7c478bd9Sstevel@tonic-gate break; 201*7c478bd9Sstevel@tonic-gate 202*7c478bd9Sstevel@tonic-gate /* 203*7c478bd9Sstevel@tonic-gate * set priority of request 204*7c478bd9Sstevel@tonic-gate */ 205*7c478bd9Sstevel@tonic-gate case 'g': 206*7c478bd9Sstevel@tonic-gate if (!Sgrades) { 207*7c478bd9Sstevel@tonic-gate if (strlen(optarg) < (size_t) 2 && isalnum(*optarg)) 208*7c478bd9Sstevel@tonic-gate Grade = *optarg; 209*7c478bd9Sstevel@tonic-gate else { 210*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("No" 211*7c478bd9Sstevel@tonic-gate " administrator defined service" 212*7c478bd9Sstevel@tonic-gate " grades available on this" 213*7c478bd9Sstevel@tonic-gate " machine.\n")); 214*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("UUCP" 215*7c478bd9Sstevel@tonic-gate " service grades range from" 216*7c478bd9Sstevel@tonic-gate " [A-Z][a-z] only.\n")); 217*7c478bd9Sstevel@tonic-gate cleanup(-1); 218*7c478bd9Sstevel@tonic-gate } 219*7c478bd9Sstevel@tonic-gate } 220*7c478bd9Sstevel@tonic-gate else { 221*7c478bd9Sstevel@tonic-gate STRNCPY(Sgrade, optarg); 222*7c478bd9Sstevel@tonic-gate if (vergrd(Sgrade) != SUCCESS) 223*7c478bd9Sstevel@tonic-gate cleanup(FAIL); 224*7c478bd9Sstevel@tonic-gate } 225*7c478bd9Sstevel@tonic-gate break; 226*7c478bd9Sstevel@tonic-gate 227*7c478bd9Sstevel@tonic-gate 228*7c478bd9Sstevel@tonic-gate case 'j': /* job id */ 229*7c478bd9Sstevel@tonic-gate jflag = 1; 230*7c478bd9Sstevel@tonic-gate break; 231*7c478bd9Sstevel@tonic-gate 232*7c478bd9Sstevel@tonic-gate 233*7c478bd9Sstevel@tonic-gate /* 234*7c478bd9Sstevel@tonic-gate * do not send failure notification to user 235*7c478bd9Sstevel@tonic-gate */ 236*7c478bd9Sstevel@tonic-gate case 'n': 237*7c478bd9Sstevel@tonic-gate nflag++; 238*7c478bd9Sstevel@tonic-gate break; 239*7c478bd9Sstevel@tonic-gate 240*7c478bd9Sstevel@tonic-gate /* 241*7c478bd9Sstevel@tonic-gate * send success notification to user 242*7c478bd9Sstevel@tonic-gate */ 243*7c478bd9Sstevel@tonic-gate case 'z': 244*7c478bd9Sstevel@tonic-gate zflag++; 245*7c478bd9Sstevel@tonic-gate break; 246*7c478bd9Sstevel@tonic-gate 247*7c478bd9Sstevel@tonic-gate /* 248*7c478bd9Sstevel@tonic-gate * -p or - option specifies input from pipe 249*7c478bd9Sstevel@tonic-gate */ 250*7c478bd9Sstevel@tonic-gate case 'p': 251*7c478bd9Sstevel@tonic-gate pipein = 1; 252*7c478bd9Sstevel@tonic-gate break; 253*7c478bd9Sstevel@tonic-gate 254*7c478bd9Sstevel@tonic-gate /* 255*7c478bd9Sstevel@tonic-gate * do not start transfer 256*7c478bd9Sstevel@tonic-gate */ 257*7c478bd9Sstevel@tonic-gate case 'r': 258*7c478bd9Sstevel@tonic-gate startjob = 0; 259*7c478bd9Sstevel@tonic-gate break; 260*7c478bd9Sstevel@tonic-gate 261*7c478bd9Sstevel@tonic-gate case 's': 262*7c478bd9Sstevel@tonic-gate fopt = optarg; 263*7c478bd9Sstevel@tonic-gate _Statop++; 264*7c478bd9Sstevel@tonic-gate break; 265*7c478bd9Sstevel@tonic-gate 266*7c478bd9Sstevel@tonic-gate /* 267*7c478bd9Sstevel@tonic-gate * debugging level 268*7c478bd9Sstevel@tonic-gate */ 269*7c478bd9Sstevel@tonic-gate case 'x': 270*7c478bd9Sstevel@tonic-gate Debug = atoi(optarg); 271*7c478bd9Sstevel@tonic-gate if (Debug <= 0) 272*7c478bd9Sstevel@tonic-gate Debug = 1; 273*7c478bd9Sstevel@tonic-gate break; 274*7c478bd9Sstevel@tonic-gate 275*7c478bd9Sstevel@tonic-gate default: 276*7c478bd9Sstevel@tonic-gate usage(); 277*7c478bd9Sstevel@tonic-gate } 278*7c478bd9Sstevel@tonic-gate } 279*7c478bd9Sstevel@tonic-gate 280*7c478bd9Sstevel@tonic-gate DEBUG(4, "\n\n** %s **\n", "START"); 281*7c478bd9Sstevel@tonic-gate 282*7c478bd9Sstevel@tonic-gate if( optind >= argc ) 283*7c478bd9Sstevel@tonic-gate usage(); 284*7c478bd9Sstevel@tonic-gate 285*7c478bd9Sstevel@tonic-gate /* 286*7c478bd9Sstevel@tonic-gate * copy arguments into a buffer for later 287*7c478bd9Sstevel@tonic-gate * processing 288*7c478bd9Sstevel@tonic-gate */ 289*7c478bd9Sstevel@tonic-gate inargs[0] = '\0'; 290*7c478bd9Sstevel@tonic-gate for (; optind < argc; optind++) { 291*7c478bd9Sstevel@tonic-gate DEBUG(4, "arg - %s:", argv[optind]); 292*7c478bd9Sstevel@tonic-gate STRNCAT(inargs, " "); 293*7c478bd9Sstevel@tonic-gate STRNCAT(inargs, argv[optind]); 294*7c478bd9Sstevel@tonic-gate } 295*7c478bd9Sstevel@tonic-gate 296*7c478bd9Sstevel@tonic-gate /* 297*7c478bd9Sstevel@tonic-gate * get working directory and change 298*7c478bd9Sstevel@tonic-gate * to spool directory 299*7c478bd9Sstevel@tonic-gate */ 300*7c478bd9Sstevel@tonic-gate DEBUG(4, "arg - %s\n", inargs); 301*7c478bd9Sstevel@tonic-gate gwd(Wrkdir); 302*7c478bd9Sstevel@tonic-gate if(fopt){ 303*7c478bd9Sstevel@tonic-gate if(*fopt != '/') { 304*7c478bd9Sstevel@tonic-gate (void) snprintf(_Sfile, (sizeof(_Sfile) - 1), 305*7c478bd9Sstevel@tonic-gate "%s/%s", Wrkdir, fopt); 306*7c478bd9Sstevel@tonic-gate _Sfile[sizeof(_Sfile) - 1] = '\0'; 307*7c478bd9Sstevel@tonic-gate } 308*7c478bd9Sstevel@tonic-gate else { 309*7c478bd9Sstevel@tonic-gate (void) snprintf(_Sfile, (sizeof(_Sfile) - 1), 310*7c478bd9Sstevel@tonic-gate "%s", fopt); 311*7c478bd9Sstevel@tonic-gate _Sfile[sizeof(_Sfile) - 1] = '\0'; 312*7c478bd9Sstevel@tonic-gate } 313*7c478bd9Sstevel@tonic-gate } 314*7c478bd9Sstevel@tonic-gate else 315*7c478bd9Sstevel@tonic-gate strcpy(_Sfile, "dummy"); 316*7c478bd9Sstevel@tonic-gate 317*7c478bd9Sstevel@tonic-gate if (chdir(WORKSPACE) != 0) { 318*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 319*7c478bd9Sstevel@tonic-gate gettext("No spool directory - %s - get help\n"), WORKSPACE); 320*7c478bd9Sstevel@tonic-gate cleanup(EX_OSERR); 321*7c478bd9Sstevel@tonic-gate } 322*7c478bd9Sstevel@tonic-gate /* 323*7c478bd9Sstevel@tonic-gate * find remote system name 324*7c478bd9Sstevel@tonic-gate * remote name is first to know that 325*7c478bd9Sstevel@tonic-gate * is not > or < 326*7c478bd9Sstevel@tonic-gate */ 327*7c478bd9Sstevel@tonic-gate ap = inargs; 328*7c478bd9Sstevel@tonic-gate xsys[0] = '\0'; 329*7c478bd9Sstevel@tonic-gate while ((ap = getprm(ap, (char *)NULL, prm)) != NULL) { 330*7c478bd9Sstevel@tonic-gate if (prm[0] == '>' || prm[0] == '<') { 331*7c478bd9Sstevel@tonic-gate ap = getprm(ap, (char *)NULL, prm); 332*7c478bd9Sstevel@tonic-gate continue; 333*7c478bd9Sstevel@tonic-gate } 334*7c478bd9Sstevel@tonic-gate 335*7c478bd9Sstevel@tonic-gate /* 336*7c478bd9Sstevel@tonic-gate * split name into system name 337*7c478bd9Sstevel@tonic-gate * and command name 338*7c478bd9Sstevel@tonic-gate */ 339*7c478bd9Sstevel@tonic-gate (void) split(prm, xsys, CNULL, rest); 340*7c478bd9Sstevel@tonic-gate break; 341*7c478bd9Sstevel@tonic-gate } 342*7c478bd9Sstevel@tonic-gate if (xsys[0] == '\0') 343*7c478bd9Sstevel@tonic-gate STRNCPY(xsys, Myname); 344*7c478bd9Sstevel@tonic-gate STRNCPY(Rmtname, xsys); 345*7c478bd9Sstevel@tonic-gate DEBUG(4, "xsys %s\n", xsys); 346*7c478bd9Sstevel@tonic-gate 347*7c478bd9Sstevel@tonic-gate /* get real Myname - it depends on who I'm calling--Rmtname */ 348*7c478bd9Sstevel@tonic-gate (void) mchFind(Rmtname); 349*7c478bd9Sstevel@tonic-gate myName(Myname); 350*7c478bd9Sstevel@tonic-gate 351*7c478bd9Sstevel@tonic-gate /* 352*7c478bd9Sstevel@tonic-gate * check to see if system name is valid 353*7c478bd9Sstevel@tonic-gate */ 354*7c478bd9Sstevel@tonic-gate if (versys(xsys) != 0) { 355*7c478bd9Sstevel@tonic-gate /* 356*7c478bd9Sstevel@tonic-gate * bad system name 357*7c478bd9Sstevel@tonic-gate */ 358*7c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("bad system name: %s\n"), xsys); 359*7c478bd9Sstevel@tonic-gate if (fprx != NULL) 360*7c478bd9Sstevel@tonic-gate (void) fclose(fprx); 361*7c478bd9Sstevel@tonic-gate if (fpc != NULL) 362*7c478bd9Sstevel@tonic-gate (void) fclose(fpc); 363*7c478bd9Sstevel@tonic-gate cleanup(EX_NOHOST); 364*7c478bd9Sstevel@tonic-gate } 365*7c478bd9Sstevel@tonic-gate 366*7c478bd9Sstevel@tonic-gate DEBUG(6, "User %s\n", User); 367*7c478bd9Sstevel@tonic-gate if (retaddr == NULL) 368*7c478bd9Sstevel@tonic-gate retaddr = User; 369*7c478bd9Sstevel@tonic-gate 370*7c478bd9Sstevel@tonic-gate /* 371*7c478bd9Sstevel@tonic-gate * initialize command buffer 372*7c478bd9Sstevel@tonic-gate */ 373*7c478bd9Sstevel@tonic-gate *cmd = '\0'; 374*7c478bd9Sstevel@tonic-gate 375*7c478bd9Sstevel@tonic-gate /* 376*7c478bd9Sstevel@tonic-gate * generate JCL files to work from 377*7c478bd9Sstevel@tonic-gate */ 378*7c478bd9Sstevel@tonic-gate 379*7c478bd9Sstevel@tonic-gate /* 380*7c478bd9Sstevel@tonic-gate * fpc is the C. file for the local site. 381*7c478bd9Sstevel@tonic-gate * collect commands into cfile. 382*7c478bd9Sstevel@tonic-gate * commit if not empty (at end). 383*7c478bd9Sstevel@tonic-gate * 384*7c478bd9Sstevel@tonic-gate * the appropriate C. file. 385*7c478bd9Sstevel@tonic-gate */ 386*7c478bd9Sstevel@tonic-gate gename(CMDPRE, xsys, Grade, cfile); 387*7c478bd9Sstevel@tonic-gate DEBUG(9, "cfile = %s\n", cfile); 388*7c478bd9Sstevel@tonic-gate ASSERT(access(cfile, 0) != 0, Fl_EXISTS, cfile, errno); 389*7c478bd9Sstevel@tonic-gate fpc = fdopen(ret = creat(cfile, CFILEMODE), "w"); 390*7c478bd9Sstevel@tonic-gate ASSERT(ret >= 0 && fpc != NULL, Ct_OPEN, cfile, errno); 391*7c478bd9Sstevel@tonic-gate setbuf(fpc, CNULL); 392*7c478bd9Sstevel@tonic-gate 393*7c478bd9Sstevel@tonic-gate /* set Jobid -- C.jobid */ 394*7c478bd9Sstevel@tonic-gate STRNCPY(Jobid, BASENAME(cfile, '.')); 395*7c478bd9Sstevel@tonic-gate 396*7c478bd9Sstevel@tonic-gate /* 397*7c478bd9Sstevel@tonic-gate * rxfile is the X. file for the job, fprx is its stream ptr. 398*7c478bd9Sstevel@tonic-gate * if the command is to be executed locally, rxfile becomes 399*7c478bd9Sstevel@tonic-gate * a local X. file, otherwise we send it as a D. file to the 400*7c478bd9Sstevel@tonic-gate * remote site. 401*7c478bd9Sstevel@tonic-gate */ 402*7c478bd9Sstevel@tonic-gate 403*7c478bd9Sstevel@tonic-gate gename(DATAPRE, xsys, 'X', rxfile); 404*7c478bd9Sstevel@tonic-gate DEBUG(9, "rxfile = %s\n", rxfile); 405*7c478bd9Sstevel@tonic-gate ASSERT(access(rxfile, 0) != 0, Fl_EXISTS, rxfile, errno); 406*7c478bd9Sstevel@tonic-gate fprx = fdopen(ret = creat(rxfile, DFILEMODE), "w"); 407*7c478bd9Sstevel@tonic-gate ASSERT(ret >= 0 && fprx != NULL, Ct_WRITE, rxfile, errno); 408*7c478bd9Sstevel@tonic-gate setbuf(fprx, CNULL); 409*7c478bd9Sstevel@tonic-gate clearerr(fprx); 410*7c478bd9Sstevel@tonic-gate 411*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx,"%c %s %s\n", X_USER, User, Myname); 412*7c478bd9Sstevel@tonic-gate if (zflag) { 413*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c return status on success\n", 414*7c478bd9Sstevel@tonic-gate X_COMMENT); 415*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx,"%c\n", X_SENDZERO); 416*7c478bd9Sstevel@tonic-gate } 417*7c478bd9Sstevel@tonic-gate 418*7c478bd9Sstevel@tonic-gate if (nflag) { 419*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c don't return status on failure\n", 420*7c478bd9Sstevel@tonic-gate X_COMMENT); 421*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx,"%c\n", X_SENDNOTHING); 422*7c478bd9Sstevel@tonic-gate } else { 423*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c return status on failure\n", 424*7c478bd9Sstevel@tonic-gate X_COMMENT); 425*7c478bd9Sstevel@tonic-gate fprintf(fprx,"%c\n", X_NONZERO); 426*7c478bd9Sstevel@tonic-gate } 427*7c478bd9Sstevel@tonic-gate 428*7c478bd9Sstevel@tonic-gate if (bringback) { 429*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c return input on abnormal exit\n", 430*7c478bd9Sstevel@tonic-gate X_COMMENT); 431*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx,"%c\n", X_BRINGBACK); 432*7c478bd9Sstevel@tonic-gate } 433*7c478bd9Sstevel@tonic-gate 434*7c478bd9Sstevel@tonic-gate if (_Statop) 435*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx,"%c %s\n", X_MAILF, _Sfile); 436*7c478bd9Sstevel@tonic-gate 437*7c478bd9Sstevel@tonic-gate if (retaddr != NULL) { 438*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c return address for status or input return\n", 439*7c478bd9Sstevel@tonic-gate X_COMMENT); 440*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx,"%c %s\n", X_RETADDR, retaddr); 441*7c478bd9Sstevel@tonic-gate } 442*7c478bd9Sstevel@tonic-gate 443*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c job id for status reporting\n", X_COMMENT); 444*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx,"%c %s\n", X_JOBID, Jobid); 445*7c478bd9Sstevel@tonic-gate 446*7c478bd9Sstevel@tonic-gate /* 447*7c478bd9Sstevel@tonic-gate * create a JCL file to spool pipe input into 448*7c478bd9Sstevel@tonic-gate */ 449*7c478bd9Sstevel@tonic-gate if (pipein) { 450*7c478bd9Sstevel@tonic-gate /* 451*7c478bd9Sstevel@tonic-gate * fpd is the D. file into which we now read 452*7c478bd9Sstevel@tonic-gate * input from stdin 453*7c478bd9Sstevel@tonic-gate */ 454*7c478bd9Sstevel@tonic-gate 455*7c478bd9Sstevel@tonic-gate gename(DATAPRE, Myname, 'B', dfile); 456*7c478bd9Sstevel@tonic-gate 457*7c478bd9Sstevel@tonic-gate ASSERT(access(dfile, 0) != 0, Fl_EXISTS, dfile, errno); 458*7c478bd9Sstevel@tonic-gate fpd = fdopen(ret = creat(dfile, DFILEMODE), "w"); 459*7c478bd9Sstevel@tonic-gate ASSERT(ret >= 0 && fpd != NULL, Ct_OPEN, dfile, errno); 460*7c478bd9Sstevel@tonic-gate 461*7c478bd9Sstevel@tonic-gate /* 462*7c478bd9Sstevel@tonic-gate * read pipe to EOF 463*7c478bd9Sstevel@tonic-gate */ 464*7c478bd9Sstevel@tonic-gate while (!feof(stdin)) { 465*7c478bd9Sstevel@tonic-gate ret = fread(buf, 1, BUFSIZ, stdin); 466*7c478bd9Sstevel@tonic-gate ASSERT(fwrite(buf, 1, ret, fpd) == ret, Ct_WRITE, 467*7c478bd9Sstevel@tonic-gate dfile, errno); 468*7c478bd9Sstevel@tonic-gate } 469*7c478bd9Sstevel@tonic-gate ASSERT(fflush(fpd) != EOF && ferror(fpd) == 0, Ct_WRITE, dfile, errno); 470*7c478bd9Sstevel@tonic-gate (void) fclose(fpd); 471*7c478bd9Sstevel@tonic-gate 472*7c478bd9Sstevel@tonic-gate /* 473*7c478bd9Sstevel@tonic-gate * if command is to be executed on remote 474*7c478bd9Sstevel@tonic-gate * create extra JCL 475*7c478bd9Sstevel@tonic-gate */ 476*7c478bd9Sstevel@tonic-gate if (!EQUALSN(Myname, xsys, MAXBASENAME)) { 477*7c478bd9Sstevel@tonic-gate GENSEND(fpc, dfile, dfile, dfile); 478*7c478bd9Sstevel@tonic-gate } 479*7c478bd9Sstevel@tonic-gate 480*7c478bd9Sstevel@tonic-gate /* 481*7c478bd9Sstevel@tonic-gate * create file for X_ commands 482*7c478bd9Sstevel@tonic-gate */ 483*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s\n", X_RQDFILE, dfile); 484*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s\n", X_STDIN, dfile); 485*7c478bd9Sstevel@tonic-gate 486*7c478bd9Sstevel@tonic-gate if (EQUALS(Myname, xsys)) 487*7c478bd9Sstevel@tonic-gate wfcommit(dfile, dfile, xsys); 488*7c478bd9Sstevel@tonic-gate 489*7c478bd9Sstevel@tonic-gate } 490*7c478bd9Sstevel@tonic-gate /* 491*7c478bd9Sstevel@tonic-gate * parse command 492*7c478bd9Sstevel@tonic-gate */ 493*7c478bd9Sstevel@tonic-gate ap = inargs; 494*7c478bd9Sstevel@tonic-gate while ((ap = getprm(ap, (char *)NULL, prm)) != NULL) { 495*7c478bd9Sstevel@tonic-gate DEBUG(4, "prm - %s\n", prm); 496*7c478bd9Sstevel@tonic-gate 497*7c478bd9Sstevel@tonic-gate /* 498*7c478bd9Sstevel@tonic-gate * redirection of I/O 499*7c478bd9Sstevel@tonic-gate */ 500*7c478bd9Sstevel@tonic-gate if ( prm[0] == '<' ) { 501*7c478bd9Sstevel@tonic-gate if (prm[1] == '<') { 502*7c478bd9Sstevel@tonic-gate fprintf(stderr, 503*7c478bd9Sstevel@tonic-gate gettext("'<<' may not be used in command\n")); 504*7c478bd9Sstevel@tonic-gate cleanup(EX_USAGE); 505*7c478bd9Sstevel@tonic-gate } 506*7c478bd9Sstevel@tonic-gate redir = X_STDIN; 507*7c478bd9Sstevel@tonic-gate continue; 508*7c478bd9Sstevel@tonic-gate } 509*7c478bd9Sstevel@tonic-gate if ( prm[0] == '>' ) { 510*7c478bd9Sstevel@tonic-gate if (prm[1] == '>') { 511*7c478bd9Sstevel@tonic-gate fprintf(stderr, 512*7c478bd9Sstevel@tonic-gate gettext("'>>' may not be used in command\n")); 513*7c478bd9Sstevel@tonic-gate cleanup(EX_USAGE); 514*7c478bd9Sstevel@tonic-gate } 515*7c478bd9Sstevel@tonic-gate if (prm[1] == '|') { 516*7c478bd9Sstevel@tonic-gate fprintf(stderr, 517*7c478bd9Sstevel@tonic-gate gettext("'>|' may not be used in command\n")); 518*7c478bd9Sstevel@tonic-gate cleanup(EX_USAGE); 519*7c478bd9Sstevel@tonic-gate } 520*7c478bd9Sstevel@tonic-gate if (prm[1] == '&') { 521*7c478bd9Sstevel@tonic-gate fprintf(stderr, 522*7c478bd9Sstevel@tonic-gate gettext("'>&' may not be used in command\n")); 523*7c478bd9Sstevel@tonic-gate cleanup(EX_USAGE); 524*7c478bd9Sstevel@tonic-gate } 525*7c478bd9Sstevel@tonic-gate redir = X_STDOUT; 526*7c478bd9Sstevel@tonic-gate continue; 527*7c478bd9Sstevel@tonic-gate } 528*7c478bd9Sstevel@tonic-gate if ( EQUALS(prm, "2>") ) { 529*7c478bd9Sstevel@tonic-gate redir = X_STDERR; 530*7c478bd9Sstevel@tonic-gate continue; 531*7c478bd9Sstevel@tonic-gate } 532*7c478bd9Sstevel@tonic-gate 533*7c478bd9Sstevel@tonic-gate /* 534*7c478bd9Sstevel@tonic-gate * some terminator 535*7c478bd9Sstevel@tonic-gate */ 536*7c478bd9Sstevel@tonic-gate if ( prm[0] == '|' || prm[0] == '^' 537*7c478bd9Sstevel@tonic-gate || prm[0] == '&' || prm[0] == ';') { 538*7c478bd9Sstevel@tonic-gate if (*cmd != '\0') /* not 1st thing on line */ 539*7c478bd9Sstevel@tonic-gate APPCMD(prm); 540*7c478bd9Sstevel@tonic-gate command = TRUE; 541*7c478bd9Sstevel@tonic-gate continue; 542*7c478bd9Sstevel@tonic-gate } 543*7c478bd9Sstevel@tonic-gate 544*7c478bd9Sstevel@tonic-gate /* 545*7c478bd9Sstevel@tonic-gate * process command or file or option 546*7c478bd9Sstevel@tonic-gate * break out system and file name and 547*7c478bd9Sstevel@tonic-gate * use default if necessary 548*7c478bd9Sstevel@tonic-gate */ 549*7c478bd9Sstevel@tonic-gate ret = split(prm, syspart, CNULL, rest); 550*7c478bd9Sstevel@tonic-gate DEBUG(4, "syspart -> %s, ", syspart); 551*7c478bd9Sstevel@tonic-gate DEBUG(4, "rest -> %s, ", rest); 552*7c478bd9Sstevel@tonic-gate DEBUG(4, "ret -> %d\n", ret); 553*7c478bd9Sstevel@tonic-gate 554*7c478bd9Sstevel@tonic-gate if (command && redir == '\0') { 555*7c478bd9Sstevel@tonic-gate /* 556*7c478bd9Sstevel@tonic-gate * command 557*7c478bd9Sstevel@tonic-gate */ 558*7c478bd9Sstevel@tonic-gate APPCMD(rest); 559*7c478bd9Sstevel@tonic-gate command = FALSE; 560*7c478bd9Sstevel@tonic-gate continue; 561*7c478bd9Sstevel@tonic-gate } 562*7c478bd9Sstevel@tonic-gate 563*7c478bd9Sstevel@tonic-gate if (syspart[0] == '\0') { 564*7c478bd9Sstevel@tonic-gate STRNCPY(syspart, Myname); 565*7c478bd9Sstevel@tonic-gate DEBUG(6, "syspart -> %s\n", syspart); 566*7c478bd9Sstevel@tonic-gate } else if (versys(syspart) != 0) { 567*7c478bd9Sstevel@tonic-gate /* 568*7c478bd9Sstevel@tonic-gate * bad system name 569*7c478bd9Sstevel@tonic-gate */ 570*7c478bd9Sstevel@tonic-gate fprintf(stderr, 571*7c478bd9Sstevel@tonic-gate gettext("bad system name: %s\n"), syspart); 572*7c478bd9Sstevel@tonic-gate if (fprx != NULL) 573*7c478bd9Sstevel@tonic-gate (void) fclose(fprx); 574*7c478bd9Sstevel@tonic-gate if (fpc != NULL) 575*7c478bd9Sstevel@tonic-gate (void) fclose(fpc); 576*7c478bd9Sstevel@tonic-gate cleanup(EX_NOHOST); 577*7c478bd9Sstevel@tonic-gate } 578*7c478bd9Sstevel@tonic-gate 579*7c478bd9Sstevel@tonic-gate /* 580*7c478bd9Sstevel@tonic-gate * process file or option 581*7c478bd9Sstevel@tonic-gate */ 582*7c478bd9Sstevel@tonic-gate 583*7c478bd9Sstevel@tonic-gate /* 584*7c478bd9Sstevel@tonic-gate * process file argument 585*7c478bd9Sstevel@tonic-gate * expand filename and create JCL card for 586*7c478bd9Sstevel@tonic-gate * redirected output 587*7c478bd9Sstevel@tonic-gate * e.g., X file sys 588*7c478bd9Sstevel@tonic-gate */ 589*7c478bd9Sstevel@tonic-gate if ((redir == X_STDOUT) || (redir == X_STDERR)) { 590*7c478bd9Sstevel@tonic-gate if (rest[0] != '~') 591*7c478bd9Sstevel@tonic-gate if (ckexpf(rest)) 592*7c478bd9Sstevel@tonic-gate cleanup(EX_OSERR); 593*7c478bd9Sstevel@tonic-gate ASSERT(fprintf(fprx, "%c %s %s\n", redir, rest, 594*7c478bd9Sstevel@tonic-gate syspart) >= 0, Ct_WRITE, rxfile, errno); 595*7c478bd9Sstevel@tonic-gate redir = '\0'; 596*7c478bd9Sstevel@tonic-gate continue; 597*7c478bd9Sstevel@tonic-gate } 598*7c478bd9Sstevel@tonic-gate 599*7c478bd9Sstevel@tonic-gate /* 600*7c478bd9Sstevel@tonic-gate * if no system specified, then being 601*7c478bd9Sstevel@tonic-gate * processed locally 602*7c478bd9Sstevel@tonic-gate */ 603*7c478bd9Sstevel@tonic-gate if (ret == NOSYSPART && redir == '\0') { 604*7c478bd9Sstevel@tonic-gate 605*7c478bd9Sstevel@tonic-gate /* 606*7c478bd9Sstevel@tonic-gate * option 607*7c478bd9Sstevel@tonic-gate */ 608*7c478bd9Sstevel@tonic-gate APPCMD(rest); 609*7c478bd9Sstevel@tonic-gate continue; 610*7c478bd9Sstevel@tonic-gate } 611*7c478bd9Sstevel@tonic-gate 612*7c478bd9Sstevel@tonic-gate 613*7c478bd9Sstevel@tonic-gate /* local xeqn + local file (!x !f) */ 614*7c478bd9Sstevel@tonic-gate if ((EQUALSN(xsys, Myname, MAXBASENAME)) 615*7c478bd9Sstevel@tonic-gate && (EQUALSN(xsys, syspart, MAXBASENAME))) { 616*7c478bd9Sstevel@tonic-gate /* 617*7c478bd9Sstevel@tonic-gate * create JCL card 618*7c478bd9Sstevel@tonic-gate */ 619*7c478bd9Sstevel@tonic-gate if (ckexpf(rest)) 620*7c478bd9Sstevel@tonic-gate cleanup(EX_OSERR); 621*7c478bd9Sstevel@tonic-gate /* 622*7c478bd9Sstevel@tonic-gate * JCL card for local input 623*7c478bd9Sstevel@tonic-gate * e.g., I file 624*7c478bd9Sstevel@tonic-gate */ 625*7c478bd9Sstevel@tonic-gate if (redir == X_STDIN) { 626*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s\n", X_STDIN, rest); 627*7c478bd9Sstevel@tonic-gate } else 628*7c478bd9Sstevel@tonic-gate APPCMD(rest); 629*7c478bd9Sstevel@tonic-gate ASSERT(fprx != NULL, Ct_WRITE, rxfile, errno); 630*7c478bd9Sstevel@tonic-gate redir = '\0'; 631*7c478bd9Sstevel@tonic-gate continue; 632*7c478bd9Sstevel@tonic-gate } 633*7c478bd9Sstevel@tonic-gate 634*7c478bd9Sstevel@tonic-gate /* remote xeqn + local file (sys!x !f) */ 635*7c478bd9Sstevel@tonic-gate if (EQUALSN(syspart, Myname, MAXBASENAME)) { 636*7c478bd9Sstevel@tonic-gate /* 637*7c478bd9Sstevel@tonic-gate * check access to local file 638*7c478bd9Sstevel@tonic-gate * if cflag is set, copy to spool directory 639*7c478bd9Sstevel@tonic-gate * otherwise, just mention it in the X. file 640*7c478bd9Sstevel@tonic-gate */ 641*7c478bd9Sstevel@tonic-gate if (ckexpf(rest)) 642*7c478bd9Sstevel@tonic-gate cleanup(EX_OSERR); 643*7c478bd9Sstevel@tonic-gate DEBUG(4, "rest %s\n", rest); 644*7c478bd9Sstevel@tonic-gate 645*7c478bd9Sstevel@tonic-gate /* see if I can read this file as read uid, gid */ 646*7c478bd9Sstevel@tonic-gate if (uidstat(rest, &stbuf) != 0) { 647*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 648*7c478bd9Sstevel@tonic-gate gettext("can't get file status %s\n"), rest); 649*7c478bd9Sstevel@tonic-gate cleanup(EX_OSERR); 650*7c478bd9Sstevel@tonic-gate } 651*7c478bd9Sstevel@tonic-gate /* XXX - doesn't check group list */ 652*7c478bd9Sstevel@tonic-gate if ( !(stbuf.st_mode & ANYREAD) 653*7c478bd9Sstevel@tonic-gate && !(stbuf.st_uid == Uid && stbuf.st_mode & 0400) 654*7c478bd9Sstevel@tonic-gate && !(stbuf.st_gid ==getgid() && stbuf.st_mode & 0040) 655*7c478bd9Sstevel@tonic-gate ) { 656*7c478bd9Sstevel@tonic-gate fprintf(stderr, 657*7c478bd9Sstevel@tonic-gate gettext("permission denied %s\n"), rest); 658*7c478bd9Sstevel@tonic-gate cleanup(EX_CANTCREAT); 659*7c478bd9Sstevel@tonic-gate } 660*7c478bd9Sstevel@tonic-gate 661*7c478bd9Sstevel@tonic-gate /* D. file for sending local file */ 662*7c478bd9Sstevel@tonic-gate gename(DATAPRE, xsys, 'A', dfile); 663*7c478bd9Sstevel@tonic-gate 664*7c478bd9Sstevel@tonic-gate if (cflag || !(stbuf.st_mode & ANYREAD)) { 665*7c478bd9Sstevel@tonic-gate /* make local copy */ 666*7c478bd9Sstevel@tonic-gate if (uidxcp(rest, dfile) != 0) { 667*7c478bd9Sstevel@tonic-gate fprintf(stderr, 668*7c478bd9Sstevel@tonic-gate gettext("can't copy %s\n"), rest); 669*7c478bd9Sstevel@tonic-gate cleanup(EX_CANTCREAT); 670*7c478bd9Sstevel@tonic-gate } 671*7c478bd9Sstevel@tonic-gate (void) chmod(dfile, DFILEMODE); 672*7c478bd9Sstevel@tonic-gate /* generate 'send' entry in command file */ 673*7c478bd9Sstevel@tonic-gate GENSEND(fpc, rest, dfile, dfile); 674*7c478bd9Sstevel@tonic-gate } else /* don't make local copy */ 675*7c478bd9Sstevel@tonic-gate GENSEND(fpc, rest, dfile, dfile); 676*7c478bd9Sstevel@tonic-gate 677*7c478bd9Sstevel@tonic-gate /* 678*7c478bd9Sstevel@tonic-gate * JCL cards for redirected input in X. file, 679*7c478bd9Sstevel@tonic-gate * e.g. 680*7c478bd9Sstevel@tonic-gate * I D.xxx 681*7c478bd9Sstevel@tonic-gate * F D.xxx 682*7c478bd9Sstevel@tonic-gate */ 683*7c478bd9Sstevel@tonic-gate if (redir == X_STDIN) { 684*7c478bd9Sstevel@tonic-gate /* 685*7c478bd9Sstevel@tonic-gate * don't bother making a X_RQDFILE line that 686*7c478bd9Sstevel@tonic-gate * renames stdin on the remote side, since the 687*7c478bd9Sstevel@tonic-gate * remote command can't know its name anyway 688*7c478bd9Sstevel@tonic-gate */ 689*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s\n", X_STDIN, dfile); 690*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s\n", X_RQDFILE, dfile); 691*7c478bd9Sstevel@tonic-gate } else { 692*7c478bd9Sstevel@tonic-gate APPCMD(BASENAME(rest, '/'));; 693*7c478bd9Sstevel@tonic-gate /* 694*7c478bd9Sstevel@tonic-gate * generate X. JCL card that specifies 695*7c478bd9Sstevel@tonic-gate * F file 696*7c478bd9Sstevel@tonic-gate */ 697*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s %s\n", X_RQDFILE, 698*7c478bd9Sstevel@tonic-gate dfile, BASENAME(rest, '/')); 699*7c478bd9Sstevel@tonic-gate } 700*7c478bd9Sstevel@tonic-gate redir = '\0'; 701*7c478bd9Sstevel@tonic-gate 702*7c478bd9Sstevel@tonic-gate continue; 703*7c478bd9Sstevel@tonic-gate } 704*7c478bd9Sstevel@tonic-gate 705*7c478bd9Sstevel@tonic-gate /* local xeqn + remote file (!x sys!f ) */ 706*7c478bd9Sstevel@tonic-gate if (EQUALS(Myname, xsys)) { 707*7c478bd9Sstevel@tonic-gate /* 708*7c478bd9Sstevel@tonic-gate * expand receive file name 709*7c478bd9Sstevel@tonic-gate */ 710*7c478bd9Sstevel@tonic-gate if (ckexpf(rest)) 711*7c478bd9Sstevel@tonic-gate cleanup(EX_OSERR); 712*7c478bd9Sstevel@tonic-gate /* 713*7c478bd9Sstevel@tonic-gate * strategy: 714*7c478bd9Sstevel@tonic-gate * request rest from syspart. when it arrives, 715*7c478bd9Sstevel@tonic-gate * we can run the command. 716*7c478bd9Sstevel@tonic-gate * 717*7c478bd9Sstevel@tonic-gate * tfile is command file for receive from remote. 718*7c478bd9Sstevel@tonic-gate * we defer commiting until later so 719*7c478bd9Sstevel@tonic-gate * that only one C. file is created per site. 720*7c478bd9Sstevel@tonic-gate * 721*7c478bd9Sstevel@tonic-gate * dfile is name of data file to receive into; 722*7c478bd9Sstevel@tonic-gate * we don't use it, just name it. 723*7c478bd9Sstevel@tonic-gate * 724*7c478bd9Sstevel@tonic-gate * once the data file arrives from syspart. 725*7c478bd9Sstevel@tonic-gate * arrange so that in the X. file (fprx), rest is 726*7c478bd9Sstevel@tonic-gate * required and named appropriately. this 727*7c478bd9Sstevel@tonic-gate * necessitates local access to SPOOL/syspart, which 728*7c478bd9Sstevel@tonic-gate * is handled by a hook in uuxqt that allows files 729*7c478bd9Sstevel@tonic-gate * in SPOOL/syspart to be renamed on the F line. 730*7c478bd9Sstevel@tonic-gate * 731*7c478bd9Sstevel@tonic-gate * pictorially: 732*7c478bd9Sstevel@tonic-gate * 733*7c478bd9Sstevel@tonic-gate * ===== syspart/C.syspart.... ===== (tfile) 734*7c478bd9Sstevel@tonic-gate * R rest D.syspart... (dfile) 735*7c478bd9Sstevel@tonic-gate * 736*7c478bd9Sstevel@tonic-gate * 737*7c478bd9Sstevel@tonic-gate * ===== local/X.local... ===== (fprx) 738*7c478bd9Sstevel@tonic-gate * F SPOOL/syspart/D.syspart... rest (dfile) 739*7c478bd9Sstevel@tonic-gate * 740*7c478bd9Sstevel@tonic-gate * 741*7c478bd9Sstevel@tonic-gate */ 742*7c478bd9Sstevel@tonic-gate if (gtcfile(tfile, syspart) != SUCCESS) { 743*7c478bd9Sstevel@tonic-gate gename(CMDPRE, syspart, 'R', tfile); 744*7c478bd9Sstevel@tonic-gate 745*7c478bd9Sstevel@tonic-gate ASSERT(access(tfile, 0) != 0, 746*7c478bd9Sstevel@tonic-gate Fl_EXISTS, tfile, errno); 747*7c478bd9Sstevel@tonic-gate svcfile(tfile, syspart, Sgrade); 748*7c478bd9Sstevel@tonic-gate (void) close(creat(tfile, CFILEMODE)); 749*7c478bd9Sstevel@tonic-gate } 750*7c478bd9Sstevel@tonic-gate fp = fopen(tfile, "a"); 751*7c478bd9Sstevel@tonic-gate ASSERT(fp != NULL, Ct_OPEN, tfile, errno); 752*7c478bd9Sstevel@tonic-gate setbuf(fp, CNULL); 753*7c478bd9Sstevel@tonic-gate gename(DATAPRE, syspart, 'R', dfile); 754*7c478bd9Sstevel@tonic-gate 755*7c478bd9Sstevel@tonic-gate /* prepare JCL card to receive file */ 756*7c478bd9Sstevel@tonic-gate GENRCV(fp, rest, dfile); 757*7c478bd9Sstevel@tonic-gate ASSERT(fflush(fp) != EOF && ferror(fp) == 0, Ct_WRITE, dfile, errno); 758*7c478bd9Sstevel@tonic-gate (void) fclose(fp); 759*7c478bd9Sstevel@tonic-gate if (rest[0] != '~') 760*7c478bd9Sstevel@tonic-gate if (ckexpf(rest)) 761*7c478bd9Sstevel@tonic-gate cleanup(EX_OSERR); 762*7c478bd9Sstevel@tonic-gate 763*7c478bd9Sstevel@tonic-gate /* 764*7c478bd9Sstevel@tonic-gate * generate receive entries 765*7c478bd9Sstevel@tonic-gate */ 766*7c478bd9Sstevel@tonic-gate if (redir == X_STDIN) { 767*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx, 768*7c478bd9Sstevel@tonic-gate "%c %s/%s/%s\n", X_RQDFILE, Spool, 769*7c478bd9Sstevel@tonic-gate syspart, dfile); 770*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s\n", X_STDIN, dfile); 771*7c478bd9Sstevel@tonic-gate } else { 772*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s/%s/%s %s\n", 773*7c478bd9Sstevel@tonic-gate X_RQDFILE, Spool, syspart, dfile, 774*7c478bd9Sstevel@tonic-gate BASENAME(rest, '/')); 775*7c478bd9Sstevel@tonic-gate APPCMD(BASENAME(rest, '/')); 776*7c478bd9Sstevel@tonic-gate } 777*7c478bd9Sstevel@tonic-gate 778*7c478bd9Sstevel@tonic-gate redir = '\0'; 779*7c478bd9Sstevel@tonic-gate continue; 780*7c478bd9Sstevel@tonic-gate } 781*7c478bd9Sstevel@tonic-gate 782*7c478bd9Sstevel@tonic-gate /* remote xeqn/file, different remotes (xsys!cmd syspart!rest) */ 783*7c478bd9Sstevel@tonic-gate if (!EQUALS(syspart, xsys)) { 784*7c478bd9Sstevel@tonic-gate /* 785*7c478bd9Sstevel@tonic-gate * strategy: 786*7c478bd9Sstevel@tonic-gate * request rest from syspart. 787*7c478bd9Sstevel@tonic-gate * 788*7c478bd9Sstevel@tonic-gate * set up a local X. file that will send rest to xsys, 789*7c478bd9Sstevel@tonic-gate * once it arrives from syspart. 790*7c478bd9Sstevel@tonic-gate * 791*7c478bd9Sstevel@tonic-gate * arrange so that in the xsys D. file (fated to become 792*7c478bd9Sstevel@tonic-gate * an X. file on xsys), rest is required and named. 793*7c478bd9Sstevel@tonic-gate * 794*7c478bd9Sstevel@tonic-gate * pictorially: 795*7c478bd9Sstevel@tonic-gate * 796*7c478bd9Sstevel@tonic-gate * ===== syspart/C.syspart.... ===== (tfile) 797*7c478bd9Sstevel@tonic-gate * R rest D.syspart... (dfile) 798*7c478bd9Sstevel@tonic-gate * 799*7c478bd9Sstevel@tonic-gate * 800*7c478bd9Sstevel@tonic-gate * ===== local/X.local... ===== (t2file) 801*7c478bd9Sstevel@tonic-gate * F Spool/syspart/D.syspart... rest (dfile) 802*7c478bd9Sstevel@tonic-gate * C uucp -C rest D.syspart... (dfile) 803*7c478bd9Sstevel@tonic-gate * 804*7c478bd9Sstevel@tonic-gate * ===== xsys/D.xsysG.... (fprx) 805*7c478bd9Sstevel@tonic-gate * F D.syspart... rest (dfile) 806*7c478bd9Sstevel@tonic-gate * or, in the case of redir == '<' 807*7c478bd9Sstevel@tonic-gate * F D.syspart... (dfile) 808*7c478bd9Sstevel@tonic-gate * I D.syspart... (dfile) 809*7c478bd9Sstevel@tonic-gate * 810*7c478bd9Sstevel@tonic-gate * while we do push rest around a bunch, 811*7c478bd9Sstevel@tonic-gate * we use the protection scheme to good effect. 812*7c478bd9Sstevel@tonic-gate * 813*7c478bd9Sstevel@tonic-gate * we must rely on uucp's treatment of requests 814*7c478bd9Sstevel@tonic-gate * from XQTDIR to get the data file to the right 815*7c478bd9Sstevel@tonic-gate * place ultimately. 816*7c478bd9Sstevel@tonic-gate */ 817*7c478bd9Sstevel@tonic-gate 818*7c478bd9Sstevel@tonic-gate /* build (or append to) C.syspart... */ 819*7c478bd9Sstevel@tonic-gate if (gtcfile(tfile, syspart) != SUCCESS) { 820*7c478bd9Sstevel@tonic-gate gename(CMDPRE, syspart, 'R', tfile); 821*7c478bd9Sstevel@tonic-gate 822*7c478bd9Sstevel@tonic-gate ASSERT(access(tfile, 0) != 0, 823*7c478bd9Sstevel@tonic-gate Fl_EXISTS, tfile, errno); 824*7c478bd9Sstevel@tonic-gate svcfile(tfile, syspart, Sgrade); 825*7c478bd9Sstevel@tonic-gate (void) close(creat(tfile, CFILEMODE)); 826*7c478bd9Sstevel@tonic-gate } 827*7c478bd9Sstevel@tonic-gate fp = fopen(tfile, "a"); 828*7c478bd9Sstevel@tonic-gate ASSERT(fp != NULL, Ct_OPEN, tfile, errno); 829*7c478bd9Sstevel@tonic-gate setbuf(fp, CNULL); 830*7c478bd9Sstevel@tonic-gate gename(DATAPRE, syspart, 'R', dfile); 831*7c478bd9Sstevel@tonic-gate GENRCV(fp, rest, dfile); 832*7c478bd9Sstevel@tonic-gate ASSERT(fflush(fp) != EOF && ferror(fp) == 0, Ct_WRITE, dfile, errno); 833*7c478bd9Sstevel@tonic-gate (void) fclose(fp); 834*7c478bd9Sstevel@tonic-gate 835*7c478bd9Sstevel@tonic-gate /* build local/X.localG... */ 836*7c478bd9Sstevel@tonic-gate /* name might collide with rxfile; no real danger */ 837*7c478bd9Sstevel@tonic-gate gename(XQTPRE, Myname, Grade, t2file); 838*7c478bd9Sstevel@tonic-gate ASSERT(access(t2file, 0)!=0, Fl_EXISTS, t2file, errno); 839*7c478bd9Sstevel@tonic-gate (void) close(creat(t2file, CFILEMODE)); 840*7c478bd9Sstevel@tonic-gate fp = fopen(t2file, "w"); 841*7c478bd9Sstevel@tonic-gate ASSERT(fp != NULL, Ct_OPEN, t2file, errno); 842*7c478bd9Sstevel@tonic-gate setbuf(fp, CNULL); 843*7c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%c third party request, job id\n", 844*7c478bd9Sstevel@tonic-gate X_COMMENT); 845*7c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%c %s\n", X_JOBID, Jobid); 846*7c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%c %s/%s/%s %s\n", X_RQDFILE, 847*7c478bd9Sstevel@tonic-gate Spool, syspart, dfile, BASENAME(rest, '/')); 848*7c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%c uucp -C %s %s!%s\n", 849*7c478bd9Sstevel@tonic-gate X_CMD, BASENAME(rest, '/'), xsys, dfile); 850*7c478bd9Sstevel@tonic-gate ASSERT(fflush(fp) != EOF && ferror(fp) == 0, Ct_WRITE, t2file, errno); 851*7c478bd9Sstevel@tonic-gate (void) fclose(fp); 852*7c478bd9Sstevel@tonic-gate 853*7c478bd9Sstevel@tonic-gate /* put t2file where uuxqt can get at it */ 854*7c478bd9Sstevel@tonic-gate wfcommit(t2file, t2file, Myname); 855*7c478bd9Sstevel@tonic-gate 856*7c478bd9Sstevel@tonic-gate /* generate xsys/X.sysG... cards */ 857*7c478bd9Sstevel@tonic-gate if (redir == X_STDIN) { 858*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s\n", 859*7c478bd9Sstevel@tonic-gate X_RQDFILE, dfile); 860*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s\n", X_STDIN, dfile); 861*7c478bd9Sstevel@tonic-gate } else { 862*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s %s\n", X_RQDFILE, 863*7c478bd9Sstevel@tonic-gate dfile, BASENAME(rest, '/')); 864*7c478bd9Sstevel@tonic-gate APPCMD(BASENAME(rest, '/')); 865*7c478bd9Sstevel@tonic-gate } 866*7c478bd9Sstevel@tonic-gate redir = '\0'; 867*7c478bd9Sstevel@tonic-gate continue; 868*7c478bd9Sstevel@tonic-gate } 869*7c478bd9Sstevel@tonic-gate 870*7c478bd9Sstevel@tonic-gate /* remote xeqn + remote file, same remote (sys!x sys!f) */ 871*7c478bd9Sstevel@tonic-gate if (rest[0] != '~') /* expand '~' on remote */ 872*7c478bd9Sstevel@tonic-gate if (ckexpf(rest)) 873*7c478bd9Sstevel@tonic-gate cleanup(EX_OSERR); 874*7c478bd9Sstevel@tonic-gate if (redir == X_STDIN) { 875*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s\n", X_STDIN, rest); 876*7c478bd9Sstevel@tonic-gate } 877*7c478bd9Sstevel@tonic-gate else 878*7c478bd9Sstevel@tonic-gate APPCMD(rest); 879*7c478bd9Sstevel@tonic-gate redir = '\0'; 880*7c478bd9Sstevel@tonic-gate continue; 881*7c478bd9Sstevel@tonic-gate 882*7c478bd9Sstevel@tonic-gate } 883*7c478bd9Sstevel@tonic-gate 884*7c478bd9Sstevel@tonic-gate /* 885*7c478bd9Sstevel@tonic-gate * place command to be executed in JCL file 886*7c478bd9Sstevel@tonic-gate */ 887*7c478bd9Sstevel@tonic-gate (void) fprintf(fprx, "%c %s\n", X_CMD, cmd); 888*7c478bd9Sstevel@tonic-gate ASSERT(fflush(fprx) != EOF && ferror(fprx) == 0, Ct_WRITE, rxfile, errno); 889*7c478bd9Sstevel@tonic-gate (void) fclose(fprx); /* rxfile is ready for commit */ 890*7c478bd9Sstevel@tonic-gate logent(cmd, "QUEUED"); 891*7c478bd9Sstevel@tonic-gate 892*7c478bd9Sstevel@tonic-gate gename(XQTPRE, Myname, Grade, tfile); 893*7c478bd9Sstevel@tonic-gate if (EQUALS(xsys, Myname)) { 894*7c478bd9Sstevel@tonic-gate /* local xeqn -- use X_ file here */ 895*7c478bd9Sstevel@tonic-gate /* this use of the X_ file can not collide with the earlier one */ 896*7c478bd9Sstevel@tonic-gate wfcommit(rxfile, tfile, xsys); 897*7c478bd9Sstevel@tonic-gate 898*7c478bd9Sstevel@tonic-gate /* 899*7c478bd9Sstevel@tonic-gate * see if -r option requested JCL to be queued only 900*7c478bd9Sstevel@tonic-gate */ 901*7c478bd9Sstevel@tonic-gate if (startjob) 902*7c478bd9Sstevel@tonic-gate xuuxqt(Myname); 903*7c478bd9Sstevel@tonic-gate } else { 904*7c478bd9Sstevel@tonic-gate /* remote xeqn -- send rxfile to remote */ 905*7c478bd9Sstevel@tonic-gate /* put it in a place where cico can get at it */ 906*7c478bd9Sstevel@tonic-gate /* X_ file name might collide with an earlier use, */ 907*7c478bd9Sstevel@tonic-gate /* but that one lives locally, while this one gets shipped */ 908*7c478bd9Sstevel@tonic-gate 909*7c478bd9Sstevel@tonic-gate GENSEND(fpc, rxfile, tfile, rxfile); 910*7c478bd9Sstevel@tonic-gate } 911*7c478bd9Sstevel@tonic-gate 912*7c478bd9Sstevel@tonic-gate cfileUsed = (ftell(fpc) != 0L); /* was cfile used? */ 913*7c478bd9Sstevel@tonic-gate ASSERT(fflush(fpc) != EOF && ferror(fpc) == 0, Ct_WRITE, cfile, errno); 914*7c478bd9Sstevel@tonic-gate (void) fclose(fpc); 915*7c478bd9Sstevel@tonic-gate 916*7c478bd9Sstevel@tonic-gate /* commit C. files for remote receive */ 917*7c478bd9Sstevel@tonic-gate 918*7c478bd9Sstevel@tonic-gate commitall(); 919*7c478bd9Sstevel@tonic-gate 920*7c478bd9Sstevel@tonic-gate /* 921*7c478bd9Sstevel@tonic-gate * has any command been placed in command JCL file 922*7c478bd9Sstevel@tonic-gate */ 923*7c478bd9Sstevel@tonic-gate if (cfileUsed) { 924*7c478bd9Sstevel@tonic-gate 925*7c478bd9Sstevel@tonic-gate svcfile(cfile, xsys, Sgrade); 926*7c478bd9Sstevel@tonic-gate commitall(); 927*7c478bd9Sstevel@tonic-gate 928*7c478bd9Sstevel@tonic-gate /* 929*7c478bd9Sstevel@tonic-gate * see if -r option requested JCL to be queued only 930*7c478bd9Sstevel@tonic-gate */ 931*7c478bd9Sstevel@tonic-gate if (startjob) 932*7c478bd9Sstevel@tonic-gate xuucico(xsys); 933*7c478bd9Sstevel@tonic-gate } else 934*7c478bd9Sstevel@tonic-gate unlink(cfile); 935*7c478bd9Sstevel@tonic-gate 936*7c478bd9Sstevel@tonic-gate if (jflag) { /* print Jobid */ 937*7c478bd9Sstevel@tonic-gate STRNCPY(Jobid, jid()); 938*7c478bd9Sstevel@tonic-gate printf("%s\n", Jobid); 939*7c478bd9Sstevel@tonic-gate } 940*7c478bd9Sstevel@tonic-gate 941*7c478bd9Sstevel@tonic-gate cleanup(0); 942*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 943*7c478bd9Sstevel@tonic-gate } 944*7c478bd9Sstevel@tonic-gate 945*7c478bd9Sstevel@tonic-gate 946*7c478bd9Sstevel@tonic-gate /* 947*7c478bd9Sstevel@tonic-gate * cleanup and unlink if error 948*7c478bd9Sstevel@tonic-gate * code -> exit code 949*7c478bd9Sstevel@tonic-gate * return: 950*7c478bd9Sstevel@tonic-gate * none 951*7c478bd9Sstevel@tonic-gate */ 952*7c478bd9Sstevel@tonic-gate void 953*7c478bd9Sstevel@tonic-gate cleanup(code) 954*7c478bd9Sstevel@tonic-gate register int code; 955*7c478bd9Sstevel@tonic-gate { 956*7c478bd9Sstevel@tonic-gate static int first = 1; 957*7c478bd9Sstevel@tonic-gate 958*7c478bd9Sstevel@tonic-gate /* prevent recursion on errors */ 959*7c478bd9Sstevel@tonic-gate if (first) { 960*7c478bd9Sstevel@tonic-gate first = 0; 961*7c478bd9Sstevel@tonic-gate rmlock(CNULL); 962*7c478bd9Sstevel@tonic-gate if (code) { 963*7c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("uux failed ( %d )\n"), code); 964*7c478bd9Sstevel@tonic-gate wfabort(); 965*7c478bd9Sstevel@tonic-gate } 966*7c478bd9Sstevel@tonic-gate } 967*7c478bd9Sstevel@tonic-gate DEBUG(1, "exit code %d\n", code); 968*7c478bd9Sstevel@tonic-gate if (code < 0) 969*7c478bd9Sstevel@tonic-gate exit(-code); 970*7c478bd9Sstevel@tonic-gate else 971*7c478bd9Sstevel@tonic-gate exit(code); 972*7c478bd9Sstevel@tonic-gate } 973*7c478bd9Sstevel@tonic-gate 974*7c478bd9Sstevel@tonic-gate /* 975*7c478bd9Sstevel@tonic-gate * catch signal then cleanup and exit 976*7c478bd9Sstevel@tonic-gate */ 977*7c478bd9Sstevel@tonic-gate static void 978*7c478bd9Sstevel@tonic-gate onintr(inter) 979*7c478bd9Sstevel@tonic-gate register int inter; 980*7c478bd9Sstevel@tonic-gate { 981*7c478bd9Sstevel@tonic-gate char str[30]; 982*7c478bd9Sstevel@tonic-gate (void) signal(inter, SIG_IGN); 983*7c478bd9Sstevel@tonic-gate (void) sprintf(str, "XSIGNAL %d", inter); 984*7c478bd9Sstevel@tonic-gate logent(str, "XCAUGHT"); 985*7c478bd9Sstevel@tonic-gate cleanup(EX_TEMPFAIL); 986*7c478bd9Sstevel@tonic-gate } 987*7c478bd9Sstevel@tonic-gate 988*7c478bd9Sstevel@tonic-gate 989*7c478bd9Sstevel@tonic-gate static void 990*7c478bd9Sstevel@tonic-gate usage() 991*7c478bd9Sstevel@tonic-gate { 992*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Usage: %s [-bcCjnprz] [-a NAME]" 993*7c478bd9Sstevel@tonic-gate " [-g GRADE] [-s FILE] [-x NUM] command-string\n"), Progname); 994*7c478bd9Sstevel@tonic-gate exit(EX_USAGE); 995*7c478bd9Sstevel@tonic-gate } 996