file reorg, pathnames.h, paths.h
[unix-history] / usr / src / usr.bin / uucp / uucico / cntrl.c
index 33a4331..ec865c0 100644 (file)
@@ -1,13 +1,15 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)cntrl.c    5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)cntrl.c    5.12    (Berkeley) %G%";
 #endif
 
 #include "uucp.h"
 #endif
 
 #include "uucp.h"
-#include <sys/types.h>
 #include <sys/stat.h>
 #include "uust.h"
 
 extern int errno;
 #include <sys/stat.h>
 #include "uust.h"
 
 extern int errno;
+extern int turntime;
+int willturn;
+int HaveSentHup = 0;
 
 struct Proto {
        char P_id;
 
 struct Proto {
        char P_id;
@@ -22,12 +24,11 @@ struct Proto {
 extern int gturnon(), gturnoff();
 extern int grdmsg(), grddata();
 extern int gwrmsg(), gwrdata();
 extern int gturnon(), gturnoff();
 extern int grdmsg(), grddata();
 extern int gwrmsg(), gwrdata();
-extern int imsg(), omsg();
-#ifdef BSDTCP
-extern int tnullf();
+extern int imsg(), omsg(), nullf();
+#ifdef TCPIP
 extern int twrmsg(), trdmsg();
 extern int twrdata(), trddata();
 extern int twrmsg(), trdmsg();
 extern int twrdata(), trddata();
-#endif BSDTCP
+#endif TCPIP
 #ifdef PAD
 extern int fturnon(), fturnoff();
 extern int frdmsg(), frddata();
 #ifdef PAD
 extern int fturnon(), fturnoff();
 extern int frdmsg(), frddata();
@@ -35,9 +36,9 @@ extern int fwrmsg(), fwrdata();
 #endif PAD
 
 struct Proto Ptbl[]={
 #endif PAD
 
 struct Proto Ptbl[]={
-#ifdef BSDTCP
-       't', tnullf, trdmsg, twrmsg, trddata, twrdata, tnullf,
-#endif BSDTCP
+#ifdef TCPIP
+       't', nullf, trdmsg, twrmsg, trddata, twrdata, nullf,
+#endif TCPIP
 #ifdef PAD
        'f', fturnon, frdmsg, fwrmsg, frddata, fwrdata, fturnoff,
 #endif PAD
 #ifdef PAD
        'f', fturnon, frdmsg, fwrmsg, frddata, fwrdata, fturnoff,
 #endif PAD
@@ -49,12 +50,15 @@ int (*Imsg)() = imsg, (*Omsg)() = omsg;
 
 int (*Rdmsg)()=imsg, (*Rddata)();
 int (*Wrmsg)()=omsg, (*Wrdata)();
 
 int (*Rdmsg)()=imsg, (*Rddata)();
 int (*Wrmsg)()=omsg, (*Wrdata)();
-int (*Turnon)(), (*Turnoff)();
+int (*Turnon)()=nullf, (*Turnoff)() = nullf;
 
 
+struct timeb Now, LastTurned, LastCheckedNoLogin;
 
 static char *YES = "Y";
 static char *NO = "N";
 
 
 static char *YES = "Y";
 static char *NO = "N";
 
+int TransferSucceeded = 1;
+
 /*  failure messages  */
 #define EM_MAX         6
 #define EM_LOCACC      "N1"    /* local access to file denied */
 /*  failure messages  */
 #define EM_MAX         6
 #define EM_LOCACC      "N1"    /* local access to file denied */
@@ -105,7 +109,6 @@ char Dfile[MAXFULLNAME];
  * To avoid a huge backlog of X. files, start uuxqt every so often.
  */
 static int nXfiles = 0;        /* number of X files since last uuxqt start */
  * To avoid a huge backlog of X. files, start uuxqt every so often.
  */
 static int nXfiles = 0;        /* number of X files since last uuxqt start */
-static int nXQTs = 0;  /* number of uuxqts started */
 static char send_or_receive;
 struct stat stbuf;
 
 static char send_or_receive;
 struct stat stbuf;
 
@@ -138,12 +141,35 @@ char *wkpre;
 
        pnum = getpid();
        Wfile[0] = '\0';
 
        pnum = getpid();
        Wfile[0] = '\0';
+       willturn = turntime > 0;
+remaster:
+#ifdef USG
+       time(&LastTurned.time);
+       LastTurned.millitm = 0;
+#else !USG
+       ftime(&LastTurned);
+#endif !USG
+       send_or_receive = RESET;
+       HaveSentHup = 0;
 top:
        for (i = 0; i < sizeof wrkvec / sizeof wrkvec[0]; i++)
                wrkvec[i] = 0;
        DEBUG(4, "*** TOP ***  -  role=%s\n", role ? "MASTER" : "SLAVE");
 top:
        for (i = 0; i < sizeof wrkvec / sizeof wrkvec[0]; i++)
                wrkvec[i] = 0;
        DEBUG(4, "*** TOP ***  -  role=%s\n", role ? "MASTER" : "SLAVE");
-       setline(RESET);
-       send_or_receive = RESET;
+       setproctitle("%s: %s", Rmtname, role ? "MASTER" : "SLAVE");
+       setupline(RESET);
+       if (Now.time > (LastCheckedNoLogin.time+60)) {
+               LastCheckedNoLogin = Now;
+               if (access(NOLOGIN, 0) == 0) {
+                       logent(NOLOGIN, "UUCICO SHUTDOWN");
+                       if (Debug > 4)
+                               logent("DEBUGGING", "continuing anyway");
+                       else {
+                               WMESG(HUP, YES);
+                               RMESG(HUP, msg, 1);
+                               goto process;
+                       }
+               }
+       }
        if (role == MASTER) {
                /* get work */
                if (ReverseRole || (narg = gtwvec(Wfile, Spool, wkpre, wrkvec)) == 0) {
        if (role == MASTER) {
                /* get work */
                if (ReverseRole || (narg = gtwvec(Wfile, Spool, wkpre, wrkvec)) == 0) {
@@ -168,17 +194,18 @@ top:
                mailopt = index(W_OPTNS, 'm') != NULL;
                ntfyopt = index(W_OPTNS, 'n') != NULL;
 
                mailopt = index(W_OPTNS, 'm') != NULL;
                ntfyopt = index(W_OPTNS, 'n') != NULL;
 
-               if (narg < 5) {
+               if (narg < 5 || W_TYPE[1] != '\0') {
                        char *bnp;
                        bnp = rindex(Wfile, '/');
                        sprintf(rqstr, "%s/%s", CORRUPT, bnp ? bnp + 1 : Wfile);
                        xmv(Wfile, rqstr);
                        char *bnp;
                        bnp = rindex(Wfile, '/');
                        sprintf(rqstr, "%s/%s", CORRUPT, bnp ? bnp + 1 : Wfile);
                        xmv(Wfile, rqstr);
-                       logent(Wfile, "CMD FILE CORRUPTED");
+                       syslog(LOG_WARNING, "%s CORRUPTED: %d args", Wfile,
+                               narg);
                        Wfile[0] = '\0';
                        goto top;
                }
                sprintf(User, "%.9s", W_USER);
                        Wfile[0] = '\0';
                        goto top;
                }
                sprintf(User, "%.9s", W_USER);
-               sprintf(rqstr, "%s %s %s %s", W_TYPE, W_FILE1,
+               sprintf(rqstr, "(%s %s %s %s)", W_TYPE, W_FILE1,
                  W_FILE2, W_USER);
                logent(rqstr, "REQUEST");
                if (wrktype == SNDFILE ) {
                  W_FILE2, W_USER);
                logent(rqstr, "REQUEST");
                if (wrktype == SNDFILE ) {
@@ -198,6 +225,7 @@ top:
                           (fp = fopen(subfile(filename), "r")) == NULL) {
                                /*  can not read data file  */
                                logent("CAN'T READ DATA", _FAILED);
                           (fp = fopen(subfile(filename), "r")) == NULL) {
                                /*  can not read data file  */
                                logent("CAN'T READ DATA", _FAILED);
+                               TransferSucceeded = 1; /* else will keep sending */
                                USRF(USR_LOCACC);
                                unlinkdf(Dfile);
                                lnotify(User, filename, "can't access");
                                USRF(USR_LOCACC);
                                unlinkdf(Dfile);
                                lnotify(User, filename, "can't access");
@@ -208,8 +236,11 @@ top:
                        &&  (stbuf.st_mode & ANYREAD) == 0) {
                e_access:;
                                /*  access denied  */
                        &&  (stbuf.st_mode & ANYREAD) == 0) {
                e_access:;
                                /*  access denied  */
-                               fclose(fp);
-                               fp = NULL;
+                               if (fp != NULL) {
+                                       fclose(fp);
+                                       fp = NULL;
+                               }
+                               TransferSucceeded = 1; /* else will keep sending */
                                logent("DENIED", "ACCESS");
                                USRF(USR_LOCACC);
                                unlinkdf(W_DFILE);
                                logent("DENIED", "ACCESS");
                                USRF(USR_LOCACC);
                                unlinkdf(W_DFILE);
@@ -217,7 +248,7 @@ top:
                                goto top;
                        }
 
                                goto top;
                        }
 
-                       setline(SNDFILE);
+                       setupline(SNDFILE);
                }
 
                if (wrktype == RCVFILE) {
                }
 
                if (wrktype == RCVFILE) {
@@ -227,6 +258,7 @@ top:
                         || chkperm(filename, index(W_OPTNS, 'd'))) {
                                /*  access denied  */
                                logent("DENIED", "ACCESS");
                         || chkperm(filename, index(W_OPTNS, 'd'))) {
                                /*  access denied  */
                                logent("DENIED", "ACCESS");
+                               TransferSucceeded = 1; /* else will keep trying */
                                USRF(USR_LOCACC);
                                lnotify(User, filename, "access denied");
                                goto top;
                                USRF(USR_LOCACC);
                                lnotify(User, filename, "access denied");
                                goto top;
@@ -239,7 +271,7 @@ top:
                                unlinkdf(Dfile);
                                goto top;
                        }
                                unlinkdf(Dfile);
                                goto top;
                        }
-                       setline(RCVFILE);
+                       setupline(RCVFILE);
                }
 sendmsg:
                DEBUG(4, "wrktype - %c\n", wrktype);
                }
 sendmsg:
                DEBUG(4, "wrktype - %c\n", wrktype);
@@ -250,8 +282,9 @@ sendmsg:
 
        /* role is slave */
        RAMESG(msg, 1);
 
        /* role is slave */
        RAMESG(msg, 1);
-       goto process;
-
+       if (willturn < 0)
+               willturn = msg[0] == HUP;
+                       
 process:
        DEBUG(4, "PROCESS: msg - %s\n", msg);
        switch (msg[0]) {
 process:
        DEBUG(4, "PROCESS: msg - %s\n", msg);
        switch (msg[0]) {
@@ -260,26 +293,38 @@ process:
                DEBUG(4, "RQSTCMPT:\n", CNULL);
                if (msg[1] == 'N') {
                        i = atoi(&msg[2]);
                DEBUG(4, "RQSTCMPT:\n", CNULL);
                if (msg[1] == 'N') {
                        i = atoi(&msg[2]);
-                       if (i<0 || i>EM_MAX) i=0;
-                       USRF( 1 << i );
+                       if (i<0 || i>EM_MAX)
                                i = 0;
                                i = 0;
+                       USRF( 1 << i );
                        logent(Em_msg[i], "REQUEST FAILED");
                        logent(Em_msg[i], "REQUEST FAILED");
-                       if (strcmp(&msg[1], EM_NOTMP) == 0) {
-                               /* dont send him files he can't save */
-                               WMESG(HUP, "");
-                               RMESG(HUP, msg, 1);
-                               goto process;
-                       }
+                       TransferSucceeded = 1; /* He had his chance */
                }
                }
-               if (msg[1] == 'Y')
+               if (msg[1] == 'Y') {
                        USRF(USR_COK);
                        USRF(USR_COK);
-               if (role == MASTER) {
+                       TransferSucceeded = 1;
+               }
+               if (role == MASTER)
                        notify(mailopt, W_USER, W_FILE1, Rmtname, &msg[1]);
                        notify(mailopt, W_USER, W_FILE1, Rmtname, &msg[1]);
+
+               if (msg[2] == 'M' && role == MASTER) {
+                       extern int Nfiles;
+                       WMESG(HUP, "");
+                       RMESG(HUP, msg, 1);
+                       logent(Rmtname, "TURNAROUND");
+#ifdef USG
+                               time(&LastTurned.time);
+                               LastTurned.millitm = 0;
+#else !USG
+                               ftime(&LastTurned);
+#endif !USG
+                       Nfiles = 0; /* force rescan of queue for work */
+                       goto process;
                }
                goto top;
 
        case HUP:
                DEBUG(4, "HUP:\n", CNULL);
                }
                goto top;
 
        case HUP:
                DEBUG(4, "HUP:\n", CNULL);
+               HaveSentHup = 1;
                if (msg[1] == 'Y') {
                        if (role == MASTER)
                                WMESG(HUP, YES);
                if (msg[1] == 'Y') {
                        if (role == MASTER)
                                WMESG(HUP, YES);
@@ -290,9 +335,12 @@ process:
                }
 
                if (msg[1] == 'N') {
                }
 
                if (msg[1] == 'N') {
-                       ASSERT(role == MASTER, "WRONG ROLE - HUP", CNULL, role);
+                       if (role != MASTER) {
+                               syslog(LOG_ERR, "Wrong Role - HUP");
+                               cleanup(FAIL);
+                       }
                        role = SLAVE;
                        role = SLAVE;
-                       goto top;
+                       goto remaster;
                }
 
                /* get work */
                }
 
                /* get work */
@@ -303,8 +351,17 @@ process:
                }
 
                WMESG(HUP, NO);
                }
 
                WMESG(HUP, NO);
+               /*
+                * want to create an orphan uuxqt,
+                * so a double-fork is needed.
+                */
+               if (fork() == 0) {
+                       xuuxqt();
+                       _exit(0);
+               }
+               wait((int *)0);
                role = MASTER;
                role = MASTER;
-               goto top;
+               goto remaster;
 
        case XUUCP:
                if (role == MASTER) {
 
        case XUUCP:
                if (role == MASTER) {
@@ -343,24 +400,31 @@ process:
                        USRF( 1 << i );
                        fclose(fp);
                        fp = NULL;
                        USRF( 1 << i );
                        fclose(fp);
                        fp = NULL;
+                       /* dont send him files he can't save */
                        if (strcmp(&msg[1], EM_NOTMP) == 0) {
                        if (strcmp(&msg[1], EM_NOTMP) == 0) {
-                               /* dont send him files he can't save */
                                WMESG(HUP, "");
                                RMESG(HUP, msg, 1);
                                goto process;
                        }
                        notify(mailopt, W_USER, W_FILE1, Rmtname, &msg[1]);
                                WMESG(HUP, "");
                                RMESG(HUP, msg, 1);
                                goto process;
                        }
                        notify(mailopt, W_USER, W_FILE1, Rmtname, &msg[1]);
-                       ASSERT(role == MASTER, "WRONG ROLE - SN", CNULL, role);
-                       if (msg[1] != '4')
-                               unlinkdf(W_DFILE);
+                       if (role != MASTER) {
+                               syslog(LOG_ERR, "Wrong Role - SN");
+                               cleanup(FAIL);
+                       }
+                       unlinkdf(W_DFILE);
                        goto top;
                }
 
                if (msg[1] == 'Y') {
                        /* send file */
                        goto top;
                }
 
                if (msg[1] == 'Y') {
                        /* send file */
-                       ASSERT(role == MASTER, "WRONG ROLE - SY", CNULL, role);
-                       ret = fstat(fileno(fp), &stbuf);
-                       ASSERT(ret != -1, "STAT FAILED", filename, 0);
+                       if (role != MASTER) {
+                               syslog(LOG_ERR, "Wrong Role - SY");
+                               cleanup(FAIL);
+                       }
+                       if (fstat(fileno(fp), &stbuf) < 0) {
+                               syslog(LOG_ERR, "stat(%s) failed: %m",filename);
+                               cleanup(FAIL);
+                       }
                        i = 1 + (int)(stbuf.st_size / XFRRATE);
                        if (send_or_receive != SNDFILE) {
                                send_or_receive = SNDFILE;
                        i = 1 + (int)(stbuf.st_size / XFRRATE);
                        if (send_or_receive != SNDFILE) {
                                send_or_receive = SNDFILE;
@@ -380,7 +444,10 @@ process:
                }
 
                /*  SLAVE section of SNDFILE  */
                }
 
                /*  SLAVE section of SNDFILE  */
-               ASSERT(role == SLAVE, "WRONG ROLE - SLAVE", CNULL, role);
+               if (role != SLAVE) {
+                       syslog(LOG_ERR, "Wrong Role - SLAVE");
+                       cleanup(FAIL);
+               }
 
                /* request to receive file */
                /* check permissions */
 
                /* request to receive file */
                /* check permissions */
@@ -390,11 +457,12 @@ process:
                        bnp = rindex(Wfile, '/');
                        sprintf(rqstr, "%s/%s", CORRUPT, bnp ? bnp + 1 : Wfile);
                        xmv(Wfile, rqstr);
                        bnp = rindex(Wfile, '/');
                        sprintf(rqstr, "%s/%s", CORRUPT, bnp ? bnp + 1 : Wfile);
                        xmv(Wfile, rqstr);
-                       logent(Wfile, "CMD FILE CORRUPTED");
+                       syslog(LOG_WARNING, "%s CORRUPTED: %d args", Wfile, i);
                        Wfile[0] = '\0';
                        goto top;
                }
                        Wfile[0] = '\0';
                        goto top;
                }
-               sprintf(rqstr, "%s %s %s %s", W_TYPE, W_FILE1, W_FILE2, W_USER);
+               sprintf(rqstr, "(%s %s %s %s)", W_TYPE, W_FILE1, W_FILE2,
+                       W_USER);
                logent(rqstr, "REQUESTED");
                DEBUG(4, "msg - %s\n", msg);
                strcpy(filename, W_FILE2);
                logent(rqstr, "REQUESTED");
                DEBUG(4, "msg - %s\n", msg);
                strcpy(filename, W_FILE2);
@@ -455,6 +523,7 @@ process:
                fflush(fp);
                if (ferror(fp) || fclose(fp))
                        ret = FAIL;
                fflush(fp);
                if (ferror(fp) || fclose(fp))
                        ret = FAIL;
+               
                if (ret != SUCCESS) {
                        (void) unlinkdf(Dfile);
                        (*Turnoff)();
                if (ret != SUCCESS) {
                        (void) unlinkdf(Dfile);
                        (*Turnoff)();
@@ -463,7 +532,13 @@ process:
                /* copy to user directory */
                ntfyopt = index(W_OPTNS, 'n') != NULL;
                status = xmv(Dfile, filename);
                /* copy to user directory */
                ntfyopt = index(W_OPTNS, 'n') != NULL;
                status = xmv(Dfile, filename);
-               WMESG(RQSTCMPT, status ? EM_RMTCP : YES);
+
+               if (willturn && Now.time > (LastTurned.time+turntime)
+                       && iswrk(Wfile, "chk", Spool, wkpre)) {
+                               WMESG(RQSTCMPT, status ? EM_RMTCP : "YM");
+                               willturn = -1;
+               } else
+                       WMESG(RQSTCMPT, status ? EM_RMTCP : YES);
                if (i == 0)
                        ;       /* vanilla file, nothing to do */
                else if (status == 0) {
                if (i == 0)
                        ;       /* vanilla file, nothing to do */
                else if (status == 0) {
@@ -493,21 +568,21 @@ process:
                        USRF( 1 << i );
                        fclose(fp);
                        fp = NULL;
                        USRF( 1 << i );
                        fclose(fp);
                        fp = NULL;
-                       if (strcmp(&msg[1], EM_NOTMP) == 0) {
-                               /* dont send him files he can't save */
-                               WMESG(HUP, "");
-                               RMESG(HUP, msg, 1);
-                               goto process;
-                       }
                        notify(mailopt, W_USER, W_FILE1, Rmtname, &msg[1]);
                        notify(mailopt, W_USER, W_FILE1, Rmtname, &msg[1]);
-                       ASSERT(role == MASTER, "WRONG ROLE - RN", CNULL, role);
+                       if (role != MASTER) {
+                               syslog(LOG_ERR, "Wrong Role - RN");
+                               cleanup(FAIL);
+                       }
                        unlinkdf(Dfile);
                        goto top;
                }
 
                if (msg[1] == 'Y') {
                        /* receive file */
                        unlinkdf(Dfile);
                        goto top;
                }
 
                if (msg[1] == 'Y') {
                        /* receive file */
-                       ASSERT(role == MASTER, "WRONG ROLE - RY", CNULL, role);
+                       if (role != MASTER) {
+                               syslog(LOG_ERR, "Wrong Role - RY");
+                               cleanup(FAIL);
+                       }
                        if (send_or_receive != RCVFILE) {
                                send_or_receive = RCVFILE;
                                systat(Rmtname, SS_INPROGRESS, "RECEIVING");
                        if (send_or_receive != RCVFILE) {
                                send_or_receive = RCVFILE;
                                systat(Rmtname, SS_INPROGRESS, "RECEIVING");
@@ -530,27 +605,43 @@ process:
                        status = xmv(Dfile, filename);
                        WMESG(RQSTCMPT, status ? EM_RMTCP : YES);
                        notify(mailopt, W_USER, filename, Rmtname,
                        status = xmv(Dfile, filename);
                        WMESG(RQSTCMPT, status ? EM_RMTCP : YES);
                        notify(mailopt, W_USER, filename, Rmtname,
-                         status ? EM_LOCCP : YES);
+                               status ? EM_LOCCP : YES);
                        if (status == 0) {
                                sscanf(&msg[2], "%o", &filemode);
                                if (filemode <= 0)
                                        filemode = BASEMODE;
                                chmod(subfile(filename), (filemode|BASEMODE)&0777);
                                USRF(USR_COK);
                        if (status == 0) {
                                sscanf(&msg[2], "%o", &filemode);
                                if (filemode <= 0)
                                        filemode = BASEMODE;
                                chmod(subfile(filename), (filemode|BASEMODE)&0777);
                                USRF(USR_COK);
-                       }
-                       else {
+                       } else {
                                logent(_FAILED, "COPY");
                                putinpub(filename, Dfile, W_USER);
                                USRF(USR_LOCCP);
                        }
                                logent(_FAILED, "COPY");
                                putinpub(filename, Dfile, W_USER);
                                USRF(USR_LOCCP);
                        }
+                       if (msg[strlen(msg)-1] == 'M') {
+                               extern int Nfiles;
+                               WMESG(HUP, "");
+                               RMESG(HUP, msg, 1);
+                               logent(Rmtname, "TURNAROUND");
+#ifdef USG
+                               time(&LastTurned.time);
+                               LastTurned.millitm = 0;
+#else !USG
+                               ftime(&LastTurned);
+#endif !USG
+                               Nfiles = 0; /* force rescan of queue for work */
+                               goto process;
+                       }
                        goto top;
                }
 
                /*  SLAVE section of RCVFILE  */
                        goto top;
                }
 
                /*  SLAVE section of RCVFILE  */
-               ASSERT(role == SLAVE, "WRONG ROLE - SLAVE RCV", CNULL, role);
+               if (role != SLAVE) {
+                       syslog(LOG_ERR, "Wrong Role - SLAVE RCV");
+                       cleanup(FAIL);
+               }
 
                /* request to send file */
 
                /* request to send file */
-               strcpy(rqstr, msg);
+               sprintf(rqstr,"(%s)", msg);
                logent(rqstr, "REQUESTED");
 
                /* check permissions */
                logent(rqstr, "REQUESTED");
 
                /* check permissions */
@@ -560,7 +651,7 @@ process:
                        bnp = rindex(Wfile, '/');
                        sprintf(rqstr, "%s/%s", CORRUPT, bnp ? bnp + 1 : Wfile);
                        xmv(Wfile, rqstr);
                        bnp = rindex(Wfile, '/');
                        sprintf(rqstr, "%s/%s", CORRUPT, bnp ? bnp + 1 : Wfile);
                        xmv(Wfile, rqstr);
-                       logent(Wfile, "CMD FILE CORRUPTED");
+                       syslog(LOG_WARNING, "%s CORRUPTED: %d args", Wfile, i);
                        Wfile[0] = '\0';
                        goto top;
                }
                        Wfile[0] = '\0';
                        goto top;
                }
@@ -587,10 +678,18 @@ process:
                }
 
                /*  ok to send file */
                }
 
                /*  ok to send file */
-               ret = fstat(fileno(fp), &stbuf);
-               ASSERT(ret != -1, "STAT FAILED", filename, 0);
+               if (fstat(fileno(fp), &stbuf) < 0) {
+                       syslog(LOG_ERR, "stat(%s) failed: %m", filename);
+                       cleanup(FAIL);
+               }
+
                i = 1 + (int)(stbuf.st_size / XFRRATE);
                i = 1 + (int)(stbuf.st_size / XFRRATE);
-               sprintf(msg, "%s %o", YES, stbuf.st_mode & 0777);
+               if (willturn && Now.time > (LastTurned.time+turntime)
+                       && iswrk(Wfile, "chk", Spool, wkpre)) {
+                               willturn = -1;
+               }
+               sprintf(msg, "%s %o%s", YES, (int)stbuf.st_mode & 0777,
+                       willturn < 0 ? " M" : "");
                WMESG(RCVFILE, msg);
                if (send_or_receive != SNDFILE) {
                        send_or_receive = SNDFILE;
                WMESG(RCVFILE, msg);
                if (send_or_receive != SNDFILE) {
                        send_or_receive = SNDFILE;
@@ -610,19 +709,16 @@ process:
 }
 
 
 }
 
 
-/***
- *     rmesg(c, msg, n)        read message 'c'
- *                             try 'n' times
- *     char *msg, c;
+/*
+ *     read message 'c'. try 'n' times
  *
  *
- *     return code:  0  |  FAIL
+ *     return code:  SUCCESS  |  FAIL
  */
  */
-
 rmesg(c, msg, n)
 register char *msg, c;
 register int n;
 {
 rmesg(c, msg, n)
 register char *msg, c;
 register int n;
 {
-       char str[128];
+       char str[MAXFULLNAME];
 
        DEBUG(4, "rmesg - '%c' ", c);
        while ((*Rdmsg)(msg, Ifn) != SUCCESS) {
 
        DEBUG(4, "rmesg - '%c' ", c);
        while ((*Rdmsg)(msg, Ifn) != SUCCESS) {
@@ -650,13 +746,11 @@ register int n;
 }
 
 
 }
 
 
-/***
- *     wmesg(m, s)     write a message (type m)
- *     char *s, m;
+/*
+ *     write a message (type m)
  *
  *
- *     return codes: 0 - ok | FAIL - ng
+ *     return codes: SUCCESS - ok | FAIL - ng
  */
  */
-
 wmesg(m, s)
 register char *s, m;
 {
 wmesg(m, s)
 register char *s, m;
 {
@@ -665,17 +759,15 @@ register char *s, m;
        return (*Wrmsg)(m, s, Ofn);
 }
 
        return (*Wrmsg)(m, s, Ofn);
 }
 
-
-/***
- *     notify          mail results of command
+/*
+ *     mail results of command
  *
  *     return codes:  none
  */
  *
  *     return codes:  none
  */
-
 notify(mailopt, user, file, sys, msgcode)
 char *user, *file, *sys, *msgcode;
 {
 notify(mailopt, user, file, sys, msgcode)
 char *user, *file, *sys, *msgcode;
 {
-       char str[200];
+       char str[BUFSIZ];
        int i;
        char *msg;
 
        int i;
        char *msg;
 
@@ -695,12 +787,11 @@ char *user, *file, *sys, *msgcode;
        return;
 }
 
        return;
 }
 
-/***
- *     lnotify(user, file, mesg)       - local notify
+/*
+ *     local notify
  *
  *     return code - none
  */
  *
  *     return code - none
  */
-
 lnotify(user, file, mesg)
 char *user, *file, *mesg;
 {
 lnotify(user, file, mesg)
 char *user, *file, *mesg;
 {
@@ -710,20 +801,16 @@ char *user, *file, *mesg;
        return;
 }
 
        return;
 }
 
+char UsingProtocol;
 
 
-/***
- *     startup(role)
- *     int role;
- *
- *     startup  -  this routine will converse with the remote
- *     machine, agree upon a protocol (if possible) and start the
- *     protocol.
+/*
+ *     converse with the remote machine, agree upon a protocol (if possible)
+ *     and start the protocol.
  *
  *     return codes:
  *             SUCCESS - successful protocol selection
  *             FAIL - can't find common or open failed
  */
  *
  *     return codes:
  *             SUCCESS - successful protocol selection
  *             FAIL - can't find common or open failed
  */
-
 startup(role)
 int role;
 {
 startup(role)
 int role;
 {
@@ -745,6 +832,7 @@ int role;
                if (stptcl(str) != 0)
                        return FAIL;
                DEBUG(4, "protocol %s\n", str);
                if (stptcl(str) != 0)
                        return FAIL;
                DEBUG(4, "protocol %s\n", str);
+               UsingProtocol = str[0];
                return SUCCESS;
        }
        else {
                return SUCCESS;
        }
        else {
@@ -757,39 +845,36 @@ int role;
                if (stptcl(&msg[1]) != 0)
                        return FAIL;
                DEBUG(4, "Protocol %s\n", msg);
                if (stptcl(&msg[1]) != 0)
                        return FAIL;
                DEBUG(4, "Protocol %s\n", msg);
+               UsingProtocol = msg[1];
                return SUCCESS;
        }
 }
 
                return SUCCESS;
        }
 }
 
-
-/*******
- *     char
- *     fptcl(str)
- *     char *str;
- *
- *     fptcl  -  this routine will choose a protocol from
- *     the input string (str) and return the found letter.
+/*
+ *     choose a protocol from the input string (str) and return the it
  *
  *     return codes:
  *             '\0'  -  no acceptable protocol
  *             any character  -  the chosen protocol
  */
  *
  *     return codes:
  *             '\0'  -  no acceptable protocol
  *             any character  -  the chosen protocol
  */
-
 char
 fptcl(str)
 register char *str;
 {
        register struct Proto *p;
 char
 fptcl(str)
 register char *str;
 {
        register struct Proto *p;
-       extern char *Flds[];
+       extern char LineType[];
 
        for (p = Ptbl; p->P_id != '\0'; p++) {
 
        for (p = Ptbl; p->P_id != '\0'; p++) {
-#ifdef BSDTCP
-               if (!IsTcpIp && p->P_id == 't') /* Only use 't' on TCP/IP */
+#ifdef TCPIP
+               /* Only use 't' on TCP/IP */
+               if (p->P_id == 't' && strcmp("TCP", LineType))
                        continue;
                        continue;
-#endif BSDTCP
+#endif TCPIP
+#ifdef PAD
                /* only use 'f' protocol on PAD */
                /* only use 'f' protocol on PAD */
-               if (strcmp("PAD", Flds[F_LINE]) && p->P_id == 'f')
+               if (p->P_id == 'f' && strcmp("PAD", LineType))
                        continue;
                        continue;
+#endif PAD
                if (index(str, p->P_id) != NULL) {
                        return p->P_id;
                }
                if (index(str, p->P_id) != NULL) {
                        return p->P_id;
                }
@@ -798,20 +883,9 @@ register char *str;
        return '\0';
 }
 
        return '\0';
 }
 
-
-/***
- *     char *
- *     blptcl(str)
- *     char *str;
- *
- *     blptcl  -  this will build a string of the
- *     letters of the available protocols and return
- *     the string (str).
- *
- *     return:
- *             a pointer to string (str)
+/*
+ *     build a string of the letters of the available protocols 
  */
  */
-
 char *
 blptcl(str)
 register char *str;
 char *
 blptcl(str)
 register char *str;
@@ -825,11 +899,8 @@ register char *str;
        return str;
 }
 
        return str;
 }
 
-/***
- *     stptcl(c)
- *     char *c;
- *
- *     stptcl  -  this routine will set up the six routines
+/*
+ *     this routine will set up the six routines
  *     (Rdmsg, Wrmsg, Rddata, Wrdata, Turnon, Turnoff) for the
  *     desired protocol.
  *
  *     (Rdmsg, Wrmsg, Rddata, Wrdata, Turnon, Turnoff) for the
  *     desired protocol.
  *
@@ -838,7 +909,6 @@ register char *str;
  *             FAIL - no find or failed to open
  *
  */
  *             FAIL - no find or failed to open
  *
  */
-
 stptcl(c)
 register char *c;
 {
 stptcl(c)
 register char *c;
 {
@@ -863,15 +933,14 @@ register char *c;
        return FAIL;
 }
 
        return FAIL;
 }
 
-/***
- *     putinpub        put file in public place
- *                     if successful, filename is modified
+/*
+ *     put file in public place. if successful, filename is modified
  *
  *
- *     return code  0 | FAIL
+ *     return code  SUCCESS | FAIL
  */
 
 putinpub(file, tmp, user)
  */
 
 putinpub(file, tmp, user)
-register char *file, *user, *tmp;
+register char *file, *tmp, *user;
 {
        char fullname[MAXFULLNAME];
        char *lastpart();
 {
        char fullname[MAXFULLNAME];
        char *lastpart();
@@ -880,6 +949,7 @@ register char *file, *user, *tmp;
        sprintf(fullname, "%s/%s/", PUBDIR, user);
        if (mkdirs(fullname) != 0) {
                /* can not make directories */
        sprintf(fullname, "%s/%s/", PUBDIR, user);
        if (mkdirs(fullname) != 0) {
                /* can not make directories */
+               DEBUG(1, "Cannot mkdirs(%s)\n", fullname);
                return FAIL;
        }
        strcat(fullname, lastpart(file));
                return FAIL;
        }
        strcat(fullname, lastpart(file));
@@ -891,8 +961,8 @@ register char *file, *user, *tmp;
        return status;
 }
 
        return status;
 }
 
-/***
- *     unlinkdf(file)  - unlink D. file
+/*
+ *     unlink D. file
  *
  *     return code - none
  */
  *
  *     return code - none
  */
@@ -905,12 +975,11 @@ register char *file;
        return;
 }
 
        return;
 }
 
-/***
- *     arrived - notify receiver of arrived file
+/*
+ *     notify receiver of arrived file
  *
  *     return code - none
  */
  *
  *     return code - none
  */
-
 arrived(opt, file, nuser, rmtsys, rmtuser)
 char *file, *nuser, *rmtsys, *rmtuser;
 {
 arrived(opt, file, nuser, rmtsys, rmtuser)
 char *file, *nuser, *rmtsys, *rmtuser;
 {
@@ -922,3 +991,8 @@ char *file, *nuser, *rmtsys, *rmtuser;
        mailst(nuser, mbuf, CNULL);
        return;
 }
        mailst(nuser, mbuf, CNULL);
        return;
 }
+
+nullf()
+{
+       return SUCCESS;
+}