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