Esempio n. 1
0
END_TEST

START_TEST (stash_remove_conf_test) {
  int res;
  conftable conftab;

  res = pr_stash_remove_conf(NULL, NULL);
  fail_unless(res == -1, "Failed to handle null arguments");
  fail_unless(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)",
    errno, strerror(errno));

  res = pr_stash_remove_conf("foo", NULL);
  fail_unless(res == 0, "Expected %d, got %d", 0, res);

  memset(&conftab, 0, sizeof(conftab));
  conftab.directive = pstrdup(p, "foo");
  res = pr_stash_add_symbol(PR_SYM_CONF, &conftab);
  fail_unless(res == 0, "Failed to add CONF symbol: %s", strerror(errno));

  res = pr_stash_add_symbol(PR_SYM_CONF, &conftab);
  fail_unless(res == 0, "Failed to add CONF symbol: %s", strerror(errno));

  res = pr_stash_remove_conf("foo", NULL);
  fail_unless(res == 2, "Expected %d, got %d", 2, res);
}
Esempio n. 2
0
END_TEST

START_TEST (stash_remove_auth_test) {
  int res;
  authtable authtab;

  res = pr_stash_remove_auth(NULL, NULL);
  fail_unless(res == -1, "Failed to handle null arguments");
  fail_unless(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)",
    errno, strerror(errno));

  res = pr_stash_remove_auth("foo", NULL);
  fail_unless(res == 0, "Expected %d, got %d", 0, res);

  memset(&authtab, 0, sizeof(authtab));
  authtab.name = pstrdup(p, "foo");
  res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab);
  fail_unless(res == 0, "Failed to add AUTH symbol: %s", strerror(errno));

  res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab);
  fail_unless(res == 0, "Failed to add AUTH symbol: %s", strerror(errno));

  res = pr_stash_remove_auth("foo", NULL);
  fail_unless(res == 2, "Expected %d, got %d", 2, res);
}
Esempio n. 3
0
END_TEST

START_TEST (stash_remove_hook_test) {
  int res;
  cmdtable hooktab;

  res = pr_stash_remove_hook(NULL, NULL);
  fail_unless(res == -1, "Failed to handle null arguments");
  fail_unless(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)",
    errno, strerror(errno));

  res = pr_stash_remove_hook("foo", NULL);
  fail_unless(res == 0, "Expected %d, got %d", 0, res);

  memset(&hooktab, 0, sizeof(hooktab));
  hooktab.command = pstrdup(p, "foo");
  res = pr_stash_add_symbol(PR_SYM_HOOK, &hooktab);
  fail_unless(res == 0, "Failed to add HOOK symbol: %s", strerror(errno));

  res = pr_stash_add_symbol(PR_SYM_HOOK, &hooktab);
  fail_unless(res == 0, "Failed to add HOOK symbol: %s", strerror(errno));

  res = pr_stash_remove_hook("foo", NULL);
  fail_unless(res == 2, "Expected %d, got %d", 2, res);
}
Esempio n. 4
0
int pr_module_load_cmdtab(module *m) {
  if (m == NULL ||
      m->name == NULL) {
    errno = EINVAL;
    return -1;
  }

  if (m->cmdtable) {
    cmdtable *cmdtab;

    for (cmdtab = m->cmdtable; cmdtab->command; cmdtab++) {
      cmdtab->m = m;

      if (cmdtab->cmd_type == HOOK) {
        if (pr_stash_add_symbol(PR_SYM_HOOK, cmdtab) < 0) {
          return -1;
        }

      } else {
        /* All other cmd_types are for CMDs: PRE_CMD, CMD, POST_CMD, etc. */
        if (pr_stash_add_symbol(PR_SYM_CMD, cmdtab) < 0) {
          return -1;
        }
      }
    }
  }

  return 0;
}
Esempio n. 5
0
END_TEST

