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
27*462be471Sceastha /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*462be471Sceastha /* All Rights Reserved */
29*462be471Sceastha
307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate #include "uucp.h"
337c478bd9Sstevel@tonic-gate #include "log.h"
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate * execute commands set up by a uux command,
377c478bd9Sstevel@tonic-gate * usually from a remote machine - set by uucp.
387c478bd9Sstevel@tonic-gate */
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate #ifndef V7
417c478bd9Sstevel@tonic-gate #define LOGNAME "LOGNAME=uucp"
427c478bd9Sstevel@tonic-gate #else
437c478bd9Sstevel@tonic-gate #define LOGNAME "USER=uucp"
447c478bd9Sstevel@tonic-gate #endif
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate #define C_COMMAND 1
477c478bd9Sstevel@tonic-gate #define C_FILE 2
487c478bd9Sstevel@tonic-gate #define BAD_COMMAND 1
497c478bd9Sstevel@tonic-gate #define BAD_FILE 2
507c478bd9Sstevel@tonic-gate #define USAGEPREFIX "Usage:"
517c478bd9Sstevel@tonic-gate #define USAGE "[-x DEBUG] [-s SYSTEM]"
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate char _Xfile[MAXFULLNAME];
547c478bd9Sstevel@tonic-gate char _Cmd[2 * BUFSIZ]; /* build up command buffer */
557c478bd9Sstevel@tonic-gate int _CargType; /* argument type of next C argument */
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate static void retosndr(), uucpst();
587c478bd9Sstevel@tonic-gate static int chkFile();
597c478bd9Sstevel@tonic-gate static int doFileChk();
607c478bd9Sstevel@tonic-gate void cleanup(), xprocess();
617c478bd9Sstevel@tonic-gate
62*462be471Sceastha int
main(argc,argv,envp)637c478bd9Sstevel@tonic-gate main(argc, argv, envp)
64*462be471Sceastha int argc;
657c478bd9Sstevel@tonic-gate char *argv[];
667c478bd9Sstevel@tonic-gate char *envp[];
677c478bd9Sstevel@tonic-gate {
687c478bd9Sstevel@tonic-gate DIR *fp1;
697c478bd9Sstevel@tonic-gate struct limits limitval;
707c478bd9Sstevel@tonic-gate int ret, maxnumb;
717c478bd9Sstevel@tonic-gate char dirname[MAXFULLNAME], lockname[MAXFULLNAME];
727c478bd9Sstevel@tonic-gate void onintr();
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate /* Set locale environment variables local definitions */
757c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
767c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
777c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */
787c478bd9Sstevel@tonic-gate #endif
797c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate (void) signal(SIGILL, onintr);
827c478bd9Sstevel@tonic-gate (void) signal(SIGTRAP, onintr);
837c478bd9Sstevel@tonic-gate (void) signal(SIGIOT, onintr);
847c478bd9Sstevel@tonic-gate (void) signal(SIGEMT, onintr);
857c478bd9Sstevel@tonic-gate (void) signal(SIGFPE, onintr);
867c478bd9Sstevel@tonic-gate (void) signal(SIGBUS, onintr);
877c478bd9Sstevel@tonic-gate (void) signal(SIGSEGV, onintr);
887c478bd9Sstevel@tonic-gate (void) signal(SIGSYS, onintr);
897c478bd9Sstevel@tonic-gate (void) signal(SIGPIPE, onintr);
907c478bd9Sstevel@tonic-gate (void) signal(SIGTERM, SIG_IGN);
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate /* choose LOGFILE */
937c478bd9Sstevel@tonic-gate (void) strcpy(Logfile, LOGUUXQT);
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate /*
967c478bd9Sstevel@tonic-gate * get local system name
977c478bd9Sstevel@tonic-gate */
987c478bd9Sstevel@tonic-gate Env = envp;
997c478bd9Sstevel@tonic-gate Nstat.t_qtime = time((time_t *)0);
1007c478bd9Sstevel@tonic-gate (void) strcpy(Progname, "uuxqt");
1017c478bd9Sstevel@tonic-gate Pchar = 'Q';
1027c478bd9Sstevel@tonic-gate uucpname(Myname);
1037c478bd9Sstevel@tonic-gate Ofn = 1;
1047c478bd9Sstevel@tonic-gate Ifn = 0;
1057c478bd9Sstevel@tonic-gate dirname[0] = dirname[MAXFULLNAME-1] = NULLCHAR;
1067c478bd9Sstevel@tonic-gate while ((ret = getopt(argc, argv, "s:x:")) != EOF) {
1077c478bd9Sstevel@tonic-gate switch (ret) {
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate /*
1107c478bd9Sstevel@tonic-gate * debugging level
1117c478bd9Sstevel@tonic-gate */
1127c478bd9Sstevel@tonic-gate case 'x':
1137c478bd9Sstevel@tonic-gate Debug = atoi(optarg);
1147c478bd9Sstevel@tonic-gate if (Debug <= 0)
1157c478bd9Sstevel@tonic-gate Debug = 1;
1167c478bd9Sstevel@tonic-gate break;
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gate case 's':
1197c478bd9Sstevel@tonic-gate /*
1207c478bd9Sstevel@tonic-gate * fake out uuxqt and use the argument as if
1217c478bd9Sstevel@tonic-gate * it were the spool directory for the purpose
1227c478bd9Sstevel@tonic-gate * of determining what subdirectories to search
1237c478bd9Sstevel@tonic-gate * EX: mkdir /tmp/foo; touch /tmp/foo/[baz, gorp]
1247c478bd9Sstevel@tonic-gate * uuxqt -s/tmp/foo
1257c478bd9Sstevel@tonic-gate * this will cause uuxqt to only run on the sub
1267c478bd9Sstevel@tonic-gate * baz and gorp in the Spool directory. Trust me.
1277c478bd9Sstevel@tonic-gate */
1287c478bd9Sstevel@tonic-gate (void) strlcpy(dirname, optarg,
1297c478bd9Sstevel@tonic-gate (MAXFULLNAME - sizeof (SEQLOCK)));
1307c478bd9Sstevel@tonic-gate break;
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate default:
1337c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s %s %s\n",
1347c478bd9Sstevel@tonic-gate gettext(USAGEPREFIX), Progname, gettext(USAGE));
1357c478bd9Sstevel@tonic-gate exit(1);
1367c478bd9Sstevel@tonic-gate }
1377c478bd9Sstevel@tonic-gate }
1387c478bd9Sstevel@tonic-gate if (argc != optind) {
1397c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s %s %s\n",
1407c478bd9Sstevel@tonic-gate gettext(USAGEPREFIX), Progname, gettext(USAGE));
1417c478bd9Sstevel@tonic-gate exit(1);
1427c478bd9Sstevel@tonic-gate }
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate DEBUG(4, "\n\n** START **\n%s", "");
1457c478bd9Sstevel@tonic-gate acInit("rexe");
1467c478bd9Sstevel@tonic-gate scInit("rexe");
1477c478bd9Sstevel@tonic-gate if (scanlimit("uuxqt", &limitval) == FAIL) {
1487c478bd9Sstevel@tonic-gate DEBUG(1, "No limits for uuxqt in %s\n", LIMITS);
1497c478bd9Sstevel@tonic-gate } else {
1507c478bd9Sstevel@tonic-gate maxnumb = limitval.totalmax;
1517c478bd9Sstevel@tonic-gate if (maxnumb < 0) {
1527c478bd9Sstevel@tonic-gate DEBUG(4, "Non-positive limit for uuxqt in %s\n", LIMITS);
1537c478bd9Sstevel@tonic-gate DEBUG(1, "No limits for uuxqt\n%s", "");
1547c478bd9Sstevel@tonic-gate } else {
1557c478bd9Sstevel@tonic-gate DEBUG(4, "Uuxqt limit %d -- ", maxnumb);
1567c478bd9Sstevel@tonic-gate ret = cuantos(X_LOCKPRE, X_LOCKDIR);
1577c478bd9Sstevel@tonic-gate DEBUG(4, "found %d -- ", ret);
1587c478bd9Sstevel@tonic-gate if (maxnumb >= 0 && ret >= maxnumb) {
1597c478bd9Sstevel@tonic-gate DEBUG(4, "exiting.%s\n", "");
1607c478bd9Sstevel@tonic-gate exit(0);
1617c478bd9Sstevel@tonic-gate }
1627c478bd9Sstevel@tonic-gate DEBUG(4, "continuing.%s\n", "");
1637c478bd9Sstevel@tonic-gate }
1647c478bd9Sstevel@tonic-gate }
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gate /*
1677c478bd9Sstevel@tonic-gate * determine user who started uuxqt (in principle)
1687c478bd9Sstevel@tonic-gate */
1697c478bd9Sstevel@tonic-gate strcpy(User, "uucp"); /* in case all else fails (can't happen) */
1707c478bd9Sstevel@tonic-gate Uid = getuid();
1717c478bd9Sstevel@tonic-gate Euid = geteuid(); /* this should be UUCPUID */
1727c478bd9Sstevel@tonic-gate guinfo(Euid, User);
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate if (Uid == 0)
1757c478bd9Sstevel@tonic-gate (void) setuid(UUCPUID);
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate setuucp(User);
1787c478bd9Sstevel@tonic-gate DEBUG(4, "User - %s\n", User);
1797c478bd9Sstevel@tonic-gate guinfo(Uid, Loginuser);
1807c478bd9Sstevel@tonic-gate
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate DEBUG(4, "process\n%s", "");
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate fp1 = opendir(Spool);
1867c478bd9Sstevel@tonic-gate ASSERT(fp1 != NULL, Ct_OPEN, Spool, errno);
1877c478bd9Sstevel@tonic-gate if (dirname[0] != NULLCHAR) {
1887c478bd9Sstevel@tonic-gate /* look for special characters in remote name */
1897c478bd9Sstevel@tonic-gate if (strpbrk(dirname, Shchar) != NULL) {
1907c478bd9Sstevel@tonic-gate /* ignore naughty name */
1917c478bd9Sstevel@tonic-gate DEBUG(4, "Bad remote name '%s'", dirname);
1927c478bd9Sstevel@tonic-gate errent("BAD REMOTE NAME", dirname, 0, __FILE__, __LINE__);
1937c478bd9Sstevel@tonic-gate closedir(fp1);
1947c478bd9Sstevel@tonic-gate cleanup(101);
1957c478bd9Sstevel@tonic-gate }
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate (void) snprintf(lockname, sizeof (lockname), "%s.%s",
1997c478bd9Sstevel@tonic-gate X_LOCK, dirname);
2007c478bd9Sstevel@tonic-gate if (mklock(lockname) == SUCCESS) {
2017c478bd9Sstevel@tonic-gate xprocess(dirname);
2027c478bd9Sstevel@tonic-gate rmlock(CNULL);
2037c478bd9Sstevel@tonic-gate }
2047c478bd9Sstevel@tonic-gate } else {
2057c478bd9Sstevel@tonic-gate while (gdirf(fp1, dirname, Spool) == TRUE) {
2067c478bd9Sstevel@tonic-gate if (strpbrk(dirname, Shchar) != NULL) {
2077c478bd9Sstevel@tonic-gate /* skip naughty names */
2087c478bd9Sstevel@tonic-gate errent("BAD REMOTE NAME", dirname, 0,
2097c478bd9Sstevel@tonic-gate __FILE__, __LINE__);
2107c478bd9Sstevel@tonic-gate continue;
2117c478bd9Sstevel@tonic-gate }
2127c478bd9Sstevel@tonic-gate (void) snprintf(lockname, sizeof (lockname), "%s.%s",
2137c478bd9Sstevel@tonic-gate X_LOCK, dirname);
2147c478bd9Sstevel@tonic-gate if (mklock(lockname) != SUCCESS)
2157c478bd9Sstevel@tonic-gate continue;
2167c478bd9Sstevel@tonic-gate xprocess(dirname);
2177c478bd9Sstevel@tonic-gate rmlock(CNULL);
2187c478bd9Sstevel@tonic-gate }
2197c478bd9Sstevel@tonic-gate }
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate closedir(fp1);
2227c478bd9Sstevel@tonic-gate cleanup(0);
2237c478bd9Sstevel@tonic-gate /* NOTREACHED */
224*462be471Sceastha return (0);
2257c478bd9Sstevel@tonic-gate }
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate void
cleanup(code)2287c478bd9Sstevel@tonic-gate cleanup(code)
2297c478bd9Sstevel@tonic-gate int code;
2307c478bd9Sstevel@tonic-gate {
2317c478bd9Sstevel@tonic-gate rmlock(CNULL);
2327c478bd9Sstevel@tonic-gate exit(code);
2337c478bd9Sstevel@tonic-gate }
2347c478bd9Sstevel@tonic-gate
2357c478bd9Sstevel@tonic-gate /*
2367c478bd9Sstevel@tonic-gate * catch signal then cleanup and exit
2377c478bd9Sstevel@tonic-gate */
2387c478bd9Sstevel@tonic-gate void
onintr(inter)2397c478bd9Sstevel@tonic-gate onintr(inter)
240*462be471Sceastha int inter;
2417c478bd9Sstevel@tonic-gate {
2427c478bd9Sstevel@tonic-gate char str[30];
2437c478bd9Sstevel@tonic-gate (void) signal(inter, SIG_IGN);
2447c478bd9Sstevel@tonic-gate (void) sprintf(str, "QSIGNAL %d", inter);
2457c478bd9Sstevel@tonic-gate logent(str, "QCAUGHT");
2467c478bd9Sstevel@tonic-gate acEndexe(cpucycle(), PARTIAL); /* stop collecting accounting log */
2477c478bd9Sstevel@tonic-gate cleanup(-inter);
2487c478bd9Sstevel@tonic-gate }
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate #define XCACHESIZE (4096 / (MAXBASENAME + 1))
2517c478bd9Sstevel@tonic-gate static char xcache[XCACHESIZE][MAXBASENAME + 1]; /* cache for X. files */
2527c478bd9Sstevel@tonic-gate static int xcachesize = 0; /* how many left? */
2537c478bd9Sstevel@tonic-gate
2547c478bd9Sstevel@tonic-gate /*
2557c478bd9Sstevel@tonic-gate * stash an X. file so we can process them sorted first by grade, then by
2567c478bd9Sstevel@tonic-gate * sequence number
2577c478bd9Sstevel@tonic-gate */
2587c478bd9Sstevel@tonic-gate static void
xstash(file)2597c478bd9Sstevel@tonic-gate xstash(file)
2607c478bd9Sstevel@tonic-gate char *file;
2617c478bd9Sstevel@tonic-gate {
2627c478bd9Sstevel@tonic-gate if (xcachesize < XCACHESIZE) {
2637c478bd9Sstevel@tonic-gate DEBUG(4, "stashing %s\n", file);
2647c478bd9Sstevel@tonic-gate (void) strlcpy(xcache[xcachesize++], file, (MAXBASENAME + 1));
2657c478bd9Sstevel@tonic-gate }
2667c478bd9Sstevel@tonic-gate }
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate /*
2697c478bd9Sstevel@tonic-gate * xcompare
2707c478bd9Sstevel@tonic-gate * comparison routine for for qsort()
2717c478bd9Sstevel@tonic-gate */
2727c478bd9Sstevel@tonic-gate static int
xcompare(f1,f2)2737c478bd9Sstevel@tonic-gate xcompare(f1, f2)
274*462be471Sceastha const void *f1, *f2;
2757c478bd9Sstevel@tonic-gate {
2767c478bd9Sstevel@tonic-gate /* assumes file name is X.siteG1234 */
2777c478bd9Sstevel@tonic-gate /* use -strcmp() so that xstash is sorted largest first */
2787c478bd9Sstevel@tonic-gate /* pull files out of the stash from largest index to smallest */
2797c478bd9Sstevel@tonic-gate
2807c478bd9Sstevel@tonic-gate return (-strcmp((char *)f1 + strlen((char *)f1) - 5,
2817c478bd9Sstevel@tonic-gate (char *)f2 + strlen((char *)f2) - 5));
2827c478bd9Sstevel@tonic-gate }
2837c478bd9Sstevel@tonic-gate
2847c478bd9Sstevel@tonic-gate /*
2857c478bd9Sstevel@tonic-gate * xsort
2867c478bd9Sstevel@tonic-gate * sort the cached X. files,
2877c478bd9Sstevel@tonic-gate * largest (last) to smallest (next to be processed)
2887c478bd9Sstevel@tonic-gate */
2897c478bd9Sstevel@tonic-gate static void
xsort()2907c478bd9Sstevel@tonic-gate xsort()
2917c478bd9Sstevel@tonic-gate {
2927c478bd9Sstevel@tonic-gate DEBUG(4, "xsort: first was %s\n", xcache[0]);
2937c478bd9Sstevel@tonic-gate qsort(xcache, xcachesize, MAXBASENAME + 1, xcompare);
2947c478bd9Sstevel@tonic-gate DEBUG(4, "xsort: first is %s\n", xcache[0]);
2957c478bd9Sstevel@tonic-gate }
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gate /*
2987c478bd9Sstevel@tonic-gate * xget
2997c478bd9Sstevel@tonic-gate * return smallest X. file in cache
3007c478bd9Sstevel@tonic-gate * (hint: it's the last one in the array)
3017c478bd9Sstevel@tonic-gate */
3027c478bd9Sstevel@tonic-gate static int
xget(file)3037c478bd9Sstevel@tonic-gate xget(file)
3047c478bd9Sstevel@tonic-gate char *file;
3057c478bd9Sstevel@tonic-gate {
3067c478bd9Sstevel@tonic-gate if (xcachesize > 0) {
3077c478bd9Sstevel@tonic-gate strlcpy(file, xcache[--xcachesize], (MAXBASENAME + 1));
3087c478bd9Sstevel@tonic-gate DEBUG(4, "xget: returning %s\n", file);
3097c478bd9Sstevel@tonic-gate return (1);
3107c478bd9Sstevel@tonic-gate } else {
3117c478bd9Sstevel@tonic-gate /* avoid horror of xcachesize < 0 (impossible, you say?)! */
3127c478bd9Sstevel@tonic-gate xcachesize = 0;
3137c478bd9Sstevel@tonic-gate return (0);
3147c478bd9Sstevel@tonic-gate }
3157c478bd9Sstevel@tonic-gate }
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate
3187c478bd9Sstevel@tonic-gate /*
3197c478bd9Sstevel@tonic-gate * get a file to execute
3207c478bd9Sstevel@tonic-gate * file -> a read to return filename in
3217c478bd9Sstevel@tonic-gate * returns:
3227c478bd9Sstevel@tonic-gate * 0 -> no file
3237c478bd9Sstevel@tonic-gate * 1 -> file to execute
3247c478bd9Sstevel@tonic-gate */
3257c478bd9Sstevel@tonic-gate int
gt_Xfile(file,dir)3267c478bd9Sstevel@tonic-gate gt_Xfile(file, dir)
327*462be471Sceastha char *file, *dir;
3287c478bd9Sstevel@tonic-gate {
3297c478bd9Sstevel@tonic-gate DIR *pdir;
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate if (xcachesize == 0) {
3327c478bd9Sstevel@tonic-gate /* open spool directory */
3337c478bd9Sstevel@tonic-gate pdir = opendir(dir);
3347c478bd9Sstevel@tonic-gate /* this was an ASSERT, but it's not so bad as all that */
3357c478bd9Sstevel@tonic-gate if (pdir == NULL)
3367c478bd9Sstevel@tonic-gate return (0);
3377c478bd9Sstevel@tonic-gate
3387c478bd9Sstevel@tonic-gate /* scan spool directory looking for X. files to stash */
3397c478bd9Sstevel@tonic-gate while (gnamef(pdir, file) == TRUE) {
3407c478bd9Sstevel@tonic-gate DEBUG(4, "gt_Xfile got %s\n", file);
3417c478bd9Sstevel@tonic-gate /* look for x prefix */
3427c478bd9Sstevel@tonic-gate if (file[0] != XQTPRE)
3437c478bd9Sstevel@tonic-gate continue;
3447c478bd9Sstevel@tonic-gate
3457c478bd9Sstevel@tonic-gate /* check to see if required files have arrived */
3467c478bd9Sstevel@tonic-gate if (gotfiles(file))
3477c478bd9Sstevel@tonic-gate xstash(file);
3487c478bd9Sstevel@tonic-gate if (xcachesize >= XCACHESIZE)
3497c478bd9Sstevel@tonic-gate break;
3507c478bd9Sstevel@tonic-gate }
3517c478bd9Sstevel@tonic-gate closedir(pdir);
3527c478bd9Sstevel@tonic-gate xsort();
3537c478bd9Sstevel@tonic-gate }
3547c478bd9Sstevel@tonic-gate
3557c478bd9Sstevel@tonic-gate return (xget(file));
3567c478bd9Sstevel@tonic-gate }
3577c478bd9Sstevel@tonic-gate
3587c478bd9Sstevel@tonic-gate /*
3597c478bd9Sstevel@tonic-gate * check for needed files
3607c478bd9Sstevel@tonic-gate * file -> name of file to check
3617c478bd9Sstevel@tonic-gate * return:
3627c478bd9Sstevel@tonic-gate * 0 -> not ready
3637c478bd9Sstevel@tonic-gate * 1 -> all files ready
3647c478bd9Sstevel@tonic-gate */
3657c478bd9Sstevel@tonic-gate int
gotfiles(file)3667c478bd9Sstevel@tonic-gate gotfiles(file)
367*462be471Sceastha char *file;
3687c478bd9Sstevel@tonic-gate {
369*462be471Sceastha FILE *fp;
3707c478bd9Sstevel@tonic-gate struct stat stbuf;
3717c478bd9Sstevel@tonic-gate char buf[BUFSIZ], rqfile[MAXNAMESIZE];
3727c478bd9Sstevel@tonic-gate
3737c478bd9Sstevel@tonic-gate fp = fopen(file, "r");
3747c478bd9Sstevel@tonic-gate if (fp == NULL)
3757c478bd9Sstevel@tonic-gate return (FALSE);
3767c478bd9Sstevel@tonic-gate
3777c478bd9Sstevel@tonic-gate while (fgets(buf, BUFSIZ, fp) != NULL) {
3787c478bd9Sstevel@tonic-gate DEBUG(4, "%s\n", buf);
3797c478bd9Sstevel@tonic-gate
3807c478bd9Sstevel@tonic-gate /*
3817c478bd9Sstevel@tonic-gate * look at required files
3827c478bd9Sstevel@tonic-gate */
3837c478bd9Sstevel@tonic-gate if (buf[0] != X_RQDFILE)
3847c478bd9Sstevel@tonic-gate continue;
3857c478bd9Sstevel@tonic-gate (void) sscanf(&buf[1], "%63s", rqfile);
3867c478bd9Sstevel@tonic-gate
3877c478bd9Sstevel@tonic-gate /*
3887c478bd9Sstevel@tonic-gate * expand file name
3897c478bd9Sstevel@tonic-gate */
3907c478bd9Sstevel@tonic-gate expfile(rqfile);
3917c478bd9Sstevel@tonic-gate
3927c478bd9Sstevel@tonic-gate /*
3937c478bd9Sstevel@tonic-gate * see if file exists
3947c478bd9Sstevel@tonic-gate */
3957c478bd9Sstevel@tonic-gate if (stat(rqfile, &stbuf) == -1) {
3967c478bd9Sstevel@tonic-gate fclose(fp);
3977c478bd9Sstevel@tonic-gate return (FALSE);
3987c478bd9Sstevel@tonic-gate }
3997c478bd9Sstevel@tonic-gate }
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate fclose(fp);
4027c478bd9Sstevel@tonic-gate return (TRUE);
4037c478bd9Sstevel@tonic-gate }
4047c478bd9Sstevel@tonic-gate
4057c478bd9Sstevel@tonic-gate /*
4067c478bd9Sstevel@tonic-gate * remove execute files to x-directory
4077c478bd9Sstevel@tonic-gate *
4087c478bd9Sstevel@tonic-gate * _Xfile is a global
4097c478bd9Sstevel@tonic-gate * return:
4107c478bd9Sstevel@tonic-gate * none
4117c478bd9Sstevel@tonic-gate */
4127c478bd9Sstevel@tonic-gate void
rm_Xfiles()4137c478bd9Sstevel@tonic-gate rm_Xfiles()
4147c478bd9Sstevel@tonic-gate {
415*462be471Sceastha FILE *fp;
4167c478bd9Sstevel@tonic-gate char buf[BUFSIZ], file[MAXNAMESIZE], tfile[MAXNAMESIZE];
4177c478bd9Sstevel@tonic-gate char tfull[MAXFULLNAME];
4187c478bd9Sstevel@tonic-gate
4197c478bd9Sstevel@tonic-gate if ((fp = fopen(_Xfile, "r")) == NULL) {
4207c478bd9Sstevel@tonic-gate DEBUG(4, "rm_Xfiles: can't read %s\n", _Xfile);
4217c478bd9Sstevel@tonic-gate return;
4227c478bd9Sstevel@tonic-gate }
4237c478bd9Sstevel@tonic-gate
4247c478bd9Sstevel@tonic-gate /*
4257c478bd9Sstevel@tonic-gate * (void) unlink each file belonging to job
4267c478bd9Sstevel@tonic-gate */
4277c478bd9Sstevel@tonic-gate while (fgets(buf, BUFSIZ, fp) != NULL) {
4287c478bd9Sstevel@tonic-gate if (buf[0] != X_RQDFILE)
4297c478bd9Sstevel@tonic-gate continue;
4307c478bd9Sstevel@tonic-gate if (sscanf(&buf[1], "%63s%63s", file, tfile) < 2)
4317c478bd9Sstevel@tonic-gate continue;
4327c478bd9Sstevel@tonic-gate (void) snprintf(tfull, sizeof (tfull), "%s/%s", XQTDIR, tfile);
4337c478bd9Sstevel@tonic-gate (void) unlink(tfull);
4347c478bd9Sstevel@tonic-gate }
4357c478bd9Sstevel@tonic-gate fclose(fp);
4367c478bd9Sstevel@tonic-gate }
4377c478bd9Sstevel@tonic-gate
4387c478bd9Sstevel@tonic-gate /*
4397c478bd9Sstevel@tonic-gate * move execute files to x-directory
4407c478bd9Sstevel@tonic-gate * _Xfile is a global
4417c478bd9Sstevel@tonic-gate * return:
4427c478bd9Sstevel@tonic-gate * none
4437c478bd9Sstevel@tonic-gate */
4447c478bd9Sstevel@tonic-gate void
mv_Xfiles()4457c478bd9Sstevel@tonic-gate mv_Xfiles()
4467c478bd9Sstevel@tonic-gate {
447*462be471Sceastha FILE *fp;
4487c478bd9Sstevel@tonic-gate char buf[BUFSIZ], ffile[MAXFULLNAME], tfile[MAXNAMESIZE];
4497c478bd9Sstevel@tonic-gate char tfull[MAXFULLNAME];
4507c478bd9Sstevel@tonic-gate
4517c478bd9Sstevel@tonic-gate if ((fp = fopen(_Xfile, "r")) == NULL) {
4527c478bd9Sstevel@tonic-gate DEBUG(4, "mv_Xfiles: can't read %s\n", _Xfile);
4537c478bd9Sstevel@tonic-gate return;
4547c478bd9Sstevel@tonic-gate }
4557c478bd9Sstevel@tonic-gate
4567c478bd9Sstevel@tonic-gate while (fgets(buf, BUFSIZ, fp) != NULL) {
4577c478bd9Sstevel@tonic-gate if (buf[0] != X_RQDFILE)
4587c478bd9Sstevel@tonic-gate continue;
4597c478bd9Sstevel@tonic-gate if (sscanf(&buf[1], "%63s%63s", ffile, tfile) < 2)
4607c478bd9Sstevel@tonic-gate continue;
4617c478bd9Sstevel@tonic-gate
4627c478bd9Sstevel@tonic-gate /*
4637c478bd9Sstevel@tonic-gate * expand file names and move to
4647c478bd9Sstevel@tonic-gate * execute directory
4657c478bd9Sstevel@tonic-gate * Make files readable by anyone
4667c478bd9Sstevel@tonic-gate */
4677c478bd9Sstevel@tonic-gate expfile(ffile);
4687c478bd9Sstevel@tonic-gate (void) snprintf(tfull, sizeof (tfull), "%s/%s", XQTDIR, tfile);
4697c478bd9Sstevel@tonic-gate
4707c478bd9Sstevel@tonic-gate if (chkpth(ffile, CK_READ) == FAIL)
4717c478bd9Sstevel@tonic-gate continue; /* execution will fail later */
4727c478bd9Sstevel@tonic-gate if (chkpth(tfull, CK_WRITE) == FAIL) {
4737c478bd9Sstevel@tonic-gate /*
4747c478bd9Sstevel@tonic-gate * tfull will have been canonicalized. If
4757c478bd9Sstevel@tonic-gate * it still points to XQTDIR, allow us to
4767c478bd9Sstevel@tonic-gate * write there.
4777c478bd9Sstevel@tonic-gate */
4787c478bd9Sstevel@tonic-gate if (!PREFIX(XQTDIR, tfull))
4797c478bd9Sstevel@tonic-gate continue; /* execution will fail later */
4807c478bd9Sstevel@tonic-gate /* otherwise, keep going */
4817c478bd9Sstevel@tonic-gate }
4827c478bd9Sstevel@tonic-gate
4837c478bd9Sstevel@tonic-gate ASSERT(xmv(ffile, tfull) == 0, "XMV ERROR", tfull, errno);
4847c478bd9Sstevel@tonic-gate chmod(tfull, PUB_FILEMODE);
4857c478bd9Sstevel@tonic-gate }
4867c478bd9Sstevel@tonic-gate fclose(fp);
4877c478bd9Sstevel@tonic-gate }
4887c478bd9Sstevel@tonic-gate
4897c478bd9Sstevel@tonic-gate /*
4907c478bd9Sstevel@tonic-gate * undo what mv_Xfiles did
4917c478bd9Sstevel@tonic-gate * _Xfile is a global
4927c478bd9Sstevel@tonic-gate * return:
4937c478bd9Sstevel@tonic-gate * none
4947c478bd9Sstevel@tonic-gate */
4957c478bd9Sstevel@tonic-gate void
unmv_Xfiles()4967c478bd9Sstevel@tonic-gate unmv_Xfiles()
4977c478bd9Sstevel@tonic-gate {
4987c478bd9Sstevel@tonic-gate FILE *fp;
4997c478bd9Sstevel@tonic-gate char buf[BUFSIZ], ffile[MAXNAMESIZE], tfile[MAXNAMESIZE];
5007c478bd9Sstevel@tonic-gate char tfull[MAXFULLNAME], ffull[MAXFULLNAME], xfull[MAXFULLNAME];
5017c478bd9Sstevel@tonic-gate
5027c478bd9Sstevel@tonic-gate (void) snprintf(xfull, MAXFULLNAME, "%s/%s", RemSpool, _Xfile);
5037c478bd9Sstevel@tonic-gate if ((fp = fopen(xfull, "r")) == NULL) {
5047c478bd9Sstevel@tonic-gate DEBUG(4, "unmv_Xfiles: can't read %s\n", xfull);
5057c478bd9Sstevel@tonic-gate return;
5067c478bd9Sstevel@tonic-gate }
5077c478bd9Sstevel@tonic-gate
5087c478bd9Sstevel@tonic-gate while (fgets(buf, BUFSIZ, fp) != NULL) {
5097c478bd9Sstevel@tonic-gate if (buf[0] != X_RQDFILE)
5107c478bd9Sstevel@tonic-gate continue;
5117c478bd9Sstevel@tonic-gate if (sscanf(&buf[1], "%63s%63s", ffile, tfile) < 2)
5127c478bd9Sstevel@tonic-gate continue;
5137c478bd9Sstevel@tonic-gate
5147c478bd9Sstevel@tonic-gate /*
5157c478bd9Sstevel@tonic-gate * expand file names and move back to
5167c478bd9Sstevel@tonic-gate * spool directory
5177c478bd9Sstevel@tonic-gate * Make files readable by uucp
5187c478bd9Sstevel@tonic-gate */
5197c478bd9Sstevel@tonic-gate (void) snprintf(ffull, MAXFULLNAME, "%s/%s", RemSpool, ffile);
5207c478bd9Sstevel@tonic-gate /* i know we're in .Xqtdir, but ... */
5217c478bd9Sstevel@tonic-gate (void) snprintf(tfull, MAXFULLNAME, "%s/%s", XQTDIR, tfile);
5227c478bd9Sstevel@tonic-gate
5237c478bd9Sstevel@tonic-gate if (chkpth(ffull, CK_WRITE) == FAIL ||
5247c478bd9Sstevel@tonic-gate chkpth(tfull, CK_READ) == FAIL)
5257c478bd9Sstevel@tonic-gate continue;
5267c478bd9Sstevel@tonic-gate
5277c478bd9Sstevel@tonic-gate ASSERT(xmv(tfull, ffull) == 0, "XMV ERROR", ffull, errno);
5287c478bd9Sstevel@tonic-gate (void) chmod(ffull, (mode_t)0600);
5297c478bd9Sstevel@tonic-gate }
5307c478bd9Sstevel@tonic-gate fclose(fp);
5317c478bd9Sstevel@tonic-gate }
5327c478bd9Sstevel@tonic-gate
5337c478bd9Sstevel@tonic-gate /*
5347c478bd9Sstevel@tonic-gate * chkpart - checks the string (ptr points to it) for illegal command or
5357c478bd9Sstevel@tonic-gate * file permission restriction - called recursively
5367c478bd9Sstevel@tonic-gate * to check lines that have `string` or (string) form.
5377c478bd9Sstevel@tonic-gate * _Cmd is the buffer where the command is built up.
5387c478bd9Sstevel@tonic-gate * _CargType is the type of the next C line argument
5397c478bd9Sstevel@tonic-gate *
5407c478bd9Sstevel@tonic-gate * Return:
5417c478bd9Sstevel@tonic-gate * BAD_FILE if a non permitted file is found
5427c478bd9Sstevel@tonic-gate * BAD_COMMAND if non permitted command is found
5437c478bd9Sstevel@tonic-gate * 0 - ok
5447c478bd9Sstevel@tonic-gate */
5457c478bd9Sstevel@tonic-gate
5467c478bd9Sstevel@tonic-gate static int
chkpart(char * ptr)5477c478bd9Sstevel@tonic-gate chkpart(char *ptr)
5487c478bd9Sstevel@tonic-gate {
5497c478bd9Sstevel@tonic-gate char prm[BUFSIZ], whitesp[BUFSIZ], rqtcmd[BUFSIZ], xcmd[BUFSIZ];
5507c478bd9Sstevel@tonic-gate char savechar[2]; /* one character string with NULL */
5517c478bd9Sstevel@tonic-gate int ret;
5527c478bd9Sstevel@tonic-gate
5537c478bd9Sstevel@tonic-gate /* _CargType is the arg type for this iteration (cmd or file) */
5547c478bd9Sstevel@tonic-gate while ((ptr = getprm(ptr, whitesp, prm)) != NULL) {
5557c478bd9Sstevel@tonic-gate DEBUG(4, "prm='%s'\n", prm);
5567c478bd9Sstevel@tonic-gate switch (*prm) {
5577c478bd9Sstevel@tonic-gate
5587c478bd9Sstevel@tonic-gate /* End of command delimiter */
5597c478bd9Sstevel@tonic-gate case ';':
5607c478bd9Sstevel@tonic-gate case '^':
5617c478bd9Sstevel@tonic-gate case '&':
5627c478bd9Sstevel@tonic-gate case '|':
5637c478bd9Sstevel@tonic-gate (void) strlcat(_Cmd, whitesp, sizeof (_Cmd));
5647c478bd9Sstevel@tonic-gate (void) strlcat(_Cmd, prm, sizeof (_Cmd));
5657c478bd9Sstevel@tonic-gate _CargType = C_COMMAND;
5667c478bd9Sstevel@tonic-gate continue;
5677c478bd9Sstevel@tonic-gate
5687c478bd9Sstevel@tonic-gate /* Other delimiter */
5697c478bd9Sstevel@tonic-gate case '>':
5707c478bd9Sstevel@tonic-gate case '<':
5717c478bd9Sstevel@tonic-gate (void) strlcat(_Cmd, whitesp, sizeof (_Cmd));
5727c478bd9Sstevel@tonic-gate (void) strlcat(_Cmd, prm, sizeof (_Cmd));
5737c478bd9Sstevel@tonic-gate continue;
5747c478bd9Sstevel@tonic-gate
5757c478bd9Sstevel@tonic-gate case '`': /* don't allow any ` commands */
5767c478bd9Sstevel@tonic-gate case '\\':
5777c478bd9Sstevel@tonic-gate return (BAD_COMMAND);
5787c478bd9Sstevel@tonic-gate
5797c478bd9Sstevel@tonic-gate /* Some allowable quoted string */
5807c478bd9Sstevel@tonic-gate case '(':
5817c478bd9Sstevel@tonic-gate case '"':
5827c478bd9Sstevel@tonic-gate case '\'':
5837c478bd9Sstevel@tonic-gate /* must recurse */
5847c478bd9Sstevel@tonic-gate savechar[0] = *prm;
5857c478bd9Sstevel@tonic-gate savechar[1] = NULLCHAR;
5867c478bd9Sstevel@tonic-gate /* put leading white space & first char into command */
5877c478bd9Sstevel@tonic-gate (void) strlcat(_Cmd, whitesp, sizeof (_Cmd));
5887c478bd9Sstevel@tonic-gate (void) strlcat(_Cmd, savechar, sizeof (_Cmd));
5897c478bd9Sstevel@tonic-gate savechar[0] = prm[strlen(prm)-1];
5907c478bd9Sstevel@tonic-gate prm[strlen(prm)-1] = NULLCHAR; /* delete last character */
5917c478bd9Sstevel@tonic-gate
5927c478bd9Sstevel@tonic-gate /* recurse */
5937c478bd9Sstevel@tonic-gate if (ret = chkpart(prm+1)) { /* failed */
5947c478bd9Sstevel@tonic-gate return (ret);
5957c478bd9Sstevel@tonic-gate }
5967c478bd9Sstevel@tonic-gate /* put last char into command */
5977c478bd9Sstevel@tonic-gate (void) strlcat(_Cmd, savechar, sizeof (_Cmd));
5987c478bd9Sstevel@tonic-gate continue;
5997c478bd9Sstevel@tonic-gate
6007c478bd9Sstevel@tonic-gate case '2':
6017c478bd9Sstevel@tonic-gate if (*(prm+1) == '>') {
6027c478bd9Sstevel@tonic-gate (void) strlcat(_Cmd, whitesp, sizeof (_Cmd));
6037c478bd9Sstevel@tonic-gate (void) strlcat(_Cmd, prm, sizeof (_Cmd));
6047c478bd9Sstevel@tonic-gate continue;
6057c478bd9Sstevel@tonic-gate }
6067c478bd9Sstevel@tonic-gate /* fall through if not "2>" */
6077c478bd9Sstevel@tonic-gate
6087c478bd9Sstevel@tonic-gate default: /* check for command or file */
6097c478bd9Sstevel@tonic-gate break;
6107c478bd9Sstevel@tonic-gate }
6117c478bd9Sstevel@tonic-gate
6127c478bd9Sstevel@tonic-gate if (_CargType == C_COMMAND) {
6137c478bd9Sstevel@tonic-gate (void) strlcpy(rqtcmd, prm, sizeof (rqtcmd));
6147c478bd9Sstevel@tonic-gate if (*rqtcmd == '~')
6157c478bd9Sstevel@tonic-gate expfile(rqtcmd);
6167c478bd9Sstevel@tonic-gate if ((cmdOK(rqtcmd, xcmd)) == FALSE)
6177c478bd9Sstevel@tonic-gate return (BAD_COMMAND);
6187c478bd9Sstevel@tonic-gate (void) strlcat(_Cmd, whitesp, sizeof (_Cmd));
6197c478bd9Sstevel@tonic-gate (void) strlcat(_Cmd, xcmd, sizeof (_Cmd));
6207c478bd9Sstevel@tonic-gate _CargType = C_FILE;
6217c478bd9Sstevel@tonic-gate continue;
6227c478bd9Sstevel@tonic-gate }
6237c478bd9Sstevel@tonic-gate
6247c478bd9Sstevel@tonic-gate (void) strlcpy(rqtcmd, prm, sizeof (rqtcmd));
6257c478bd9Sstevel@tonic-gate if (*rqtcmd == '~')
6267c478bd9Sstevel@tonic-gate expfile(rqtcmd);
6277c478bd9Sstevel@tonic-gate if (chkFile(rqtcmd)) {
6287c478bd9Sstevel@tonic-gate return (BAD_FILE);
6297c478bd9Sstevel@tonic-gate } else {
6307c478bd9Sstevel@tonic-gate (void) strlcat(_Cmd, whitesp, sizeof (_Cmd));
6317c478bd9Sstevel@tonic-gate (void) strlcat(_Cmd, rqtcmd, sizeof (_Cmd));
6327c478bd9Sstevel@tonic-gate }
6337c478bd9Sstevel@tonic-gate }
6347c478bd9Sstevel@tonic-gate if (whitesp[0] != '\0')
6357c478bd9Sstevel@tonic-gate /* restore any trailing white space */
6367c478bd9Sstevel@tonic-gate (void) strlcat(_Cmd, whitesp, sizeof (_Cmd));
6377c478bd9Sstevel@tonic-gate return (0); /* all ok */
6387c478bd9Sstevel@tonic-gate }
6397c478bd9Sstevel@tonic-gate
6407c478bd9Sstevel@tonic-gate /*
6417c478bd9Sstevel@tonic-gate * chkFile - try to find a path name in the prm.
6427c478bd9Sstevel@tonic-gate * if found, check it for access permission.
6437c478bd9Sstevel@tonic-gate *
6447c478bd9Sstevel@tonic-gate * check file access permissions
6457c478bd9Sstevel@tonic-gate * if ! in name assume that access on local machine is required
6467c478bd9Sstevel@tonic-gate *
6477c478bd9Sstevel@tonic-gate * Return:
6487c478bd9Sstevel@tonic-gate * BAD_FILE - not permitted
6497c478bd9Sstevel@tonic-gate * 0 - ok
6507c478bd9Sstevel@tonic-gate */
6517c478bd9Sstevel@tonic-gate
6527c478bd9Sstevel@tonic-gate static int
chkFile(char * prm)6537c478bd9Sstevel@tonic-gate chkFile(char *prm)
6547c478bd9Sstevel@tonic-gate {
6557c478bd9Sstevel@tonic-gate char *p, buf[BUFSIZ];
6567c478bd9Sstevel@tonic-gate
6577c478bd9Sstevel@tonic-gate (void) strlcpy(buf, prm, sizeof (buf));
6587c478bd9Sstevel@tonic-gate switch (*prm) {
6597c478bd9Sstevel@tonic-gate case '~':
6607c478bd9Sstevel@tonic-gate case '/':
6617c478bd9Sstevel@tonic-gate if (doFileChk(buf))
6627c478bd9Sstevel@tonic-gate return (BAD_FILE);
6637c478bd9Sstevel@tonic-gate else
6647c478bd9Sstevel@tonic-gate return (0);
6657c478bd9Sstevel@tonic-gate /*NOTREACHED*/
6667c478bd9Sstevel@tonic-gate
6677c478bd9Sstevel@tonic-gate case '!':
6687c478bd9Sstevel@tonic-gate return (chkFile(buf+1));
6697c478bd9Sstevel@tonic-gate /*NOTREACHED*/
6707c478bd9Sstevel@tonic-gate
6717c478bd9Sstevel@tonic-gate default:
6727c478bd9Sstevel@tonic-gate break;
6737c478bd9Sstevel@tonic-gate }
6747c478bd9Sstevel@tonic-gate
6757c478bd9Sstevel@tonic-gate if ((p = strchr(buf, '!')) == NULL) { /* no "!", look for "/" */
6767c478bd9Sstevel@tonic-gate if ((p = strchr(buf, '/')) == NULL) { /* ok */
6777c478bd9Sstevel@tonic-gate return (0);
6787c478bd9Sstevel@tonic-gate }
6797c478bd9Sstevel@tonic-gate if (doFileChk(p))
6807c478bd9Sstevel@tonic-gate return (BAD_FILE);
6817c478bd9Sstevel@tonic-gate else
6827c478bd9Sstevel@tonic-gate return (0);
6837c478bd9Sstevel@tonic-gate }
6847c478bd9Sstevel@tonic-gate
6857c478bd9Sstevel@tonic-gate /* there is at least one '!' - see if it refers to my system */
6867c478bd9Sstevel@tonic-gate if (PREFIX(Myname, buf)) /* my system so far, check further */
6877c478bd9Sstevel@tonic-gate return (chkFile(p+1)); /* recurse with thing after '!' */
6887c478bd9Sstevel@tonic-gate else /* not my system - not my worry */
6897c478bd9Sstevel@tonic-gate return (0);
6907c478bd9Sstevel@tonic-gate }
6917c478bd9Sstevel@tonic-gate
6927c478bd9Sstevel@tonic-gate /*
6937c478bd9Sstevel@tonic-gate * doFileChk - check file path permission
6947c478bd9Sstevel@tonic-gate * NOTE: file is assumed to be a buffer that expfile an
6957c478bd9Sstevel@tonic-gate * write into.
6967c478bd9Sstevel@tonic-gate * Return
6977c478bd9Sstevel@tonic-gate * BAD_FILE - not allowed
6987c478bd9Sstevel@tonic-gate * 0 - ok
6997c478bd9Sstevel@tonic-gate */
7007c478bd9Sstevel@tonic-gate
7017c478bd9Sstevel@tonic-gate static int
doFileChk(char * file)7027c478bd9Sstevel@tonic-gate doFileChk(char *file)
7037c478bd9Sstevel@tonic-gate {
7047c478bd9Sstevel@tonic-gate expfile(file);
7057c478bd9Sstevel@tonic-gate DEBUG(7, "fullname: %s\n", file);
7067c478bd9Sstevel@tonic-gate if (chkpth(file, CK_READ) == FAIL ||
7077c478bd9Sstevel@tonic-gate chkpth(file, CK_WRITE) == FAIL)
7087c478bd9Sstevel@tonic-gate return (BAD_FILE);
7097c478bd9Sstevel@tonic-gate else
7107c478bd9Sstevel@tonic-gate return (0);
7117c478bd9Sstevel@tonic-gate }
7127c478bd9Sstevel@tonic-gate
7137c478bd9Sstevel@tonic-gate
7147c478bd9Sstevel@tonic-gate /*
7157c478bd9Sstevel@tonic-gate * return stuff to user
7167c478bd9Sstevel@tonic-gate * user -> user to notify
7177c478bd9Sstevel@tonic-gate * rmt -> system name where user resides
7187c478bd9Sstevel@tonic-gate * file -> file to return (generally contains input)
7197c478bd9Sstevel@tonic-gate * cmd -> command that was to be executed
7207c478bd9Sstevel@tonic-gate * buf -> user friendly face saving uplifting edifying missive
7217c478bd9Sstevel@tonic-gate * errfile -> stderr output from cmd xeqn
7227c478bd9Sstevel@tonic-gate * return:
7237c478bd9Sstevel@tonic-gate * none
7247c478bd9Sstevel@tonic-gate */
7257c478bd9Sstevel@tonic-gate static void
retosndr(user,rmt,file,cmd,buf,errfile)7267c478bd9Sstevel@tonic-gate retosndr(user, rmt, file, cmd, buf, errfile)
7277c478bd9Sstevel@tonic-gate char *user, *rmt, *file, *cmd, *buf, *errfile;
7287c478bd9Sstevel@tonic-gate {
7297c478bd9Sstevel@tonic-gate char ruser[BUFSIZ], msg[BUFSIZ], subj[BUFSIZ];
7307c478bd9Sstevel@tonic-gate
7317c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof (msg), "%s\t[%s %s (%s)]\n\t%s\n%s\n",
7327c478bd9Sstevel@tonic-gate gettext("remote execution"), gettext("uucp job"),
7337c478bd9Sstevel@tonic-gate *Jobid ? Jobid : &_Xfile[2], timeStamp(), cmd, buf);
7347c478bd9Sstevel@tonic-gate
7357c478bd9Sstevel@tonic-gate DEBUG(5, "retosndr %s, ", msg);
7367c478bd9Sstevel@tonic-gate
7377c478bd9Sstevel@tonic-gate if (EQUALS(rmt, Myname))
7387c478bd9Sstevel@tonic-gate (void) strlcpy(ruser, user, sizeof (ruser));
7397c478bd9Sstevel@tonic-gate else
7407c478bd9Sstevel@tonic-gate (void) snprintf(ruser, sizeof (ruser), "%s!%s", rmt, user);
7417c478bd9Sstevel@tonic-gate
7427c478bd9Sstevel@tonic-gate (void) strlcpy(subj, gettext("remote execution status"), sizeof (subj));
7437c478bd9Sstevel@tonic-gate mailst(ruser, subj, msg, file, errfile);
7447c478bd9Sstevel@tonic-gate }
7457c478bd9Sstevel@tonic-gate
7467c478bd9Sstevel@tonic-gate
7477c478bd9Sstevel@tonic-gate /*
7487c478bd9Sstevel@tonic-gate * uucpst - send the status message back using a uucp command
7497c478bd9Sstevel@tonic-gate * NOTE - this would be better if the file could be appended.
7507c478bd9Sstevel@tonic-gate * - suggestion for the future - if rmail would take a file name
7517c478bd9Sstevel@tonic-gate * instead of just person, then that facility would be correct,
7527c478bd9Sstevel@tonic-gate * and this routine would not be needed.
7537c478bd9Sstevel@tonic-gate */
7547c478bd9Sstevel@tonic-gate
7557c478bd9Sstevel@tonic-gate static void
uucpst(rmt,tofile,errfile,cmd,buf)7567c478bd9Sstevel@tonic-gate uucpst(rmt, tofile, errfile, cmd, buf)
7577c478bd9Sstevel@tonic-gate char *rmt, *tofile, *errfile, *cmd, *buf;
7587c478bd9Sstevel@tonic-gate {
7597c478bd9Sstevel@tonic-gate char arg[MAXFULLNAME], tmp[NAMESIZE], msg[BUFSIZ];
7607c478bd9Sstevel@tonic-gate pid_t pid, ret;
7617c478bd9Sstevel@tonic-gate int status;
7627c478bd9Sstevel@tonic-gate FILE *fp, *fi;
7637c478bd9Sstevel@tonic-gate
7647c478bd9Sstevel@tonic-gate (void) snprintf(msg, sizeof (msg), "%s %s (%s) %s\n\t%s\n%s\n",
7657c478bd9Sstevel@tonic-gate gettext("uucp job"), *Jobid ? Jobid : &_Xfile[2], timeStamp(),
7667c478bd9Sstevel@tonic-gate gettext("remote execution"), cmd, buf);
7677c478bd9Sstevel@tonic-gate
7687c478bd9Sstevel@tonic-gate (void) snprintf(tmp, sizeof (tmp), "%s.%ld", rmt, (long)getpid());
7697c478bd9Sstevel@tonic-gate if ((fp = fopen(tmp, "w")) == NULL)
7707c478bd9Sstevel@tonic-gate return;
7717c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s\n", msg);
7727c478bd9Sstevel@tonic-gate
7737c478bd9Sstevel@tonic-gate /* copy back stderr */
7747c478bd9Sstevel@tonic-gate if (*errfile != '\0' && NOTEMPTY(errfile) &&
7757c478bd9Sstevel@tonic-gate (fi = fopen(errfile, "r")) != NULL) {
7767c478bd9Sstevel@tonic-gate fputs("\n\t===== stderr was =====\n", fp);
7777c478bd9Sstevel@tonic-gate if (xfappend(fi, fp) != SUCCESS)
7787c478bd9Sstevel@tonic-gate fputs("\n\t===== well, i tried =====\n", fp);
7797c478bd9Sstevel@tonic-gate (void) fclose(fi);
7807c478bd9Sstevel@tonic-gate fputc('\n', fp);
7817c478bd9Sstevel@tonic-gate }
7827c478bd9Sstevel@tonic-gate
7837c478bd9Sstevel@tonic-gate
7847c478bd9Sstevel@tonic-gate (void) fclose(fp);
7857c478bd9Sstevel@tonic-gate (void) snprintf(arg, sizeof (arg), "%s!%s", rmt, tofile);
7867c478bd9Sstevel@tonic-gate
7877c478bd9Sstevel@tonic-gate /* start uucp */
7887c478bd9Sstevel@tonic-gate
7897c478bd9Sstevel@tonic-gate if ((pid = vfork()) == 0) {
7907c478bd9Sstevel@tonic-gate (void) close(0);
7917c478bd9Sstevel@tonic-gate (void) close(1);
7927c478bd9Sstevel@tonic-gate (void) close(2);
7937c478bd9Sstevel@tonic-gate (void) open("/dev/null", 2);
7947c478bd9Sstevel@tonic-gate (void) open("/dev/null", 2);
7957c478bd9Sstevel@tonic-gate (void) open("/dev/null", 2);
7967c478bd9Sstevel@tonic-gate (void) signal(SIGINT, SIG_IGN);
7977c478bd9Sstevel@tonic-gate (void) signal(SIGHUP, SIG_IGN);
7987c478bd9Sstevel@tonic-gate (void) signal(SIGQUIT, SIG_IGN);
7997c478bd9Sstevel@tonic-gate ucloselog();
8007c478bd9Sstevel@tonic-gate
8017c478bd9Sstevel@tonic-gate (void) execle("/usr/bin/uucp", "UUCP",
8027c478bd9Sstevel@tonic-gate "-C", tmp, arg, (char *)0, Env);
8037c478bd9Sstevel@tonic-gate _exit(100);
8047c478bd9Sstevel@tonic-gate }
8057c478bd9Sstevel@tonic-gate
8067c478bd9Sstevel@tonic-gate if (pid == -1)
8077c478bd9Sstevel@tonic-gate return;
8087c478bd9Sstevel@tonic-gate
8097c478bd9Sstevel@tonic-gate while ((ret = wait(&status)) != pid)
8107c478bd9Sstevel@tonic-gate if (ret == -1 && errno != EINTR)
8117c478bd9Sstevel@tonic-gate break;
8127c478bd9Sstevel@tonic-gate
8137c478bd9Sstevel@tonic-gate (void) unlink(tmp);
8147c478bd9Sstevel@tonic-gate }
8157c478bd9Sstevel@tonic-gate
8167c478bd9Sstevel@tonic-gate void
xprocess(dirname)8177c478bd9Sstevel@tonic-gate xprocess(dirname)
8187c478bd9Sstevel@tonic-gate char *dirname;
8197c478bd9Sstevel@tonic-gate {
8207c478bd9Sstevel@tonic-gate char fdgrade(); /* returns default service grade on system */
8217c478bd9Sstevel@tonic-gate int return_stdin; /* return stdin for failed commands */
8227c478bd9Sstevel@tonic-gate int cmdok, ret, badfiles;
8237c478bd9Sstevel@tonic-gate mode_t mask;
8247c478bd9Sstevel@tonic-gate int send_zero; /* return successful completion status */
8257c478bd9Sstevel@tonic-gate int send_nonzero; /* return unsuccessful completion status */
8267c478bd9Sstevel@tonic-gate int send_nothing; /* request for no exit status */
8277c478bd9Sstevel@tonic-gate int store_status; /* store status of command in local file */
8287c478bd9Sstevel@tonic-gate char lbuf[BUFSIZ];
8297c478bd9Sstevel@tonic-gate char dqueue; /* var to hold the default service grade */
8307c478bd9Sstevel@tonic-gate char *errname = ""; /* name of local stderr output file */
8317c478bd9Sstevel@tonic-gate char *p;
8327c478bd9Sstevel@tonic-gate char sendsys[MAXNAMESIZE];
8337c478bd9Sstevel@tonic-gate char dfile[MAXFULLNAME], cfile[MAXFULLNAME], incmd[BUFSIZ];
8347c478bd9Sstevel@tonic-gate char errDfile[BUFSIZ];
8357c478bd9Sstevel@tonic-gate char fin[MAXFULLNAME];
8367c478bd9Sstevel@tonic-gate char fout[MAXFULLNAME], sysout[NAMESIZE];
8377c478bd9Sstevel@tonic-gate char ferr[MAXFULLNAME], syserr[NAMESIZE];
8387c478bd9Sstevel@tonic-gate char file[MAXFULLNAME], tempname[NAMESIZE];
8397c478bd9Sstevel@tonic-gate char _Sfile[MAXFULLNAME]; /* name of local file for status */
8407c478bd9Sstevel@tonic-gate FILE *xfp, *fp;
8417c478bd9Sstevel@tonic-gate struct stat sb;
8427c478bd9Sstevel@tonic-gate char buf[BUFSIZ], user[BUFSIZ], retaddr[BUFSIZ], retuser[BUFSIZ],
8437c478bd9Sstevel@tonic-gate msgbuf[BUFSIZ];
8447c478bd9Sstevel@tonic-gate char origsys[MAXFULLNAME], origuser[MAXFULLNAME];
8457c478bd9Sstevel@tonic-gate
8467c478bd9Sstevel@tonic-gate (void) strlcpy(Rmtname, dirname, sizeof (Rmtname));
8477c478bd9Sstevel@tonic-gate chremdir(Rmtname);
8487c478bd9Sstevel@tonic-gate (void) mchFind(Rmtname);
8497c478bd9Sstevel@tonic-gate while (gt_Xfile(_Xfile, RemSpool) > 0) {
8507c478bd9Sstevel@tonic-gate DEBUG(4, "_Xfile - %s\n", _Xfile);
8517c478bd9Sstevel@tonic-gate
8527c478bd9Sstevel@tonic-gate if ((xfp = fopen(_Xfile, "r")) == NULL) {
8537c478bd9Sstevel@tonic-gate toCorrupt(_Xfile);
8547c478bd9Sstevel@tonic-gate continue;
8557c478bd9Sstevel@tonic-gate }
8567c478bd9Sstevel@tonic-gate ASSERT(xfp != NULL, Ct_OPEN, _Xfile, errno);
8577c478bd9Sstevel@tonic-gate
8587c478bd9Sstevel@tonic-gate if (stat(_Xfile, &sb) != -1)
8597c478bd9Sstevel@tonic-gate Nstat.t_qtime = sb.st_mtime;
8607c478bd9Sstevel@tonic-gate /*
8617c478bd9Sstevel@tonic-gate * initialize to defaults
8627c478bd9Sstevel@tonic-gate */
8637c478bd9Sstevel@tonic-gate (void) strlcpy(user, User, sizeof (user));
8647c478bd9Sstevel@tonic-gate (void) strcpy(fin, "/dev/null");
8657c478bd9Sstevel@tonic-gate (void) strcpy(fout, "/dev/null");
8667c478bd9Sstevel@tonic-gate (void) strcpy(ferr, "/dev/null");
8677c478bd9Sstevel@tonic-gate (void) sprintf(sysout, "%.*s", MAXBASENAME, Myname);
8687c478bd9Sstevel@tonic-gate (void) sprintf(syserr, "%.*s", MAXBASENAME, Myname);
8697c478bd9Sstevel@tonic-gate badfiles = 0;
8707c478bd9Sstevel@tonic-gate *incmd = *retaddr = *retuser = *Jobid = NULLCHAR;
8717c478bd9Sstevel@tonic-gate initSeq();
8727c478bd9Sstevel@tonic-gate send_zero = send_nonzero = send_nothing = 0;
8737c478bd9Sstevel@tonic-gate store_status = 0;
8747c478bd9Sstevel@tonic-gate return_stdin = 0;
8757c478bd9Sstevel@tonic-gate
8767c478bd9Sstevel@tonic-gate while (fgets(buf, BUFSIZ, xfp) != NULL) {
8777c478bd9Sstevel@tonic-gate /*
8787c478bd9Sstevel@tonic-gate * interpret JCL card
8797c478bd9Sstevel@tonic-gate */
8807c478bd9Sstevel@tonic-gate switch (buf[0]) {
8817c478bd9Sstevel@tonic-gate case X_USER:
8827c478bd9Sstevel@tonic-gate /*
8837c478bd9Sstevel@tonic-gate * user name
8847c478bd9Sstevel@tonic-gate * (ignore Rmtname)
8857c478bd9Sstevel@tonic-gate * The utmpx username field is 32 characters long;
8867c478bd9Sstevel@tonic-gate * UUCP usage truncates system name to 14 bytes.
8877c478bd9Sstevel@tonic-gate */
8887c478bd9Sstevel@tonic-gate (void) sscanf(&buf[1], "%32s%14s", user, origsys);
8897c478bd9Sstevel@tonic-gate (void) strlcpy(origuser, user, sizeof (origuser));
8907c478bd9Sstevel@tonic-gate break;
8917c478bd9Sstevel@tonic-gate
8927c478bd9Sstevel@tonic-gate case X_STDIN:
8937c478bd9Sstevel@tonic-gate /*
8947c478bd9Sstevel@tonic-gate * standard input
8957c478bd9Sstevel@tonic-gate */
8967c478bd9Sstevel@tonic-gate (void) sscanf(&buf[1], "%256s", fin);
8977c478bd9Sstevel@tonic-gate expfile(fin);
8987c478bd9Sstevel@tonic-gate if (chkpth(fin, CK_READ)) {
8997c478bd9Sstevel@tonic-gate DEBUG(4, "badfile - in: %s\n", fin);
9007c478bd9Sstevel@tonic-gate badfiles = 1;
9017c478bd9Sstevel@tonic-gate }
9027c478bd9Sstevel@tonic-gate break;
9037c478bd9Sstevel@tonic-gate
9047c478bd9Sstevel@tonic-gate case X_STDOUT:
9057c478bd9Sstevel@tonic-gate /*
9067c478bd9Sstevel@tonic-gate * standard output
9077c478bd9Sstevel@tonic-gate */
9087c478bd9Sstevel@tonic-gate (void) sscanf(&buf[1], "%256s%14s", fout, sysout);
9097c478bd9Sstevel@tonic-gate if ((p = strpbrk(sysout, "!/")) != NULL)
9107c478bd9Sstevel@tonic-gate *p = NULLCHAR; /* these are dangerous */
9117c478bd9Sstevel@tonic-gate if (*sysout != NULLCHAR && !EQUALS(sysout, Myname))
9127c478bd9Sstevel@tonic-gate break;
9137c478bd9Sstevel@tonic-gate
9147c478bd9Sstevel@tonic-gate expfile(fout);
9157c478bd9Sstevel@tonic-gate if (chkpth(fout, CK_WRITE)) {
9167c478bd9Sstevel@tonic-gate badfiles = 1;
9177c478bd9Sstevel@tonic-gate DEBUG(4, "badfile - out: %s\n", fout);
9187c478bd9Sstevel@tonic-gate }
9197c478bd9Sstevel@tonic-gate break;
9207c478bd9Sstevel@tonic-gate
9217c478bd9Sstevel@tonic-gate case X_STDERR: /* standard error */
9227c478bd9Sstevel@tonic-gate (void) sscanf(&buf[1], "%256s%14s", ferr, syserr);
9237c478bd9Sstevel@tonic-gate if ((p = strpbrk(syserr, "!/")) != NULL)
9247c478bd9Sstevel@tonic-gate *p = NULLCHAR; /* these are dangerous */
9257c478bd9Sstevel@tonic-gate if (*syserr != NULLCHAR && !EQUALS(syserr, Myname))
9267c478bd9Sstevel@tonic-gate break;
9277c478bd9Sstevel@tonic-gate
9287c478bd9Sstevel@tonic-gate expfile(ferr);
9297c478bd9Sstevel@tonic-gate if (chkpth(ferr, CK_WRITE)) {
9307c478bd9Sstevel@tonic-gate badfiles = 1;
9317c478bd9Sstevel@tonic-gate DEBUG(4, "badfile - error: %s\n", ferr);
9327c478bd9Sstevel@tonic-gate }
9337c478bd9Sstevel@tonic-gate break;
9347c478bd9Sstevel@tonic-gate
9357c478bd9Sstevel@tonic-gate
9367c478bd9Sstevel@tonic-gate case X_CMD: /* command to execute */
9377c478bd9Sstevel@tonic-gate (void) strlcpy(incmd, &buf[2], sizeof (incmd));
9387c478bd9Sstevel@tonic-gate if (*(incmd + strlen(incmd) - 1) == '\n')
9397c478bd9Sstevel@tonic-gate *(incmd + strlen(incmd) - 1) = NULLCHAR;
9407c478bd9Sstevel@tonic-gate break;
9417c478bd9Sstevel@tonic-gate
9427c478bd9Sstevel@tonic-gate case X_MAILF: /* put status in _Sfile */
9437c478bd9Sstevel@tonic-gate store_status = 1;
9447c478bd9Sstevel@tonic-gate (void) sscanf(&buf[1], "%256s", _Sfile);
9457c478bd9Sstevel@tonic-gate break;
9467c478bd9Sstevel@tonic-gate
9477c478bd9Sstevel@tonic-gate case X_SENDNOTHING: /* no failure notification */
9487c478bd9Sstevel@tonic-gate send_nothing++;
9497c478bd9Sstevel@tonic-gate break;
9507c478bd9Sstevel@tonic-gate
9517c478bd9Sstevel@tonic-gate case X_SENDZERO: /* success notification */
9527c478bd9Sstevel@tonic-gate send_zero++;
9537c478bd9Sstevel@tonic-gate break;
9547c478bd9Sstevel@tonic-gate
9557c478bd9Sstevel@tonic-gate case X_NONZERO: /* failure notification */
9567c478bd9Sstevel@tonic-gate send_nonzero++;
9577c478bd9Sstevel@tonic-gate break;
9587c478bd9Sstevel@tonic-gate
9597c478bd9Sstevel@tonic-gate case X_BRINGBACK: /* return stdin on command failure */
9607c478bd9Sstevel@tonic-gate return_stdin = 1;
9617c478bd9Sstevel@tonic-gate break;
9627c478bd9Sstevel@tonic-gate
9637c478bd9Sstevel@tonic-gate
9647c478bd9Sstevel@tonic-gate case X_RETADDR:
9657c478bd9Sstevel@tonic-gate /*
9667c478bd9Sstevel@tonic-gate * return address -- is user's name
9677c478bd9Sstevel@tonic-gate * put "Rmtname!" in front of it so mail
9687c478bd9Sstevel@tonic-gate * will always get back to remote system.
9697c478bd9Sstevel@tonic-gate */
9707c478bd9Sstevel@tonic-gate (void) sscanf(&buf[1], "%s", retuser);
9717c478bd9Sstevel@tonic-gate
9727c478bd9Sstevel@tonic-gate /*
9737c478bd9Sstevel@tonic-gate * Creates string of Rmtname!Rmtname!user which
9747c478bd9Sstevel@tonic-gate * confuses rmail.
9757c478bd9Sstevel@tonic-gate * (void) strcat(strcat(strcpy(retaddr, Rmtname), "!"),
9767c478bd9Sstevel@tonic-gate * retuser);
9777c478bd9Sstevel@tonic-gate */
9787c478bd9Sstevel@tonic-gate break;
9797c478bd9Sstevel@tonic-gate
9807c478bd9Sstevel@tonic-gate case X_JOBID:
9817c478bd9Sstevel@tonic-gate /*
9827c478bd9Sstevel@tonic-gate * job id for notification
9837c478bd9Sstevel@tonic-gate * (should be MAXBASENAME, not 14, but no can do)
9847c478bd9Sstevel@tonic-gate */
9857c478bd9Sstevel@tonic-gate (void) sscanf(&buf[1], "%14s", Jobid);
9867c478bd9Sstevel@tonic-gate break;
9877c478bd9Sstevel@tonic-gate
9887c478bd9Sstevel@tonic-gate default:
9897c478bd9Sstevel@tonic-gate break;
9907c478bd9Sstevel@tonic-gate }
9917c478bd9Sstevel@tonic-gate }
9927c478bd9Sstevel@tonic-gate
9937c478bd9Sstevel@tonic-gate fclose(xfp);
9947c478bd9Sstevel@tonic-gate DEBUG(4, "fin - %s, ", fin);
9957c478bd9Sstevel@tonic-gate DEBUG(4, "fout - %s, ", fout);
9967c478bd9Sstevel@tonic-gate DEBUG(4, "ferr - %s, ", ferr);
9977c478bd9Sstevel@tonic-gate DEBUG(4, "sysout - %s, ", sysout);
9987c478bd9Sstevel@tonic-gate DEBUG(4, "syserr - %s, ", syserr);
9997c478bd9Sstevel@tonic-gate DEBUG(4, "user - %s\n", user);
10007c478bd9Sstevel@tonic-gate DEBUG(4, "incmd - %s\n", incmd);
10017c478bd9Sstevel@tonic-gate
10027c478bd9Sstevel@tonic-gate scRexe(origsys, origuser, Loginuser, incmd);
10037c478bd9Sstevel@tonic-gate
10047c478bd9Sstevel@tonic-gate if (retuser[0] != NULLCHAR)
10057c478bd9Sstevel@tonic-gate (void) strlcpy(user, retuser, sizeof (user)); /* pick on this guy */
10067c478bd9Sstevel@tonic-gate
10077c478bd9Sstevel@tonic-gate /* get rid of stuff that can be dangerous */
10087c478bd9Sstevel@tonic-gate if ((p = strpbrk(user, Shchar)) != NULL) {
10097c478bd9Sstevel@tonic-gate *p = NULLCHAR;
10107c478bd9Sstevel@tonic-gate }
10117c478bd9Sstevel@tonic-gate
10127c478bd9Sstevel@tonic-gate if (incmd[0] == NULLCHAR) {
10137c478bd9Sstevel@tonic-gate /* this is a bad X. file - just get rid of it */
10147c478bd9Sstevel@tonic-gate toCorrupt(_Xfile);
10157c478bd9Sstevel@tonic-gate continue;
10167c478bd9Sstevel@tonic-gate }
10177c478bd9Sstevel@tonic-gate
10187c478bd9Sstevel@tonic-gate /*
10197c478bd9Sstevel@tonic-gate * send_nothing must be explicitly requested to avert failure status
10207c478bd9Sstevel@tonic-gate * send_zero must be explicitly requested for success notification
10217c478bd9Sstevel@tonic-gate */
10227c478bd9Sstevel@tonic-gate if (!send_nothing)
10237c478bd9Sstevel@tonic-gate send_nonzero++;
10247c478bd9Sstevel@tonic-gate
10257c478bd9Sstevel@tonic-gate /*
10267c478bd9Sstevel@tonic-gate * command execution
10277c478bd9Sstevel@tonic-gate */
10287c478bd9Sstevel@tonic-gate
10297c478bd9Sstevel@tonic-gate /*
10307c478bd9Sstevel@tonic-gate * generate a temporary file (if necessary)
10317c478bd9Sstevel@tonic-gate * to hold output to be shipped back
10327c478bd9Sstevel@tonic-gate */
10337c478bd9Sstevel@tonic-gate if (EQUALS(fout, "/dev/null"))
10347c478bd9Sstevel@tonic-gate (void) strcpy(dfile, "/dev/null");
10357c478bd9Sstevel@tonic-gate else {
10367c478bd9Sstevel@tonic-gate gename(DATAPRE, sysout, 'O', tempname);
10377c478bd9Sstevel@tonic-gate (void) snprintf(dfile, sizeof (dfile), "%s/%s", WORKSPACE,
10387c478bd9Sstevel@tonic-gate tempname);
10397c478bd9Sstevel@tonic-gate }
10407c478bd9Sstevel@tonic-gate
10417c478bd9Sstevel@tonic-gate /*
10427c478bd9Sstevel@tonic-gate * generate a temporary file (if necessary)
10437c478bd9Sstevel@tonic-gate * to hold errors to be shipped back
10447c478bd9Sstevel@tonic-gate */
10457c478bd9Sstevel@tonic-gate /*
10467c478bd9Sstevel@tonic-gate * This is what really should be done. However for compatibility
10477c478bd9Sstevel@tonic-gate * for the interim at least, we will always create temp file
10487c478bd9Sstevel@tonic-gate * so we can return error output. If this temp file IS conditionally
10497c478bd9Sstevel@tonic-gate * created, we must remove the unlink() of errDfile at the end
10507c478bd9Sstevel@tonic-gate * because it may REALLY be /dev/null.
10517c478bd9Sstevel@tonic-gate * if (EQUALS(ferr, "/dev/null"))
10527c478bd9Sstevel@tonic-gate * (void) strcpy(errDfile, "/dev/null");
10537c478bd9Sstevel@tonic-gate * else {
10547c478bd9Sstevel@tonic-gate */
10557c478bd9Sstevel@tonic-gate gename(DATAPRE, syserr, 'E', tempname);
10567c478bd9Sstevel@tonic-gate (void) snprintf(errDfile, sizeof (errDfile), "%s/%s",
10577c478bd9Sstevel@tonic-gate WORKSPACE, tempname);
10587c478bd9Sstevel@tonic-gate /*
10597c478bd9Sstevel@tonic-gate * }
10607c478bd9Sstevel@tonic-gate */
10617c478bd9Sstevel@tonic-gate
10627c478bd9Sstevel@tonic-gate /* initialize command line */
10637c478bd9Sstevel@tonic-gate /* set up two environment variables, remote machine name */
10647c478bd9Sstevel@tonic-gate /* and remote user name if available from R line */
10657c478bd9Sstevel@tonic-gate /*
10667c478bd9Sstevel@tonic-gate * xcu4 requires that uucp *does* expand wildcards and uux *does not*
10677c478bd9Sstevel@tonic-gate * expand wild cards... Further restrictions are that uux must work
10687c478bd9Sstevel@tonic-gate * with every other uucp / uux that initiated a request, so nothing
10697c478bd9Sstevel@tonic-gate * strange can been done to communicate that it was uucp that sent
10707c478bd9Sstevel@tonic-gate * the request and not uux, What we settle on here is looking for
10717c478bd9Sstevel@tonic-gate * the command name uucp and expanding wildcards in only that case.
10727c478bd9Sstevel@tonic-gate * It is true that a user can spoof this using uux, but in reality
10737c478bd9Sstevel@tonic-gate * this would be identical to using the uucp command to start with.
10747c478bd9Sstevel@tonic-gate */
10757c478bd9Sstevel@tonic-gate if (strncmp(incmd, "uucp ", 5) == 0) {
10767c478bd9Sstevel@tonic-gate (void) snprintf(_Cmd, sizeof (_Cmd),
10777c478bd9Sstevel@tonic-gate "%s %s UU_MACHINE=%s UU_USER=%s "
10787c478bd9Sstevel@tonic-gate " export UU_MACHINE UU_USER PATH; ",
10797c478bd9Sstevel@tonic-gate PATH, LOGNAME, Rmtname, user);
10807c478bd9Sstevel@tonic-gate } else {
10817c478bd9Sstevel@tonic-gate (void) snprintf(_Cmd, sizeof (_Cmd),
10827c478bd9Sstevel@tonic-gate "%s %s UU_MACHINE=%s UU_USER=%s "
10837c478bd9Sstevel@tonic-gate " export UU_MACHINE UU_USER PATH; set -f; ",
10847c478bd9Sstevel@tonic-gate PATH, LOGNAME, Rmtname, user);
10857c478bd9Sstevel@tonic-gate }
10867c478bd9Sstevel@tonic-gate
10877c478bd9Sstevel@tonic-gate /*
10887c478bd9Sstevel@tonic-gate * check to see if command can be executed
10897c478bd9Sstevel@tonic-gate */
10907c478bd9Sstevel@tonic-gate _CargType = C_COMMAND; /* the first thing is a command */
10917c478bd9Sstevel@tonic-gate cmdok = chkpart(incmd);
10927c478bd9Sstevel@tonic-gate
10937c478bd9Sstevel@tonic-gate if (badfiles || (cmdok == BAD_COMMAND) || cmdok == BAD_FILE) {
10947c478bd9Sstevel@tonic-gate if (cmdok == BAD_COMMAND) {
10957c478bd9Sstevel@tonic-gate (void) snprintf(lbuf, sizeof (lbuf), "%s!%s XQT DENIED",
10967c478bd9Sstevel@tonic-gate Rmtname, user);
10977c478bd9Sstevel@tonic-gate (void) snprintf(msgbuf, sizeof (msgbuf),
10987c478bd9Sstevel@tonic-gate "execution permission denied to %s!%s", Rmtname, user);
10997c478bd9Sstevel@tonic-gate } else {
11007c478bd9Sstevel@tonic-gate (void) snprintf(lbuf, sizeof (lbuf),
11017c478bd9Sstevel@tonic-gate "%s!%s XQT - STDIN/STDOUT/FILE ACCESS DENIED",
11027c478bd9Sstevel@tonic-gate Rmtname, user);
11037c478bd9Sstevel@tonic-gate (void) snprintf(msgbuf, sizeof (msgbuf),
11047c478bd9Sstevel@tonic-gate "file access denied to %s!%s", Rmtname, user);
11057c478bd9Sstevel@tonic-gate }
11067c478bd9Sstevel@tonic-gate logent(incmd, lbuf);
11077c478bd9Sstevel@tonic-gate DEBUG(4, "bad command %s\n", incmd);
11087c478bd9Sstevel@tonic-gate
11097c478bd9Sstevel@tonic-gate scWlog(); /* log security vialotion */
11107c478bd9Sstevel@tonic-gate
11117c478bd9Sstevel@tonic-gate if (send_nonzero)
11127c478bd9Sstevel@tonic-gate retosndr(user, Rmtname, return_stdin ? fin : "",
11137c478bd9Sstevel@tonic-gate incmd, msgbuf, "");
11147c478bd9Sstevel@tonic-gate if (store_status)
11157c478bd9Sstevel@tonic-gate uucpst(Rmtname, _Sfile, "", incmd, msgbuf);
11167c478bd9Sstevel@tonic-gate goto rmfiles;
11177c478bd9Sstevel@tonic-gate }
11187c478bd9Sstevel@tonic-gate
11197c478bd9Sstevel@tonic-gate (void) snprintf(lbuf, sizeof (lbuf), "%s!%s XQT", Rmtname, user);
11207c478bd9Sstevel@tonic-gate logent(_Cmd, lbuf);
11217c478bd9Sstevel@tonic-gate DEBUG(4, "cmd %s\n", _Cmd);
11227c478bd9Sstevel@tonic-gate
11237c478bd9Sstevel@tonic-gate /* move files to execute directory and change to that directory */
11247c478bd9Sstevel@tonic-gate
11257c478bd9Sstevel@tonic-gate mv_Xfiles();
11267c478bd9Sstevel@tonic-gate
11277c478bd9Sstevel@tonic-gate ASSERT(chdir(XQTDIR) == 0, Ct_CHDIR, XQTDIR, errno);
11287c478bd9Sstevel@tonic-gate acRexe(&_Xfile[2], origsys, origuser, Myname, Loginuser, incmd);
11297c478bd9Sstevel@tonic-gate
11307c478bd9Sstevel@tonic-gate /* invoke shell to execute command */
11317c478bd9Sstevel@tonic-gate
11327c478bd9Sstevel@tonic-gate mask = umask(0);
11337c478bd9Sstevel@tonic-gate DEBUG(7, "full cmd: %s\n", _Cmd);
11347c478bd9Sstevel@tonic-gate
11357c478bd9Sstevel@tonic-gate cpucycle();
11367c478bd9Sstevel@tonic-gate ret = shio(_Cmd, fin, dfile, errDfile);
11377c478bd9Sstevel@tonic-gate if (ret == 0)
11387c478bd9Sstevel@tonic-gate acEndexe(cpucycle(), COMPLETE);
11397c478bd9Sstevel@tonic-gate else
11407c478bd9Sstevel@tonic-gate acEndexe(cpucycle(), PARTIAL);
11417c478bd9Sstevel@tonic-gate
11427c478bd9Sstevel@tonic-gate umask(mask);
11437c478bd9Sstevel@tonic-gate if (ret == -1) { /* -1 means the fork() failed */
11447c478bd9Sstevel@tonic-gate unmv_Xfiles(); /* put things back */
11457c478bd9Sstevel@tonic-gate errent(Ct_FORK, buf, errno, __FILE__, __LINE__);
11467c478bd9Sstevel@tonic-gate cleanup(1);
11477c478bd9Sstevel@tonic-gate }
11487c478bd9Sstevel@tonic-gate
11497c478bd9Sstevel@tonic-gate if (ret == 0) { /* exit == signal == 0 */
11507c478bd9Sstevel@tonic-gate (void) strcpy(msgbuf, "exited normally");
11517c478bd9Sstevel@tonic-gate } else { /* exit != 0 */
11527c478bd9Sstevel@tonic-gate int exitcode = (ret >> 8) & 0377;
11537c478bd9Sstevel@tonic-gate
11547c478bd9Sstevel@tonic-gate if (exitcode) {
11557c478bd9Sstevel@tonic-gate /* exit != 0 */
11567c478bd9Sstevel@tonic-gate (void) snprintf(msgbuf, sizeof (msgbuf),
11577c478bd9Sstevel@tonic-gate "exited with status %d", exitcode);
11587c478bd9Sstevel@tonic-gate } else {
11597c478bd9Sstevel@tonic-gate /* signal != 0 */
11607c478bd9Sstevel@tonic-gate (void) snprintf(msgbuf, sizeof (msgbuf),
11617c478bd9Sstevel@tonic-gate "terminated by signal %d", ret & 0177);
11627c478bd9Sstevel@tonic-gate }
11637c478bd9Sstevel@tonic-gate DEBUG(5, "%s\n", msgbuf);
11647c478bd9Sstevel@tonic-gate (void) snprintf(lbuf, sizeof (lbuf), "%s - %s", incmd, msgbuf);
11657c478bd9Sstevel@tonic-gate logent(lbuf, "COMMAND FAIL");
11667c478bd9Sstevel@tonic-gate }
11677c478bd9Sstevel@tonic-gate
11687c478bd9Sstevel@tonic-gate /* change back to spool directory */
11697c478bd9Sstevel@tonic-gate
11707c478bd9Sstevel@tonic-gate chremdir(Rmtname);
11717c478bd9Sstevel@tonic-gate
11727c478bd9Sstevel@tonic-gate /* remove file */
11737c478bd9Sstevel@tonic-gate
11747c478bd9Sstevel@tonic-gate rm_Xfiles();
11757c478bd9Sstevel@tonic-gate
11767c478bd9Sstevel@tonic-gate /*
11777c478bd9Sstevel@tonic-gate * We used to append stderr to stdout. Since stderr can
11787c478bd9Sstevel@tonic-gate * now be specified separately, never append it to stdout.
11797c478bd9Sstevel@tonic-gate * It can still be gotten via -s status file option.
11807c478bd9Sstevel@tonic-gate */
11817c478bd9Sstevel@tonic-gate
11827c478bd9Sstevel@tonic-gate if (!EQUALS(fout, "/dev/null")) {
11837c478bd9Sstevel@tonic-gate /*
11847c478bd9Sstevel@tonic-gate * if output is on this machine copy output
11857c478bd9Sstevel@tonic-gate * there, otherwise spawn job to send to send
11867c478bd9Sstevel@tonic-gate * output elsewhere.
11877c478bd9Sstevel@tonic-gate */
11887c478bd9Sstevel@tonic-gate
11897c478bd9Sstevel@tonic-gate if (EQUALS(sysout, Myname)) {
11907c478bd9Sstevel@tonic-gate if ((xmv(dfile, fout)) != 0) {
11917c478bd9Sstevel@tonic-gate logent("FAILED", "COPY");
11927c478bd9Sstevel@tonic-gate scWrite();
11937c478bd9Sstevel@tonic-gate (void) snprintf(msgbuf + strlen(msgbuf),
11947c478bd9Sstevel@tonic-gate (sizeof (msgbuf) - strlen(msgbuf)),
11957c478bd9Sstevel@tonic-gate "\nCould not move stdout to %s,", fout);
11967c478bd9Sstevel@tonic-gate if (putinpub(fout, dfile, origuser) == 0)
11977c478bd9Sstevel@tonic-gate (void) snprintf(msgbuf + strlen(msgbuf),
11987c478bd9Sstevel@tonic-gate (sizeof (msgbuf) - strlen(msgbuf)),
11997c478bd9Sstevel@tonic-gate "\n\tstdout left in %s.", fout);
12007c478bd9Sstevel@tonic-gate else
12017c478bd9Sstevel@tonic-gate (void) strlcat(msgbuf, " stdout lost.",
12027c478bd9Sstevel@tonic-gate sizeof (msgbuf));
12037c478bd9Sstevel@tonic-gate }
12047c478bd9Sstevel@tonic-gate } else {
1205*462be471Sceastha char *bname;
1206*462be471Sceastha
12077c478bd9Sstevel@tonic-gate if (eaccess(GRADES, 04) != -1)
12087c478bd9Sstevel@tonic-gate dqueue = fdgrade();
12097c478bd9Sstevel@tonic-gate else
12107c478bd9Sstevel@tonic-gate dqueue = Grade;
12117c478bd9Sstevel@tonic-gate gename(CMDPRE, sysout, dqueue, tempname);
12127c478bd9Sstevel@tonic-gate (void) snprintf(cfile, sizeof (cfile), "%s/%s",
12137c478bd9Sstevel@tonic-gate WORKSPACE, tempname);
12147c478bd9Sstevel@tonic-gate fp = fdopen(ret = creat(cfile, CFILEMODE), "w");
12157c478bd9Sstevel@tonic-gate ASSERT(ret >= 0 && fp != NULL, Ct_OPEN, cfile, errno);
1216*462be471Sceastha bname = BASENAME(dfile, '/');
12177c478bd9Sstevel@tonic-gate (void) fprintf(fp, "S %s %s %s -d %s 0666\n",
1218*462be471Sceastha bname, fout, user, bname);
12197c478bd9Sstevel@tonic-gate fclose(fp);
12207c478bd9Sstevel@tonic-gate (void) snprintf(sendsys, sizeof (sendsys), "%s/%c", sysout,
12217c478bd9Sstevel@tonic-gate dqueue);
12227c478bd9Sstevel@tonic-gate sendsys[MAXNAMESIZE-1] = '\0';
12237c478bd9Sstevel@tonic-gate wfcommit(dfile, BASENAME(dfile, '/'), sendsys);
12247c478bd9Sstevel@tonic-gate wfcommit(cfile, BASENAME(cfile, '/'), sendsys);
12257c478bd9Sstevel@tonic-gate }
12267c478bd9Sstevel@tonic-gate }
12277c478bd9Sstevel@tonic-gate if (!EQUALS(ferr, "/dev/null")) {
12287c478bd9Sstevel@tonic-gate /*
12297c478bd9Sstevel@tonic-gate * if stderr is on this machine copy output
12307c478bd9Sstevel@tonic-gate * there, otherwise spawn job to send to send
12317c478bd9Sstevel@tonic-gate * it elsewhere.
12327c478bd9Sstevel@tonic-gate */
12337c478bd9Sstevel@tonic-gate if (EQUALS(syserr, Myname)) {
12347c478bd9Sstevel@tonic-gate errname = ferr;
12357c478bd9Sstevel@tonic-gate if ((xmv(errDfile, ferr)) != 0) {
12367c478bd9Sstevel@tonic-gate logent("FAILED", "COPY");
12377c478bd9Sstevel@tonic-gate scWrite();
12387c478bd9Sstevel@tonic-gate (void) snprintf(msgbuf + strlen(msgbuf),
12397c478bd9Sstevel@tonic-gate (sizeof (msgbuf) - strlen(msgbuf)),
12407c478bd9Sstevel@tonic-gate "\nCould not move stderr to %s,", ferr);
12417c478bd9Sstevel@tonic-gate if (putinpub(ferr, errDfile, origuser) == 0) {
12427c478bd9Sstevel@tonic-gate (void) snprintf(msgbuf+strlen(msgbuf),
12437c478bd9Sstevel@tonic-gate (sizeof (msgbuf) - strlen(msgbuf)),
12447c478bd9Sstevel@tonic-gate "\n\tstderr left in %s", ferr);
12457c478bd9Sstevel@tonic-gate } else {
12467c478bd9Sstevel@tonic-gate errname = errDfile;
12477c478bd9Sstevel@tonic-gate (void) strlcat(msgbuf, " stderr lost.",
12487c478bd9Sstevel@tonic-gate sizeof (msgbuf));
12497c478bd9Sstevel@tonic-gate }
12507c478bd9Sstevel@tonic-gate }
12517c478bd9Sstevel@tonic-gate } else {
1252*462be471Sceastha char *bname;
1253*462be471Sceastha
12547c478bd9Sstevel@tonic-gate if (eaccess(GRADES, 04) != -1)
12557c478bd9Sstevel@tonic-gate dqueue = fdgrade();
12567c478bd9Sstevel@tonic-gate else
12577c478bd9Sstevel@tonic-gate dqueue = Grade;
12587c478bd9Sstevel@tonic-gate gename(CMDPRE, syserr, dqueue, tempname);
12597c478bd9Sstevel@tonic-gate (void) snprintf(cfile, sizeof (cfile), "%s/%s",
12607c478bd9Sstevel@tonic-gate WORKSPACE, tempname);
12617c478bd9Sstevel@tonic-gate fp = fdopen(ret = creat(cfile, CFILEMODE), "w");
12627c478bd9Sstevel@tonic-gate ASSERT(ret >= 0 && fp != NULL, Ct_OPEN, cfile, errno);
1263*462be471Sceastha bname = BASENAME(errDfile, '/');
12647c478bd9Sstevel@tonic-gate (void) fprintf(fp, "S %s %s %s -d %s 0666\n",
1265*462be471Sceastha bname, ferr, user, bname);
12667c478bd9Sstevel@tonic-gate fclose(fp);
12677c478bd9Sstevel@tonic-gate (void) snprintf(sendsys, sizeof (sendsys), "%s/%c",
12687c478bd9Sstevel@tonic-gate syserr, dqueue);
12697c478bd9Sstevel@tonic-gate sendsys[MAXNAMESIZE-1] = '\0';
12707c478bd9Sstevel@tonic-gate wfcommit(errDfile, BASENAME(errDfile, '/'), sendsys);
12717c478bd9Sstevel@tonic-gate wfcommit(cfile, BASENAME(cfile, '/'), sendsys);
12727c478bd9Sstevel@tonic-gate }
12737c478bd9Sstevel@tonic-gate } else {
12747c478bd9Sstevel@tonic-gate /*
12757c478bd9Sstevel@tonic-gate * If we conditionally create stderr tempfile, we must
12767c478bd9Sstevel@tonic-gate * remove this unlink() since errDfile may REALLY be /dev/null
12777c478bd9Sstevel@tonic-gate */
12787c478bd9Sstevel@tonic-gate unlink(errDfile);
12797c478bd9Sstevel@tonic-gate }
12807c478bd9Sstevel@tonic-gate
12817c478bd9Sstevel@tonic-gate if (ret == 0) {
12827c478bd9Sstevel@tonic-gate if (send_zero)
12837c478bd9Sstevel@tonic-gate retosndr(user, Rmtname, "", incmd, msgbuf, "");
12847c478bd9Sstevel@tonic-gate if (store_status)
12857c478bd9Sstevel@tonic-gate uucpst(Rmtname, _Sfile, "", incmd, msgbuf);
12867c478bd9Sstevel@tonic-gate } else {
12877c478bd9Sstevel@tonic-gate if (send_nonzero)
12887c478bd9Sstevel@tonic-gate retosndr(user, Rmtname, return_stdin ? fin : "",
12897c478bd9Sstevel@tonic-gate incmd, msgbuf, errname);
12907c478bd9Sstevel@tonic-gate if (store_status)
12917c478bd9Sstevel@tonic-gate uucpst(Rmtname, _Sfile, errname, incmd, msgbuf);
12927c478bd9Sstevel@tonic-gate }
12937c478bd9Sstevel@tonic-gate
12947c478bd9Sstevel@tonic-gate rmfiles:
12957c478bd9Sstevel@tonic-gate
12967c478bd9Sstevel@tonic-gate /* delete job files in spool directory */
12977c478bd9Sstevel@tonic-gate xfp = fopen(_Xfile, "r");
12987c478bd9Sstevel@tonic-gate ASSERT(xfp != NULL, Ct_OPEN, _Xfile, errno);
12997c478bd9Sstevel@tonic-gate while (fgets(buf, BUFSIZ, xfp) != NULL) {
13007c478bd9Sstevel@tonic-gate if (buf[0] != X_RQDFILE)
13017c478bd9Sstevel@tonic-gate continue;
13027c478bd9Sstevel@tonic-gate (void) sscanf(&buf[1], "%63s", file);
13037c478bd9Sstevel@tonic-gate expfile(file);
13047c478bd9Sstevel@tonic-gate if (chkpth(file, CK_WRITE) != FAIL)
13057c478bd9Sstevel@tonic-gate (void) unlink(file);
13067c478bd9Sstevel@tonic-gate }
13077c478bd9Sstevel@tonic-gate (void) unlink(_Xfile);
13087c478bd9Sstevel@tonic-gate fclose(xfp);
13097c478bd9Sstevel@tonic-gate }
13107c478bd9Sstevel@tonic-gate }
1311