Subject: [260] Removing the shutdown file

From: Andreas Schuch <[email-masked]>
Date: Wed, 03 Aug 1994 12:46:41 +0200 (MET DST)

In the INSTALL file of wu-ftpd 2.4 it is recommended to create a link
in order for shutdown to work properly for real and anonymous user, e.g.
    ln -s ~ftp/etc/shutmsg /etc/shutmsg

When the ftp service shall be restarted after an ftpshut, the correct
shutdown file ~ftp/etc/shutmsg must be removed. Deleting /etc/shutmsg
only kills the link, the actual file remains. To avoid this I wrote a
small program 'ftprestart' which checks the access file for the place of
the shutdown file, follows all links and then deletes the appropriate
file.

Andreas Schuch

--- cut here ---
/* ftprestart 
 * ======= 
 * removes the ftpd shutdown file.
 */

#include "config.h"

#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <memory.h>

#include "pathnames.h"

int
main(int argc, char **argv)
{
    FILE *accessfile;
    char *sp = NULL;
    char linebuf[1024],shutmsg[256];
    int len;
    char *p;

    if ((accessfile = fopen(_PATH_FTPACCESS, "r")) == NULL) {
        if (errno != ENOENT)
            perror("ftprestart: could not open() access file");
        return(1);
    }
    while (! feof(accessfile)) {
      if (fgets(linebuf,sizeof(linebuf)-1,accessfile)==NULL) break;
      if (strncasecmp(linebuf,"shutdown",8)==0) {
        (void) strtok(linebuf," \t");
        sp=strncpy(shutmsg,strtok(NULL," \t"),sizeof(shutmsg));
        shutmsg[sizeof(shutmsg)-1]='\0';
        if ((p=strchr(sp,'\n'))!=NULL) *p='\0';
      }
    }
    fclose(accessfile);

    if ( sp == NULL ) {
        fprintf(stderr, "No shutdown file defined in ftpaccess file.\n");
        return(1);
    }

#ifdef HAVE_SYMLINK
    do {
      if ((len=readlink(sp,linebuf,sizeof(linebuf)-1))>=0) {
        linebuf[len]='\0';
        sp=linebuf;
      }
    } while (errno==0);
#else
    errno=EINVAL;
#endif
    if ((errno==EINVAL) && (unlink(sp)==0)) {
      printf("ftprestart: %s removed.\n",sp);
      return(0);
    }
    else {
      perror("ftprestart: could not unlink() shutdown file");
      return(1);
    }
}