START_TEST (auth_endgrent_test) {
    int res;
    authtable authtab;
    char *sym_name = "endgrent";

    pr_auth_endgrent(p);
    fail_unless(endgrent_count == 0, "Expected call count 0, got %u",
                endgrent_count);
    mark_point();

    /* Load the appropriate AUTH symbol, and call it. */

    memset(&authtab, 0, sizeof(authtab));
    authtab.name = sym_name;
    authtab.handler = handle_endgrent;
    authtab.m = &unit_tests_module;
    res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab);
    fail_unless(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name,
                strerror(errno));

    pr_auth_endgrent(p);
    fail_unless(endgrent_count == 1, "Expected call count 1, got %u",
                endgrent_count);

    pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &unit_tests_module);
}
Esempio n. 6
0
END_TEST

START_TEST (auth_cache_name2gid_failed_test) {
    int res;
    gid_t gid;
    authtable authtab;
    char *sym_name = "name2gid";

    /* Load the appropriate AUTH symbol, and call it. */

    memset(&authtab, 0, sizeof(authtab));
    authtab.name = sym_name;
    authtab.handler = decline_name2gid;
    authtab.m = &unit_tests_module;
    res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab);
    fail_unless(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name,
                strerror(errno));

    mark_point();

    gid = pr_auth_name2gid(p, PR_TEST_AUTH_NAME);
    fail_unless(gid == (gid_t) -1, "Expected -1, got %lu", (unsigned long) gid);
    fail_unless(name2gid_count == 1, "Expected call count 1, got %u",
                name2gid_count);

    /* Call again; the call counter should NOT increment due to caching. */

    gid = pr_auth_name2gid(p, PR_TEST_AUTH_NAME);
    fail_unless(gid == (gid_t) -1, "Expected -1, got %lu", (unsigned long) gid);
    fail_unless(name2gid_count == 1, "Expected call count 1, got %u",
                name2gid_count);

    pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &unit_tests_module);
}
Esempio n. 7
0
END_TEST

START_TEST (auth_name2gid_test) {
    int res;
    gid_t gid;
    authtable authtab;
    char *sym_name = "name2gid";

    pr_auth_cache_set(FALSE, PR_AUTH_CACHE_FL_BAD_NAME2GID);

    gid = pr_auth_name2gid(NULL, NULL);
    fail_unless(gid == (gid_t) -1, "Found GID unexpectedly");
    fail_unless(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)",
                errno, strerror(errno));

    gid = pr_auth_name2gid(p, PR_TEST_AUTH_NAME);
    fail_unless(gid == (gid_t) -1, "Found GID unexpectedly");
    fail_unless(name2gid_count == 0, "Expected call count 0, got %u",
                name2gid_count);
    mark_point();

    /* Load the appropriate AUTH symbol, and call it. */

    memset(&authtab, 0, sizeof(authtab));
    authtab.name = sym_name;
    authtab.handler = handle_name2gid;
    authtab.m = &unit_tests_module;
    res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab);
    fail_unless(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name,
                strerror(errno));

    mark_point();

    gid = pr_auth_name2gid(p, PR_TEST_AUTH_NAME);
    fail_unless(gid == PR_TEST_AUTH_GID, "Expected GID %lu, got %lu",
                (unsigned long) PR_TEST_AUTH_GID, (unsigned long) gid);
    fail_unless(name2gid_count == 1, "Expected call count 1, got %u",
                name2gid_count);

    mark_point();

    /* Call again; the call counter should NOT increment due to caching. */

    gid = pr_auth_name2gid(p, PR_TEST_AUTH_NAME);
    fail_unless(gid == PR_TEST_AUTH_GID, "Expected GID %lu, got %lu",
                (unsigned long) PR_TEST_AUTH_GID, (unsigned long) gid);
    fail_unless(name2gid_count == 1, "Expected call count 1, got %u",
                name2gid_count);

    pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &unit_tests_module);
}
Esempio n. 8
0
END_TEST

