// Most of this is ripped from GreyLine's code from glftpd
#include <string.h>
#include <stdio.h>
#include <sys/param.h>
#include <sys/file.h>

main(int argc, char *argv[]) {
  int fdes = -1;
  uid_t oldid = getuid();
  char dupelogpath[MAXPATHLEN];
  char direntry[MAXPATHLEN];
  char frame_buf[64];
  struct tm *ptr;
  time_t timenow = time(NULL);
  mode_t oldmask;

  printf("Dupediradd for glftpd, v1.0 by Usurper, June 1999\n");
  printf("This util adds a dirname to the dupe database.\n");

  if (argc < 2) {
    printf("Usage: %s dirname [/glftpd/ftp-data]\n", argv[0]);
    return;
  }
  if (argc < 3)
    strcpy(dupelogpath, "/glftpd/ftp-data");
  else 
    strncpy(dupelogpath, argv[2], sizeof(dupelogpath)-15);
  strcat(dupelogpath, "/logs/dupelog");

  ptr = (struct tm *)localtime(&timenow);
  strftime(frame_buf, 64, "%m%d%y",ptr);
  snprintf(direntry, sizeof(direntry), "%s %s\n",frame_buf, argv[1]);
  seteuid(0);
  fdes = open(dupelogpath, O_CREAT | O_WRONLY | O_APPEND, 0666);
  umask(oldmask);
  if (fdes < 0) {
    seteuid(oldid);
    printf("Error opening %s\n", dupelogpath);
    return;
  }
  write (fdes, direntry , strlen( direntry ));
  close (fdes);
  seteuid(oldid);
  printf("Directory successfully added.\n");
}
