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