START_TEST (auth_getgrgid_test) {
    int res;
    struct group *gr;
    authtable authtab;
    char *sym_name = "getgrgid";

    gr = pr_auth_getgrgid(NULL, -1);
    fail_unless(gr == NULL, "Found grgid unexpectedly");
    fail_unless(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)",
                errno, strerror(errno));

    gr = pr_auth_getgrgid(p, PR_TEST_AUTH_GID);
    fail_unless(gr == NULL, "Found grgid unexpectedly");
    fail_unless(getgrgid_count == 0, "Expected call count 0, got %u",
                getgrgid_count);
    mark_point();

    /* Load the appropriate AUTH symbol, and call it. */

    memset(&authtab, 0, sizeof(authtab));
    authtab.name = sym_name;
    authtab.handler = handle_getgrgid;
    authtab.m = &unit_tests_module;
    res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab);
    fail_unless(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name,
                strerror(errno));

    mark_point();

    gr = pr_auth_getgrgid(p, PR_TEST_AUTH_GID);
    fail_unless(gr != NULL, "Failed to find grgid: %s", strerror(errno));
    fail_unless(getgrgid_count == 1, "Expected call count 1, got %u",
                getgrgid_count);

    mark_point();

    gr = pr_auth_getgrgid(p, 5);
    fail_unless(gr == NULL, "Found grgid for GID 5 unexpectedly");
    fail_unless(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)",
                errno, strerror(errno));
    fail_unless(getgrgid_count == 2, "Expected call count 2, got %u",
                getgrgid_count);

    pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &unit_tests_module);
}
Esempio n. 9
0
END_TEST

START_TEST (auth_getpwnam_test) {
    int res;
    struct passwd *pw;
    authtable authtab;
    char *sym_name = "getpwnam";

    pw = pr_auth_getpwnam(NULL, NULL);
    fail_unless(pw == NULL, "Found pwnam unexpectedly");
    fail_unless(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)",
                errno, strerror(errno));

    pw = pr_auth_getpwnam(p, PR_TEST_AUTH_NAME);
    fail_unless(pw == NULL, "Found pwnam unexpectedly");
    fail_unless(getpwnam_count == 0, "Expected call count 0, got %u",
                getpwnam_count);
    mark_point();

    /* Load the appropriate AUTH symbol, and call it. */

    memset(&authtab, 0, sizeof(authtab));
    authtab.name = sym_name;
    authtab.handler = handle_getpwnam;
    authtab.m = &unit_tests_module;
    res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab);
    fail_unless(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name,
                strerror(errno));

    mark_point();

    pw = pr_auth_getpwnam(p, PR_TEST_AUTH_NAME);
    fail_unless(pw != NULL, "Failed to find pwnam: %s", strerror(errno));
    fail_unless(getpwnam_count == 1, "Expected call count 1, got %u",
                getpwnam_count);

    mark_point();

    pw = pr_auth_getpwnam(p, "other");
    fail_unless(pw == NULL, "Found pwnam for user 'other' unexpectedly");
    fail_unless(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)",
                errno, strerror(errno));
    fail_unless(getpwnam_count == 2, "Expected call count 2, got %u",
                getpwnam_count);

    pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &unit_tests_module);
}
Esempio n. 10
0
END_TEST

START_TEST (auth_gid2name_test) {
    int res;
    const char *name;
    authtable authtab;
    char *sym_name = "gid2name";

    pr_auth_cache_set(FALSE, PR_AUTH_CACHE_FL_BAD_GID2NAME);

    name = pr_auth_gid2name(NULL, -1);
    fail_unless(name == NULL, "Found name unexpectedly: %s", name);
    fail_unless(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)",
                errno, strerror(errno));
    mark_point();

    name = pr_auth_gid2name(p, PR_TEST_AUTH_GID);
    fail_unless(name != NULL, "Failed to find name for GID %lu: %s",
                (unsigned long) PR_TEST_AUTH_GID, strerror(errno));
    fail_unless(strcmp(name, PR_TEST_AUTH_GID_STR) == 0,
                "Expected name '%s', got '%s'", PR_TEST_AUTH_GID_STR, name);
    fail_unless(gid2name_count == 0, "Expected call count 0, got %u",
                gid2name_count);
    mark_point();

    /* Load the appropriate AUTH symbol, and call it. */

    memset(&authtab, 0, sizeof(authtab));
    authtab.name = sym_name;
    authtab.handler = handle_gid2name;
    authtab.m = &unit_tests_module;
    res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab);
    fail_unless(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name,
                strerror(errno));

    mark_point();

    name = pr_auth_gid2name(p, PR_TEST_AUTH_GID);
    fail_unless(name != NULL, "Expected name, got null");
    fail_unless(strcmp(name, PR_TEST_AUTH_NAME) == 0,
                "Expected name '%s', got '%s'", PR_TEST_AUTH_NAME, name);
    fail_unless(gid2name_count == 1, "Expected call count 1, got %u",
                gid2name_count);

    pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &unit_tests_module);
}
Esempio n. 11
0
END_TEST

