⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uuxqt.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifndef lintstatic char sccsid[] = "@(#)uuxqt.c	4.1 (decvax!larry) 7/2/90";#endif/* *	uuxqt will execute commands set up by a uux command, *	usually from a remote machine - set by uucp. *//***************** * Mods: *	decvax!larry - handle subdirectories properly. *		     - add concurrency on command type basis via the  *			-c option *		     - create lock files for each command to prevent *			other uuxqt from executing the same command. *		     - handle system V.? return address *		     - D.files were not being removed - fixed 12/12/85 *****************//************************************************************************ *									* *			Copyright (c) 1984 by				* *		Digital Equipment Corporation, Maynard, MA		* *			All rights reserved.				* *									* *   This software is furnished under a license and may be used and	* *   copied  only  in accordance with the terms of such license and	* *   with the  inclusion  of  the  above  copyright  notice.   This	* *   software  or  any  other copies thereof may not be provided or	* *   otherwise made available to any other person.  No title to and	* *   ownership of the software is hereby transferred.			* *									* *   This software is  derived  from  software  received  from  the	* *   University    of   California,   Berkeley,   and   from   Bell	* *   Laboratories.  Use, duplication, or disclosure is  subject  to	* *   restrictions  under  license  agreements  with  University  of	* *   California and with AT&T.						* *									* *   The information in this software is subject to change  without	* *   notice  and should not be construed as a commitment by Digital	* *   Equipment Corporation.						* *									* *   Digital assumes no responsibility for the use  or  reliability	* *   of its software on equipment which is not supplied by Digital.	* *									* ************************************************************************/#include "uucp.h"#include <sys/types.h>#include <sys/stat.h>#include <stdio.h>#include <sys/file.h>#include <errno.h>#ifdef NDIR#include "ndir.h"#else#include "sys/dir.h"#endif#define APPCMD(d) {\char *p;\for (p = d; *p != '\0';) *cmdp++ = *p++;\*cmdp++ = ' ';\*cmdp = '\0';}#define	NCMDS	50struct command {	char *cmd;	int xeqlevel;} Cmds[NCMDS];int notiok = 1;int nonzero = 0;int getpid();int getepid();int Euid;   /* effective user id */int errno;char PATH[MAXFULLNAME] = "PATH=/bin:/usr/bin";/*  to remove restrictions from uuxqt *  define ALLOK 1 * *  to add allowable commands, add to the file CMDFILE *  A line of form "PATH=..." changes the search path */main(argc, argv)char *argv[];{	char xcmd[MAXFULLNAME];	int argnok;	char xfile[MAXFULLNAME], user[MAXFULLNAME], buf[BUFSIZ];	char lbuf[MAXFULLNAME];	char cfile[MAXFULLNAME], dfile[MAXFULLNAME];	char file[MAXFULLNAME];	char fin[MAXFULLNAME], sysout[NAMESIZE], fout[MAXFULLNAME];	char ferr[MAXFULLNAME];	char xsys[NAMESIZE];	FILE *xfp, *dfp, *fp;	char path[MAXFULLNAME];	char cmdtype[MAXFULLNAME];	char lock[MAXFULLNAME];	char retaddr[MAXFULLNAME];	int ret_input;	struct stat stbuf;	char cmd[BUFSIZ];	/* set size of prm to something large -- cmcl2!salkind */	char *cmdp, prm[1000], *ptr;	char *getprm(), *lastpart();	int uid, ret, badfiles, i;	int stcico = 0;	char retstat[30];	int orig_uid = getuid();	char *argp[2];	int narg = 0;	strcpy(Progname, "uuxqt");	uucpname(Myname);	/* Try to run as uucp -- rti!trt */	setgid(getegid());	setuid(geteuid());	Euid = geteuid();	umask(WFMASK);	Ofn = 1;	Ifn = 0;	cmdtype[0]='\0';	while (argc>1 && argv[1][0] == '-') {		switch(argv[1][1]){		case 'x':			chkdebug(orig_uid);			Debug = atoi(&argv[1][2]);			if (Debug <= 0)				Debug = 1;			break;		case 'c':			sprintf(cmdtype, "%s", &argv[1][2]);			break;		default:			fprintf(stderr, "unknown flag %s\n", argv[1]);				break;		}		--argc;  argv++;	}	DEBUG(4, "\n\n** %s **\n", "START");	uid = getuid();	guinfo(uid, User, path);	DEBUG(4, "User - %s\n", User);	sprintf(lock,"%s%s",X_LOCK,cmdtype);	DEBUG(5, "the lock is :%s:\n",lock);	if (ulockf(lock, (time_t)  X_LOCKTIME) != 0)		exit(0);	fp = fopen(CMDFILE, "r");	if (fp == NULL) {		/* Fall-back if CMDFILE missing. Sept 1982, rti!trt */		logent("CAN'T OPEN", CMDFILE);		Cmds[0].cmd = "rmail";		Cmds[0].xeqlevel = 1;		Cmds[1].cmd = "rnews";		Cmds[1].xeqlevel = 1;		Cmds[2].cmd = NULL;		goto doprocess;	}	DEBUG(5, "%s opened\n", CMDFILE);	for (i=0; i<NCMDS-1 && cfgets(cmd, sizeof(cmd), fp) != NULL; i++) {		/* get command */		narg = getargs(cmd, argp);		if (strncmp(argp[0], "PATH=", 5) == 0) {			/* kludge to change path in L.cmd file */			strcpy(PATH, argp[0]);			i--; /* kludge */			continue;		}		Cmds[i].cmd = malloc((unsigned)(strlen(argp[0])+1));		strcpy(Cmds[i].cmd, argp[0]);		DEBUG(5, "cmd = %s\n", Cmds[i].cmd);		if (narg < 2  || argp[1][0] != 'X') {			DEBUG(5, "default xeq level provided %d\n", 9);			Cmds[i].xeqlevel = 9;		}				else  			Cmds[i].xeqlevel = atoi(&argp[1][1]);		DEBUG(4, "xeq level for command is %d\n", Cmds[i].xeqlevel);	}	Cmds[i].cmd = 0;	fclose(fp);	/* make temporary file for standard error output */	sprintf(ferr,"%s/LTMP.ERR.%d", SPOOL, getpid());nextsys:  /* switch to another per system spool directory */	while(gnsys(xsys, XQTPRE)) {	  DEBUG(5, "nextsys: %s\n", xsys);	  mkspname(xsys);	  DEBUG(5, "spooldir: %s\n", Spool);	  subchdir(Spool);	  strcpy(Wrkdir, Spool);doprocess:  /* process work in the spool directory */	  DEBUG(4, "process %s\n", "");	  while (gtxfile(xfile) > 0) {		ultouch();	/* rti!trt */		DEBUG(4, "xfile - %s\n", xfile);		if ((xfp = fopen(subfile(xfile), "r")) == NULL) {			ASSERT_NOFAIL(xfp != NULL,"uuxqt collision - no damage",				xfile, 0);			continue;		}		if (flock(fileno(xfp), LOCK_EX|LOCK_NB) < 0) {/*			ASSERT_NOFAIL(0,"uuxqt collision check - no damage",				xfile, 0);*/			fclose(xfp);			continue;		}					/*  initialize to default  */		strcpy(user, User);		strcpy(fin, "/dev/null");		strcpy(fout, "/dev/null");		sprintf(sysout, "%.7s", Myname);		retaddr[0] = '\0';		badfiles = 0;	/* this was missing -- rti!trt */		notiok = 1;		nonzero = 0;		ret_input = 0;		while (fgets(buf, BUFSIZ, xfp) != NULL) {			switch (buf[0]) {			case X_USER:				sscanf(&buf[1], "%s%s", user, Rmtname);				break;			case X_STDIN:				sscanf(&buf[1], "%s", fin);				i = expfile(fin);				/* rti!trt: do not check permissions of				 * vanilla spool file */				if (i != 0				 && (chkpth("", "", fin) || anyread(fin) != 0))					badfiles = 1;				break;			case X_STDOUT:				sscanf(&buf[1], "%s%s", fout, sysout);				sysout[7] = '\0';				/* rti!trt: do not check permissions of				 * vanilla spool file.  DO check permissions				 * of writing on a non-vanilla file */				i = 1;				if (fout[0] != '~' || prefix(sysout, Myname))					i = expfile(fout);				if (i != 0				 && (chkpth("", "", fout)					|| chkperm(fout, (char *)1)))					badfiles = 1;				break;			case X_CMD:				strcpy(cmd, &buf[2]);				if (*(cmd + strlen(cmd) - 1) == '\n')					*(cmd + strlen(cmd) - 1) = '\0';				break;			case X_NONOTI:				notiok = 0;				break;			case X_NONZERO:				nonzero = 1;				break;			case X_INPUT:     /* not used yet */				ret_input = 1;				break;			case X_RETURNADDR:				sscanf(&buf[1], "%s", retaddr);				break;			default:				break;			}		}/*		fclose(xfp);*/		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);		/*  command execution  */		if (strcmp(fout, "/dev/null") == SAME)			strcpy(dfile,"/dev/null");		else			gename(DATAPRE, sysout, 'O', dfile);		/* expand file names where necessary */		expfile(dfile);		strcpy(buf, PATH);		strcat(buf, ";export PATH;");		cmdp = buf + strlen(buf);		ptr = cmd;		xcmd[0] = '\0';		argnok = 0;		while ((ptr = getprm(ptr, prm)) != NULL) {			if (prm[0] == ';' || prm[0] == '^'			  || prm[0] == '&'  || prm[0] == '|') {				xcmd[0] = '\0';				APPCMD(prm);				continue;			}			if ((argnok = argok(xcmd, prm)) != 0) 				/*  command not valid  */				break;			/* if LCK.XQTxcmd exists then another			 * uuxqt daemon is running specifically			 * for the command specified by xcmd			 */			/* a null cmdtype implies a general uuxqt */			if (cmdtype[0] == '\0') {				sprintf(lock,"%s%s",X_LOCK,xcmd);				if (stat(lock,&stbuf) != -1) {					DEBUG(3,"uuxqt running for command: %s\n", xcmd);					fclose(xfp);					goto doprocess;				}			}			else   /* only xqt commands of type cmdtype */				if (strncmp(cmdtype,xcmd,strlen(cmdtype))) {					DEBUG(3,"xcmd=%s not the desired type\n",xcmd);					fclose(xfp);					goto doprocess;				}						if (prm[0] == '~')				expfile(prm);			APPCMD(prm);		}					if (argnok || badfiles) {			sprintf(lbuf, "%s XQT DENIED", user);			logent(cmd, lbuf);			DEBUG(4, "bad command %s\n", prm);			notify(user, Rmtname, cmd, "DENIED", ferr, retaddr);			goto rmfiles;		}		sprintf(lbuf, "%s %s XQT", user, xfile);		logent(buf, lbuf);		DEBUG(4, "cmd %s\n", buf);		mvxfiles(xfile);		subchdir(XQTDIR);				ret = shio(buf, fin, dfile, (char *)NULL, ferr);/* watcgl.11, dmmartindale, signal and exit values were reversed */		sprintf(retstat, "signal %d, exit %d", ret & 0377,		  (ret>>8) & 0377);		DEBUG(5,"retstat is %s: \n", retstat);		/* don't return exit status for mail commands */		if (strcmp(xcmd, "rmail") == SAME)			notiok = 0;		/* only return nonzero (fail) exit status for news commands */		if (strcmp(xcmd, "rnews") == SAME)			nonzero = 1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -