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

📄 cntrl.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 2 页
字号:
			}		}		/* do not allow incoming C.files */		if (prefix(SPOOL,filename) && *(lastpart(filename))==CMDPRE) {			/* dont reject if going to /usr/spool/uucppublic */			if (!prefix(PUBDIR,filename)) {				WMESG(SNDFILE, EM_RMTACC);				ASSERT_NOFAIL(0,					"Incoming C.files are not permitted",					filename, 0);				goto top;			}		}		sprintf(User, "%.9s", W_USER);		DEBUG(4, "chkpth ok Rmtname - %s\n", Rmtname);		sprintf(Dfile, "%s/TM./TM.%05d.%03d", SPOOL, pnum, tmpnum++);		if((fp = fopen(Dfile, "w")) == NULL) {			WMESG(SNDFILE, EM_NOTMP);			logent("CAN'T OPEN", "DENIED");			unlinkdf(Dfile);			goto top;		}		WMESG(SNDFILE, YES);		ret = (*Rddata)(Ifn, fp);		/* ittvax!swatt: (try to) make sure IO successful */		fflush(fp);		if (ferror(fp) || fclose(fp))			ret = FAIL;		if (ret != 0) {			(*Turnoff)();			return(FAIL);		}		/* copy to user directory */		ntfyopt = index(W_OPTNS, 'n') != NULL;		status = xmv(Dfile, filename);		WMESG(RQSTCMPT, status ? EM_RMTCP : YES);		if (status == 0) {			sscanf(W_MODE, "%o", &filemode);			if (filemode <= 0)				filemode = BASEMODE;			chmod(subfile(filename), filemode | BASEMODE);			arrived(ntfyopt, filename, W_NUSER, Rmtname, User);		}		else {			logent("FAILED", "COPY");			status = putinpub(filename, Dfile, W_USER);			DEBUG(4, "->PUBDIR %d\n", status);			if (status == 0)				arrived(ntfyopt, filename, W_NUSER,				  Rmtname, User);		}		goto top;	case RCVFILE:		/*  MASTER section of RCVFILE  */		DEBUG(4, "%s\n", "RCVFILE:");		if (msg[1] == 'N') {			i = atoi(&msg[2]);			if (i < 0 || i > EM_MAX)				i = 0;			logent(Em_msg[i], "REQUEST");			USRF( 1 << i );			notify(mailopt, W_USER, W_FILE1, Rmtname, &msg[1]);			fclose(fp);			unlinkdf(Dfile);			ASSERT2(role == MASTER, "WRONG ROLE", "", role);			goto top;		}		if (msg[1] == 'Y') {			/* receive file */			if (role != MASTER) {				ASSERT_NOFAIL(role == MASTER, "WRONG ROLE", "", role);				fclose(fp);				return(FAIL);			}			ret = (*Rddata)(Ifn, fp);			/* ittvax!swatt: (try to) make sure IO successful */			fflush(fp);			if (ferror(fp) || fclose(fp))				ret = FAIL;			if (ret != 0) {				(*Turnoff)();				USRF(USR_CFAIL);				return(FAIL);			}			/* copy to user directory */			if (isdir(subfile(filename))) {				strcat(filename, "/");				strcat(filename, lastpart(W_FILE1));			}			status = xmv(Dfile, filename);			WMESG(RQSTCMPT, status ? EM_RMTCP : YES);			notify(mailopt, W_USER, filename, Rmtname,			  status ? EM_LOCCP : YES);			if (status == 0) {				sscanf(&msg[2], "%o", &filemode);				if (filemode <= 0)					filemode = BASEMODE;				chmod(subfile(filename), filemode | BASEMODE);				USRF(USR_COK);			}			else {				logent("FAILED", "COPY");				putinpub(filename, Dfile, W_USER);				USRF(USR_LOCCP);			}			goto top;		}		/*  SLAVE section of RCVFILE  */		ASSERT2(role == SLAVE, "WRONG ROLE", "", role);		/* request to send file */		strcpy(rqstr, msg);		logent(rqstr, "REQUESTED");		/* check permissions */		i = getargs(msg, wrkvec);		ASSERT2(i > 3, "ARG COUNT<4", "", i);		DEBUG(4, "msg - %s\n", msg);		DEBUG(4, "W_FILE1 - %s\n", W_FILE1);		strcpy(filename, W_FILE1);		expfile(filename);		if (isdir(subfile(filename))) {			strcat(filename, "/");			strcat(filename, lastpart(W_FILE2));		}		sprintf(User, "%.9s", W_USER);		if (chkpth("", Rmtname, filename) || anyread(filename)) {			WMESG(RCVFILE, EM_RMTACC);			logent("DENIED", "PERMISSION");			goto top;		}		DEBUG(4, "chkpth ok Rmtname - %s\n", Rmtname);		if ((fp = fopen(subfile(filename), "r")) == NULL) {			WMESG(RCVFILE, EM_RMTACC);			logent("CAN'T OPEN", "DENIED");			goto top;		}		/*  ok to send file */		ret = fstat(fileno(fp), &stbuf);		ASSERT2(ret != -1, "STAT FAILED", filename, 0);		i = 1 + (int)(stbuf.st_size / XFRRATE);		sprintf(msg, "%s %o", YES, stbuf.st_mode & 0777);		WMESG(RCVFILE, msg);		ret = (*Wrdata)(fp, Ofn);		fclose(fp);		if (ret != 0) {			(*Turnoff)();			return(FAIL);		}		RMESG(RQSTCMPT, msg, i);		goto process;	}	(*Turnoff)();	return(FAIL);}/*** *	rmesg(c, msg, n)	read message 'c' *				try 'n' times *	char *msg, c; * *	return code:  0  |  FAIL */rmesg(c, msg, n)char *msg, c;int n;{	char str[50];	DEBUG(4, "rmesg - '%c' ", c);	while ((*Rdmsg)(msg, Ifn) != 0) {		if (--n > 0)			continue;		DEBUG(4, "got %s\n", "FAIL");		sprintf(str, "expected '%c' got FAIL", c);		logent(str, "BAD READ1");		return(FAIL);	}	if (c != '\0' && msg[0] != c) {		DEBUG(4, "got %s\n", msg);		sprintf(str, "expected '%c' got %.25s", c, msg);		logent(str, "BAD READ2");		return(FAIL);	}	DEBUG(4, "got %.25s\n", msg);	return(0);}/*** *	wmesg(m, s)	write a message (type m) *	char *s, m; * *	return codes: 0 - ok | FAIL - ng */wmesg(m, s)char *s, m;{	DEBUG(4, "wmesg '%c'", m);	DEBUG(4, "%.25s\n", s);	return((*Wrmsg)(m, s, Ofn));}/*** *	notify		mail results of command * *	return codes:  none */notify(mailopt, user, file, sys, msgcode)char *user, *file, *sys, *msgcode;{	char str[200];	int i;	char *msg;	if (!mailopt && *msgcode == 'Y')		return;	if (*msgcode == 'Y')		msg = "copy succeeded";	else {		i = atoi(msgcode + 1);		if (i < 1 || i > EM_MAX)			i = 0;		msg = Em_msg[i];	}	sprintf(str, "file %s, system %s\n%s\n",		file, sys, msg);	mailst(user, str, "");	return;}/*** *	lnotify(user, file, mesg)	- local notify * *	return code - none */lnotify(user, file, mesg)char *user, *file, *mesg;{	char mbuf[200];	sprintf(mbuf, "file %s on %s\n%s\n", file, Myname, mesg);	mailst(user, mbuf, "");	return;}/*** *	startup(role) *	int role; * *	startup  -  this routine will converse with the remote *	machine, agree upon a protocol (if possible) and start the *	protocol. * *	return codes: *		SUCCESS - successful protocol selection *		FAIL - can't find common or open failed */startup(role)int role;{	extern (*Rdmsg)(), (*Wrmsg)();	extern char *blptcl(), fptcl();	char msg[BUFSIZ], str[BUFSIZ];	Rdmsg = Imsg;	Wrmsg = Omsg;	if (role == MASTER) {		RMESG(SLTPTCL, msg, 1);		if ((str[0] = fptcl(&msg[1])) == NULL) {			/* no protocol match */			WMESG(USEPTCL, NO);			return(FAIL);		}		str[1] = '\0';		WMESG(USEPTCL, str);		if (stptcl(str) != 0)			return(FAIL);		DEBUG(4, "protocol %s\n", str);		return(SUCCESS);	}	else {		WMESG(SLTPTCL, blptcl(str));		RMESG(USEPTCL, msg, 1);		if (msg[1] == 'N') {			return(FAIL);		}		if (stptcl(&msg[1]) != 0)			return(FAIL);		DEBUG(4, "Protocol %s\n", msg);		return(SUCCESS);	}}/******* *	char *	fptcl(str) *	char *str; * *	fptcl  -  this routine will choose a protocol from *	the input string (str) and return the found letter. * *	return codes: *		'\0'  -  no acceptable protocol *		any character  -  the chosen protocol */charfptcl(str)char *str;{	struct Proto *p;	/* first try to pick the preferred protocol */	if (index(str, Prefproto) != NULL) {		/* sanity - now make sure that we know this proto too */		for (p = Ptbl; p->P_id != '\0'; p++) {			if (p->P_id == Prefproto) {				return(p->P_id);			}		}	}			/* Couldn't get the preferred proto - look for any match */	for (p = Ptbl; p->P_id != '\0'; p++) {		if (index(str, p->P_id) != NULL) {			return(p->P_id);		}	}	return('\0');}/*** *	char * *	blptcl(str) *	char *str; * *	blptcl  -  this will build a string of the *	letters of the available protocols and return *	the string (str). * *	return: *		a pointer to string (str) */char *blptcl(str)char *str;{	struct Proto *p;	char *s;	for (p = Ptbl, s = str; (*s++ = p->P_id) != '\0'; p++);	return(str);}/*** *	stptcl(c) *	char *c; * *	stptcl  -  this routine will set up the six routines *	(Rdmsg, Wrmsg, Rddata, Wrdata, Turnon, Turnoff) for the *	desired protocol. * *	return codes: *		SUCCESS - ok *		FAIL - no find or failed to open * */stptcl(c)char *c;{	struct Proto *p;	for (p = Ptbl; p->P_id != '\0'; p++) {		if (*c == p->P_id) {			/* found protocol - set routines */			Rdmsg = p->P_rdmsg;			Wrmsg = p->P_wrmsg;			Rddata = p->P_rddata;			Wrdata = p->P_wrdata;			Turnon = p->P_turnon;			Turnoff = p->P_turnoff;			if ((*Turnon)() != 0)				return(FAIL);			DEBUG(4, "Proto started %c\n", *c);			return(SUCCESS);		}	}	DEBUG(4, "Proto start-fail %c\n", *c);	return(FAIL);}/*** *	putinpub	put file in public place *			if successful, filename is modified * *	return code  0 | FAIL */putinpub(file, tmp, user)char *file, *user, *tmp;{	char fullname[MAXFULLNAME];	char *lastpart();	int status;	sprintf(fullname, "%s/%s/", PUBDIR, user);	if (mkdirs(fullname) != 0) {		/* can not make directories */		return(FAIL);	}	strcat(fullname, lastpart(file));	status = xmv(tmp, fullname);	if (status == 0) {		strcpy(file, fullname);		chmod(fullname, BASEMODE);	}	return(status);}/*** *	unlinkdf(file)	- unlink D. file * *	return code - none */unlinkdf(file)char *file;{	if (strlen(file) > 6)		unlink(subfile(file));	return;}/*** *	arrived - notify receiver of arrived file * *	return code - none */arrived(opt, file, nuser, rmtsys, rmtuser)char *file, *nuser, *rmtsys, *rmtuser;{	char mbuf[200];	if (!opt)		return;	sprintf(mbuf, "%s from %s!%s arrived\n", file, rmtsys, rmtuser);	mailst(nuser, mbuf, "");	return;}

⌨️ 快捷键说明

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