START_TEST (auth_getgroups_test) {
    int res;
    array_header *gids = NULL;
    authtable authtab;
    char *sym_name = "getgroups";

    res = pr_auth_getgroups(NULL, NULL, NULL, NULL);
    fail_unless(res < 0, "Failed to handle null arguments");
    fail_unless(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)",
                errno, strerror(errno));

    res = pr_auth_getgroups(p, PR_TEST_AUTH_NAME, &gids, NULL);
    fail_unless(res < 0, "Found groups for '%s' unexpectedly", PR_TEST_AUTH_NAME);
    fail_unless(getgroups_count == 0, "Expected call count 0, got %u",
                getgroups_count);
    mark_point();

    /* Load the appropriate AUTH symbol, and call it. */

    memset(&authtab, 0, sizeof(authtab));
    authtab.name = sym_name;
    authtab.handler = handle_getgroups;
    authtab.m = &unit_tests_module;
    res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab);
    fail_unless(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name,
                strerror(errno));

    mark_point();

    res = pr_auth_getgroups(p, PR_TEST_AUTH_NAME, &gids, NULL);
    fail_unless(res > 0, "Expected group count 1 for '%s', got %d: %s",
                PR_TEST_AUTH_NAME, res, strerror(errno));
    fail_unless(getgroups_count == 1, "Expected call count 1, got %u",
                getgroups_count);

    res = pr_auth_getgroups(p, "other", &gids, NULL);
    fail_unless(res < 0, "Found groups for 'other' unexpectedly");
    fail_unless(getgroups_count == 2, "Expected call count 2, got %u",
                getgroups_count);

    pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &unit_tests_module);
}
Esempio n. 12
0
int pr_module_load_conftab(module *m) {
  if (m == NULL ||
      m->name == NULL) {
    errno = EINVAL;
    return -1;
  }

  if (m->conftable) {
    conftable *conftab;

    for (conftab = m->conftable; conftab->directive; conftab++) {
      conftab->m = m;

      if (pr_stash_add_symbol(PR_SYM_CONF, conftab) < 0) {
        return -1;
      }
    }
  }

  return 0;
}
Esempio n. 13
0
int pr_module_load_authtab(module *m) {
  if (m == NULL ||
      m->name == NULL) {
    errno = EINVAL;
    return -1;
  }

  if (m->authtable) {
    authtable *authtab;

    for (authtab = m->authtable; authtab->name; authtab++) {
      authtab->m = m;

      if (pr_stash_add_symbol(PR_SYM_AUTH, authtab) < 0) {
        return -1;
      }
    }
  }

  return 0;
}
Esempio n. 14
0
END_TEST

START_TEST (auth_cache_uid2name_failed_test) {
    int res;
    const char *name;
    authtable authtab;
    char *sym_name = "uid2name";

    /* Load the appropriate AUTH symbol, and call it. */

    memset(&authtab, 0, sizeof(authtab));
    authtab.name = sym_name;
    authtab.handler = decline_uid2name;
    authtab.m = &unit_tests_module;
    res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab);
    fail_unless(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name,
                strerror(errno));

    mark_point();

    name = pr_auth_uid2name(p, PR_TEST_AUTH_UID);
    fail_unless(name != NULL, "Expected name, got null");
    fail_unless(strcmp(name, PR_TEST_AUTH_UID_STR) == 0,
                "Expected name '%s', got '%s'", PR_TEST_AUTH_UID_STR, name);
    fail_unless(uid2name_count == 1, "Expected call count 1, got %u",
                uid2name_count);

    /* Call again; the call counter should NOT increment due to caching. */

    name = pr_auth_uid2name(p, PR_TEST_AUTH_UID);
    fail_unless(name != NULL, "Expected name, got null");
    fail_unless(strcmp(name, PR_TEST_AUTH_UID_STR) == 0,
                "Expected name '%s', got '%s'", PR_TEST_AUTH_UID_STR, name);
    fail_unless(uid2name_count == 1, "Expected call count 1, got %u",
                uid2name_count);

    pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &unit_tests_module);
}
Esempio n. 15
0
END_TEST

