#include "uucp.h"
#include "log.h"
#ifndef V7
#define LOGNAME "LOGNAME=uucp"
#else
#define LOGNAME "USER=uucp"
#endif
#define C_COMMAND 1
#define C_FILE 2
#define BAD_COMMAND 1
#define BAD_FILE 2
#define USAGEPREFIX "Usage:"
#define USAGE "[-x DEBUG] [-s SYSTEM]"
char _Xfile[MAXFULLNAME];
char _Cmd[2 * BUFSIZ];
int _CargType;
static void retosndr(), uucpst();
static int chkFile();
static int doFileChk();
void cleanup(), xprocess();
int
main(argc, argv, envp)
int argc;
char *argv[];
char *envp[];
{
DIR *fp1;
struct limits limitval;
int ret, maxnumb;
char dirname[MAXFULLNAME], lockname[MAXFULLNAME];
void onintr();
(void) setlocale(LC_ALL, "");
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
(void) signal(SIGILL, onintr);
(void) signal(SIGTRAP, onintr);
(void) signal(SIGIOT, onintr);
(void) signal(SIGEMT, onintr);
(void) signal(SIGFPE, onintr);
(void) signal(SIGBUS, onintr);
(void) signal(SIGSEGV, onintr);
(void) signal(SIGSYS, onintr);
(void) signal(SIGPIPE, onintr);
(void) signal(SIGTERM, SIG_IGN);
(void) strcpy(Logfile, LOGUUXQT);
Env = envp;
Nstat.t_qtime = time((time_t *)0);
(void) strcpy(Progname, "uuxqt");
Pchar = 'Q';
uucpname(Myname);
Ofn = 1;
Ifn = 0;
dirname[0] = dirname[MAXFULLNAME-1] = NULLCHAR;
while ((ret = getopt(argc, argv, "s:x:")) != EOF) {
switch (ret) {
case 'x':
Debug = atoi(optarg);
if (Debug <= 0)
Debug = 1;
break;
case 's':
(void) strlcpy(dirname, optarg,
(MAXFULLNAME - sizeof (SEQLOCK)));
break;
default:
(void) fprintf(stderr, "%s %s %s\n",
gettext(USAGEPREFIX), Progname, gettext(USAGE));
exit(1);
}
}
if (argc != optind) {
(void) fprintf(stderr, "%s %s %s\n",
gettext(USAGEPREFIX), Progname, gettext(USAGE));
exit(1);
}
DEBUG(4, "\n\n** START **\n%s", "");
acInit("rexe");
scInit("rexe");
if (scanlimit("uuxqt", &limitval) == FAIL) {
DEBUG(1, "No limits for uuxqt in %s\n", LIMITS);
} else {
maxnumb = limitval.totalmax;
if (maxnumb < 0) {
DEBUG(4, "Non-positive limit for uuxqt in %s\n", LIMITS);
DEBUG(1, "No limits for uuxqt\n%s", "");
} else {
DEBUG(4, "Uuxqt limit %d -- ", maxnumb);
ret = cuantos(X_LOCKPRE, X_LOCKDIR);
DEBUG(4, "found %d -- ", ret);
if (maxnumb >= 0 && ret >= maxnumb) {
DEBUG(4, "exiting.%s\n", "");
exit(0);
}
DEBUG(4, "continuing.%s\n", "");
}
}
strcpy(User, "uucp");
Uid = getuid();
Euid = geteuid();
guinfo(Euid, User);
if (Uid == 0)
(void) setuid(UUCPUID);
setuucp(User);
DEBUG(4, "User - %s\n", User);
guinfo(Uid, Loginuser);
DEBUG(4, "process\n%s", "");
fp1 = opendir(Spool);
ASSERT(fp1 != NULL, Ct_OPEN, Spool, errno);
if (dirname[0] != NULLCHAR) {
if (strpbrk(dirname, Shchar) != NULL) {
DEBUG(4, "Bad remote name '%s'", dirname);
errent("BAD REMOTE NAME", dirname, 0, __FILE__, __LINE__);
closedir(fp1);
cleanup(101);
}
(void) snprintf(lockname, sizeof (lockname), "%s.%s",
X_LOCK, dirname);
if (mklock(lockname) == SUCCESS) {
xprocess(dirname);
rmlock(CNULL);
}
} else {
while (gdirf(fp1, dirname, Spool) == TRUE) {
if (strpbrk(dirname, Shchar) != NULL) {
errent("BAD REMOTE NAME", dirname, 0,
__FILE__, __LINE__);
continue;
}
(void) snprintf(lockname, sizeof (lockname), "%s.%s",
X_LOCK, dirname);
if (mklock(lockname) != SUCCESS)
continue;
xprocess(dirname);
rmlock(CNULL);
}
}
closedir(fp1);
cleanup(0);
return (0);
}
void
cleanup(code)
int code;
{
rmlock(CNULL);
exit(code);
}
void
onintr(inter)
int inter;
{
char str[30];
(void) signal(inter, SIG_IGN);
(void) sprintf(str, "QSIGNAL %d", inter);
logent(str, "QCAUGHT");
acEndexe(cpucycle(), PARTIAL);
cleanup(-inter);
}
#define XCACHESIZE (4096 / (MAXBASENAME + 1))
static char xcache[XCACHESIZE][MAXBASENAME + 1];
static int xcachesize = 0;
static void
xstash(file)
char *file;
{
if (xcachesize < XCACHESIZE) {
DEBUG(4, "stashing %s\n", file);
(void) strlcpy(xcache[xcachesize++], file, (MAXBASENAME + 1));
}
}
static int
xcompare(f1, f2)
const void *f1, *f2;
{
return (-strcmp((char *)f1 + strlen((char *)f1) - 5,
(char *)f2 + strlen((char *)f2) - 5));
}
static void
xsort()
{
DEBUG(4, "xsort: first was %s\n", xcache[0]);
qsort(xcache, xcachesize, MAXBASENAME + 1, xcompare);
DEBUG(4, "xsort: first is %s\n", xcache[0]);
}
static int
xget(file)
char *file;
{
if (xcachesize > 0) {
strlcpy(file, xcache[--xcachesize], (MAXBASENAME + 1));
DEBUG(4, "xget: returning %s\n", file);
return (1);
} else {
xcachesize = 0;
return (0);
}
}
int
gt_Xfile(file, dir)
char *file, *dir;
{
DIR *pdir;
if (xcachesize == 0) {
pdir = opendir(dir);
if (pdir == NULL)
return (0);
while (gnamef(pdir, file) == TRUE) {
DEBUG(4, "gt_Xfile got %s\n", file);
if (file[0] != XQTPRE)
continue;
if (gotfiles(file))
xstash(file);
if (xcachesize >= XCACHESIZE)
break;
}
closedir(pdir);
xsort();
}
return (xget(file));
}
int
gotfiles(file)
char *file;
{
FILE *fp;
struct stat stbuf;
char buf[BUFSIZ], rqfile[MAXNAMESIZE];
fp = fopen(file, "r");
if (fp == NULL)
return (FALSE);
while (fgets(buf, BUFSIZ, fp) != NULL) {
DEBUG(4, "%s\n", buf);
if (buf[0] != X_RQDFILE)
continue;
(void) sscanf(&buf[1], "%63s", rqfile);
expfile(rqfile);
if (stat(rqfile, &stbuf) == -1) {
fclose(fp);
return (FALSE);
}
}
fclose(fp);
return (TRUE);
}
void
rm_Xfiles()
{
FILE *fp;
char buf[BUFSIZ], file[MAXNAMESIZE], tfile[MAXNAMESIZE];
char tfull[MAXFULLNAME];
if ((fp = fopen(_Xfile, "r")) == NULL) {
DEBUG(4, "rm_Xfiles: can't read %s\n", _Xfile);
return;
}
while (fgets(buf, BUFSIZ, fp) != NULL) {
if (buf[0] != X_RQDFILE)
continue;
if (sscanf(&buf[1], "%63s%63s", file, tfile) < 2)
continue;
(void) snprintf(tfull, sizeof (tfull), "%s/%s", XQTDIR, tfile);
(void) unlink(tfull);
}
fclose(fp);
}
void
mv_Xfiles()
{
FILE *fp;
char buf[BUFSIZ], ffile[MAXFULLNAME], tfile[MAXNAMESIZE];
char tfull[MAXFULLNAME];
if ((fp = fopen(_Xfile, "r")) == NULL) {
DEBUG(4, "mv_Xfiles: can't read %s\n", _Xfile);
return;
}
while (fgets(buf, BUFSIZ, fp) != NULL) {
if (buf[0] != X_RQDFILE)
continue;
if (sscanf(&buf[1], "%63s%63s", ffile, tfile) < 2)
continue;
expfile(ffile);
(void) snprintf(tfull, sizeof (tfull), "%s/%s", XQTDIR, tfile);
if (chkpth(ffile, CK_READ) == FAIL)
continue;
if (chkpth(tfull, CK_WRITE) == FAIL) {
if (!PREFIX(XQTDIR, tfull))
continue;
}
ASSERT(xmv(ffile, tfull) == 0, "XMV ERROR", tfull, errno);
chmod(tfull, PUB_FILEMODE);
}
fclose(fp);
}
void
unmv_Xfiles()
{
FILE *fp;
char buf[BUFSIZ], ffile[MAXNAMESIZE], tfile[MAXNAMESIZE];
char tfull[MAXFULLNAME], ffull[MAXFULLNAME], xfull[MAXFULLNAME];
(void) snprintf(xfull, MAXFULLNAME, "%s/%s", RemSpool, _Xfile);
if ((fp = fopen(xfull, "r")) == NULL) {
DEBUG(4, "unmv_Xfiles: can't read %s\n", xfull);
return;
}
while (fgets(buf, BUFSIZ, fp) != NULL) {
if (buf[0] != X_RQDFILE)
continue;
if (sscanf(&buf[1], "%63s%63s", ffile, tfile) < 2)
continue;
(void) snprintf(ffull, MAXFULLNAME, "%s/%s", RemSpool, ffile);
(void) snprintf(tfull, MAXFULLNAME, "%s/%s", XQTDIR, tfile);
if (chkpth(ffull, CK_WRITE) == FAIL ||
chkpth(tfull, CK_READ) == FAIL)
continue;
ASSERT(xmv(tfull, ffull) == 0, "XMV ERROR", ffull, errno);
(void) chmod(ffull, (mode_t)0600);
}
fclose(fp);
}
static int
chkpart(char *ptr)
{
char prm[BUFSIZ], whitesp[BUFSIZ], rqtcmd[BUFSIZ], xcmd[BUFSIZ];
char savechar[2];
int ret;
while ((ptr = getprm(ptr, whitesp, prm)) != NULL) {
DEBUG(4, "prm='%s'\n", prm);
switch (*prm) {
case ';':
case '^':
case '&':
case '|':
(void) strlcat(_Cmd, whitesp, sizeof (_Cmd));
(void) strlcat(_Cmd, prm, sizeof (_Cmd));
_CargType = C_COMMAND;
continue;
case '>':
case '<':
(void) strlcat(_Cmd, whitesp, sizeof (_Cmd));
(void) strlcat(_Cmd, prm, sizeof (_Cmd));
continue;
case '`':
case '\\':
return (BAD_COMMAND);
case '(':
case '"':
case '\'':
savechar[0] = *prm;
savechar[1] = NULLCHAR;
(void) strlcat(_Cmd, whitesp, sizeof (_Cmd));
(void) strlcat(_Cmd, savechar, sizeof (_Cmd));
savechar[0] = prm[strlen(prm)-1];
prm[strlen(prm)-1] = NULLCHAR;
if (ret = chkpart(prm+1)) {
return (ret);
}
(void) strlcat(_Cmd, savechar, sizeof (_Cmd));
continue;
case '2':
if (*(prm+1) == '>') {
(void) strlcat(_Cmd, whitesp, sizeof (_Cmd));
(void) strlcat(_Cmd, prm, sizeof (_Cmd));
continue;
}
default:
break;
}
if (_CargType == C_COMMAND) {
(void) strlcpy(rqtcmd, prm, sizeof (rqtcmd));
if (*rqtcmd == '~')
expfile(rqtcmd);
if ((cmdOK(rqtcmd, xcmd)) == FALSE)
return (BAD_COMMAND);
(void) strlcat(_Cmd, whitesp, sizeof (_Cmd));
(void) strlcat(_Cmd, xcmd, sizeof (_Cmd));
_CargType = C_FILE;
continue;
}
(void) strlcpy(rqtcmd, prm, sizeof (rqtcmd));
if (*rqtcmd == '~')
expfile(rqtcmd);
if (chkFile(rqtcmd)) {
return (BAD_FILE);
} else {
(void) strlcat(_Cmd, whitesp, sizeof (_Cmd));
(void) strlcat(_Cmd, rqtcmd, sizeof (_Cmd));
}
}
if (whitesp[0] != '\0')
(void) strlcat(_Cmd, whitesp, sizeof (_Cmd));
return (0);
}
static int
chkFile(char *prm)
{
char *p, buf[BUFSIZ];
(void) strlcpy(buf, prm, sizeof (buf));
switch (*prm) {
case '~':
case '/':
if (doFileChk(buf))
return (BAD_FILE);
else
return (0);
case '!':
return (chkFile(buf+1));
default:
break;
}
if ((p = strchr(buf, '!')) == NULL) {
if ((p = strchr(buf, '/')) == NULL) {
return (0);
}
if (doFileChk(p))
return (BAD_FILE);
else
return (0);
}
if (PREFIX(Myname, buf))
return (chkFile(p+1));
else
return (0);
}
static int
doFileChk(char *file)
{
expfile(file);
DEBUG(7, "fullname: %s\n", file);
if (chkpth(file, CK_READ) == FAIL ||
chkpth(file, CK_WRITE) == FAIL)
return (BAD_FILE);
else
return (0);
}
static void
retosndr(user, rmt, file, cmd, buf, errfile)
char *user, *rmt, *file, *cmd, *buf, *errfile;
{
char ruser[BUFSIZ], msg[BUFSIZ], subj[BUFSIZ];
(void) snprintf(msg, sizeof (msg), "%s\t[%s %s (%s)]\n\t%s\n%s\n",
gettext("remote execution"), gettext("uucp job"),
*Jobid ? Jobid : &_Xfile[2], timeStamp(), cmd, buf);
DEBUG(5, "retosndr %s, ", msg);
if (EQUALS(rmt, Myname))
(void) strlcpy(ruser, user, sizeof (ruser));
else
(void) snprintf(ruser, sizeof (ruser), "%s!%s", rmt, user);
(void) strlcpy(subj, gettext("remote execution status"), sizeof (subj));
mailst(ruser, subj, msg, file, errfile);
}
static void
uucpst(rmt, tofile, errfile, cmd, buf)
char *rmt, *tofile, *errfile, *cmd, *buf;
{
char arg[MAXFULLNAME], tmp[NAMESIZE], msg[BUFSIZ];
pid_t pid, ret;
int status;
FILE *fp, *fi;
(void) snprintf(msg, sizeof (msg), "%s %s (%s) %s\n\t%s\n%s\n",
gettext("uucp job"), *Jobid ? Jobid : &_Xfile[2], timeStamp(),
gettext("remote execution"), cmd, buf);
(void) snprintf(tmp, sizeof (tmp), "%s.%ld", rmt, (long)getpid());
if ((fp = fopen(tmp, "w")) == NULL)
return;
(void) fprintf(fp, "%s\n", msg);
if (*errfile != '\0' && NOTEMPTY(errfile) &&
(fi = fopen(errfile, "r")) != NULL) {
fputs("\n\t===== stderr was =====\n", fp);
if (xfappend(fi, fp) != SUCCESS)
fputs("\n\t===== well, i tried =====\n", fp);
(void) fclose(fi);
fputc('\n', fp);
}
(void) fclose(fp);
(void) snprintf(arg, sizeof (arg), "%s!%s", rmt, tofile);
if ((pid = vfork()) == 0) {
(void) close(0);
(void) close(1);
(void) close(2);
(void) open("/dev/null", 2);
(void) open("/dev/null", 2);
(void) open("/dev/null", 2);
(void) signal(SIGINT, SIG_IGN);
(void) signal(SIGHUP, SIG_IGN);
(void) signal(SIGQUIT, SIG_IGN);
ucloselog();
(void) execle("/usr/bin/uucp", "UUCP",
"-C", tmp, arg, (char *)0, Env);
_exit(100);
}
if (pid == -1)
return;
while ((ret = wait(&status)) != pid)
if (ret == -1 && errno != EINTR)
break;
(void) unlink(tmp);
}
void
xprocess(dirname)
char *dirname;
{
char fdgrade();
int return_stdin;
int cmdok, ret, badfiles;
mode_t mask;
int send_zero;
int send_nonzero;
int send_nothing;
int store_status;
char lbuf[BUFSIZ];
char dqueue;
char *errname = "";
char *p;
char sendsys[MAXNAMESIZE];
char dfile[MAXFULLNAME], cfile[MAXFULLNAME], incmd[BUFSIZ];
char errDfile[BUFSIZ];
char fin[MAXFULLNAME];
char fout[MAXFULLNAME], sysout[NAMESIZE];
char ferr[MAXFULLNAME], syserr[NAMESIZE];
char file[MAXFULLNAME], tempname[NAMESIZE];
char _Sfile[MAXFULLNAME];
FILE *xfp, *fp;
struct stat sb;
char buf[BUFSIZ], user[BUFSIZ], retaddr[BUFSIZ], retuser[BUFSIZ],
msgbuf[BUFSIZ];
char origsys[MAXFULLNAME], origuser[MAXFULLNAME];
(void) strlcpy(Rmtname, dirname, sizeof (Rmtname));
chremdir(Rmtname);
(void) mchFind(Rmtname);
while (gt_Xfile(_Xfile, RemSpool) > 0) {
DEBUG(4, "_Xfile - %s\n", _Xfile);
if ((xfp = fopen(_Xfile, "r")) == NULL) {
toCorrupt(_Xfile);
continue;
}
ASSERT(xfp != NULL, Ct_OPEN, _Xfile, errno);
if (stat(_Xfile, &sb) != -1)
Nstat.t_qtime = sb.st_mtime;
(void) strlcpy(user, User, sizeof (user));
(void) strcpy(fin, "/dev/null");
(void) strcpy(fout, "/dev/null");
(void) strcpy(ferr, "/dev/null");
(void) sprintf(sysout, "%.*s", MAXBASENAME, Myname);
(void) sprintf(syserr, "%.*s", MAXBASENAME, Myname);
badfiles = 0;
*incmd = *retaddr = *retuser = *Jobid = NULLCHAR;
initSeq();
send_zero = send_nonzero = send_nothing = 0;
store_status = 0;
return_stdin = 0;
while (fgets(buf, BUFSIZ, xfp) != NULL) {
switch (buf[0]) {
case X_USER:
(void) sscanf(&buf[1], "%32s%14s", user, origsys);
(void) strlcpy(origuser, user, sizeof (origuser));
break;
case X_STDIN:
(void) sscanf(&buf[1], "%256s", fin);
expfile(fin);
if (chkpth(fin, CK_READ)) {
DEBUG(4, "badfile - in: %s\n", fin);
badfiles = 1;
}
break;
case X_STDOUT:
(void) sscanf(&buf[1], "%256s%14s", fout, sysout);
if ((p = strpbrk(sysout, "!/")) != NULL)
*p = NULLCHAR;
if (*sysout != NULLCHAR && !EQUALS(sysout, Myname))
break;
expfile(fout);
if (chkpth(fout, CK_WRITE)) {
badfiles = 1;
DEBUG(4, "badfile - out: %s\n", fout);
}
break;
case X_STDERR:
(void) sscanf(&buf[1], "%256s%14s", ferr, syserr);
if ((p = strpbrk(syserr, "!/")) != NULL)
*p = NULLCHAR;
if (*syserr != NULLCHAR && !EQUALS(syserr, Myname))
break;
expfile(ferr);
if (chkpth(ferr, CK_WRITE)) {
badfiles = 1;
DEBUG(4, "badfile - error: %s\n", ferr);
}
break;
case X_CMD:
(void) strlcpy(incmd, &buf[2], sizeof (incmd));
if (*(incmd + strlen(incmd) - 1) == '\n')
*(incmd + strlen(incmd) - 1) = NULLCHAR;
break;
case X_MAILF:
store_status = 1;
(void) sscanf(&buf[1], "%256s", _Sfile);
break;
case X_SENDNOTHING:
send_nothing++;
break;
case X_SENDZERO:
send_zero++;
break;
case X_NONZERO:
send_nonzero++;
break;
case X_BRINGBACK:
return_stdin = 1;
break;
case X_RETADDR:
(void) sscanf(&buf[1], "%s", retuser);
break;
case X_JOBID:
(void) sscanf(&buf[1], "%14s", Jobid);
break;
default:
break;
}
}
fclose(xfp);
DEBUG(4, "fin - %s, ", fin);
DEBUG(4, "fout - %s, ", fout);
DEBUG(4, "ferr - %s, ", ferr);
DEBUG(4, "sysout - %s, ", sysout);
DEBUG(4, "syserr - %s, ", syserr);
DEBUG(4, "user - %s\n", user);
DEBUG(4, "incmd - %s\n", incmd);
scRexe(origsys, origuser, Loginuser, incmd);
if (retuser[0] != NULLCHAR)
(void) strlcpy(user, retuser, sizeof (user));
if ((p = strpbrk(user, Shchar)) != NULL) {
*p = NULLCHAR;
}
if (incmd[0] == NULLCHAR) {
toCorrupt(_Xfile);
continue;
}
if (!send_nothing)
send_nonzero++;
if (EQUALS(fout, "/dev/null"))
(void) strcpy(dfile, "/dev/null");
else {
gename(DATAPRE, sysout, 'O', tempname);
(void) snprintf(dfile, sizeof (dfile), "%s/%s", WORKSPACE,
tempname);
}
gename(DATAPRE, syserr, 'E', tempname);
(void) snprintf(errDfile, sizeof (errDfile), "%s/%s",
WORKSPACE, tempname);
if (strncmp(incmd, "uucp ", 5) == 0) {
(void) snprintf(_Cmd, sizeof (_Cmd),
"%s %s UU_MACHINE=%s UU_USER=%s "
" export UU_MACHINE UU_USER PATH; ",
PATH, LOGNAME, Rmtname, user);
} else {
(void) snprintf(_Cmd, sizeof (_Cmd),
"%s %s UU_MACHINE=%s UU_USER=%s "
" export UU_MACHINE UU_USER PATH; set -f; ",
PATH, LOGNAME, Rmtname, user);
}
_CargType = C_COMMAND;
cmdok = chkpart(incmd);
if (badfiles || (cmdok == BAD_COMMAND) || cmdok == BAD_FILE) {
if (cmdok == BAD_COMMAND) {
(void) snprintf(lbuf, sizeof (lbuf), "%s!%s XQT DENIED",
Rmtname, user);
(void) snprintf(msgbuf, sizeof (msgbuf),
"execution permission denied to %s!%s", Rmtname, user);
} else {
(void) snprintf(lbuf, sizeof (lbuf),
"%s!%s XQT - STDIN/STDOUT/FILE ACCESS DENIED",
Rmtname, user);
(void) snprintf(msgbuf, sizeof (msgbuf),
"file access denied to %s!%s", Rmtname, user);
}
logent(incmd, lbuf);
DEBUG(4, "bad command %s\n", incmd);
scWlog();
if (send_nonzero)
retosndr(user, Rmtname, return_stdin ? fin : "",
incmd, msgbuf, "");
if (store_status)
uucpst(Rmtname, _Sfile, "", incmd, msgbuf);
goto rmfiles;
}
(void) snprintf(lbuf, sizeof (lbuf), "%s!%s XQT", Rmtname, user);
logent(_Cmd, lbuf);
DEBUG(4, "cmd %s\n", _Cmd);
mv_Xfiles();
ASSERT(chdir(XQTDIR) == 0, Ct_CHDIR, XQTDIR, errno);
acRexe(&_Xfile[2], origsys, origuser, Myname, Loginuser, incmd);
mask = umask(0);
DEBUG(7, "full cmd: %s\n", _Cmd);
cpucycle();
ret = shio(_Cmd, fin, dfile, errDfile);
if (ret == 0)
acEndexe(cpucycle(), COMPLETE);
else
acEndexe(cpucycle(), PARTIAL);
umask(mask);
if (ret == -1) {
unmv_Xfiles();
errent(Ct_FORK, buf, errno, __FILE__, __LINE__);
cleanup(1);
}
if (ret == 0) {
(void) strcpy(msgbuf, "exited normally");
} else {
int exitcode = (ret >> 8) & 0377;
if (exitcode) {
(void) snprintf(msgbuf, sizeof (msgbuf),
"exited with status %d", exitcode);
} else {
(void) snprintf(msgbuf, sizeof (msgbuf),
"terminated by signal %d", ret & 0177);
}
DEBUG(5, "%s\n", msgbuf);
(void) snprintf(lbuf, sizeof (lbuf), "%s - %s", incmd, msgbuf);
logent(lbuf, "COMMAND FAIL");
}
chremdir(Rmtname);
rm_Xfiles();
if (!EQUALS(fout, "/dev/null")) {
if (EQUALS(sysout, Myname)) {
if ((xmv(dfile, fout)) != 0) {
logent("FAILED", "COPY");
scWrite();
(void) snprintf(msgbuf + strlen(msgbuf),
(sizeof (msgbuf) - strlen(msgbuf)),
"\nCould not move stdout to %s,", fout);
if (putinpub(fout, dfile, origuser) == 0)
(void) snprintf(msgbuf + strlen(msgbuf),
(sizeof (msgbuf) - strlen(msgbuf)),
"\n\tstdout left in %s.", fout);
else
(void) strlcat(msgbuf, " stdout lost.",
sizeof (msgbuf));
}
} else {
char *bname;
if (eaccess(GRADES, 04) != -1)
dqueue = fdgrade();
else
dqueue = Grade;
gename(CMDPRE, sysout, dqueue, tempname);
(void) snprintf(cfile, sizeof (cfile), "%s/%s",
WORKSPACE, tempname);
fp = fdopen(ret = creat(cfile, CFILEMODE), "w");
ASSERT(ret >= 0 && fp != NULL, Ct_OPEN, cfile, errno);
bname = BASENAME(dfile, '/');
(void) fprintf(fp, "S %s %s %s -d %s 0666\n",
bname, fout, user, bname);
fclose(fp);
(void) snprintf(sendsys, sizeof (sendsys), "%s/%c", sysout,
dqueue);
sendsys[MAXNAMESIZE-1] = '\0';
wfcommit(dfile, BASENAME(dfile, '/'), sendsys);
wfcommit(cfile, BASENAME(cfile, '/'), sendsys);
}
}
if (!EQUALS(ferr, "/dev/null")) {
if (EQUALS(syserr, Myname)) {
errname = ferr;
if ((xmv(errDfile, ferr)) != 0) {
logent("FAILED", "COPY");
scWrite();
(void) snprintf(msgbuf + strlen(msgbuf),
(sizeof (msgbuf) - strlen(msgbuf)),
"\nCould not move stderr to %s,", ferr);
if (putinpub(ferr, errDfile, origuser) == 0) {
(void) snprintf(msgbuf+strlen(msgbuf),
(sizeof (msgbuf) - strlen(msgbuf)),
"\n\tstderr left in %s", ferr);
} else {
errname = errDfile;
(void) strlcat(msgbuf, " stderr lost.",
sizeof (msgbuf));
}
}
} else {
char *bname;
if (eaccess(GRADES, 04) != -1)
dqueue = fdgrade();
else
dqueue = Grade;
gename(CMDPRE, syserr, dqueue, tempname);
(void) snprintf(cfile, sizeof (cfile), "%s/%s",
WORKSPACE, tempname);
fp = fdopen(ret = creat(cfile, CFILEMODE), "w");
ASSERT(ret >= 0 && fp != NULL, Ct_OPEN, cfile, errno);
bname = BASENAME(errDfile, '/');
(void) fprintf(fp, "S %s %s %s -d %s 0666\n",
bname, ferr, user, bname);
fclose(fp);
(void) snprintf(sendsys, sizeof (sendsys), "%s/%c",
syserr, dqueue);
sendsys[MAXNAMESIZE-1] = '\0';
wfcommit(errDfile, BASENAME(errDfile, '/'), sendsys);
wfcommit(cfile, BASENAME(cfile, '/'), sendsys);
}
} else {
unlink(errDfile);
}
if (ret == 0) {
if (send_zero)
retosndr(user, Rmtname, "", incmd, msgbuf, "");
if (store_status)
uucpst(Rmtname, _Sfile, "", incmd, msgbuf);
} else {
if (send_nonzero)
retosndr(user, Rmtname, return_stdin ? fin : "",
incmd, msgbuf, errname);
if (store_status)
uucpst(Rmtname, _Sfile, errname, incmd, msgbuf);
}
rmfiles:
xfp = fopen(_Xfile, "r");
ASSERT(xfp != NULL, Ct_OPEN, _Xfile, errno);
while (fgets(buf, BUFSIZ, xfp) != NULL) {
if (buf[0] != X_RQDFILE)
continue;
(void) sscanf(&buf[1], "%63s", file);
expfile(file);
if (chkpth(file, CK_WRITE) != FAIL)
(void) unlink(file);
}
(void) unlink(_Xfile);
fclose(xfp);
}
}