Ejemplo n.º 1
0
END_TEST

START_TEST (module_load_authtab_test) {
    int res;
    module m;
    authtable authtab[] = {
        { 0, "setpwent", NULL },
        { 0, NULL, NULL }
    };

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

    memset(&m, 0, sizeof(m));

    res = pr_module_load_authtab(&m);
    fail_unless(res < 0, "Failed to handle null module name");
    fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
                strerror(errno), errno);

    m.name = "testsuite";
    res = pr_module_load_authtab(&m);
    fail_unless(res == 0, "Failed to load module authtab: %s", strerror(errno));

    pr_module_unload(&m);
    fail_unless(res == 0, "Failed to unload module: %s", strerror(errno));

    m.authtable = authtab;
    res = pr_module_load_authtab(&m);
    fail_unless(res == 0, "Failed to load module authtab: %s", strerror(errno));

    pr_module_unload(&m);
    fail_unless(res == 0, "Failed to unload module: %s", strerror(errno));
}
Ejemplo n.º 2
0
int pr_module_load(module *m) {
  char buf[256];

  if (m == NULL ||
      m->name == NULL) {
    errno = EINVAL;
    return -1;
  }

  /* Check the API version the module wants to use. */
  if (m->api_version < PR_MODULE_API_VERSION) {
    errno = EACCES;
    return -1;
  }

  /* Do not allow multiple modules with the same name. */
  memset(buf, '\0', sizeof(buf));
  snprintf(buf, sizeof(buf), "mod_%s.c", m->name);
  buf[sizeof(buf)-1] = '\0';

  if (pr_module_get(buf) != NULL) {
    errno = EEXIST;
    return -1;
  }

  /* Invoke the module's initialization routine. */
  if (!m->init ||
      m->init() >= 0) {

    /* Assign a priority to this module. */
    m->priority = curr_module_pri++;

    /* Add the module's config, cmd, and auth tables. */
    if (pr_module_load_conftab(m) < 0) {
      return -1;
    }

    if (pr_module_load_cmdtab(m) < 0) {
      return -1;
    }

    if (pr_module_load_authtab(m) < 0) {
      return -1;
    }

    /* Add the module to the loaded_modules list. */
    if (loaded_modules) {
      m->next = loaded_modules;
      loaded_modules->prev = m;
    }

    loaded_modules = m;

    /* Generate an event. */
    pr_event_generate("core.module-load", buf);
    return 0;
  }

  errno = EPERM;
  return -1;
}