START_TEST (stash_remove_symbol_test) {
  int res;
  conftable conftab;
  cmdtable cmdtab, hooktab;
  authtable authtab;

  res = pr_stash_remove_symbol(0, NULL, NULL);
  fail_unless(res == -1, "Failed to handle null arguments");
  fail_unless(errno == EINVAL, "Failed to set errno to EINVAL (got %d)",
    errno);

  res = pr_stash_remove_symbol(0, "foo", NULL);
  fail_unless(res == -1, "Failed to handle bad symbol type");
  fail_unless(errno == EINVAL, "Failed to set errno to EINVAL (got %d)",
    errno);

  res = pr_stash_remove_symbol(PR_SYM_CONF, "foo", NULL);
  fail_unless(res == 0, "Expected %d, got %d", 0, res);

  memset(&conftab, 0, sizeof(conftab));
  conftab.directive = pstrdup(p, "foo");
  res = pr_stash_add_symbol(PR_SYM_CONF, &conftab);
  fail_unless(res == 0, "Failed to add CONF symbol: %s", strerror(errno));

  res = pr_stash_add_symbol(PR_SYM_CONF, &conftab);
  fail_unless(res == 0, "Failed to add CONF symbol: %s", strerror(errno));

  res = pr_stash_remove_symbol(PR_SYM_CONF, "foo", NULL);
  fail_unless(res == 2, "Expected %d, got %d", 2, res);

  memset(&cmdtab, 0, sizeof(cmdtab));
  cmdtab.command = pstrdup(p, "foo");
  res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab);
  fail_unless(res == 0, "Failed to add CMD symbol: %s", strerror(errno));

  res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab);
  fail_unless(res == 0, "Failed to add CMD symbol: %s", strerror(errno));

  res = pr_stash_remove_symbol(PR_SYM_CMD, "foo", NULL);
  fail_unless(res == 2, "Expected %d, got %d", 2, res);

  memset(&authtab, 0, sizeof(authtab));
  authtab.name = pstrdup(p, "foo");
  res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab);
  fail_unless(res == 0, "Failed to add AUTH symbol: %s", strerror(errno));

  res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab);
  fail_unless(res == 0, "Failed to add AUTH symbol: %s", strerror(errno));

  res = pr_stash_remove_symbol(PR_SYM_AUTH, "foo", NULL);
  fail_unless(res == 2, "Expected %d, got %d", 2, res);

  memset(&hooktab, 0, sizeof(hooktab));
  hooktab.command = pstrdup(p, "foo");
  res = pr_stash_add_symbol(PR_SYM_HOOK, &hooktab);
  fail_unless(res == 0, "Failed to add HOOK symbol: %s", strerror(errno));

  res = pr_stash_add_symbol(PR_SYM_HOOK, &hooktab);
  fail_unless(res == 0, "Failed to add HOOK symbol: %s", strerror(errno));

  res = pr_stash_remove_symbol(PR_SYM_HOOK, "foo", NULL);
  fail_unless(res == 2, "Expected %d, got %d", 2, res);
}
Esempio n. 16
0
END_TEST

