xref: /titanic_53/usr/src/cmd/bnu/cntrl.c (revision ace1a5f11236a072fca1b5e0ea1416a083a9f2aa)
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*ace1a5f1Sdp  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include "uucp.h"
347c478bd9Sstevel@tonic-gate #include "log.h"
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate void notify(), lnotify(), unlinkdf(), arrived();
377c478bd9Sstevel@tonic-gate static void stmesg();
387c478bd9Sstevel@tonic-gate static int nospace();
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate struct Proto {
417c478bd9Sstevel@tonic-gate 	char P_id;
427c478bd9Sstevel@tonic-gate 	int (*P_turnon)();
437c478bd9Sstevel@tonic-gate 	int (*P_rdmsg)();
447c478bd9Sstevel@tonic-gate 	int (*P_wrmsg)();
457c478bd9Sstevel@tonic-gate 	int (*P_rddata)();
467c478bd9Sstevel@tonic-gate 	int (*P_wrdata)();
477c478bd9Sstevel@tonic-gate 	int (*P_turnoff)();
487c478bd9Sstevel@tonic-gate };
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate extern char _Protocol[];
517c478bd9Sstevel@tonic-gate extern char *findProto();
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate extern char uuxqtarg[];
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate extern int gturnon(), gturnoff();
567c478bd9Sstevel@tonic-gate extern int grdmsg(), grddata();
577c478bd9Sstevel@tonic-gate extern int gwrmsg(), gwrdata();
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate extern int wmesg(), rmesg(), expfile(), putinpub(), stptcl();
607c478bd9Sstevel@tonic-gate extern void setline(), TMname(), cleanup(), pfEndfile(), statlog(), mailst();
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate #ifdef	D_PROTOCOL
637c478bd9Sstevel@tonic-gate extern int dturnon(), dturnoff();
647c478bd9Sstevel@tonic-gate extern int drdmsg(), drddata();
657c478bd9Sstevel@tonic-gate extern int dwrmsg(), dwrdata();
667c478bd9Sstevel@tonic-gate #endif	/* D_PROTOCOL */
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate #ifdef	X_PROTOCOL
697c478bd9Sstevel@tonic-gate extern int xturnon(), xturnoff();
707c478bd9Sstevel@tonic-gate extern int xrdmsg(), xrddata();
717c478bd9Sstevel@tonic-gate extern int xwrmsg(), xwrdata();
727c478bd9Sstevel@tonic-gate #endif	/* X_PROTOCOL */
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate #ifdef E_PROTOCOL
757c478bd9Sstevel@tonic-gate extern int eturnon(), eturnoff();
767c478bd9Sstevel@tonic-gate extern int erdmsg(), erddata();
777c478bd9Sstevel@tonic-gate extern int ewrmsg(), ewrdata();
787c478bd9Sstevel@tonic-gate extern int trdmsg(), twrmsg();
797c478bd9Sstevel@tonic-gate extern int trddata(), twrdata();
807c478bd9Sstevel@tonic-gate #endif /* E_PROTOCOL */
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate #ifdef F_PROTOCOL
837c478bd9Sstevel@tonic-gate extern int fturnon(), fturnoff();
847c478bd9Sstevel@tonic-gate extern int frdmsg(), frddata();
857c478bd9Sstevel@tonic-gate extern int fwrmsg(), fwrdata();
867c478bd9Sstevel@tonic-gate #endif	/* F_PROTOCOL */
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate extern int imsg();
897c478bd9Sstevel@tonic-gate extern int omsg();
907c478bd9Sstevel@tonic-gate extern int turnoff();
917c478bd9Sstevel@tonic-gate extern long strtol();
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate struct Proto Ptbl[]={
947c478bd9Sstevel@tonic-gate 	{'g', gturnon, grdmsg, gwrmsg, grddata, gwrdata, gturnoff},
957c478bd9Sstevel@tonic-gate 	{'G', gturnon, grdmsg, gwrmsg, grddata, gwrdata, gturnoff},
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate #ifdef E_PROTOCOL
987c478bd9Sstevel@tonic-gate 	{'e', eturnon, erdmsg, ewrmsg, erddata, ewrdata, eturnoff},
997c478bd9Sstevel@tonic-gate 	{'t', eturnon, trdmsg, twrmsg, trddata, twrdata, eturnoff},
1007c478bd9Sstevel@tonic-gate #endif /* E_PROTOCOL */
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate #ifdef	D_PROTOCOL
1037c478bd9Sstevel@tonic-gate 	{'d', dturnon, drdmsg, dwrmsg, drddata, dwrdata, dturnoff},
1047c478bd9Sstevel@tonic-gate #endif	/* D_PROTOCOL */
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate #ifdef	X_PROTOCOL
1077c478bd9Sstevel@tonic-gate 	{'x', xturnon, xrdmsg, xwrmsg, xrddata, xwrdata, xturnoff},
1087c478bd9Sstevel@tonic-gate #endif	/* X_PROTOCOL */
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate #ifdef	F_PROTOCOL
1117c478bd9Sstevel@tonic-gate 	{'f', fturnon, frdmsg, fwrmsg, frddata, fwrdata, fturnoff},
1127c478bd9Sstevel@tonic-gate #endif	/* F_PROTOCOL */
1137c478bd9Sstevel@tonic-gate 	'\0'
1147c478bd9Sstevel@tonic-gate };
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate #define VALIDSIZE sizeof(Ptbl)/sizeof(struct Proto)
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate int (*Rdmsg)()=imsg, (*Rddata)();
1197c478bd9Sstevel@tonic-gate int (*Wrmsg)()=omsg, (*Wrdata)();
1207c478bd9Sstevel@tonic-gate int (*Turnon)(), (*Turnoff)()=turnoff;
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate #define YES "Y"
1247c478bd9Sstevel@tonic-gate #define NO "N"
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate #define TBUFSIZE	128	/* temporary buffer size */
1277c478bd9Sstevel@tonic-gate #define FLENRADIX	(16)	/* output radix for file start point */
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate  * failure messages
1317c478bd9Sstevel@tonic-gate  */
1327c478bd9Sstevel@tonic-gate #define EM_MAX		10
1337c478bd9Sstevel@tonic-gate #define EM_LOCACC	"N1"	/* local access to file denied */
1347c478bd9Sstevel@tonic-gate #define EM_RMTACC	"N2"	/* remote access to file/path denied */
1357c478bd9Sstevel@tonic-gate #define EM_BADUUCP	"N3"	/* a bad uucp command was generated */
1367c478bd9Sstevel@tonic-gate #define EM_NOTMP	"N4"	/* remote error - can't create temp */
1377c478bd9Sstevel@tonic-gate #define EM_RMTCP	"N5"	/* can't copy to remote directory - file in public */
1387c478bd9Sstevel@tonic-gate #define EM_LOCCP	"N6"	/* can't copy on local system */
1397c478bd9Sstevel@tonic-gate #define EM_SEEK		"N7"	/* can't seek to checkpoint */
1407c478bd9Sstevel@tonic-gate /* 	EM_		"N8" */	/* placeholder*/
1417c478bd9Sstevel@tonic-gate /* 	EM_		"N9" */	/* placeholder*/
1427c478bd9Sstevel@tonic-gate #define EM_ULIMIT	"N10"	/* receiver ulimit exceeded */
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate char *Em_msg[] = {
1457c478bd9Sstevel@tonic-gate 	"COPY FAILED (reason not given by remote)",
1467c478bd9Sstevel@tonic-gate 	"local access to file denied",
1477c478bd9Sstevel@tonic-gate 	"remote access to path/file denied",
1487c478bd9Sstevel@tonic-gate 	"system error - bad uucp command generated",
1497c478bd9Sstevel@tonic-gate 	"remote system can't create temp file",
1507c478bd9Sstevel@tonic-gate 	"can't copy to file/directory - file left in PUBDIR/user/file",
1517c478bd9Sstevel@tonic-gate 	"can't copy to file/directory - file left in PUBDIR/user/file",
1527c478bd9Sstevel@tonic-gate 	"can't seek to checkpoint",
1537c478bd9Sstevel@tonic-gate 	"COPY FAILED (reason not given by remote)", /* placeholder */
1547c478bd9Sstevel@tonic-gate 	"COPY FAILED (reason not given by remote)", /* placeholder */
1557c478bd9Sstevel@tonic-gate 	"file exceeds ulimit of receiving system",
1567c478bd9Sstevel@tonic-gate 	"forwarding error"
1577c478bd9Sstevel@tonic-gate };
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate #define XUUCP 'X'	/* execute uucp (string) */
1617c478bd9Sstevel@tonic-gate #define SLTPTCL 'P'	/* select protocol  (string)  */
1627c478bd9Sstevel@tonic-gate #define USEPTCL 'U'	/* use protocol (character) */
1637c478bd9Sstevel@tonic-gate #define RCVFILE 'R'	/* receive file (string) */
1647c478bd9Sstevel@tonic-gate #define SNDFILE 'S'	/* send file (string) */
1657c478bd9Sstevel@tonic-gate #define RQSTCMPT 'C'	/* request complete (string - yes | no) */
1667c478bd9Sstevel@tonic-gate #define HUP     'H'	/* ready to hangup (string - yes | no) */
1677c478bd9Sstevel@tonic-gate #define RESET	'X'	/* reset line modes */
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate #define W_MAX		10	/* maximum number of C. files per line */
1707c478bd9Sstevel@tonic-gate #define W_MIN		7	/* min number of entries */
1717c478bd9Sstevel@tonic-gate #define W_TYPE		wrkvec[0]
1727c478bd9Sstevel@tonic-gate #define W_FILE1		wrkvec[1]
1737c478bd9Sstevel@tonic-gate #define W_FILE2		wrkvec[2]
1747c478bd9Sstevel@tonic-gate #define W_USER		wrkvec[3]
1757c478bd9Sstevel@tonic-gate #define W_OPTNS		wrkvec[4]
1767c478bd9Sstevel@tonic-gate #define W_DFILE		wrkvec[5]
1777c478bd9Sstevel@tonic-gate #define W_MODE		wrkvec[6]
1787c478bd9Sstevel@tonic-gate #define W_NUSER		wrkvec[7]
1797c478bd9Sstevel@tonic-gate #define W_SFILE		wrkvec[8]
1807c478bd9Sstevel@tonic-gate #define W_RDFILE	wrkvec[8]
1817c478bd9Sstevel@tonic-gate #define W_POINT		wrkvec[9]
1827c478bd9Sstevel@tonic-gate #define W_FSIZE		wrkvec[9]
1837c478bd9Sstevel@tonic-gate #define W_RFILE		wrkvec[5]
1847c478bd9Sstevel@tonic-gate #define W_XFILE		wrkvec[5]
1857c478bd9Sstevel@tonic-gate char	*mf;
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate #define RMESG(m, s) if (rmesg(m, s) != 0) {(*Turnoff)(); return(FAIL);}
1887c478bd9Sstevel@tonic-gate #define RAMESG(s) if (rmesg('\0', s) != 0) {(*Turnoff)(); return(FAIL);}
1897c478bd9Sstevel@tonic-gate #define WMESG(m, s) if(wmesg(m, s) != 0) {(*Turnoff)(); return(FAIL);}
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate char Wfile[MAXFULLNAME] = {'\0'};
1927c478bd9Sstevel@tonic-gate char Dfile[MAXFULLNAME];
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate char	*wrkvec[W_MAX+1];
1957c478bd9Sstevel@tonic-gate int	statfopt;
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate /*
1987c478bd9Sstevel@tonic-gate  * Create restart point filename
1997c478bd9Sstevel@tonic-gate  */
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate static void
2027c478bd9Sstevel@tonic-gate Pname(fileid, dfile, direct)
2037c478bd9Sstevel@tonic-gate   char *fileid;
2047c478bd9Sstevel@tonic-gate   char *dfile;
2057c478bd9Sstevel@tonic-gate   int  direct;		/* indicates a direct delivery temp file nameneeded */
2067c478bd9Sstevel@tonic-gate {
2077c478bd9Sstevel@tonic-gate     char *p;
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate 	    /*
2107c478bd9Sstevel@tonic-gate 	     * If the file is direct delivery, then its name is:
2117c478bd9Sstevel@tonic-gate 	     *
2127c478bd9Sstevel@tonic-gate 	     *		/dir/dir/dir/.Pnnnnnnnn
2137c478bd9Sstevel@tonic-gate 	     *
2147c478bd9Sstevel@tonic-gate 	     * in the target directory.  We create this by replacing the
2157c478bd9Sstevel@tonic-gate 	     * name of the target file with the D.nnnnnn name from the
2167c478bd9Sstevel@tonic-gate 	     * work vector, and then overwriting the D. with .P
2177c478bd9Sstevel@tonic-gate 	     */
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 	    if (direct) {
2207c478bd9Sstevel@tonic-gate 		if (p = strrchr(dfile, '/')) {	/* find the last slash */
2217c478bd9Sstevel@tonic-gate 			p++;
2227c478bd9Sstevel@tonic-gate 			strcpy(p, fileid);	/* append D.nnnnn name to dir */
2237c478bd9Sstevel@tonic-gate 			*p++ = '.';
2247c478bd9Sstevel@tonic-gate 			*p = 'P';		/* replace beginning with .P */
2257c478bd9Sstevel@tonic-gate 	    		DEBUG(7, "Point file (direct) =%s\n", dfile);
2267c478bd9Sstevel@tonic-gate 			return;
2277c478bd9Sstevel@tonic-gate 		}
2287c478bd9Sstevel@tonic-gate 	    }
2297c478bd9Sstevel@tonic-gate 	    strcpy(dfile, RemSpool);
2307c478bd9Sstevel@tonic-gate 	    strcat(dfile, "/");
2317c478bd9Sstevel@tonic-gate 	    p = dfile + strlen(Dfile);
2327c478bd9Sstevel@tonic-gate 	    strcat(dfile, fileid);
2337c478bd9Sstevel@tonic-gate 	    *p = 'P';
2347c478bd9Sstevel@tonic-gate 	    DEBUG(7, "Point file=%s\n", dfile);
2357c478bd9Sstevel@tonic-gate 	return;
2367c478bd9Sstevel@tonic-gate }
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate /*
2407c478bd9Sstevel@tonic-gate  * execute the conversation between the two machines
2417c478bd9Sstevel@tonic-gate  * after both programs are running.
2427c478bd9Sstevel@tonic-gate  * returns:
2437c478bd9Sstevel@tonic-gate  *	SUCCESS 	-> ok
2447c478bd9Sstevel@tonic-gate  *	FAIL 		-> failed
2457c478bd9Sstevel@tonic-gate  */
2467c478bd9Sstevel@tonic-gate int
2477c478bd9Sstevel@tonic-gate cntrl()
2487c478bd9Sstevel@tonic-gate {
2497c478bd9Sstevel@tonic-gate 	FILE * fp;
2507c478bd9Sstevel@tonic-gate 	struct stat stbuf;
2517c478bd9Sstevel@tonic-gate 	extern (*Rdmsg)(), (*Wrmsg)();
2527c478bd9Sstevel@tonic-gate 	char *	p;
2537c478bd9Sstevel@tonic-gate 	long 	startp;		/* checkpoint restart point */
2547c478bd9Sstevel@tonic-gate 	long	actualsize;	/* actual file size */
2557c478bd9Sstevel@tonic-gate 	long	im;
2567c478bd9Sstevel@tonic-gate 	long	lfilemode;
2577c478bd9Sstevel@tonic-gate 	mode_t	filemode;
2587c478bd9Sstevel@tonic-gate 	int	status;
2597c478bd9Sstevel@tonic-gate 	int	i, narg;
2607c478bd9Sstevel@tonic-gate 	int	mailopt, ntfyopt;
2617c478bd9Sstevel@tonic-gate 	int	ret;
2627c478bd9Sstevel@tonic-gate 	char	tbuf[TBUFSIZE];
2637c478bd9Sstevel@tonic-gate 	char	rqstr[BUFSIZ];	/* contains the current request message */
2647c478bd9Sstevel@tonic-gate 	char	msg[BUFSIZ];
2657c478bd9Sstevel@tonic-gate 	char	filename[MAXFULLNAME], wrktype;
2667c478bd9Sstevel@tonic-gate 	char	fsize[NAMESIZE];	/* holds file size/checkpoint string */
2677c478bd9Sstevel@tonic-gate 	char	localname[MAXFULLNAME];	/* real local system name */
2687c478bd9Sstevel@tonic-gate 	char	Recspool[MAXFULLNAME];	/* spool area for slave uucico */
2697c478bd9Sstevel@tonic-gate 	static pid_t	pnum;
2707c478bd9Sstevel@tonic-gate 	extern int uuxqtflag;	/* set if received X. or D. file */
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 	pnum = getpid();
2737c478bd9Sstevel@tonic-gate 	Wfile[0] = '\0';
2747c478bd9Sstevel@tonic-gate 	(void) sprintf(Recspool, "%s/%s", SPOOL, Rmtname);
2757c478bd9Sstevel@tonic-gate top:
2767c478bd9Sstevel@tonic-gate 	(void) strcpy(User, Uucp);
2777c478bd9Sstevel@tonic-gate 	statfopt = 0;
2787c478bd9Sstevel@tonic-gate 	*Jobid = '\0';
2797c478bd9Sstevel@tonic-gate 	DEBUG(4, "*** TOP ***  -  Role=%d, ", Role);
2807c478bd9Sstevel@tonic-gate 	setline(RESET);
2817c478bd9Sstevel@tonic-gate 	if (Role == MASTER) {
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 		/*
2847c478bd9Sstevel@tonic-gate 		 * get work
2857c478bd9Sstevel@tonic-gate 		 */
2867c478bd9Sstevel@tonic-gate 		pfFindFile();
2877c478bd9Sstevel@tonic-gate 		if ((narg = gtwvec(Wfile, wrkvec, W_MAX)) == 0) {
2887c478bd9Sstevel@tonic-gate 			acEnd(COMPLETE); /*stop collecting accounting log */
2897c478bd9Sstevel@tonic-gate 			WMESG(HUP, ""); /* I(master) am done. want me to quit? */
2907c478bd9Sstevel@tonic-gate 			RMESG(HUP, msg);
2917c478bd9Sstevel@tonic-gate 			goto process;
2927c478bd9Sstevel@tonic-gate 		}
2937c478bd9Sstevel@tonic-gate 		DEBUG(7, "Wfile - %s,", Wfile);
2947c478bd9Sstevel@tonic-gate 		strncpy(Jobid, BASENAME(Wfile, '/')+2, NAMESIZE);
2957c478bd9Sstevel@tonic-gate 		Jobid[NAMESIZE-1] = '\0';
2967c478bd9Sstevel@tonic-gate 		DEBUG(7, "Jobid = %s\n", Jobid);
2977c478bd9Sstevel@tonic-gate 		wrktype = W_TYPE[0];
2987c478bd9Sstevel@tonic-gate 		pfFound(Jobid, W_OPTNS, Nstat.t_qtime);
2997c478bd9Sstevel@tonic-gate 		mailopt = strchr(W_OPTNS, 'm') != NULL;
3007c478bd9Sstevel@tonic-gate 		statfopt = strchr(W_OPTNS, 'o') != NULL;
3017c478bd9Sstevel@tonic-gate 		ntfyopt = strchr(W_OPTNS, 'n') != NULL;
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 		uucpname(localname); /* get real local machine name */
3047c478bd9Sstevel@tonic-gate 		acDojob(Jobid, localname, W_USER);
3057c478bd9Sstevel@tonic-gate 		scRequser(W_USER); /* log requestor user id */
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 		/*
3087c478bd9Sstevel@tonic-gate 		 * We used to check for corrupt workfiles here (narg < 5),
3097c478bd9Sstevel@tonic-gate 		 * but we were doing it wrong, and besides, anlwrk.c is the
3107c478bd9Sstevel@tonic-gate 		 * appropriate place to do it.
3117c478bd9Sstevel@tonic-gate 		 */
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate 		(void) sprintf(User, "%s", W_USER);
3147c478bd9Sstevel@tonic-gate 		if (wrktype == SNDFILE ) {
3157c478bd9Sstevel@tonic-gate 			(void) sprintf(rqstr, "%s!%s --> %s!%s (%s)", Myname,
3167c478bd9Sstevel@tonic-gate 			    W_FILE1, Rmtname, W_FILE2, User);
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate 			/* log destination node, user and file name */
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 			scDest(Rmtname,NOTAVAIL,W_FILE2);
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate 			/* log source node, file owner, file name, mod time and size */
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 			scSrc(Myname,scOwn(W_FILE1),W_FILE1,scMtime(W_FILE1)
3257c478bd9Sstevel@tonic-gate 						,scSize(W_FILE1));
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate 			logent(rqstr, "REQUEST");
3287c478bd9Sstevel@tonic-gate 			CDEBUG(1, "Request: %s\n", rqstr);
3297c478bd9Sstevel@tonic-gate 			mf = W_SFILE;
3307c478bd9Sstevel@tonic-gate 			(void) strcpy(filename, W_FILE1);
3317c478bd9Sstevel@tonic-gate 			expfile(filename);
3327c478bd9Sstevel@tonic-gate 			(void) strcpy(Dfile, W_DFILE);
3337c478bd9Sstevel@tonic-gate 			if ( (fp = fopen(Dfile, "r")) == NULL) {
3347c478bd9Sstevel@tonic-gate 			    if ( (fp = fopen(filename, "r")) == NULL) {
3357c478bd9Sstevel@tonic-gate 				/*  cannot read spool or original file */
3367c478bd9Sstevel@tonic-gate 				unlinkdf(Dfile);
3377c478bd9Sstevel@tonic-gate 				lnotify(User, rqstr, "can't access");
3387c478bd9Sstevel@tonic-gate 				(void) sprintf(msg, "CAN'T READ %s %d",
3397c478bd9Sstevel@tonic-gate 					filename, errno);
3407c478bd9Sstevel@tonic-gate 				logent(msg, "FAILED");
3417c478bd9Sstevel@tonic-gate 				CDEBUG(1, "Failed: Can't Read %s\n", filename);
3427c478bd9Sstevel@tonic-gate 		    		scWrite();	/* log the security violation */
3437c478bd9Sstevel@tonic-gate 				goto top;
3447c478bd9Sstevel@tonic-gate 			    } else {
3457c478bd9Sstevel@tonic-gate 				/* ensure original file is publicly readable */
3467c478bd9Sstevel@tonic-gate 				if ( !F_READANY(fileno(fp)) ) {
3477c478bd9Sstevel@tonic-gate 				    /* access denied */
3487c478bd9Sstevel@tonic-gate 				    logent("DENIED", "ACCESS");
3497c478bd9Sstevel@tonic-gate 				    unlinkdf(W_DFILE);
3507c478bd9Sstevel@tonic-gate 				    lnotify(User, rqstr, "access denied");
3517c478bd9Sstevel@tonic-gate 				    CDEBUG(1, "Failed: Access Denied\n%s", "");
3527c478bd9Sstevel@tonic-gate 		    		    scWrite();	/* log the security violation */
3537c478bd9Sstevel@tonic-gate 				    goto top;
3547c478bd9Sstevel@tonic-gate 				}
3557c478bd9Sstevel@tonic-gate 			    }
3567c478bd9Sstevel@tonic-gate 			}
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate 			if (Restart && !(fstat(fileno(fp), &stbuf))) {
3597c478bd9Sstevel@tonic-gate 				(void) sprintf(fsize, "0x%lx", stbuf.st_size);
3607c478bd9Sstevel@tonic-gate 				W_FSIZE = fsize; /* set file size in vector */
3617c478bd9Sstevel@tonic-gate 			}
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 			/* Check whether remote's ulimit is exceeded */
3647c478bd9Sstevel@tonic-gate 			if (SizeCheck) {
3657c478bd9Sstevel@tonic-gate 				if (((stbuf.st_size-1)/512 + 1) > RemUlimit) {
3667c478bd9Sstevel@tonic-gate 					/* remote ulimit exceeded */
3677c478bd9Sstevel@tonic-gate 					unlinkdf(Dfile);
3687c478bd9Sstevel@tonic-gate 					lnotify(User, rqstr, "remote ulimit exceeded");
3697c478bd9Sstevel@tonic-gate 					logent("DENIED", "REMOTE ULIMIT EXCEEDED");
3707c478bd9Sstevel@tonic-gate 					CDEBUG(1, "Denied: remote ulimit exceeded %s\n", filename);
3717c478bd9Sstevel@tonic-gate 					scWrite();
3727c478bd9Sstevel@tonic-gate 					(void) fclose(fp);
3737c478bd9Sstevel@tonic-gate 					goto top;
3747c478bd9Sstevel@tonic-gate 				}
3757c478bd9Sstevel@tonic-gate 			}
3767c478bd9Sstevel@tonic-gate 		}
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate 		if (wrktype == RCVFILE) {
3797c478bd9Sstevel@tonic-gate 			(void) sprintf(rqstr, "%s!%s --> %s!%s (%s)", Rmtname,
3807c478bd9Sstevel@tonic-gate 			    W_FILE1, Myname, W_FILE2, User);
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate 			/* log destination node, user and file name */
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate 			scDest(Myname,NOTAVAIL,W_FILE2);
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate 			/* log source node, file owner, file name, mod time and size */
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate 			scSrc(Rmtname,NOTAVAIL,W_FILE1,NOTAVAIL,NOTAVAIL);
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate 			logent(rqstr, "REQUEST");
3917c478bd9Sstevel@tonic-gate 			CDEBUG(1, "Request: %s\n", rqstr);
3927c478bd9Sstevel@tonic-gate 			mf = W_RFILE;
3937c478bd9Sstevel@tonic-gate 			(void) strcpy(filename, W_FILE2);
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate 			/* change Wrkdir to SPOOL/Rmtname in case the file being
3967c478bd9Sstevel@tonic-gate 			** requested is needed for some remote execution.
3977c478bd9Sstevel@tonic-gate 			*/
3987c478bd9Sstevel@tonic-gate 
3997c478bd9Sstevel@tonic-gate 			(void) strcpy(Wrkdir, Recspool);
4007c478bd9Sstevel@tonic-gate 			expfile(filename);
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate 			/* now change Wrkdir back to what it was
4037c478bd9Sstevel@tonic-gate 			** just being paranoid.
4047c478bd9Sstevel@tonic-gate 			*/
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate 			(void) strcpy(Wrkdir, RemSpool);
4077c478bd9Sstevel@tonic-gate 			if (chkperm(W_FILE1, filename, strchr(W_OPTNS, 'd'))) {
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate 				/* access denied */
4107c478bd9Sstevel@tonic-gate 				logent("DENIED", "ACCESS");
4117c478bd9Sstevel@tonic-gate 				lnotify(User, rqstr, "access denied");
4127c478bd9Sstevel@tonic-gate 				CDEBUG(1, "Failed: Access Denied--File: %s\n",
4137c478bd9Sstevel@tonic-gate 				    filename);
4147c478bd9Sstevel@tonic-gate 		    		scWrite();	/* log the security violation */
4157c478bd9Sstevel@tonic-gate 				goto top;
4167c478bd9Sstevel@tonic-gate 			}
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate 			/*
4197c478bd9Sstevel@tonic-gate 			 * If we are not going to spool the file in the spool
4207c478bd9Sstevel@tonic-gate 			 * directory, just use the destination file name.  If we
4217c478bd9Sstevel@tonic-gate 			 * are not supporting restart, wipe out the target file.
4227c478bd9Sstevel@tonic-gate 			 * else:
4237c478bd9Sstevel@tonic-gate 			 *
4247c478bd9Sstevel@tonic-gate 			 * If restart is enabled, make up the Point file name
4257c478bd9Sstevel@tonic-gate 			 * as the file to open, else use the TM style name.
4267c478bd9Sstevel@tonic-gate 			 *
4277c478bd9Sstevel@tonic-gate 			 * If we run into a spool name of "D.0", this implies
4287c478bd9Sstevel@tonic-gate 			 * that someone forgot to install the new uucp and
4297c478bd9Sstevel@tonic-gate 			 * uux commands.  Such jobs will not be checkpointed.
4307c478bd9Sstevel@tonic-gate 			 */
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate 			if (Restart && (strlen(W_RDFILE) > (size_t) 6)) {
4347c478bd9Sstevel@tonic-gate 				if (noSpool()) {
4357c478bd9Sstevel@tonic-gate 				    strcpy(Dfile, filename);	/* use Dest file directly */
4367c478bd9Sstevel@tonic-gate 				    Pname(W_RDFILE, Dfile, TRUE);
4377c478bd9Sstevel@tonic-gate 				}
4387c478bd9Sstevel@tonic-gate 				else
4397c478bd9Sstevel@tonic-gate 				    Pname(W_RDFILE, Dfile, FALSE);
4407c478bd9Sstevel@tonic-gate 			}
4417c478bd9Sstevel@tonic-gate 			else {
4427c478bd9Sstevel@tonic-gate 			    TMname(Dfile, pnum); /* get TM file name */
4437c478bd9Sstevel@tonic-gate 			    unlink(Dfile);
4447c478bd9Sstevel@tonic-gate 			}
4457c478bd9Sstevel@tonic-gate 
4467c478bd9Sstevel@tonic-gate 			/*
4477c478bd9Sstevel@tonic-gate 			 * If the spool file exists, it better have the right owner
4487c478bd9Sstevel@tonic-gate 			 * and permissions!
4497c478bd9Sstevel@tonic-gate 			 */
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate 			if (Restart && noSpool()) {
4527c478bd9Sstevel@tonic-gate 				if ((! stat(Dfile, &stbuf)) &&
4537c478bd9Sstevel@tonic-gate 				    ((stbuf.st_mode != (DFILEMODE|S_IFREG)) ||
4547c478bd9Sstevel@tonic-gate 				    ((stbuf.st_gid != UUCPGID) ||
4557c478bd9Sstevel@tonic-gate 				     (stbuf.st_uid != UUCPUID)))) {
4567c478bd9Sstevel@tonic-gate 				    lnotify(User, rqstr,
4577c478bd9Sstevel@tonic-gate 					"bad spool file ownership/permissions");
4587c478bd9Sstevel@tonic-gate 				    logent("BAD DESTFILE OWNER/PERMS", "FAIL");
4597c478bd9Sstevel@tonic-gate 				    CDEBUG(1, "Failed: bad dest file owner/perms 0%o; fail\n", stbuf.st_mode);
4607c478bd9Sstevel@tonic-gate 				    goto top;
4617c478bd9Sstevel@tonic-gate 				}
4627c478bd9Sstevel@tonic-gate 			}
4637c478bd9Sstevel@tonic-gate 			if ( ((fp = fopen(Dfile, "a+")) == NULL)
4647c478bd9Sstevel@tonic-gate 			     || nospace(Dfile)) {
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate 				/* can not create temp */
4677c478bd9Sstevel@tonic-gate 				if (noSpool())
4687c478bd9Sstevel@tonic-gate 				    logent("CAN'T CREATE/OPEN DEST FILE", "FAILED");
4697c478bd9Sstevel@tonic-gate 				else
4707c478bd9Sstevel@tonic-gate 				    logent("CAN'T CREATE TM FILE", "FAILED");
4717c478bd9Sstevel@tonic-gate 				CDEBUG(1, "Failed: No Space!\n%s", "");
4727c478bd9Sstevel@tonic-gate 				unlinkdf(Dfile);
4737c478bd9Sstevel@tonic-gate 				assert(Ct_CREATE, Dfile, nospace(Dfile),
4747c478bd9Sstevel@tonic-gate 				    __FILE__, __LINE__);
4757c478bd9Sstevel@tonic-gate 				cleanup(FAIL);
4767c478bd9Sstevel@tonic-gate 			}
4777c478bd9Sstevel@tonic-gate 
4787c478bd9Sstevel@tonic-gate 			/*
4797c478bd9Sstevel@tonic-gate 			 * Send the W_POINT value to the other side.
4807c478bd9Sstevel@tonic-gate 			 */
4817c478bd9Sstevel@tonic-gate 
4827c478bd9Sstevel@tonic-gate 			if (Restart) {
4837c478bd9Sstevel@tonic-gate 			    if (fstat (fileno(fp), &stbuf)) {
4847c478bd9Sstevel@tonic-gate 				logent("CAN'T STAT DFILE", "START FROM BEGINNING");
4857c478bd9Sstevel@tonic-gate 				stbuf.st_size = 0L;
4867c478bd9Sstevel@tonic-gate 			    }
4877c478bd9Sstevel@tonic-gate 
4887c478bd9Sstevel@tonic-gate 			    /*
4897c478bd9Sstevel@tonic-gate 			     * find a good start point.  Take care of simple
4907c478bd9Sstevel@tonic-gate 			     * underflow and the signed nature of longs.
4917c478bd9Sstevel@tonic-gate 			     */
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 			    DEBUG(7, "Dfile length 0x%lx\n", stbuf.st_size);
4947c478bd9Sstevel@tonic-gate 			    startp = stbuf.st_size - (stbuf.st_size % BUFSIZ);
4957c478bd9Sstevel@tonic-gate 			    if((stbuf.st_size >= 0) && (startp < 0))
4967c478bd9Sstevel@tonic-gate 				startp = 0;
4977c478bd9Sstevel@tonic-gate 
4987c478bd9Sstevel@tonic-gate 			    if(startp)
4997c478bd9Sstevel@tonic-gate 			    {
5007c478bd9Sstevel@tonic-gate 				if(startp < 0)
5017c478bd9Sstevel@tonic-gate 				    sprintf(tbuf,"start=0x%lx", startp);
5027c478bd9Sstevel@tonic-gate 				else
5037c478bd9Sstevel@tonic-gate 				    sprintf(tbuf,"start=%ld", startp);
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate 				logent(tbuf, "RESTART");
5067c478bd9Sstevel@tonic-gate 			    }
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate 			    sprintf(fsize, "0x%lx", startp);
5097c478bd9Sstevel@tonic-gate 			    W_POINT = fsize; /* set start point in vector */
5107c478bd9Sstevel@tonic-gate 			    if (lseek(fileno(fp), startp, 0) == -1) {
5117c478bd9Sstevel@tonic-gate 				WMESG(SNDFILE, EM_SEEK);
5127c478bd9Sstevel@tonic-gate 				logent("CAN'T SEEK", "DENIED");
5137c478bd9Sstevel@tonic-gate 				CDEBUG(1, "Failed, Can't seek in Dfile\n%s", "");
5147c478bd9Sstevel@tonic-gate 				unlinkdf(Dfile);
5157c478bd9Sstevel@tonic-gate 				goto top;
5167c478bd9Sstevel@tonic-gate 		    	    }
5177c478bd9Sstevel@tonic-gate 		    	    fp->_cnt = 0;
5187c478bd9Sstevel@tonic-gate 		    	    fp->_ptr = fp->_base;
5197c478bd9Sstevel@tonic-gate 			}
5207c478bd9Sstevel@tonic-gate 
5217c478bd9Sstevel@tonic-gate 			Seqn++;
5227c478bd9Sstevel@tonic-gate 			chmod(Dfile, DFILEMODE);	/* no peeking! */
5237c478bd9Sstevel@tonic-gate 			chown(Dfile, UUCPUID, UUCPGID);
5247c478bd9Sstevel@tonic-gate 
5257c478bd9Sstevel@tonic-gate 		}
5267c478bd9Sstevel@tonic-gate 		DEBUG(4, "wrktype - %c\n ", wrktype);
5277c478bd9Sstevel@tonic-gate 
5287c478bd9Sstevel@tonic-gate 		/* Build up the message itself */
5297c478bd9Sstevel@tonic-gate 
5307c478bd9Sstevel@tonic-gate 		msg[0] = '\0';
5317c478bd9Sstevel@tonic-gate 		for (i = 1; i < narg; i++) {
5327c478bd9Sstevel@tonic-gate 			(void) strcat(msg, " ");
5337c478bd9Sstevel@tonic-gate 			(void) strcat(msg, wrkvec[i]);
5347c478bd9Sstevel@tonic-gate 		}
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate 		WMESG(wrktype, msg); /* I(master) am sending you our work file */
5377c478bd9Sstevel@tonic-gate 		RMESG(wrktype, msg); /* I(master) am waiting for your response */
5387c478bd9Sstevel@tonic-gate 		goto process;
5397c478bd9Sstevel@tonic-gate 	}
5407c478bd9Sstevel@tonic-gate 
5417c478bd9Sstevel@tonic-gate 	/*
5427c478bd9Sstevel@tonic-gate 	 * role is slave
5437c478bd9Sstevel@tonic-gate 	 */
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate 	RAMESG(msg); /* I(slave) am waiting for our work file */
5467c478bd9Sstevel@tonic-gate 
5477c478bd9Sstevel@tonic-gate process:
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate 	DEBUG(4, " PROCESS: msg - %s\n", msg);
5507c478bd9Sstevel@tonic-gate 	switch (msg[0]) {
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate 	case RQSTCMPT:
5537c478bd9Sstevel@tonic-gate 		DEBUG(4, "%s\n", "RQSTCMPT:");
5547c478bd9Sstevel@tonic-gate 		if (msg[1] == 'N') {
5557c478bd9Sstevel@tonic-gate 			i = atoi(&msg[2]);
5567c478bd9Sstevel@tonic-gate 			if (i < 0 || i > EM_MAX)
5577c478bd9Sstevel@tonic-gate 				i = 0;
5587c478bd9Sstevel@tonic-gate 			logent(Em_msg[i], "REQUESTED");
5597c478bd9Sstevel@tonic-gate 		}
5607c478bd9Sstevel@tonic-gate 		if (Role == MASTER) {
5617c478bd9Sstevel@tonic-gate 		        notify(mailopt, W_USER, rqstr, Rmtname, &msg[1]);
5627c478bd9Sstevel@tonic-gate 		}
5637c478bd9Sstevel@tonic-gate 		pfEndfile("");	/* "" indicates the file transfer completely */
5647c478bd9Sstevel@tonic-gate 		goto top;
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate 	case HUP:
5677c478bd9Sstevel@tonic-gate 		DEBUG(4, "%s\n", "HUP:");
5687c478bd9Sstevel@tonic-gate 		if (msg[1] == 'Y') {
5697c478bd9Sstevel@tonic-gate 			WMESG(HUP, YES); /* let's quit */
5707c478bd9Sstevel@tonic-gate 			(*Turnoff)();
5717c478bd9Sstevel@tonic-gate 			Rdmsg = imsg;
5727c478bd9Sstevel@tonic-gate 			Wrmsg = omsg;
5737c478bd9Sstevel@tonic-gate 			Turnoff = turnoff;
5747c478bd9Sstevel@tonic-gate 			return(0);
5757c478bd9Sstevel@tonic-gate 		}
5767c478bd9Sstevel@tonic-gate 
5777c478bd9Sstevel@tonic-gate 		if (msg[1] == 'N') {
5787c478bd9Sstevel@tonic-gate 			ASSERT(Role == MASTER, Wr_ROLE, "", Role);
5797c478bd9Sstevel@tonic-gate 			Role = SLAVE;
5807c478bd9Sstevel@tonic-gate 			scReqsys(Rmtname); /* log requestor system */
5817c478bd9Sstevel@tonic-gate 			chremdir(Rmtname);
5827c478bd9Sstevel@tonic-gate 			goto top;
5837c478bd9Sstevel@tonic-gate 		}
5847c478bd9Sstevel@tonic-gate 
5857c478bd9Sstevel@tonic-gate 		/*
5867c478bd9Sstevel@tonic-gate 		 * get work
5877c478bd9Sstevel@tonic-gate 		 */
5887c478bd9Sstevel@tonic-gate 		if ( (switchRole() == FALSE) || !iswrk(Wfile) ) {
5897c478bd9Sstevel@tonic-gate 			DEBUG(5, "SLAVE-switchRole (%s)\n",
5907c478bd9Sstevel@tonic-gate 			    switchRole() ? "TRUE" : "FALSE");
5917c478bd9Sstevel@tonic-gate 			WMESG(HUP, YES); /* let's quit */
5927c478bd9Sstevel@tonic-gate 			RMESG(HUP, msg);
5937c478bd9Sstevel@tonic-gate 			goto process;
5947c478bd9Sstevel@tonic-gate 		}
5957c478bd9Sstevel@tonic-gate 
5967c478bd9Sstevel@tonic-gate 		/* Note that Wfile is the first C. to process at top
5977c478bd9Sstevel@tonic-gate 		 * set above by iswrk() call
5987c478bd9Sstevel@tonic-gate 		 */
5997c478bd9Sstevel@tonic-gate 		if (uuxqtflag) {
6007c478bd9Sstevel@tonic-gate 			xuuxqt(uuxqtarg);
6017c478bd9Sstevel@tonic-gate 			uuxqtflag = 0;
6027c478bd9Sstevel@tonic-gate 		}
6037c478bd9Sstevel@tonic-gate 		WMESG(HUP, NO); /* don't quit. I(slave) have more to do */
6047c478bd9Sstevel@tonic-gate 		Role = MASTER;
6057c478bd9Sstevel@tonic-gate 		uucpname(localname); /* get real local machine name */
6067c478bd9Sstevel@tonic-gate 		scReqsys(localname); /* log requestor system */
6077c478bd9Sstevel@tonic-gate 		acInit("xfer");
6087c478bd9Sstevel@tonic-gate 		goto top;
6097c478bd9Sstevel@tonic-gate 
6107c478bd9Sstevel@tonic-gate 	case XUUCP:
6117c478bd9Sstevel@tonic-gate 		/*
6127c478bd9Sstevel@tonic-gate 		 * slave part
6137c478bd9Sstevel@tonic-gate 		 * No longer accepted
6147c478bd9Sstevel@tonic-gate 		 */
6157c478bd9Sstevel@tonic-gate 
6167c478bd9Sstevel@tonic-gate 		WMESG(XUUCP, NO);
6177c478bd9Sstevel@tonic-gate 		goto top;
6187c478bd9Sstevel@tonic-gate 
6197c478bd9Sstevel@tonic-gate 	case SNDFILE:
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate 		/*
6227c478bd9Sstevel@tonic-gate 		 * MASTER section of SNDFILE
6237c478bd9Sstevel@tonic-gate 		 */
6247c478bd9Sstevel@tonic-gate 		DEBUG(4, "%s\n", "SNDFILE:");
6257c478bd9Sstevel@tonic-gate 		if (msg[1] == 'N')
6267c478bd9Sstevel@tonic-gate 		   {
6277c478bd9Sstevel@tonic-gate 		    i = atoi(&msg[2]);
6287c478bd9Sstevel@tonic-gate 		    if (i < 0 || i > EM_MAX)
6297c478bd9Sstevel@tonic-gate 			i = 0;
6307c478bd9Sstevel@tonic-gate 		    logent(Em_msg[i], "REQUEST");
6317c478bd9Sstevel@tonic-gate 		    notify(mailopt, W_USER, rqstr, Rmtname, &msg[1]);
6327c478bd9Sstevel@tonic-gate 		    ASSERT(Role == MASTER, Wr_ROLE, "", Role);
6337c478bd9Sstevel@tonic-gate 		    (void) fclose(fp);
6347c478bd9Sstevel@tonic-gate 		    /* if remote is out of tmp space, then just hang up */
6357c478bd9Sstevel@tonic-gate 		    ASSERT(i != 4, Em_msg[4], Rmtname, i);	/* EM_NOTMP */
6367c478bd9Sstevel@tonic-gate 		    unlinkdf(W_DFILE);
6377c478bd9Sstevel@tonic-gate 		    scWrite();	/* something is wrong on other side,
6387c478bd9Sstevel@tonic-gate 				   log the security violation */
6397c478bd9Sstevel@tonic-gate 		    Seqn++;
6407c478bd9Sstevel@tonic-gate 		    goto top;
6417c478bd9Sstevel@tonic-gate 		   }
6427c478bd9Sstevel@tonic-gate 
6437c478bd9Sstevel@tonic-gate 		if (msg[1] == 'Y') {
6447c478bd9Sstevel@tonic-gate 
6457c478bd9Sstevel@tonic-gate 			/*
6467c478bd9Sstevel@tonic-gate 			 * send file
6477c478bd9Sstevel@tonic-gate 			 */
6487c478bd9Sstevel@tonic-gate 			ASSERT(Role == MASTER, Wr_ROLE, "", Role);
6497c478bd9Sstevel@tonic-gate 			if (fstat(fileno(fp), &stbuf)) /* never fail but .. */
6507c478bd9Sstevel@tonic-gate 			    stbuf.st_size = 0;  /* for time loop calculation */
6517c478bd9Sstevel@tonic-gate 
6527c478bd9Sstevel@tonic-gate 			/*
6537c478bd9Sstevel@tonic-gate 			 * If checkpoint restart is enabled, seek to the
6547c478bd9Sstevel@tonic-gate 			 * starting point in the file.  We use hex because
6557c478bd9Sstevel@tonic-gate 			 * C doesn't support unsigned long directly.
6567c478bd9Sstevel@tonic-gate 			 */
6577c478bd9Sstevel@tonic-gate 
6587c478bd9Sstevel@tonic-gate 			if (Restart) {
6597c478bd9Sstevel@tonic-gate 			    if((startp = strtol(&msg[2], (char **) 0, FLENRADIX))) {
6607c478bd9Sstevel@tonic-gate 			        CDEBUG(1, "Restart point=0x%lx\n", startp);
6617c478bd9Sstevel@tonic-gate 				if(startp < 0)
6627c478bd9Sstevel@tonic-gate 				    sprintf(tbuf,"start=0x%lx", startp);
6637c478bd9Sstevel@tonic-gate 				else
6647c478bd9Sstevel@tonic-gate 				    sprintf(tbuf,"start=%ld", startp);
6657c478bd9Sstevel@tonic-gate 				p = tbuf + strlen(tbuf);
6667c478bd9Sstevel@tonic-gate 				if (stbuf.st_size < 0)
6677c478bd9Sstevel@tonic-gate 				    sprintf(p,", length=0x%lx", stbuf.st_size);
6687c478bd9Sstevel@tonic-gate 				else
6697c478bd9Sstevel@tonic-gate 				    sprintf(p,", length=%ld", stbuf.st_size);
6707c478bd9Sstevel@tonic-gate 
6717c478bd9Sstevel@tonic-gate 				logent(tbuf, "RESTART");
6727c478bd9Sstevel@tonic-gate 				errno = 0;
6737c478bd9Sstevel@tonic-gate 				if (lseek(fileno(fp), startp, 0) == -1) {
674*ace1a5f1Sdp 				    logent(strerror(errno), "FSEEK ERROR");
6757c478bd9Sstevel@tonic-gate 				    (void) fclose(fp);
6767c478bd9Sstevel@tonic-gate 				    (*Turnoff)();
6777c478bd9Sstevel@tonic-gate 		    		    Seqn++;
6787c478bd9Sstevel@tonic-gate 				    return(FAIL);
6797c478bd9Sstevel@tonic-gate 				}
6807c478bd9Sstevel@tonic-gate 				fp->_cnt = 0;
6817c478bd9Sstevel@tonic-gate 				fp->_ptr = fp->_base;
6827c478bd9Sstevel@tonic-gate 			    }
6837c478bd9Sstevel@tonic-gate 			}
6847c478bd9Sstevel@tonic-gate 			(void) millitick();	/* start msec timer */
6857c478bd9Sstevel@tonic-gate 			pfStrtXfer(MCHAR, SNDFILE);
6867c478bd9Sstevel@tonic-gate 			scStime(); 	/* log start transfer time for security log */
6877c478bd9Sstevel@tonic-gate 
6887c478bd9Sstevel@tonic-gate 		/* (ret != 0) implies the trammission error occurred.
6897c478bd9Sstevel@tonic-gate      	           If checkpoint protocol is available then the next
6907c478bd9Sstevel@tonic-gate 		   transfer will restart from the breakpoint of the file,
6917c478bd9Sstevel@tonic-gate 		   otherwise from the beginning of the file  */
6927c478bd9Sstevel@tonic-gate 
6937c478bd9Sstevel@tonic-gate 			ret = (*Wrdata)(fp, Ofn);
6947c478bd9Sstevel@tonic-gate 
6957c478bd9Sstevel@tonic-gate 		/* the second millitick() returns the duration between
6967c478bd9Sstevel@tonic-gate 		   the first and second call.
6977c478bd9Sstevel@tonic-gate    		   writes "PARTIAL FILE to the transfer log indicating
6987c478bd9Sstevel@tonic-gate 		   a transmission error. */
6997c478bd9Sstevel@tonic-gate 
7007c478bd9Sstevel@tonic-gate 			statlog( "->", getfilesize(), millitick(),
7017c478bd9Sstevel@tonic-gate 					(ret) ? "PARTIAL FILE" : ""  );
7027c478bd9Sstevel@tonic-gate 
7037c478bd9Sstevel@tonic-gate 			acInc();	/* increment job size in accounting log					 */
7047c478bd9Sstevel@tonic-gate 			pfEndXfer();
7057c478bd9Sstevel@tonic-gate 			scEtime();	/* log end transfer time for security log */
7067c478bd9Sstevel@tonic-gate 		    	Seqn++;
7077c478bd9Sstevel@tonic-gate 			(void) fclose(fp);
7087c478bd9Sstevel@tonic-gate 			if (ret != 0) {
7097c478bd9Sstevel@tonic-gate 				pfEndfile("PARTIAL FILE");
7107c478bd9Sstevel@tonic-gate 				acEnd(PARTIAL); /*stop collecting accounting log */
7117c478bd9Sstevel@tonic-gate 				(*Turnoff)();
7127c478bd9Sstevel@tonic-gate 				return(FAIL);
7137c478bd9Sstevel@tonic-gate 			}
7147c478bd9Sstevel@tonic-gate 
7157c478bd9Sstevel@tonic-gate 			/* loop depending on the size of the file */
7167c478bd9Sstevel@tonic-gate 			/* give an extra try for each megabyte */
7177c478bd9Sstevel@tonic-gate 			for (im = stbuf.st_size >> 10; im >= 0; --im) {
7187c478bd9Sstevel@tonic-gate 		    	    if ((ret = rmesg(RQSTCMPT, msg)) == 0)
7197c478bd9Sstevel@tonic-gate 				break;	/* got message */
7207c478bd9Sstevel@tonic-gate 			}
7217c478bd9Sstevel@tonic-gate 			if (ret != 0) {
7227c478bd9Sstevel@tonic-gate 			    (*Turnoff)();
7237c478bd9Sstevel@tonic-gate 			     return(FAIL);
7247c478bd9Sstevel@tonic-gate 			}
7257c478bd9Sstevel@tonic-gate 			unlinkdf(W_DFILE);
7267c478bd9Sstevel@tonic-gate 			goto process;
7277c478bd9Sstevel@tonic-gate 		}
7287c478bd9Sstevel@tonic-gate 
7297c478bd9Sstevel@tonic-gate 		/*
7307c478bd9Sstevel@tonic-gate 		 * SLAVE section of SNDFILE
7317c478bd9Sstevel@tonic-gate 		 */
7327c478bd9Sstevel@tonic-gate 		ASSERT(Role == SLAVE, Wr_ROLE, "", Role);
7337c478bd9Sstevel@tonic-gate 
7347c478bd9Sstevel@tonic-gate 		/*
7357c478bd9Sstevel@tonic-gate 		 * request to receive file
7367c478bd9Sstevel@tonic-gate 		 * check permissions
7377c478bd9Sstevel@tonic-gate 		 */
7387c478bd9Sstevel@tonic-gate 		i = getargs(msg, wrkvec, W_MAX);
7397c478bd9Sstevel@tonic-gate 
7407c478bd9Sstevel@tonic-gate 		scRequser(W_USER); /* log requestor user id */
7417c478bd9Sstevel@tonic-gate 
7427c478bd9Sstevel@tonic-gate 		/* log destination node, user and file name */
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate 		scDest(Myname,NOTAVAIL,W_FILE2);
7457c478bd9Sstevel@tonic-gate 
7467c478bd9Sstevel@tonic-gate 		/* log source node, file owner, file name, mod time and size */
7477c478bd9Sstevel@tonic-gate 
7487c478bd9Sstevel@tonic-gate 		scSrc(Rmtname,NOTAVAIL,W_FILE1,NOTAVAIL,NOTAVAIL);
7497c478bd9Sstevel@tonic-gate 
7507c478bd9Sstevel@tonic-gate 		/* Check for bad request */
7517c478bd9Sstevel@tonic-gate 		if (i < W_MIN) {
7527c478bd9Sstevel@tonic-gate 			WMESG(SNDFILE, EM_BADUUCP); /* you(remote master) gave me
7537c478bd9Sstevel@tonic-gate 							bad work file */
7547c478bd9Sstevel@tonic-gate 			logent("DENIED", "TOO FEW ARGS IN SLAVE SNDFILE");
7557c478bd9Sstevel@tonic-gate 			goto top;
7567c478bd9Sstevel@tonic-gate 		}
7577c478bd9Sstevel@tonic-gate 		/* SLAVE gets the original filesize from sender (MASTER) */
7587c478bd9Sstevel@tonic-gate 		/* This will be used to check the length of the P. file */
7597c478bd9Sstevel@tonic-gate 		if (Restart) {
7607c478bd9Sstevel@tonic-gate 		    if (W_FSIZE && (*W_FSIZE != '\0')) {
7617c478bd9Sstevel@tonic-gate 			actualsize = strtol(W_FSIZE, (char **) 0, FLENRADIX);
7627c478bd9Sstevel@tonic-gate 			CDEBUG(7, "Actual File Length %ld\n", actualsize);
7637c478bd9Sstevel@tonic-gate 		    } else {
7647c478bd9Sstevel@tonic-gate 			actualsize = -1;
7657c478bd9Sstevel@tonic-gate 			CDEBUG(7, "Actual File Length Not Provided\n%s", "");
7667c478bd9Sstevel@tonic-gate 		    }
7677c478bd9Sstevel@tonic-gate 		}
7687c478bd9Sstevel@tonic-gate 
7697c478bd9Sstevel@tonic-gate 		mf = W_SFILE;
7707c478bd9Sstevel@tonic-gate 		(void) sprintf(rqstr, "%s!%s --> %s!%s (%s)", Rmtname,
7717c478bd9Sstevel@tonic-gate 			    W_FILE1, Myname, W_FILE2, W_USER);
7727c478bd9Sstevel@tonic-gate 		logent(rqstr, "REMOTE REQUESTED");
7737c478bd9Sstevel@tonic-gate 		DEBUG(4, "msg - %s\n", msg);
7747c478bd9Sstevel@tonic-gate 		CDEBUG(1, "Remote Requested: %s\n", rqstr);
7757c478bd9Sstevel@tonic-gate 		(void) strcpy(filename, W_FILE2);
7767c478bd9Sstevel@tonic-gate 		expfile(filename);
7777c478bd9Sstevel@tonic-gate 		DEBUG(4, "SLAVE - filename: %s\n", filename);
7787c478bd9Sstevel@tonic-gate 		if (chkpth(filename, CK_WRITE)
7797c478bd9Sstevel@tonic-gate 		     || chkperm(W_FILE1, filename, strchr(W_OPTNS, 'd'))) {
7807c478bd9Sstevel@tonic-gate 			WMESG(SNDFILE, EM_RMTACC); /* you(remote master) can't
7817c478bd9Sstevel@tonic-gate 						send data to this file(directory) */
7827c478bd9Sstevel@tonic-gate 			logent("DENIED", "PERMISSION");
7837c478bd9Sstevel@tonic-gate 			CDEBUG(1, "Failed: Access Denied\n%s", "");
7847c478bd9Sstevel@tonic-gate 		    	scWrite(); /* log security violation */
7857c478bd9Sstevel@tonic-gate 			goto top;
7867c478bd9Sstevel@tonic-gate 		}
7877c478bd9Sstevel@tonic-gate 		(void) sprintf(User, "%s", W_USER);
7887c478bd9Sstevel@tonic-gate 
7897c478bd9Sstevel@tonic-gate 		DEBUG(4, "chkpth ok Rmtname - %s\n", Rmtname);
7907c478bd9Sstevel@tonic-gate 
7917c478bd9Sstevel@tonic-gate 
7927c478bd9Sstevel@tonic-gate 
7937c478bd9Sstevel@tonic-gate 		if (Restart && (strlen(W_DFILE) > (size_t) 6)) {
7947c478bd9Sstevel@tonic-gate 			if (noSpool()) {
7957c478bd9Sstevel@tonic-gate 			    strcpy(Dfile, filename);	/* use Dest file directly */
7967c478bd9Sstevel@tonic-gate 			    Pname(W_DFILE, Dfile, TRUE);
7977c478bd9Sstevel@tonic-gate 			    if (! Restart)
7987c478bd9Sstevel@tonic-gate 				unlink(Dfile);
7997c478bd9Sstevel@tonic-gate 			}
8007c478bd9Sstevel@tonic-gate 			else
8017c478bd9Sstevel@tonic-gate 			    Pname(W_DFILE, Dfile, FALSE);
8027c478bd9Sstevel@tonic-gate 		}
8037c478bd9Sstevel@tonic-gate 		else {
8047c478bd9Sstevel@tonic-gate 		    TMname(Dfile, pnum); /* get TM file name */
8057c478bd9Sstevel@tonic-gate 		    unlink(Dfile);
8067c478bd9Sstevel@tonic-gate 		}
8077c478bd9Sstevel@tonic-gate 
8087c478bd9Sstevel@tonic-gate 		/*
8097c478bd9Sstevel@tonic-gate 		 * If the spool file exists, it better have the right owner
8107c478bd9Sstevel@tonic-gate 		 * and permissions!
8117c478bd9Sstevel@tonic-gate 		 */
8127c478bd9Sstevel@tonic-gate 
8137c478bd9Sstevel@tonic-gate 		if (Restart && noSpool()) {
8147c478bd9Sstevel@tonic-gate 			if ((! stat(Dfile, &stbuf)) &&
8157c478bd9Sstevel@tonic-gate 			    ((stbuf.st_mode != (DFILEMODE|S_IFREG)) ||
8167c478bd9Sstevel@tonic-gate 			    ((stbuf.st_gid != UUCPGID) ||
8177c478bd9Sstevel@tonic-gate 			     (stbuf.st_uid != UUCPUID)))) {
8187c478bd9Sstevel@tonic-gate 			    WMESG(SNDFILE, EM_NOTMP); /* I(slave) see bad perms */
8197c478bd9Sstevel@tonic-gate 			    logent("BAD DESTFILE OWNER/PERMS", "FAILED");
8207c478bd9Sstevel@tonic-gate 			    CDEBUG(1, "Failed: bad dest file owner/perms 0%o\n", stbuf.st_mode);
8217c478bd9Sstevel@tonic-gate 			    goto top;
8227c478bd9Sstevel@tonic-gate 			}
8237c478bd9Sstevel@tonic-gate 		}
8247c478bd9Sstevel@tonic-gate 		if ( ((fp = fopen(Dfile, "a+")) == NULL) || nospace(Dfile) ) {
8257c478bd9Sstevel@tonic-gate 			WMESG(SNDFILE, EM_NOTMP); /* I(slave) can't create TM file */
8267c478bd9Sstevel@tonic-gate 			logent("CAN'T OPEN", "DENIED");
8277c478bd9Sstevel@tonic-gate 			CDEBUG(1, "Failed: Can't Create Temp File\n%s", "");
8287c478bd9Sstevel@tonic-gate 			unlinkdf(Dfile);
8297c478bd9Sstevel@tonic-gate 			goto top;
8307c478bd9Sstevel@tonic-gate 		}
8317c478bd9Sstevel@tonic-gate 		chmod(Dfile, DFILEMODE);	/* no peeking! */
8327c478bd9Sstevel@tonic-gate 		chown(Dfile, UUCPUID, UUCPGID);
8337c478bd9Sstevel@tonic-gate 		if (Restart && (strlen(W_DFILE) > (size_t) 6)) {
8347c478bd9Sstevel@tonic-gate 		    if(fstat(fileno(fp), &stbuf)) {
8357c478bd9Sstevel@tonic-gate 			WMESG(SNDFILE, EM_NOTMP);
8367c478bd9Sstevel@tonic-gate 			logent("CAN'T STAT", "DENIED");
8377c478bd9Sstevel@tonic-gate 			CDEBUG(1, "Failed: Can't Stat Temp File\n%s", "");
8387c478bd9Sstevel@tonic-gate 			unlinkdf(Dfile);
8397c478bd9Sstevel@tonic-gate 			Seqn++;
8407c478bd9Sstevel@tonic-gate 			goto top;
8417c478bd9Sstevel@tonic-gate 		    }
8427c478bd9Sstevel@tonic-gate 		    /*
8437c478bd9Sstevel@tonic-gate 		     * find a good start point.  Take care of simple underflow
8447c478bd9Sstevel@tonic-gate 		     * and the signed nature of longs.
8457c478bd9Sstevel@tonic-gate 		     */
8467c478bd9Sstevel@tonic-gate 
8477c478bd9Sstevel@tonic-gate 		    DEBUG(7, "Dfile length 0x%lx\n", stbuf.st_size);
8487c478bd9Sstevel@tonic-gate 		    startp = stbuf.st_size - (stbuf.st_size % BUFSIZ);
8497c478bd9Sstevel@tonic-gate 		    if((stbuf.st_size >= 0) && (startp < 0))
8507c478bd9Sstevel@tonic-gate 			startp = 0;
8517c478bd9Sstevel@tonic-gate 
8527c478bd9Sstevel@tonic-gate 		    if(startp)
8537c478bd9Sstevel@tonic-gate 		    {
8547c478bd9Sstevel@tonic-gate 			if(startp < 0)
8557c478bd9Sstevel@tonic-gate 			    sprintf(tbuf,"start=0x%lx", startp);
8567c478bd9Sstevel@tonic-gate 			else
8577c478bd9Sstevel@tonic-gate 			    sprintf(tbuf,"start=%ld", startp);
8587c478bd9Sstevel@tonic-gate 
8597c478bd9Sstevel@tonic-gate 			logent(tbuf, "RESTART");
8607c478bd9Sstevel@tonic-gate 		    }
8617c478bd9Sstevel@tonic-gate 
8627c478bd9Sstevel@tonic-gate 		    sprintf(tbuf, "%s 0x%lx", YES, startp);
8637c478bd9Sstevel@tonic-gate 		    if (lseek(fileno(fp), startp, 0) == -1) {
8647c478bd9Sstevel@tonic-gate 			WMESG(SNDFILE, EM_SEEK);
8657c478bd9Sstevel@tonic-gate 			logent("CAN'T SEEK", "DENIED");
8667c478bd9Sstevel@tonic-gate 			CDEBUG(1, "Failed, Can't seek in Dfile\n%s", "");
8677c478bd9Sstevel@tonic-gate 			unlinkdf(Dfile);
8687c478bd9Sstevel@tonic-gate 			Seqn++;
8697c478bd9Sstevel@tonic-gate 			goto top;
8707c478bd9Sstevel@tonic-gate 		    }
8717c478bd9Sstevel@tonic-gate 		    fp->_cnt = 0;
8727c478bd9Sstevel@tonic-gate 		    fp->_ptr = fp->_base;
8737c478bd9Sstevel@tonic-gate 		    CDEBUG(1," restart msg %s\n", tbuf);
8747c478bd9Sstevel@tonic-gate 		    WMESG(SNDFILE, tbuf);
8757c478bd9Sstevel@tonic-gate 		}
8767c478bd9Sstevel@tonic-gate 		else
8777c478bd9Sstevel@tonic-gate 		    WMESG(SNDFILE, YES);	/* I(slave) clear to send */
8787c478bd9Sstevel@tonic-gate 		(void) millitick();	/* start msec timer */
8797c478bd9Sstevel@tonic-gate 		pfStrtXfer(SCHAR, RCVFILE);
8807c478bd9Sstevel@tonic-gate 		scStime(); 	/* log start transfer time for security log */
8817c478bd9Sstevel@tonic-gate 		/* (ret != 0) implies the trammission error occurred.
8827c478bd9Sstevel@tonic-gate      	           If checkpoint protocol is available then the next
8837c478bd9Sstevel@tonic-gate 		   recieve will restart from the breakpoint of the file,
8847c478bd9Sstevel@tonic-gate 		   otherwise from the beginning of the file  */
8857c478bd9Sstevel@tonic-gate 
8867c478bd9Sstevel@tonic-gate 		setline(RCVFILE);
8877c478bd9Sstevel@tonic-gate 		ret = (*Rddata)(Ifn, fp);
8887c478bd9Sstevel@tonic-gate 		setline(SNDFILE);
8897c478bd9Sstevel@tonic-gate 
8907c478bd9Sstevel@tonic-gate 		/* the second millitick() returns the duration between
8917c478bd9Sstevel@tonic-gate 		   the first and second call.
8927c478bd9Sstevel@tonic-gate    		   writes "PARTIAL FILE to the transfer log indicating
8937c478bd9Sstevel@tonic-gate 		   a transmission error. */
8947c478bd9Sstevel@tonic-gate 
8957c478bd9Sstevel@tonic-gate 		statlog( "<-", getfilesize(), millitick(),
8967c478bd9Sstevel@tonic-gate 				(ret) ? "PARTIAL FILE" : ""  );
8977c478bd9Sstevel@tonic-gate 
8987c478bd9Sstevel@tonic-gate 		pfEndXfer();
8997c478bd9Sstevel@tonic-gate 		scEtime();	/* log end transfer time for security log */
9007c478bd9Sstevel@tonic-gate 		Seqn++;
9017c478bd9Sstevel@tonic-gate 
9027c478bd9Sstevel@tonic-gate 		if (ret != 0) {
9037c478bd9Sstevel@tonic-gate 			pfEndfile("PARTIAL FILE");
9047c478bd9Sstevel@tonic-gate 			(void) fclose(fp);
9057c478bd9Sstevel@tonic-gate 			if ( ret == EFBIG ) {
9067c478bd9Sstevel@tonic-gate 				WMESG(RQSTCMPT, EM_ULIMIT);
9077c478bd9Sstevel@tonic-gate 				logent("FILE EXCEEDS ULIMIT","FAILED");
9087c478bd9Sstevel@tonic-gate 				CDEBUG(1, "Failed: file size exceeds ulimit%s\n", "");
9097c478bd9Sstevel@tonic-gate 				goto top;
9107c478bd9Sstevel@tonic-gate 			}
9117c478bd9Sstevel@tonic-gate 			(*Turnoff)();
9127c478bd9Sstevel@tonic-gate 			logent("INPUT FAILURE", "IN SEND/SLAVE MODE");
9137c478bd9Sstevel@tonic-gate 			return(FAIL);
9147c478bd9Sstevel@tonic-gate 		}
9157c478bd9Sstevel@tonic-gate 		if (Restart && (actualsize != -1)) {
9167c478bd9Sstevel@tonic-gate 		    if (fstat(fileno(fp), &stbuf)) {
9177c478bd9Sstevel@tonic-gate 			(void) fclose(fp);
9187c478bd9Sstevel@tonic-gate 			unlinkdf(Dfile);
9197c478bd9Sstevel@tonic-gate 			(*Turnoff)();
9207c478bd9Sstevel@tonic-gate 			logent("CAN'T STAT PFILE", "FAILED");
9217c478bd9Sstevel@tonic-gate 			return(FAIL);
9227c478bd9Sstevel@tonic-gate 		    }
9237c478bd9Sstevel@tonic-gate 		    if (stbuf.st_size != actualsize) {
9247c478bd9Sstevel@tonic-gate 			(void) fclose(fp);
9257c478bd9Sstevel@tonic-gate 			unlinkdf(Dfile);
9267c478bd9Sstevel@tonic-gate 			(*Turnoff)();
9277c478bd9Sstevel@tonic-gate 			logent("RECEIVED SIZE NOT EQUAL TO ACTUAL SIZE", "FAILED");
9287c478bd9Sstevel@tonic-gate 			CDEBUG(1, "Failed: receive size %ld ", stbuf.st_size);
9297c478bd9Sstevel@tonic-gate 			CDEBUG(1, "not equal to actual size %ld\n", actualsize);
9307c478bd9Sstevel@tonic-gate 			return(FAIL);
9317c478bd9Sstevel@tonic-gate 		    }
9327c478bd9Sstevel@tonic-gate 		}
9337c478bd9Sstevel@tonic-gate 		(void) fclose(fp);
9347c478bd9Sstevel@tonic-gate 
9357c478bd9Sstevel@tonic-gate 		/* copy to user directory */
9367c478bd9Sstevel@tonic-gate 		ntfyopt = strchr(W_OPTNS, 'n') != NULL;
9377c478bd9Sstevel@tonic-gate 
9387c478bd9Sstevel@tonic-gate 		/*
9397c478bd9Sstevel@tonic-gate 		 * See if spool file and target file in the same file system
9407c478bd9Sstevel@tonic-gate 		 */
9417c478bd9Sstevel@tonic-gate 
9427c478bd9Sstevel@tonic-gate 		ret = 0;
9437c478bd9Sstevel@tonic-gate 		if (p = strrchr(Dfile, '/'))
9447c478bd9Sstevel@tonic-gate 		{
9457c478bd9Sstevel@tonic-gate 			*p = '\0';
9467c478bd9Sstevel@tonic-gate 			ret = PREFIX(Dfile, filename);
9477c478bd9Sstevel@tonic-gate 			*p = '/';
9487c478bd9Sstevel@tonic-gate 		}
9497c478bd9Sstevel@tonic-gate 
9507c478bd9Sstevel@tonic-gate 		if (noSpool() && ret)
9517c478bd9Sstevel@tonic-gate 		{
9527c478bd9Sstevel@tonic-gate 		    /*
9537c478bd9Sstevel@tonic-gate 		     * if we are not already in the right file, and
9547c478bd9Sstevel@tonic-gate 		     * it is theoretically in the same file system,
9557c478bd9Sstevel@tonic-gate 		     * link it there...
9567c478bd9Sstevel@tonic-gate 		     */
9577c478bd9Sstevel@tonic-gate 
9587c478bd9Sstevel@tonic-gate 		    if(strcmp (filename, Dfile)) {
9597c478bd9Sstevel@tonic-gate 			    unlink(filename);
9607c478bd9Sstevel@tonic-gate 			    if(link(Dfile, filename))
9617c478bd9Sstevel@tonic-gate 			    {
9627c478bd9Sstevel@tonic-gate 				logent("FAILED", "MOVE");
9637c478bd9Sstevel@tonic-gate 				scWrite();
9647c478bd9Sstevel@tonic-gate 				putinpub(filename, Dfile, BASENAME(W_USER,'!'));
9657c478bd9Sstevel@tonic-gate 			    }
9667c478bd9Sstevel@tonic-gate 			    else
9677c478bd9Sstevel@tonic-gate 	    			DEBUG(7, "linked Point file to %s\n", filename);
9687c478bd9Sstevel@tonic-gate 			    unlink(Dfile);
9697c478bd9Sstevel@tonic-gate 		    }
9707c478bd9Sstevel@tonic-gate 		    else
9717c478bd9Sstevel@tonic-gate 		    	DEBUG(7, "Point file and %s the same\n", filename);
9727c478bd9Sstevel@tonic-gate 		    status = 0;			/* all done */
9737c478bd9Sstevel@tonic-gate 		}
9747c478bd9Sstevel@tonic-gate 		else
9757c478bd9Sstevel@tonic-gate 		    status = xmv(Dfile, filename);
9767c478bd9Sstevel@tonic-gate 
9777c478bd9Sstevel@tonic-gate 		scSize(Dfile);	/* log source file size */
9787c478bd9Sstevel@tonic-gate 		WMESG(RQSTCMPT, status ? EM_RMTCP : YES);
9797c478bd9Sstevel@tonic-gate 		if (status == 0) {
9807c478bd9Sstevel@tonic-gate 			sscanf(W_MODE, "%lo", &lfilemode);
9817c478bd9Sstevel@tonic-gate 			if (lfilemode <= 0)
9827c478bd9Sstevel@tonic-gate 				filemode = PUB_FILEMODE;
9837c478bd9Sstevel@tonic-gate 			else
9847c478bd9Sstevel@tonic-gate 				filemode = (mode_t)lfilemode;
9857c478bd9Sstevel@tonic-gate 			if (PREFIX(RemSpool, filename))
9867c478bd9Sstevel@tonic-gate 			    chmod(filename, DFILEMODE);
9877c478bd9Sstevel@tonic-gate 			else
9887c478bd9Sstevel@tonic-gate 			    chmod(filename, (filemode & LEGALMODE) | PUB_FILEMODE);
9897c478bd9Sstevel@tonic-gate 			arrived(ntfyopt, filename, W_NUSER, Rmtname, User);
9907c478bd9Sstevel@tonic-gate 		} else {
9917c478bd9Sstevel@tonic-gate 			logent("FAILED",  "COPY");
9927c478bd9Sstevel@tonic-gate 			scWrite();	/* log the security violation */
9937c478bd9Sstevel@tonic-gate 			status = putinpub(filename, Dfile,
9947c478bd9Sstevel@tonic-gate 			    BASENAME(W_USER, '!'));
9957c478bd9Sstevel@tonic-gate 			DEBUG(4, "->PUBDIR %d\n", status);
9967c478bd9Sstevel@tonic-gate 			if (status == 0)
9977c478bd9Sstevel@tonic-gate 				arrived(ntfyopt, filename, W_NUSER,
9987c478bd9Sstevel@tonic-gate 				    Rmtname, User);
9997c478bd9Sstevel@tonic-gate 		}
10007c478bd9Sstevel@tonic-gate 		pfEndfile("");	/* "" indicates the file transfer completely */
10017c478bd9Sstevel@tonic-gate 		if ( W_FILE2[1] == '.'  &&
10027c478bd9Sstevel@tonic-gate 		    (W_FILE2[0] == XQTPRE || W_FILE2[0] == DATAPRE) )
10037c478bd9Sstevel@tonic-gate 			uuxqtflag = 1;
10047c478bd9Sstevel@tonic-gate 		goto top;
10057c478bd9Sstevel@tonic-gate 
10067c478bd9Sstevel@tonic-gate 	case RCVFILE:
10077c478bd9Sstevel@tonic-gate 
10087c478bd9Sstevel@tonic-gate 		/*
10097c478bd9Sstevel@tonic-gate 		 * MASTER section of RCVFULE
10107c478bd9Sstevel@tonic-gate 		 */
10117c478bd9Sstevel@tonic-gate 		DEBUG(4, "%s\n", "RCVFILE:");
10127c478bd9Sstevel@tonic-gate 		if (msg[1] == 'N') {
10137c478bd9Sstevel@tonic-gate 			i = atoi(&msg[2]);
10147c478bd9Sstevel@tonic-gate 			if (i < 0 || i > EM_MAX)
10157c478bd9Sstevel@tonic-gate 				i = 0;
10167c478bd9Sstevel@tonic-gate 			logent(Em_msg[i], "REQUEST");
10177c478bd9Sstevel@tonic-gate 		        notify(mailopt, W_USER, rqstr, Rmtname, &msg[1]);
10187c478bd9Sstevel@tonic-gate 			ASSERT(Role == MASTER, Wr_ROLE, "", Role);
10197c478bd9Sstevel@tonic-gate 			(void) fclose(fp);
10207c478bd9Sstevel@tonic-gate 			unlinkdf(Dfile);
10217c478bd9Sstevel@tonic-gate 		    	scWrite();	/* something is wrong on other side,
10227c478bd9Sstevel@tonic-gate 					   log the security violation */
10237c478bd9Sstevel@tonic-gate 			goto top;
10247c478bd9Sstevel@tonic-gate 		}
10257c478bd9Sstevel@tonic-gate 
10267c478bd9Sstevel@tonic-gate 		if (msg[1] == 'Y') {
10277c478bd9Sstevel@tonic-gate 
10287c478bd9Sstevel@tonic-gate 		/* MASTER gets the original filesize from sender (SLAVE) */
10297c478bd9Sstevel@tonic-gate 		/* This will be used to check the length of the P. file */
10307c478bd9Sstevel@tonic-gate 			if (Restart) {
10317c478bd9Sstevel@tonic-gate 			    *fsize = '\0';
10327c478bd9Sstevel@tonic-gate 			    sscanf(&msg[2], "%*o %s", fsize);
10337c478bd9Sstevel@tonic-gate 			    if (*fsize != '\0') {
10347c478bd9Sstevel@tonic-gate 				actualsize = strtol(fsize, (char **) 0, FLENRADIX);
10357c478bd9Sstevel@tonic-gate 				CDEBUG(7, "Actual File Length %ld\n", actualsize);
10367c478bd9Sstevel@tonic-gate 			    } else {
10377c478bd9Sstevel@tonic-gate 				actualsize = -1;
10387c478bd9Sstevel@tonic-gate 				CDEBUG(7, "Actual File Length Not Provided\n%s", "");
10397c478bd9Sstevel@tonic-gate 			    }
10407c478bd9Sstevel@tonic-gate 			}
10417c478bd9Sstevel@tonic-gate 
10427c478bd9Sstevel@tonic-gate 			/*
10437c478bd9Sstevel@tonic-gate 			 * receive file
10447c478bd9Sstevel@tonic-gate 			 */
10457c478bd9Sstevel@tonic-gate 			ASSERT(Role == MASTER, Wr_ROLE, "", Role);
10467c478bd9Sstevel@tonic-gate 			(void) millitick();	/* start msec timer */
10477c478bd9Sstevel@tonic-gate 			pfStrtXfer(MCHAR, SNDFILE);
10487c478bd9Sstevel@tonic-gate 			scStime();
10497c478bd9Sstevel@tonic-gate 		/* (ret != 0) implies the trammission error occurred.
10507c478bd9Sstevel@tonic-gate      	           If checkpoint protocol is available then the next
10517c478bd9Sstevel@tonic-gate 		   recieve will restart from the breakpoint of the file,
10527c478bd9Sstevel@tonic-gate 		   otherwise from the beginning of the file  */
10537c478bd9Sstevel@tonic-gate 
10547c478bd9Sstevel@tonic-gate 			ret = (*Rddata)(Ifn, fp);
10557c478bd9Sstevel@tonic-gate 
10567c478bd9Sstevel@tonic-gate 		/* the second millitick() returns the duration between
10577c478bd9Sstevel@tonic-gate 		   the first and second call.
10587c478bd9Sstevel@tonic-gate    		   writes "PARTIAL FILE to the transfer log indicating
10597c478bd9Sstevel@tonic-gate 		   a transmission error. */
10607c478bd9Sstevel@tonic-gate 
10617c478bd9Sstevel@tonic-gate 			statlog( "<-", getfilesize(), millitick(),
10627c478bd9Sstevel@tonic-gate 				(ret) ? "PARTIAL FILE" : ""  );
10637c478bd9Sstevel@tonic-gate 			pfEndXfer();
10647c478bd9Sstevel@tonic-gate 			scEtime();
10657c478bd9Sstevel@tonic-gate 			if (ret != 0) {
10667c478bd9Sstevel@tonic-gate 				pfEndfile("PARTIAL FILE");
10677c478bd9Sstevel@tonic-gate 				(void) fclose(fp);
10687c478bd9Sstevel@tonic-gate 				if ( ret == EFBIG ) {
10697c478bd9Sstevel@tonic-gate 					WMESG(RQSTCMPT, EM_ULIMIT);
10707c478bd9Sstevel@tonic-gate 					logent("FILE EXCEEDS ULIMIT","FAILED");
10717c478bd9Sstevel@tonic-gate 					CDEBUG(1, "Failed: file size exceeds ulimit%s\n", "");
10727c478bd9Sstevel@tonic-gate 					goto top;
10737c478bd9Sstevel@tonic-gate 				}
10747c478bd9Sstevel@tonic-gate 				(*Turnoff)();
10757c478bd9Sstevel@tonic-gate 				logent("INPUT FAILURE", "IN RECEIVE/MASTER MODE");
10767c478bd9Sstevel@tonic-gate 				return(FAIL);
10777c478bd9Sstevel@tonic-gate 			}
10787c478bd9Sstevel@tonic-gate 			if (Restart && (actualsize != -1)) {
10797c478bd9Sstevel@tonic-gate 			    if (fstat(fileno(fp), &stbuf)) {
10807c478bd9Sstevel@tonic-gate 				(void) fclose(fp);
10817c478bd9Sstevel@tonic-gate 				unlinkdf(Dfile);
10827c478bd9Sstevel@tonic-gate 				(*Turnoff)();
10837c478bd9Sstevel@tonic-gate 				logent("CAN'T STAT PFILE", "FAILED");
10847c478bd9Sstevel@tonic-gate 				return(FAIL);
10857c478bd9Sstevel@tonic-gate 			    }
10867c478bd9Sstevel@tonic-gate 			    if (stbuf.st_size != actualsize) {
10877c478bd9Sstevel@tonic-gate 				(void) fclose(fp);
10887c478bd9Sstevel@tonic-gate 				unlinkdf(Dfile);
10897c478bd9Sstevel@tonic-gate 				(*Turnoff)();
10907c478bd9Sstevel@tonic-gate 				logent("RECEIVED SIZE NOT EQUAL TO ACTUAL SIZE", "FAILED");
10917c478bd9Sstevel@tonic-gate 				CDEBUG(1, "Failed: receive size %ld ", stbuf.st_size);
10927c478bd9Sstevel@tonic-gate 				CDEBUG(1, "not equal to actual size %ld\n", actualsize);
10937c478bd9Sstevel@tonic-gate 				return(FAIL);
10947c478bd9Sstevel@tonic-gate 			    }
10957c478bd9Sstevel@tonic-gate 			}
10967c478bd9Sstevel@tonic-gate 			(void) fclose(fp);
10977c478bd9Sstevel@tonic-gate 
10987c478bd9Sstevel@tonic-gate 			/*
10997c478bd9Sstevel@tonic-gate 			 * See if spool file and target file in the same file system
11007c478bd9Sstevel@tonic-gate 			 */
11017c478bd9Sstevel@tonic-gate 
11027c478bd9Sstevel@tonic-gate 			ret = 0;
11037c478bd9Sstevel@tonic-gate 			if (p = strrchr(Dfile, '/'))
11047c478bd9Sstevel@tonic-gate 			{
11057c478bd9Sstevel@tonic-gate 				*p = '\0';
11067c478bd9Sstevel@tonic-gate 				ret = PREFIX(Dfile, filename);
11077c478bd9Sstevel@tonic-gate 				*p = '/';
11087c478bd9Sstevel@tonic-gate 			}
11097c478bd9Sstevel@tonic-gate 
11107c478bd9Sstevel@tonic-gate 			if (noSpool() && ret)
11117c478bd9Sstevel@tonic-gate 			{
11127c478bd9Sstevel@tonic-gate 			    /*
11137c478bd9Sstevel@tonic-gate 			     * if we are not already in the right file, and
11147c478bd9Sstevel@tonic-gate 			     * it is theoretically in the same file system,
11157c478bd9Sstevel@tonic-gate 			     * link it there...
11167c478bd9Sstevel@tonic-gate 			     */
11177c478bd9Sstevel@tonic-gate 
11187c478bd9Sstevel@tonic-gate 			    if(strcmp (filename, Dfile)) {
11197c478bd9Sstevel@tonic-gate 				    unlink(filename);
11207c478bd9Sstevel@tonic-gate 				    if(link(Dfile, filename))
11217c478bd9Sstevel@tonic-gate 				    {
11227c478bd9Sstevel@tonic-gate 					logent("FAILED", "MOVE");
11237c478bd9Sstevel@tonic-gate 					scWrite();
11247c478bd9Sstevel@tonic-gate 					putinpub(filename, Dfile, W_USER);
11257c478bd9Sstevel@tonic-gate 				    }
11267c478bd9Sstevel@tonic-gate 				    else
11277c478bd9Sstevel@tonic-gate 					DEBUG(7, "linked Point file to %s\n", filename);
11287c478bd9Sstevel@tonic-gate 				    unlink(Dfile);
11297c478bd9Sstevel@tonic-gate 			    }
11307c478bd9Sstevel@tonic-gate 			    else
11317c478bd9Sstevel@tonic-gate 				DEBUG(7, "Point file and %s the same\n", filename);
11327c478bd9Sstevel@tonic-gate 			    status = 0;			/* all done */
11337c478bd9Sstevel@tonic-gate 			}
11347c478bd9Sstevel@tonic-gate 			else
11357c478bd9Sstevel@tonic-gate 			    status = xmv(Dfile, filename);
11367c478bd9Sstevel@tonic-gate 
11377c478bd9Sstevel@tonic-gate 			WMESG(RQSTCMPT, status ? EM_RMTCP : YES);
11387c478bd9Sstevel@tonic-gate 			notify(mailopt, W_USER, rqstr, Rmtname,
11397c478bd9Sstevel@tonic-gate 			    status ? EM_LOCCP : YES);
11407c478bd9Sstevel@tonic-gate 			if (status == 0) {
11417c478bd9Sstevel@tonic-gate 			    sscanf(&msg[2], "%lo", &lfilemode);
11427c478bd9Sstevel@tonic-gate 			    if (lfilemode <= 0)
11437c478bd9Sstevel@tonic-gate 				filemode = PUB_FILEMODE;
11447c478bd9Sstevel@tonic-gate 			    else
11457c478bd9Sstevel@tonic-gate 				filemode = (mode_t)lfilemode;
11467c478bd9Sstevel@tonic-gate 			    if (PREFIX(RemSpool, filename))
11477c478bd9Sstevel@tonic-gate 				chmod(filename, DFILEMODE);
11487c478bd9Sstevel@tonic-gate 			    else
11497c478bd9Sstevel@tonic-gate 				chmod(filename, (filemode & LEGALMODE) | PUB_FILEMODE);
11507c478bd9Sstevel@tonic-gate 			} else {
11517c478bd9Sstevel@tonic-gate 			    logent("FAILED", "COPY");
11527c478bd9Sstevel@tonic-gate 		    	    scWrite();	/* log the security violation */
11537c478bd9Sstevel@tonic-gate 			    putinpub(filename, Dfile, W_USER);
11547c478bd9Sstevel@tonic-gate 			}
11557c478bd9Sstevel@tonic-gate 			pfEndfile("");	/* "" indicates the file transfer completely */
11567c478bd9Sstevel@tonic-gate 		if ( W_FILE2[1] == '.'  &&
11577c478bd9Sstevel@tonic-gate 		    (W_FILE2[0] == XQTPRE || W_FILE2[0] == DATAPRE) )
11587c478bd9Sstevel@tonic-gate 			uuxqtflag = 1;
11597c478bd9Sstevel@tonic-gate 			goto top;
11607c478bd9Sstevel@tonic-gate 		}
11617c478bd9Sstevel@tonic-gate 
11627c478bd9Sstevel@tonic-gate 		/*
11637c478bd9Sstevel@tonic-gate 		 * SLAVE section of RCVFILE
11647c478bd9Sstevel@tonic-gate 		 * (request to send file)
11657c478bd9Sstevel@tonic-gate 		 */
11667c478bd9Sstevel@tonic-gate 		ASSERT(Role == SLAVE, Wr_ROLE, "", Role);
11677c478bd9Sstevel@tonic-gate 
11687c478bd9Sstevel@tonic-gate 		/* check permissions */
11697c478bd9Sstevel@tonic-gate 		i = getargs(msg, wrkvec, W_MAX);
11707c478bd9Sstevel@tonic-gate 
11717c478bd9Sstevel@tonic-gate 		scRequser(W_USER); /* log requestor user id */
11727c478bd9Sstevel@tonic-gate 
11737c478bd9Sstevel@tonic-gate 		/* log destination node, user and file name */
11747c478bd9Sstevel@tonic-gate 
11757c478bd9Sstevel@tonic-gate 		scDest(Rmtname,NOTAVAIL,W_FILE2);
11767c478bd9Sstevel@tonic-gate 
11777c478bd9Sstevel@tonic-gate 		/* log source node, file owner, file name, mod time and size */
11787c478bd9Sstevel@tonic-gate 
11797c478bd9Sstevel@tonic-gate 		scSrc(Myname,scOwn(W_FILE1),W_FILE1,scMtime(W_FILE1),scSize(W_FILE1));
11807c478bd9Sstevel@tonic-gate 		/* Check for bad request */
11817c478bd9Sstevel@tonic-gate 		if (i < 5) {
11827c478bd9Sstevel@tonic-gate 			WMESG(RCVFILE, EM_BADUUCP); /* you(remote master) gave me
11837c478bd9Sstevel@tonic-gate 							bad work file */
11847c478bd9Sstevel@tonic-gate 			logent("DENIED", "TOO FEW ARGS IN SLAVE RCVFILE");
11857c478bd9Sstevel@tonic-gate 			goto top;
11867c478bd9Sstevel@tonic-gate 		}
11877c478bd9Sstevel@tonic-gate 
11887c478bd9Sstevel@tonic-gate 		(void) sprintf(rqstr, "%s!%s --> %s!%s (%s)", Myname,
11897c478bd9Sstevel@tonic-gate 			    W_FILE1, Rmtname, W_FILE2, W_USER);
11907c478bd9Sstevel@tonic-gate 		logent(rqstr, "REMOTE REQUESTED");
11917c478bd9Sstevel@tonic-gate 		CDEBUG(1, "Remote Requested: %s\n", rqstr);
11927c478bd9Sstevel@tonic-gate 		mf = W_RFILE;
11937c478bd9Sstevel@tonic-gate 		DEBUG(4, "msg - %s\n", msg);
11947c478bd9Sstevel@tonic-gate 		DEBUG(4, "W_FILE1 - %s\n", W_FILE1);
11957c478bd9Sstevel@tonic-gate 		(void) strcpy(filename, W_FILE1);
11967c478bd9Sstevel@tonic-gate 		expfile(filename);
11977c478bd9Sstevel@tonic-gate 		if (DIRECTORY(filename)) {
11987c478bd9Sstevel@tonic-gate 			(void) strcat(filename, "/");
11997c478bd9Sstevel@tonic-gate 			(void) strcat(filename, BASENAME(W_FILE2, '/'));
12007c478bd9Sstevel@tonic-gate 		}
12017c478bd9Sstevel@tonic-gate 		(void) sprintf(User, "%s", W_USER);
12027c478bd9Sstevel@tonic-gate 
12037c478bd9Sstevel@tonic-gate 		if (requestOK() == FALSE) {
12047c478bd9Sstevel@tonic-gate 			/* remote can't request data from my system */
12057c478bd9Sstevel@tonic-gate 			WMESG(RCVFILE, EM_RMTACC);
12067c478bd9Sstevel@tonic-gate 			logent("DENIED", "REQUESTING");
12077c478bd9Sstevel@tonic-gate 			CDEBUG(1, "Failed: Access Denied\n%s", "");
12087c478bd9Sstevel@tonic-gate 		    	scWrite();	/* log the security violation */
12097c478bd9Sstevel@tonic-gate 			goto top;
12107c478bd9Sstevel@tonic-gate 		}
12117c478bd9Sstevel@tonic-gate 		DEBUG(4, "requestOK for Loginuser - %s\n", Loginuser);
12127c478bd9Sstevel@tonic-gate 
12137c478bd9Sstevel@tonic-gate 		if ((fp = fopen(filename, "r")) == NULL) {
12147c478bd9Sstevel@tonic-gate 			WMESG(RCVFILE, EM_RMTACC); /* you(remote master) can't
12157c478bd9Sstevel@tonic-gate 							read my file */
12167c478bd9Sstevel@tonic-gate 			logent("CAN'T OPEN", "DENIED");
12177c478bd9Sstevel@tonic-gate 			CDEBUG(1, "Failed: Can't Open %s\n", filename);
12187c478bd9Sstevel@tonic-gate 		    	scWrite();	/* log the security violation */
12197c478bd9Sstevel@tonic-gate 			goto top;
12207c478bd9Sstevel@tonic-gate 		}
12217c478bd9Sstevel@tonic-gate 
12227c478bd9Sstevel@tonic-gate 		if (chkpth(filename, CK_READ) || !F_READANY(fileno(fp))) {
12237c478bd9Sstevel@tonic-gate 			WMESG(RCVFILE, EM_RMTACC); /* you(remote master) can't
12247c478bd9Sstevel@tonic-gate 							retrive my file */
12257c478bd9Sstevel@tonic-gate 			logent("DENIED", "PERMISSION");
12267c478bd9Sstevel@tonic-gate 			CDEBUG(1, "Failed: Access Denied\n%s", "");
12277c478bd9Sstevel@tonic-gate 		    	scWrite();	/* log the security violation */
12287c478bd9Sstevel@tonic-gate 			fclose(fp);
12297c478bd9Sstevel@tonic-gate 			goto top;
12307c478bd9Sstevel@tonic-gate 		}
12317c478bd9Sstevel@tonic-gate 		DEBUG(4, "chkpth ok Loginuser - %s\n", Loginuser);
12327c478bd9Sstevel@tonic-gate 
12337c478bd9Sstevel@tonic-gate 		ASSERT(fstat(fileno(fp), &stbuf) == 0, Ct_STAT,
12347c478bd9Sstevel@tonic-gate 		    filename, errno);
12357c478bd9Sstevel@tonic-gate 
12367c478bd9Sstevel@tonic-gate 		/* Check whether remote's ulimit is exceeded */
12377c478bd9Sstevel@tonic-gate 		if (SizeCheck) {
12387c478bd9Sstevel@tonic-gate 			if (((stbuf.st_size-1)/512 + 1) > RemUlimit) {
12397c478bd9Sstevel@tonic-gate 				/* remote ulimit exceeded */
12407c478bd9Sstevel@tonic-gate 				WMESG(RCVFILE, EM_ULIMIT);
12417c478bd9Sstevel@tonic-gate 				logent("DENIED", "REMOTE ULIMIT EXCEEDED");
12427c478bd9Sstevel@tonic-gate 				CDEBUG(1, "Denied: remote ulimit exceeded %s\n", filename);
12437c478bd9Sstevel@tonic-gate 				scWrite();
12447c478bd9Sstevel@tonic-gate 				(void) fclose(fp);
12457c478bd9Sstevel@tonic-gate 				goto top;
12467c478bd9Sstevel@tonic-gate 			}
12477c478bd9Sstevel@tonic-gate 		}
12487c478bd9Sstevel@tonic-gate 
12497c478bd9Sstevel@tonic-gate 		/*
12507c478bd9Sstevel@tonic-gate 		 * ok to send file
12517c478bd9Sstevel@tonic-gate 		 */
12527c478bd9Sstevel@tonic-gate 
12537c478bd9Sstevel@tonic-gate 		if (Restart && i >= 10) {
12547c478bd9Sstevel@tonic-gate 		    if (startp = strtol(W_POINT, (char **) 0, FLENRADIX)) {
12557c478bd9Sstevel@tonic-gate 			CDEBUG(1,"Restart point=0x%lx\n", startp);
12567c478bd9Sstevel@tonic-gate 			errno = 0;
12577c478bd9Sstevel@tonic-gate 			if (lseek(fileno(fp), startp, 0) == -1) {
12587c478bd9Sstevel@tonic-gate 			    WMESG(RCVFILE, EM_SEEK);
1259*ace1a5f1Sdp 			    logent(strerror(errno), "FSEEK ERROR");
12607c478bd9Sstevel@tonic-gate 			    (void) fclose(fp);
12617c478bd9Sstevel@tonic-gate 			    goto top;
12627c478bd9Sstevel@tonic-gate 			}
12637c478bd9Sstevel@tonic-gate 			fp->_cnt = 0;
12647c478bd9Sstevel@tonic-gate 			fp->_ptr = fp->_base;
12657c478bd9Sstevel@tonic-gate 			if(startp < 0)
12667c478bd9Sstevel@tonic-gate 			    sprintf(tbuf,"start=0x%lx", startp);
12677c478bd9Sstevel@tonic-gate 			else
12687c478bd9Sstevel@tonic-gate 			    sprintf(tbuf,"start=%ld", startp);
12697c478bd9Sstevel@tonic-gate 			p = tbuf + strlen(tbuf);
12707c478bd9Sstevel@tonic-gate 			if (stbuf.st_size < 0)
12717c478bd9Sstevel@tonic-gate 			    sprintf(p,", length=0x%lx", stbuf.st_size);
12727c478bd9Sstevel@tonic-gate 			else
12737c478bd9Sstevel@tonic-gate 			    sprintf(p,", length=%ld", stbuf.st_size);
12747c478bd9Sstevel@tonic-gate 
12757c478bd9Sstevel@tonic-gate 			logent(tbuf, "RESTART");
12767c478bd9Sstevel@tonic-gate 		   }
12777c478bd9Sstevel@tonic-gate 		}
12787c478bd9Sstevel@tonic-gate 
12797c478bd9Sstevel@tonic-gate 		if (Restart)
12807c478bd9Sstevel@tonic-gate 			(void) sprintf(msg, "%s %lo 0x%lx", YES,
12817c478bd9Sstevel@tonic-gate 				(long) (stbuf.st_mode & LEGALMODE),
12827c478bd9Sstevel@tonic-gate 				(long) stbuf.st_size);
12837c478bd9Sstevel@tonic-gate 		else
12847c478bd9Sstevel@tonic-gate 			(void) sprintf(msg, "%s %lo", YES,
12857c478bd9Sstevel@tonic-gate 				(long) (stbuf.st_mode & LEGALMODE));
12867c478bd9Sstevel@tonic-gate 		WMESG(RCVFILE, msg); /* I(slave) send you my file now */
12877c478bd9Sstevel@tonic-gate 		Seqn++;
12887c478bd9Sstevel@tonic-gate 		(void) millitick();	/* start msec timer */
12897c478bd9Sstevel@tonic-gate 		scStime();
12907c478bd9Sstevel@tonic-gate 		pfStrtXfer(SCHAR, SNDFILE);
12917c478bd9Sstevel@tonic-gate 		/* (ret != 0) implies the trammission error occurred.
12927c478bd9Sstevel@tonic-gate      	           If checkpoint protocol is available then the next
12937c478bd9Sstevel@tonic-gate 		   transfer will restart from the breakpoint of the file,
12947c478bd9Sstevel@tonic-gate 		   otherwise from the beginning of the file  */
12957c478bd9Sstevel@tonic-gate 
12967c478bd9Sstevel@tonic-gate 		ret = (*Wrdata)(fp, Ofn);
12977c478bd9Sstevel@tonic-gate 
12987c478bd9Sstevel@tonic-gate 		/* the second millitick() returns the duration between
12997c478bd9Sstevel@tonic-gate 		   the first and second call.
13007c478bd9Sstevel@tonic-gate    		   writes "PARTIAL FILE to the transfer log indicating
13017c478bd9Sstevel@tonic-gate 		   a transmission error. */
13027c478bd9Sstevel@tonic-gate 
13037c478bd9Sstevel@tonic-gate 		statlog( "->", getfilesize(), millitick(),
13047c478bd9Sstevel@tonic-gate 					(ret) ? "PARTIAL FILE" : ""  );
13057c478bd9Sstevel@tonic-gate 		pfEndXfer();
13067c478bd9Sstevel@tonic-gate 		scEtime();
13077c478bd9Sstevel@tonic-gate 
13087c478bd9Sstevel@tonic-gate 		(void) fclose(fp);
13097c478bd9Sstevel@tonic-gate 		if (ret != 0) {
13107c478bd9Sstevel@tonic-gate 			pfEndfile("PARTIAL FILE");
13117c478bd9Sstevel@tonic-gate 			(*Turnoff)();
13127c478bd9Sstevel@tonic-gate 			return(FAIL);
13137c478bd9Sstevel@tonic-gate 		}
13147c478bd9Sstevel@tonic-gate 
13157c478bd9Sstevel@tonic-gate 		/* loop depending on the size of the file */
13167c478bd9Sstevel@tonic-gate 		/* give an extra try for each megabyte */
13177c478bd9Sstevel@tonic-gate 		/* stbuf set in fstat several lines back  */
13187c478bd9Sstevel@tonic-gate 		for (im = stbuf.st_size >> 10; im >= 0; --im) {
13197c478bd9Sstevel@tonic-gate 		    if ((ret = rmesg(RQSTCMPT, msg)) == 0)
13207c478bd9Sstevel@tonic-gate 			break;	/* got message */
13217c478bd9Sstevel@tonic-gate 		}
13227c478bd9Sstevel@tonic-gate 		if (ret != 0) {
13237c478bd9Sstevel@tonic-gate 		    (*Turnoff)();
13247c478bd9Sstevel@tonic-gate 		     return(FAIL);
13257c478bd9Sstevel@tonic-gate 		}
13267c478bd9Sstevel@tonic-gate 		goto process;
13277c478bd9Sstevel@tonic-gate 	}
13287c478bd9Sstevel@tonic-gate 	(*Turnoff)();
13297c478bd9Sstevel@tonic-gate 	return(FAIL);
13307c478bd9Sstevel@tonic-gate }
13317c478bd9Sstevel@tonic-gate 
13327c478bd9Sstevel@tonic-gate 
13337c478bd9Sstevel@tonic-gate 
13347c478bd9Sstevel@tonic-gate /*
13357c478bd9Sstevel@tonic-gate  * read message
13367c478bd9Sstevel@tonic-gate  * returns:
13377c478bd9Sstevel@tonic-gate  *	0	-> success
13387c478bd9Sstevel@tonic-gate  *	FAIL	-> failure
13397c478bd9Sstevel@tonic-gate  */
13407c478bd9Sstevel@tonic-gate int
13417c478bd9Sstevel@tonic-gate rmesg(c, msg)
13427c478bd9Sstevel@tonic-gate char *msg, c;
13437c478bd9Sstevel@tonic-gate {
13447c478bd9Sstevel@tonic-gate 	char str[50];
13457c478bd9Sstevel@tonic-gate 
13467c478bd9Sstevel@tonic-gate 	DEBUG(4, "rmesg - '%c' ", c);
13477c478bd9Sstevel@tonic-gate 	if ((*Rdmsg)(msg, Ifn) != 0) {
13487c478bd9Sstevel@tonic-gate 		DEBUG(4, "got %s\n", "FAIL");
13497c478bd9Sstevel@tonic-gate 		(void) sprintf(str, "expected '%c' got FAIL", c);
13507c478bd9Sstevel@tonic-gate 		logent(str, "BAD READ");
13517c478bd9Sstevel@tonic-gate 		return(FAIL);
13527c478bd9Sstevel@tonic-gate 	}
13537c478bd9Sstevel@tonic-gate 	if (c != '\0' && msg[0] != c) {
13547c478bd9Sstevel@tonic-gate 		DEBUG(4, "got %s\n", msg);
13557c478bd9Sstevel@tonic-gate 		(void) sprintf(str, "expected '%c' got %s", c, msg);
13567c478bd9Sstevel@tonic-gate 		logent(str, "BAD READ");
13577c478bd9Sstevel@tonic-gate 		return(FAIL);
13587c478bd9Sstevel@tonic-gate 	}
13597c478bd9Sstevel@tonic-gate 	DEBUG(4, "got %s\n", msg);
13607c478bd9Sstevel@tonic-gate 	return(0);
13617c478bd9Sstevel@tonic-gate }
13627c478bd9Sstevel@tonic-gate 
13637c478bd9Sstevel@tonic-gate 
13647c478bd9Sstevel@tonic-gate /*
13657c478bd9Sstevel@tonic-gate  * write a message
13667c478bd9Sstevel@tonic-gate  * returns:
13677c478bd9Sstevel@tonic-gate  *	0	-> ok
13687c478bd9Sstevel@tonic-gate  *	FAIL	-> ng
13697c478bd9Sstevel@tonic-gate  */
13707c478bd9Sstevel@tonic-gate int
13717c478bd9Sstevel@tonic-gate wmesg(m, s)
13727c478bd9Sstevel@tonic-gate char *s, m;
13737c478bd9Sstevel@tonic-gate {
13747c478bd9Sstevel@tonic-gate 	CDEBUG(4, "wmesg '%c'", m);
13757c478bd9Sstevel@tonic-gate 	CDEBUG(4, "%s\n", s);
13767c478bd9Sstevel@tonic-gate 	return((*Wrmsg)(m, s, Ofn));
13777c478bd9Sstevel@tonic-gate }
13787c478bd9Sstevel@tonic-gate 
13797c478bd9Sstevel@tonic-gate 
13807c478bd9Sstevel@tonic-gate /*
13817c478bd9Sstevel@tonic-gate  * mail results of command
13827c478bd9Sstevel@tonic-gate  * return:
13837c478bd9Sstevel@tonic-gate  *	none
13847c478bd9Sstevel@tonic-gate  */
13857c478bd9Sstevel@tonic-gate void
13867c478bd9Sstevel@tonic-gate notify(mailopt, user, msgin, sys, msgcode)
13877c478bd9Sstevel@tonic-gate char *user, *msgin, *sys;
13887c478bd9Sstevel@tonic-gate register char *msgcode;
13897c478bd9Sstevel@tonic-gate {
13907c478bd9Sstevel@tonic-gate 	register int i;
13917c478bd9Sstevel@tonic-gate 	char str[BUFSIZ];
13927c478bd9Sstevel@tonic-gate 	register char *msg;
13937c478bd9Sstevel@tonic-gate 
13947c478bd9Sstevel@tonic-gate 	DEBUG(4,"mailopt %d, ", mailopt);
13957c478bd9Sstevel@tonic-gate 	DEBUG(4,"statfopt %d\n", statfopt);
13967c478bd9Sstevel@tonic-gate 	if (statfopt == 0 && mailopt == 0 && *msgcode == 'Y')
13977c478bd9Sstevel@tonic-gate 		return;
13987c478bd9Sstevel@tonic-gate 	if (*msgcode == 'Y')
13997c478bd9Sstevel@tonic-gate 		msg = "copy succeeded";
14007c478bd9Sstevel@tonic-gate 	else {
14017c478bd9Sstevel@tonic-gate 		i = atoi(msgcode + 1);
14027c478bd9Sstevel@tonic-gate 		if (i < 1 || i > EM_MAX)
14037c478bd9Sstevel@tonic-gate 			i = 0;
14047c478bd9Sstevel@tonic-gate 		msg = Em_msg[i];
14057c478bd9Sstevel@tonic-gate 	}
14067c478bd9Sstevel@tonic-gate 	if(statfopt){
14077c478bd9Sstevel@tonic-gate 		stmesg(msgin, msg);
14087c478bd9Sstevel@tonic-gate 		return;
14097c478bd9Sstevel@tonic-gate 	}
14107c478bd9Sstevel@tonic-gate 	(void) sprintf(str, "REQUEST: %s\n(SYSTEM: %s)  %s\n",
14117c478bd9Sstevel@tonic-gate 		msgin, sys, msg);
14127c478bd9Sstevel@tonic-gate 	mailst(user, msg, str, "", "");
14137c478bd9Sstevel@tonic-gate 	return;
14147c478bd9Sstevel@tonic-gate }
14157c478bd9Sstevel@tonic-gate 
14167c478bd9Sstevel@tonic-gate /*
14177c478bd9Sstevel@tonic-gate  * local notify
14187c478bd9Sstevel@tonic-gate  * return:
14197c478bd9Sstevel@tonic-gate  *	none
14207c478bd9Sstevel@tonic-gate  */
14217c478bd9Sstevel@tonic-gate void
14227c478bd9Sstevel@tonic-gate lnotify(user, msgin, mesg)
14237c478bd9Sstevel@tonic-gate char *user, *msgin, *mesg;
14247c478bd9Sstevel@tonic-gate {
14257c478bd9Sstevel@tonic-gate 	char mbuf[BUFSIZ];
14267c478bd9Sstevel@tonic-gate 
14277c478bd9Sstevel@tonic-gate 	if(statfopt){
14287c478bd9Sstevel@tonic-gate 		stmesg(msgin, mesg);
14297c478bd9Sstevel@tonic-gate 		return;
14307c478bd9Sstevel@tonic-gate 	}
14317c478bd9Sstevel@tonic-gate 	(void) sprintf(mbuf, "REQUEST: %s\n(SYSTEM: %s)  %s\n",
14327c478bd9Sstevel@tonic-gate 		msgin, Myname, mesg);
14337c478bd9Sstevel@tonic-gate 	mailst(user, mesg, mbuf, "", "");
14347c478bd9Sstevel@tonic-gate 	return;
14357c478bd9Sstevel@tonic-gate }
14367c478bd9Sstevel@tonic-gate 
14377c478bd9Sstevel@tonic-gate /*ARGSUSED*/
14387c478bd9Sstevel@tonic-gate static void
14397c478bd9Sstevel@tonic-gate stmesg(f, m)
14407c478bd9Sstevel@tonic-gate char	*f, *m;
14417c478bd9Sstevel@tonic-gate {
14427c478bd9Sstevel@tonic-gate #ifdef notdef
14437c478bd9Sstevel@tonic-gate 	FILE	*Cf;
14447c478bd9Sstevel@tonic-gate 	time_t	clock;
14457c478bd9Sstevel@tonic-gate 	long	td, th, tm, ts;
14467c478bd9Sstevel@tonic-gate #endif
14477c478bd9Sstevel@tonic-gate 	char msg[BUFSIZ];
14487c478bd9Sstevel@tonic-gate 
14497c478bd9Sstevel@tonic-gate 	DEBUG(4,"STMES %s\n",mf);
14507c478bd9Sstevel@tonic-gate 	sprintf(msg, "STMESG - %s", mf);
14517c478bd9Sstevel@tonic-gate 	logent("DENIED", msg);
14527c478bd9Sstevel@tonic-gate #ifdef notdef
14537c478bd9Sstevel@tonic-gate 	/*
14547c478bd9Sstevel@tonic-gate 	 * This code is a giant security hole.
14557c478bd9Sstevel@tonic-gate 	 * No checking is done on what file is
14567c478bd9Sstevel@tonic-gate 	 * written and chmod'ed.  For now we
14577c478bd9Sstevel@tonic-gate 	 * just ifdef this out.
14587c478bd9Sstevel@tonic-gate 	 */
14597c478bd9Sstevel@tonic-gate 	if((Cf = fopen(mf, "a+")) == NULL){
14607c478bd9Sstevel@tonic-gate 		chmod(mf, PUB_FILEMODE);
14617c478bd9Sstevel@tonic-gate 		return;
14627c478bd9Sstevel@tonic-gate 	}
14637c478bd9Sstevel@tonic-gate 	(void) time(&clock);
14647c478bd9Sstevel@tonic-gate 	(void) fprintf(Cf, "uucp job: %s (%s) ", Jobid, timeStamp());
14657c478bd9Sstevel@tonic-gate 	td = clock - Nstat.t_qtime;
14667c478bd9Sstevel@tonic-gate 	ts = td%60;
14677c478bd9Sstevel@tonic-gate 	td /= 60;
14687c478bd9Sstevel@tonic-gate 	tm = td%60;
14697c478bd9Sstevel@tonic-gate 	td /= 60;
14707c478bd9Sstevel@tonic-gate 	th = td;
14717c478bd9Sstevel@tonic-gate 	(void) fprintf(Cf, "(%ld:%ld:%ld)\n%s\n%s\n\n", th, tm, ts, f, m);
14727c478bd9Sstevel@tonic-gate 	(void) fclose(Cf);
14737c478bd9Sstevel@tonic-gate 	chmod(mf, PUB_FILEMODE);
14747c478bd9Sstevel@tonic-gate #endif
14757c478bd9Sstevel@tonic-gate }
14767c478bd9Sstevel@tonic-gate 
14777c478bd9Sstevel@tonic-gate /*
14787c478bd9Sstevel@tonic-gate  * converse with the remote machine, agree upon a
14797c478bd9Sstevel@tonic-gate  * protocol (if possible) and start the protocol.
14807c478bd9Sstevel@tonic-gate  * return:
14817c478bd9Sstevel@tonic-gate  *	SUCCESS	-> successful protocol selection
14827c478bd9Sstevel@tonic-gate  *	FAIL	-> can't find common or open failed
14837c478bd9Sstevel@tonic-gate  */
14847c478bd9Sstevel@tonic-gate startup()
14857c478bd9Sstevel@tonic-gate {
14867c478bd9Sstevel@tonic-gate 	extern (*Rdmsg)(), (*Wrmsg)();
14877c478bd9Sstevel@tonic-gate 	extern imsg(), omsg();
14887c478bd9Sstevel@tonic-gate 	extern void blptcl();
14897c478bd9Sstevel@tonic-gate 	extern int fptcl();
14907c478bd9Sstevel@tonic-gate 	char msg[BUFSIZ], str[BUFSIZ];
14917c478bd9Sstevel@tonic-gate 
14927c478bd9Sstevel@tonic-gate 	Rdmsg = imsg;
14937c478bd9Sstevel@tonic-gate 	Wrmsg = omsg;
14947c478bd9Sstevel@tonic-gate 	Turnoff = turnoff;
14957c478bd9Sstevel@tonic-gate 	blptcl(str);
14967c478bd9Sstevel@tonic-gate 	if (Role == MASTER) {
14977c478bd9Sstevel@tonic-gate 		RMESG(SLTPTCL, msg);
14987c478bd9Sstevel@tonic-gate 		if ( fptcl(&msg[1], str) == FAIL) {
14997c478bd9Sstevel@tonic-gate 		    /* no protocol match */
15007c478bd9Sstevel@tonic-gate 		    WMESG(USEPTCL, NO);
15017c478bd9Sstevel@tonic-gate 		    return(FAIL);
15027c478bd9Sstevel@tonic-gate 		} else {
15037c478bd9Sstevel@tonic-gate 		    /* got protocol match */
15047c478bd9Sstevel@tonic-gate 		    WMESG(USEPTCL, &msg[1]);
15057c478bd9Sstevel@tonic-gate 		    return(stptcl(&msg[1]));
15067c478bd9Sstevel@tonic-gate 		}
15077c478bd9Sstevel@tonic-gate 	} else {
15087c478bd9Sstevel@tonic-gate 		WMESG(SLTPTCL, str);
15097c478bd9Sstevel@tonic-gate 		RMESG(USEPTCL, msg);
15107c478bd9Sstevel@tonic-gate 		if ( fptcl(&msg[1], str) == FAIL ) {
15117c478bd9Sstevel@tonic-gate 			return(FAIL);
15127c478bd9Sstevel@tonic-gate 		} else {
15137c478bd9Sstevel@tonic-gate 		    return(stptcl(&msg[1]));
15147c478bd9Sstevel@tonic-gate 		}
15157c478bd9Sstevel@tonic-gate 	}
15167c478bd9Sstevel@tonic-gate }
15177c478bd9Sstevel@tonic-gate 
15187c478bd9Sstevel@tonic-gate /*
15197c478bd9Sstevel@tonic-gate  * choose a protocol from the input string (str)
15207c478bd9Sstevel@tonic-gate  * and return the found letter.
15217c478bd9Sstevel@tonic-gate  * Use the MASTER string (valid) for order of selection.
15227c478bd9Sstevel@tonic-gate  * return:
15237c478bd9Sstevel@tonic-gate  *	'\0'		-> no acceptable protocol
15247c478bd9Sstevel@tonic-gate  *	any character	-> the chosen protocol
15257c478bd9Sstevel@tonic-gate  */
15267c478bd9Sstevel@tonic-gate int
15277c478bd9Sstevel@tonic-gate fptcl(str, valid)
15287c478bd9Sstevel@tonic-gate register char *str, *valid;
15297c478bd9Sstevel@tonic-gate {
15307c478bd9Sstevel@tonic-gate 	char *l;
15317c478bd9Sstevel@tonic-gate 
15327c478bd9Sstevel@tonic-gate 	DEBUG(9, "Slave protocol list(%s)\n", str);
15337c478bd9Sstevel@tonic-gate 	DEBUG(9, "Master protocol list(%s)\n", valid);
15347c478bd9Sstevel@tonic-gate 
15357c478bd9Sstevel@tonic-gate 	for (l = valid; *l != '\0'; l++) {
15367c478bd9Sstevel@tonic-gate 		if ( strchr(str, *l) != NULL) {
15377c478bd9Sstevel@tonic-gate 		    *str = *l;
15387c478bd9Sstevel@tonic-gate 		    *(str+1) = '\0';
15397c478bd9Sstevel@tonic-gate 		    /* also update string with parms */
15407c478bd9Sstevel@tonic-gate 		    strcpy(_Protocol, findProto(_Protocol, *str));
15417c478bd9Sstevel@tonic-gate 		    return(SUCCESS);
15427c478bd9Sstevel@tonic-gate 		}
15437c478bd9Sstevel@tonic-gate 	}
15447c478bd9Sstevel@tonic-gate 	return(FAIL);
15457c478bd9Sstevel@tonic-gate }
15467c478bd9Sstevel@tonic-gate 
15477c478bd9Sstevel@tonic-gate /*
15487c478bd9Sstevel@tonic-gate  * build a string of the letters of the available
15497c478bd9Sstevel@tonic-gate  * protocols and return the string (str).  The string consists of protocols
15507c478bd9Sstevel@tonic-gate  * that are specified in the Systems and Devices files.  If nothing was
15517c478bd9Sstevel@tonic-gate  * specified in those files, then the string is the list of protocols from
15527c478bd9Sstevel@tonic-gate  * our Ptble.
15537c478bd9Sstevel@tonic-gate  *
15547c478bd9Sstevel@tonic-gate  *	str =		place to put the protocol list
15557c478bd9Sstevel@tonic-gate  *	length =	size of buffer at str
15567c478bd9Sstevel@tonic-gate  *
15577c478bd9Sstevel@tonic-gate  * return:
15587c478bd9Sstevel@tonic-gate  *	a pointer to string (str)
15597c478bd9Sstevel@tonic-gate  */
15607c478bd9Sstevel@tonic-gate void
15617c478bd9Sstevel@tonic-gate blptcl(str)
15627c478bd9Sstevel@tonic-gate register char *str;
15637c478bd9Sstevel@tonic-gate {
15647c478bd9Sstevel@tonic-gate 	register struct Proto *p;
15657c478bd9Sstevel@tonic-gate 	register char *validPtr;
15667c478bd9Sstevel@tonic-gate 
15677c478bd9Sstevel@tonic-gate 	/* Build list of valid protocols. */
15687c478bd9Sstevel@tonic-gate 	for (validPtr = str, p = Ptbl; (*validPtr = p->P_id) != NULLCHAR;
15697c478bd9Sstevel@tonic-gate 		validPtr++, p++);
15707c478bd9Sstevel@tonic-gate 
15717c478bd9Sstevel@tonic-gate 	/* Build _Protocol */
15727c478bd9Sstevel@tonic-gate 	(void) protoString(str);	/* Get desired protocols. */
15737c478bd9Sstevel@tonic-gate 	return;
15747c478bd9Sstevel@tonic-gate }
15757c478bd9Sstevel@tonic-gate 
15767c478bd9Sstevel@tonic-gate /*
15777c478bd9Sstevel@tonic-gate  * set up the six routines (Rdmg. Wrmsg, Rddata
15787c478bd9Sstevel@tonic-gate  * Wrdata, Turnon, Turnoff) for the desired protocol.
15797c478bd9Sstevel@tonic-gate  * returns:
15807c478bd9Sstevel@tonic-gate  *	SUCCESS 	-> ok
15817c478bd9Sstevel@tonic-gate  *	FAIL		-> no find or failed to open
15827c478bd9Sstevel@tonic-gate  */
15837c478bd9Sstevel@tonic-gate int
15847c478bd9Sstevel@tonic-gate stptcl(c)
15857c478bd9Sstevel@tonic-gate register char *c;
15867c478bd9Sstevel@tonic-gate {
15877c478bd9Sstevel@tonic-gate 	register struct Proto *p;
15887c478bd9Sstevel@tonic-gate 
15897c478bd9Sstevel@tonic-gate 	for (p = Ptbl; p->P_id != '\0'; p++) {
15907c478bd9Sstevel@tonic-gate 		if (*c == p->P_id) {
15917c478bd9Sstevel@tonic-gate 
15927c478bd9Sstevel@tonic-gate 			/*
15937c478bd9Sstevel@tonic-gate 			 * found protocol
15947c478bd9Sstevel@tonic-gate 			 * set routine
15957c478bd9Sstevel@tonic-gate 			 */
15967c478bd9Sstevel@tonic-gate 			Rdmsg = p->P_rdmsg;
15977c478bd9Sstevel@tonic-gate 			Wrmsg = p->P_wrmsg;
15987c478bd9Sstevel@tonic-gate 			Rddata = p->P_rddata;
15997c478bd9Sstevel@tonic-gate 			Wrdata = p->P_wrdata;
16007c478bd9Sstevel@tonic-gate 			Turnon = p->P_turnon;
16017c478bd9Sstevel@tonic-gate 			Turnoff = p->P_turnoff;
16027c478bd9Sstevel@tonic-gate 			if ((*Turnon)() != 0)
16037c478bd9Sstevel@tonic-gate 				break;
16047c478bd9Sstevel@tonic-gate 			CDEBUG(4, "Proto started %c\n", *c);
16057c478bd9Sstevel@tonic-gate 			pfPtcl(c);
16067c478bd9Sstevel@tonic-gate 			return(SUCCESS);
16077c478bd9Sstevel@tonic-gate 		}
16087c478bd9Sstevel@tonic-gate 	}
16097c478bd9Sstevel@tonic-gate 	CDEBUG(4, "Proto start-fail %c\n", *c);
16107c478bd9Sstevel@tonic-gate 	return(FAIL);
16117c478bd9Sstevel@tonic-gate }
16127c478bd9Sstevel@tonic-gate 
16137c478bd9Sstevel@tonic-gate /*
16147c478bd9Sstevel@tonic-gate  * unlink D. file
16157c478bd9Sstevel@tonic-gate  * returns:
16167c478bd9Sstevel@tonic-gate  *	none
16177c478bd9Sstevel@tonic-gate  */
16187c478bd9Sstevel@tonic-gate void
16197c478bd9Sstevel@tonic-gate unlinkdf(file)
16207c478bd9Sstevel@tonic-gate register char *file;
16217c478bd9Sstevel@tonic-gate {
16227c478bd9Sstevel@tonic-gate 	if (strlen(file) > (size_t) 6)
16237c478bd9Sstevel@tonic-gate 		(void) unlink(file);
16247c478bd9Sstevel@tonic-gate 	return;
16257c478bd9Sstevel@tonic-gate }
16267c478bd9Sstevel@tonic-gate 
16277c478bd9Sstevel@tonic-gate /*
16287c478bd9Sstevel@tonic-gate  * notify receiver of arrived file
16297c478bd9Sstevel@tonic-gate  * returns:
16307c478bd9Sstevel@tonic-gate  *	none
16317c478bd9Sstevel@tonic-gate  */
16327c478bd9Sstevel@tonic-gate void
16337c478bd9Sstevel@tonic-gate arrived(opt, file, nuser, rmtsys, rmtuser)
16347c478bd9Sstevel@tonic-gate char *file, *nuser, *rmtsys, *rmtuser;
16357c478bd9Sstevel@tonic-gate {
16367c478bd9Sstevel@tonic-gate 	char mbuf[200];
16377c478bd9Sstevel@tonic-gate 
16387c478bd9Sstevel@tonic-gate 	if (!opt)
16397c478bd9Sstevel@tonic-gate 		return;
16407c478bd9Sstevel@tonic-gate 	(void) sprintf(mbuf, "%s from %s!%s arrived\n", file, rmtsys, rmtuser);
16417c478bd9Sstevel@tonic-gate 	mailst(nuser, mbuf, mbuf, "", "");
16427c478bd9Sstevel@tonic-gate 	return;
16437c478bd9Sstevel@tonic-gate }
16447c478bd9Sstevel@tonic-gate 
16457c478bd9Sstevel@tonic-gate 
16467c478bd9Sstevel@tonic-gate /*
16477c478bd9Sstevel@tonic-gate  * Check to see if there is space for file
16487c478bd9Sstevel@tonic-gate  */
16497c478bd9Sstevel@tonic-gate 
16507c478bd9Sstevel@tonic-gate #define FREESPACE 50  /* Minimum freespace in blocks to permit transfer */
16517c478bd9Sstevel@tonic-gate #define FREENODES 5   /* Minimum number of inodes to permit transfer */
16527c478bd9Sstevel@tonic-gate 
16537c478bd9Sstevel@tonic-gate /*ARGSUSED*/
16547c478bd9Sstevel@tonic-gate static int
16557c478bd9Sstevel@tonic-gate nospace(name)
16567c478bd9Sstevel@tonic-gate char *name;
16577c478bd9Sstevel@tonic-gate #ifdef NOUSTAT
16587c478bd9Sstevel@tonic-gate {return(FALSE);}
16597c478bd9Sstevel@tonic-gate #else
16607c478bd9Sstevel@tonic-gate {
16617c478bd9Sstevel@tonic-gate 	struct stat statb;
16627c478bd9Sstevel@tonic-gate #ifdef STATFS
16637c478bd9Sstevel@tonic-gate 	struct statfs statfsb;
16647c478bd9Sstevel@tonic-gate #else
16657c478bd9Sstevel@tonic-gate 	struct ustat ustatb;
16667c478bd9Sstevel@tonic-gate #endif
16677c478bd9Sstevel@tonic-gate 
16687c478bd9Sstevel@tonic-gate 	if( stat(name, &statb) < 0 )
16697c478bd9Sstevel@tonic-gate 		return(TRUE);
16707c478bd9Sstevel@tonic-gate #ifdef	RT
16717c478bd9Sstevel@tonic-gate 	if( (statb.st_mode|S_IFMT) == S_IFREG ||
16727c478bd9Sstevel@tonic-gate 	    (statb.st_mode|S_IFMT) == S_IFEXT ||
16737c478bd9Sstevel@tonic-gate 	    (statb.st_mode&S_IFMT) == S_IF1EXT )
16747c478bd9Sstevel@tonic-gate #else
16757c478bd9Sstevel@tonic-gate 	if( (statb.st_mode&S_IFMT) == S_IFREG )
16767c478bd9Sstevel@tonic-gate #endif
16777c478bd9Sstevel@tonic-gate 	{
16787c478bd9Sstevel@tonic-gate #ifdef STATFS
16797c478bd9Sstevel@tonic-gate 		if( statfs(name, &statfsb)<0 )
16807c478bd9Sstevel@tonic-gate #else
16817c478bd9Sstevel@tonic-gate 		if( ustat(statb.st_dev, &ustatb)<0 )
16827c478bd9Sstevel@tonic-gate #endif
16837c478bd9Sstevel@tonic-gate 			return(TRUE);
16847c478bd9Sstevel@tonic-gate #ifdef STATFS
16857c478bd9Sstevel@tonic-gate 		/*
16867c478bd9Sstevel@tonic-gate 		 * Use 512-byte blocks, because that's the unit "ustat" tends
16877c478bd9Sstevel@tonic-gate 		 * to work in.
16887c478bd9Sstevel@tonic-gate 		 */
16897c478bd9Sstevel@tonic-gate 		if( ((statfsb.f_bavail*statfsb.f_bsize)/512) < FREESPACE )
16907c478bd9Sstevel@tonic-gate #else
16917c478bd9Sstevel@tonic-gate 		if( ustatb.f_tfree < FREESPACE )
16927c478bd9Sstevel@tonic-gate #endif
16937c478bd9Sstevel@tonic-gate 		{
16947c478bd9Sstevel@tonic-gate 			logent("FREESPACE IS LOW","REMOTE TRANSFER DENIED - ");
16957c478bd9Sstevel@tonic-gate 			return(TRUE);
16967c478bd9Sstevel@tonic-gate 		}
16977c478bd9Sstevel@tonic-gate #ifdef STATFS
16987c478bd9Sstevel@tonic-gate 		/*
16997c478bd9Sstevel@tonic-gate 		 * The test for "> 0" is there because the @$%#@#@$ NFS
17007c478bd9Sstevel@tonic-gate 		 * protocol doesn't pass the number of free files over the
17017c478bd9Sstevel@tonic-gate 		 * wire, so "statfs" on an NFS file system always returns -1.
17027c478bd9Sstevel@tonic-gate 		 */
17037c478bd9Sstevel@tonic-gate 		if( statfsb.f_ffree > 0
17047c478bd9Sstevel@tonic-gate 		    && statfsb.f_ffree < FREENODES )
17057c478bd9Sstevel@tonic-gate #else
17067c478bd9Sstevel@tonic-gate 		if( ustatb.f_tinode < FREENODES )
17077c478bd9Sstevel@tonic-gate #endif
17087c478bd9Sstevel@tonic-gate 		{
17097c478bd9Sstevel@tonic-gate 			logent("TOO FEW INODES","REMOTE TRANSFER DENIED - ");
17107c478bd9Sstevel@tonic-gate 			return(TRUE);
17117c478bd9Sstevel@tonic-gate 		}
17127c478bd9Sstevel@tonic-gate 	}
17137c478bd9Sstevel@tonic-gate 	return(FALSE);
17147c478bd9Sstevel@tonic-gate }
17157c478bd9Sstevel@tonic-gate #endif
17167c478bd9Sstevel@tonic-gate 
17177c478bd9Sstevel@tonic-gate #ifdef V7USTAT
17187c478bd9Sstevel@tonic-gate int
17197c478bd9Sstevel@tonic-gate ustat(dev, ustat)
17207c478bd9Sstevel@tonic-gate int	dev;
17217c478bd9Sstevel@tonic-gate struct ustat *ustat;
17227c478bd9Sstevel@tonic-gate {
17237c478bd9Sstevel@tonic-gate 	FILE	*dfp, *popen();
17247c478bd9Sstevel@tonic-gate 	char	*fval, buf[BUFSIZ];
17257c478bd9Sstevel@tonic-gate 
17267c478bd9Sstevel@tonic-gate 	sprintf(buf, "%s %d %d 2>&1", V7USTAT, major(dev), minor(dev));
17277c478bd9Sstevel@tonic-gate 	if ((dfp = popen(buf, "r")) == NULL)
17287c478bd9Sstevel@tonic-gate 		return(-1);
17297c478bd9Sstevel@tonic-gate 	fval = fgets(buf, sizeof(buf), dfp);
17307c478bd9Sstevel@tonic-gate 	if (pclose(dfp) != 0
17317c478bd9Sstevel@tonic-gate 	 || fval == NULL
17327c478bd9Sstevel@tonic-gate 	 || sscanf(buf, "%d %d", &ustat->f_tfree, &ustat->f_tinode) != 2)
17337c478bd9Sstevel@tonic-gate 		return(-1);
17347c478bd9Sstevel@tonic-gate 	return(0);
17357c478bd9Sstevel@tonic-gate }
17367c478bd9Sstevel@tonic-gate #endif	/* V7USTAT */
1737