static char sccsid
[] = "@(#)uuxqt.c 5.2 (Berkeley) 7/2/83";
for (p = d; *p != '\0';) *cmdp++ = *p++;\
* uuxqt will execute commands set up by a uux command,
* usually from a remote machine - set by uucp.
char PATH
[MAXFULLNAME
] = "PATH=/bin:/usr/bin";
/* to remove restrictions from uuxqt
* to add allowable commands, add to the file CMDFILE
* A line of form "PATH=..." changes the search path
char xfile
[MAXFULLNAME
], user
[32], buf
[BUFSIZ
];
char cfile
[NAMESIZE
], dfile
[MAXFULLNAME
];
char fin
[MAXFULLNAME
], sysout
[NAMESIZE
], fout
[MAXFULLNAME
];
/* set size of prm to something large -- cmcl2!salkind */
char *cmdp
, prm
[1000], *ptr
;
char *getprm(), *lastpart();
strcpy(Progname
, "uuxqt");
/* Try to run as uucp -- rti!trt */
while (argc
>1 && argv
[1][0] == '-') {
Debug
= atoi(&argv
[1][2]);
fprintf(stderr
, "unknown flag %s\n", argv
[1]);
DEBUG(4, "\n\n** %s **\n", "START");
DEBUG(4, "User - %s\n", User
);
if (ulockf(X_LOCK
, (time_t) X_LOCKTIME
) != 0)
fp
= fopen(CMDFILE
, "r");
/* Fall-back if CMDFILE missing. Sept 1982, rti!trt */
logent("CAN'T OPEN", CMDFILE
);
DEBUG(5, "%s opened\n", CMDFILE
);
for (i
=0; i
<NCMDS
-1 && cfgets(xcmd
, sizeof(xcmd
), fp
) != NULL
; i
++) {
xcmd
[strlen(xcmd
)-1] = '\0';
if (strncmp(xcmd
, "PATH=", 5) == 0) {
DEBUG(5, "xcmd = %s\n", xcmd
);
Cmds
[i
] = malloc((unsigned)(strlen(xcmd
)+1));
DEBUG(4, "process %s\n", "");
while (gtxfile(xfile
) > 0) {
DEBUG(4, "xfile - %s\n", xfile
);
xfp
= fopen(subfile(xfile
), "r");
ASSERT(xfp
!= NULL
, "CAN'T OPEN", xfile
, 0);
/* initialize to default */
strcpy(fin
, "/dev/null");
strcpy(fout
, "/dev/null");
sprintf(sysout
, "%.7s", Myname
);
badfiles
= 0; /* this was missing -- rti!trt */
while (fgets(buf
, BUFSIZ
, xfp
) != NULL
) {
sscanf(&buf
[1], "%s%s", user
, Rmtname
);
sscanf(&buf
[1], "%s", fin
);
/* rti!trt: do not check permissions of
&& (chkpth("", "", fin
) || anyread(fin
) != 0))
sscanf(&buf
[1], "%s%s", fout
, sysout
);
/* rti!trt: do not check permissions of
* vanilla spool file. DO check permissions
* of writing on a non-vanilla file */
if (fout
[0] != '~' || prefix(sysout
, Myname
))
|| chkperm(fout
, (char *)1)))
if (*(cmd
+ strlen(cmd
) - 1) == '\n')
*(cmd
+ strlen(cmd
) - 1) = '\0';
DEBUG(4, "fin - %s, ", fin
);
DEBUG(4, "fout - %s, ", fout
);
DEBUG(4, "sysout - %s, ", sysout
);
DEBUG(4, "user - %s\n", user
);
DEBUG(4, "cmd - %s\n", cmd
);
if (strcmp(fout
, "/dev/null") == SAME
)
strcpy(dfile
,"/dev/null");
gename(DATAPRE
, sysout
, 'O', dfile
);
/* expand file names where necessary */
strcat(buf
, ";export PATH;");
cmdp
= buf
+ strlen(buf
);
while ((ptr
= getprm(ptr
, prm
)) != NULL
) {
if (prm
[0] == ';' || prm
[0] == '^'
|| prm
[0] == '&' || prm
[0] == '|') {
if ((argnok
= argok(xcmd
, prm
)) != 0)
if (argnok
|| badfiles
) {
sprintf(lbuf
, "%s XQT DENIED", user
);
DEBUG(4, "bad command %s\n", prm
);
notify(user
, Rmtname
, cmd
, "DENIED");
sprintf(lbuf
, "%s XQT", user
);
DEBUG(4, "cmd %s\n", buf
);
ret
= shio(buf
, fin
, dfile
, (char *)NULL
);
/* watcgl.11, dmmartindale, signal and exit values were reversed */
sprintf(retstat
, "signal %d, exit %d", ret
& 0377,
if (strcmp(xcmd
, "rmail") == SAME
)
if (strcmp(xcmd
, "rnews") == SAME
)
if (notiok
&& (!nonzero
|| (nonzero
&& ret
!= 0)))
notify(user
, Rmtname
, cmd
, retstat
);
else if (ret
!= 0 && strcmp(xcmd
, "rmail") == SAME
) {
/* mail failed - return letter to sender */
retosndr(user
, Rmtname
, fin
);
sprintf(buf
, "ret (%o) from %s!%s", ret
, Rmtname
, user
);
logent("MAIL FAIL", buf
);
DEBUG(4, "exit cmd - %d\n", ret
);
/* exit status not zero */
dfp
= fopen(subfile(dfile
), "a");
ASSERT(dfp
!= NULL
, "CAN'T OPEN", dfile
, 0);
fprintf(dfp
, "exit status %d", ret
);
if (strcmp(fout
, "/dev/null") != SAME
) {
if (prefix(sysout
, Myname
)) {
gename(CMDPRE
, sysout
, 'O', cfile
);
fp
= fopen(subfile(cfile
), "w");
ASSERT(fp
!= NULL
, "OPEN", cfile
, 0);
fprintf(fp
, "S %s %s %s - %s 0666\n",
dfile
, fout
, user
, lastpart(dfile
));
xfp
= fopen(subfile(xfile
), "r");
ASSERT(xfp
!= NULL
, "CAN'T OPEN", xfile
, 0);
while (fgets(buf
, BUFSIZ
, xfp
) != NULL
) {
sscanf(&buf
[1], "%s", file
);
* gtxfile(file) get a file to execute
* return codes: 0 - no file | 1 - file to execute
* Mod to recheck for X-able files. Sept 1982, rti!trt.
* Suggested by utzoo.2458 (utzoo!henry)
* Uses iswrk/gtwrkf to keep files in sequence, May 1983.
if (!gtwrkf(Spool
, file
)) {
if (!iswrk(file
, "get", Spool
, pre
))
DEBUG(4, "file - %s\n", file
);
/* skip spurious subdirectories */
if (strcmp(pre
, file
) == SAME
)
* gotfiles(file) check for needed files
* return codes: 0 - not ready | 1 - all files ready
char buf
[BUFSIZ
], rqfile
[MAXFULLNAME
];
fp
= fopen(subfile(file
), "r");
while (fgets(buf
, BUFSIZ
, fp
) != NULL
) {
sscanf(&buf
[1], "%s", rqfile
);
if (stat(subfile(rqfile
), &stbuf
) == -1) {
* rmxfiles(xfile) remove execute files to x-directory
char buf
[BUFSIZ
], file
[NAMESIZE
], tfile
[NAMESIZE
];
if((fp
= fopen(subfile(xfile
), "r")) == NULL
)
while (fgets(buf
, BUFSIZ
, fp
) != NULL
) {
if (sscanf(&buf
[1], "%s%s", file
, tfile
) < 2)
sprintf(tfull
, "%s/%s", XQTDIR
, tfile
);
* mvxfiles(xfile) move execute files to x-directory
char buf
[BUFSIZ
], ffile
[MAXFULLNAME
], tfile
[NAMESIZE
];
if((fp
= fopen(subfile(xfile
), "r")) == NULL
)
while (fgets(buf
, BUFSIZ
, fp
) != NULL
) {
if (sscanf(&buf
[1], "%s%s", ffile
, tfile
) < 2)
sprintf(tfull
, "%s/%s", XQTDIR
, tfile
);
/* duke!rti, ncsu!mcm: use xmv, not link(II) */
ASSERT(ret
== 0, "XQTDIR ERROR", "", ret
);
* argok(xc, cmd) check for valid command/argumanet
* *NOTE - side effect is to set xc to the
* command to be executed.
/* don't allow sh command strings `....` */
/* don't allow redirection of standard in or out */
/* don't allow other funny stuff */
/* but there are probably total holes here */
/* post-script. ittvax!swatt has a uuxqt that solves this. */
/* This version of uuxqt will shortly disappear */
if (index(cmd
, '`') != NULL
|| index(cmd
, '>') != NULL
|| index(cmd
, ';') != NULL
|| index(cmd
, '^') != NULL
|| index(cmd
, '&') != NULL
|| index(cmd
, '|') != NULL
|| index(cmd
, '<') != NULL
)
if (strcmp(cmd
, *ptr
) == SAME
)
* notify send mail to user giving execution results
* This program assumes new mail command - send remote mail
notify(user
, rmt
, cmd
, str
)
char *user
, *rmt
, *cmd
, *str
;
sprintf(text
, "uuxqt cmd (%.50s) status (%s)", cmd
, str
);
sprintf(ruser
, "%s!%s", rmt
, user
);
* retosndr - return mail to sender
retosndr(user
, rmt
, file
)
if (strcmp(rmt
, Myname
) == SAME
)
sprintf(ruser
, "%s!%s", rmt
, user
);
mailst(ruser
, "Mail failed. Letter returned to sender.\n", file
);
mailst(ruser
, "Mail failed. Letter returned to sender.\n", "");