START_TEST (stash_get_symbol_test) {
  int res;
  void *sym;
  conftable conftab;
  cmdtable cmdtab, hooktab;
  authtable authtab;

  sym = pr_stash_get_symbol(0, NULL, NULL, NULL);
  fail_unless(sym == NULL, "Failed to handle null arguments");
  fail_unless(errno == EINVAL, "Failed to set errno to EINVAL (got %d)",
    errno);

  sym = pr_stash_get_symbol(0, "foo", NULL, NULL);
  fail_unless(sym == NULL, "Failed to handle bad type argument");
  fail_unless(errno == EINVAL, "Failed to set errno to EINVAL (got %d)",
    errno);

  sym = pr_stash_get_symbol(PR_SYM_CONF, "foo", NULL, NULL);
  fail_unless(sym == NULL, "Failed to handle nonexistent CONF symbol");
  fail_unless(errno == ENOENT, "Failed to set errno to ENOENT (got %d)",
    errno);

  sym = pr_stash_get_symbol(PR_SYM_CMD, "foo", NULL, NULL);
  fail_unless(sym == NULL, "Failed to handle nonexistent CMD symbol");
  fail_unless(errno == ENOENT, "Failed to set errno to ENOENT (got %d)",
    errno);

  sym = pr_stash_get_symbol(PR_SYM_AUTH, "foo", NULL, NULL);
  fail_unless(sym == NULL, "Failed to handle nonexistent AUTH symbol");
  fail_unless(errno == ENOENT, "Failed to set errno to ENOENT (got %d)",
    errno);

  sym = pr_stash_get_symbol(PR_SYM_HOOK, "foo", NULL, NULL);
  fail_unless(sym == NULL, "Failed to handle nonexistent HOOK symbol");
  fail_unless(errno == ENOENT, "Failed to set errno to ENOENT (got %d)",
    errno);

  memset(&conftab, 0, sizeof(conftab));
  conftab.directive = pstrdup(p, "foo");
  res = pr_stash_add_symbol(PR_SYM_CONF, &conftab);
  fail_unless(res == 0, "Failed to add CONF symbol: %s", strerror(errno));

  sym = pr_stash_get_symbol(PR_SYM_CONF, "foo", NULL, NULL);
  fail_unless(sym != NULL, "Failed to get CONF symbol: %s", strerror(errno));
  fail_unless(sym == &conftab, "Expected %p, got %p", &conftab, sym);

  sym = pr_stash_get_symbol(PR_SYM_CONF, "foo", sym, NULL);
  fail_unless(sym == NULL, "Unexpectedly found CONF symbol");
  fail_unless(errno == ENOENT, "Failed to set errno to ENOENT (got %d)",
    errno);

  memset(&cmdtab, 0, sizeof(cmdtab));
  cmdtab.command = pstrdup(p, "foo");
  res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab);
  fail_unless(res == 0, "Failed to add CMD symbol: %s", strerror(errno));

  sym = pr_stash_get_symbol(PR_SYM_CMD, "foo", NULL, NULL);
  fail_unless(sym != NULL, "Failed to get CMD symbol: %s", strerror(errno));
  fail_unless(sym == &cmdtab, "Expected %p, got %p", &cmdtab, sym);

  sym = pr_stash_get_symbol(PR_SYM_CMD, "foo", sym, NULL);
  fail_unless(sym == NULL, "Unexpectedly found CMD symbol");
  fail_unless(errno == ENOENT, "Failed to set errno to ENOENT (got %d)",
    errno);

  memset(&authtab, 0, sizeof(authtab));
  authtab.name = pstrdup(p, "foo");
  res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab);
  fail_unless(res == 0, "Failed to add AUTH symbol: %s", strerror(errno));

  sym = pr_stash_get_symbol(PR_SYM_AUTH, "foo", NULL, NULL);
  fail_unless(sym != NULL, "Failed to get AUTH symbol: %s", strerror(errno));
  fail_unless(sym == &authtab, "Expected %p, got %p", &authtab, sym);

  sym = pr_stash_get_symbol(PR_SYM_AUTH, "foo", sym, NULL);
  fail_unless(sym == NULL, "Unexpectedly found AUTH symbol");
  fail_unless(errno == ENOENT, "Failed to set errno to ENOENT (got %d)",
    errno);

  memset(&hooktab, 0, sizeof(hooktab));
  hooktab.command = pstrdup(p, "foo");
  res = pr_stash_add_symbol(PR_SYM_HOOK, &hooktab);
  fail_unless(res == 0, "Failed to add HOOK symbol: %s", strerror(errno));

  sym = pr_stash_get_symbol(PR_SYM_HOOK, "foo", NULL, NULL);
  fail_unless(sym != NULL, "Failed to get HOOK symbol: %s", strerror(errno));
  fail_unless(sym == &hooktab, "Expected %p, got %p", &hooktab, sym);

  sym = pr_stash_get_symbol(PR_SYM_HOOK, "foo", sym, NULL);
  fail_unless(sym == NULL, "Unexpectedly found HOOK symbol");
  fail_unless(errno == ENOENT, "Failed to set errno to ENOENT (got %d)",
    errno);
}
Esempio n. 17
0
END_TEST

