Example #1
0
static void finish_terminate(void) {
  if (is_master &&
      mpid == getpid()) {
    PRIVS_ROOT

    /* Do not need the pidfile any longer. */
    if (ServerType == SERVER_STANDALONE &&
        !nodaemon) {
      pr_pidfile_remove();
    }

    /* Run any exit handlers registered in the master process here, so that
     * they may have the benefit of root privs.  More than likely these
     * exit handlers were registered by modules' module initialization
     * functions, which also occur under root priv conditions.
     *
     * If an exit handler is registered after the fork(), it won't be run here;
     * that registration occurs in a different process space.
     */
    pr_event_generate("core.exit", NULL);
    pr_event_generate("core.shutdown", NULL);

    /* Remove the registered exit handlers now, so that the ensuing
     * pr_session_end() call (outside the root privs condition) does not call
     * the exit handlers for the master process again.
     */
    pr_event_unregister(NULL, "core.exit", NULL);
    pr_event_unregister(NULL, "core.shutdown", NULL);

    PRIVS_RELINQUISH

    if (ServerType == SERVER_STANDALONE) {
      pr_log_pri(PR_LOG_NOTICE, "ProFTPD " PROFTPD_VERSION_TEXT
        " standalone mode SHUTDOWN");

      /* Clean up the scoreboard */
      PRIVS_ROOT
      pr_delete_scoreboard();
      PRIVS_RELINQUISH
    }
Example #2
0
END_TEST

START_TEST (scoreboard_get_daemon_uptime_test) {
  int res;
  const char *dir = "/tmp/prt-scoreboard/", *path = "/tmp/prt-scoreboard/test",
    *mutex_path = "/tmp/prt-scoreboard/test.lck";
  time_t daemon_uptime, now;

  res = mkdir(dir, 0775);
  fail_unless(res == 0, "Failed to create directory '%s': %s", dir,
    strerror(errno));

  res = chmod(dir, 0775);
  if (res < 0) {
    int xerrno = errno;

    (void) rmdir(dir);
    fail("Failed to set perms on '%s' to 0775': %s", dir, strerror(xerrno));
  }

  res = pr_set_scoreboard(path);
  if (res < 0) {
    int xerrno = errno;

    (void) rmdir(dir);
    fail("Failed to set scoreboard to '%s': %s", path, strerror(xerrno));
  }

  (void) unlink(path);
  (void) unlink(mutex_path);

  res = pr_open_scoreboard(O_RDWR);
  if (res < 0) {
    int xerrno = errno;

    (void) unlink(path);
    (void) unlink(mutex_path);
    (void) rmdir(dir);

    fail("Failed to open scoreboard: %s", strerror(xerrno));
  }

  daemon_uptime = pr_scoreboard_get_daemon_uptime();
  now = time(NULL);

  if (daemon_uptime > now) {
    (void) unlink(path);
    (void) unlink(mutex_path);
    (void) rmdir(dir);

    fail("Expected %lu, got %lu", (unsigned long) now,
      (unsigned long) daemon_uptime);
  }

  pr_delete_scoreboard();

  ServerType = SERVER_INETD;

  res = pr_open_scoreboard(O_RDWR);
  if (res < 0) {
    int xerrno = errno;

    (void) unlink(path);
    (void) unlink(mutex_path);
    (void) rmdir(dir);

    fail("Failed to open scoreboard: %s", strerror(xerrno));
  }

  daemon_uptime = pr_scoreboard_get_daemon_uptime();
  if (daemon_uptime != 0) {
    (void) unlink(path);
    (void) unlink(mutex_path);
    (void) rmdir(dir);

    fail("Expected %lu, got %lu", (unsigned long) 0,
      (unsigned long) daemon_uptime);
  }

  (void) unlink(path);
  (void) unlink(mutex_path);
  (void) rmdir(dir);
}
Example #3
0
END_TEST

START_TEST (scoreboard_delete_test) {
  int res;
  const char *dir = "/tmp/prt-scoreboard/", *path = "/tmp/prt-scoreboard/test",
    *mutex_path = "/tmp/prt-scoreboard/test.lck";
  struct stat st;

  res = mkdir(dir, 0775);
  fail_unless(res == 0, "Failed to create directory '%s': %s", dir,
    strerror(errno));

  res = chmod(dir, 0775);
  if (res < 0) {
    int xerrno = errno;

    (void) rmdir(dir);
    fail("Failed to set perms on '%s' to 0775': %s", dir, strerror(xerrno));
  }

  res = pr_set_scoreboard(path);
  if (res < 0) {
    int xerrno = errno;

    (void) rmdir(dir);
    fail("Failed to set scoreboard to '%s': %s", path, strerror(xerrno));
  }

  (void) unlink(path);
  (void) unlink(mutex_path);

  res = pr_open_scoreboard(O_RDWR);
  if (res < 0) {
    int xerrno = errno;

    (void) unlink(mutex_path);
    (void) unlink(path);
    (void) rmdir(dir);

    fail("Failed to open scoreboard: %s", strerror(xerrno));
  }

  res = stat(pr_get_scoreboard(), &st);
  if (res < 0) {
    int xerrno = errno;

    (void) unlink(mutex_path);
    (void) unlink(path);
    (void) rmdir(dir);

    fail("Failed to stat scoreboard: %s", strerror(xerrno));
  }

  pr_delete_scoreboard();

  res = stat(pr_get_scoreboard(), &st);
  if (res == 0) {
    (void) unlink(path);
    (void) unlink(mutex_path);
    (void) rmdir(dir);

    fail("Unexpectedly found deleted scoreboard");
  }

  res = stat(pr_get_scoreboard_mutex(), &st);
  if (res == 0) {
    (void) unlink(path);
    (void) unlink(mutex_path);
    (void) rmdir(dir);

    fail("Unexpectedly found deleted scoreboard mutex");
  }

  (void) unlink(path);
  (void) unlink(mutex_path);
  (void) rmdir(dir);
}