START_TEST (stash_remove_cmd_test) {
  int res;
  cmdtable cmdtab, cmdtab2;

  res = pr_stash_remove_cmd(NULL, NULL, 0, NULL, -1);
  fail_unless(res == -1, "Failed to handle null arguments");
  fail_unless(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)",
    errno, strerror(errno));

  res = pr_stash_remove_cmd("foo", NULL, 0, NULL, -1);
  fail_unless(res == 0, "Expected %d, got %d", 0, res);

  memset(&cmdtab, 0, sizeof(cmdtab));
  cmdtab.command = pstrdup(p, "foo");
  res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab);
  fail_unless(res == 0, "Failed to add CMD symbol: %s", strerror(errno));

  memset(&cmdtab2, 0, sizeof(cmdtab2));
  cmdtab2.command = pstrdup(p, "foo");
  res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab2);
  fail_unless(res == 0, "Failed to add CMD symbol: %s", strerror(errno));

  res = pr_stash_remove_cmd("foo", NULL, 0, NULL, -1);
  fail_unless(res == 2, "Expected %d, got %d", 2, res);

  /* Remove only the PRE_CMD cmd handlers */
  mark_point();
  memset(&cmdtab, 0, sizeof(cmdtab));
  cmdtab.command = pstrdup(p, "foo");
  cmdtab.cmd_type = PRE_CMD;
  res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab);
  fail_unless(res == 0, "Failed to add CMD symbol: %s", strerror(errno));

  memset(&cmdtab2, 0, sizeof(cmdtab2));
  cmdtab2.command = pstrdup(p, "foo");
  cmdtab2.cmd_type = CMD;
  res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab2);
  fail_unless(res == 0, "Failed to add CMD symbol: %s", strerror(errno));

  mark_point();
  res = pr_stash_remove_cmd("foo", NULL, PRE_CMD, NULL, -1);
  fail_unless(res == 1, "Expected %d, got %d", 1, res);
  (void) pr_stash_remove_symbol(PR_SYM_CMD, "foo", NULL);

  /* Remove only the G_WRITE cmd handlers */
  mark_point();
  memset(&cmdtab, 0, sizeof(cmdtab));
  cmdtab.command = pstrdup(p, "foo");
  cmdtab.group = G_WRITE;
  res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab);
  fail_unless(res == 0, "Failed to add CMD symbol: %s", strerror(errno));

  memset(&cmdtab2, 0, sizeof(cmdtab2));
  cmdtab2.command = pstrdup(p, "foo");
  res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab2);
  fail_unless(res == 0, "Failed to add CMD symbol: %s", strerror(errno));

  mark_point();
  res = pr_stash_remove_cmd("foo", NULL, 0, G_WRITE, -1);
  fail_unless(res == 1, "Expected %d, got %d", 1, res);
  (void) pr_stash_remove_symbol(PR_SYM_CMD, "foo", NULL);

  /* Remove only the CL_SFTP cmd handlers */
  mark_point();
  memset(&cmdtab, 0, sizeof(cmdtab));
  cmdtab.command = pstrdup(p, "foo");
  cmdtab.cmd_class = CL_SFTP;
  res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab);
  fail_unless(res == 0, "Failed to add CMD symbol: %s", strerror(errno));

  memset(&cmdtab2, 0, sizeof(cmdtab2));
  cmdtab2.command = pstrdup(p, "foo");
  cmdtab2.cmd_class = CL_MISC;
  res = pr_stash_add_symbol(PR_SYM_CMD, &cmdtab2);
  fail_unless(res == 0, "Failed to add CMD symbol: %s", strerror(errno));

  mark_point();
  res = pr_stash_remove_cmd("foo", NULL, 0, NULL, CL_SFTP);
  fail_unless(res == 1, "Expected %d, got %d", 1, res);
  (void) pr_stash_remove_symbol(PR_SYM_CMD, "foo", NULL);
}