int snmp_mib_init(void) { /* Iterate through all of the MIBs, deactivating some of them * if the related module is not loaded. */ if (pr_module_exists("mod_tls.c") == TRUE) { register unsigned int i; /* Handle mod_tls-related MIBs. */ for (i = 1; snmp_mibs[i].mib_oidlen != 0; i++) { int db_id = snmp_db_get_field_db_id(snmp_mibs[i].db_field); switch (db_id) { case SNMP_DB_ID_TLS: snmp_mibs[i].mib_enabled = TRUE; break; } } } if (pr_module_exists("mod_sftp.c") == TRUE) { register unsigned int i; /* Handle mod_sftp-related MIBs. */ for (i = 1; snmp_mibs[i].mib_oidlen != 0; i++) { int db_id = snmp_db_get_field_db_id(snmp_mibs[i].db_field); switch (db_id) { case SNMP_DB_ID_SSH: case SNMP_DB_ID_SFTP: case SNMP_DB_ID_SCP: snmp_mibs[i].mib_enabled = TRUE; break; } } } if (pr_module_exists("mod_ban.c") == TRUE) { register unsigned int i; /* Handle mod_ban-related MIBs. */ for (i = 1; snmp_mibs[i].mib_oidlen != 0; i++) { int db_id = snmp_db_get_field_db_id(snmp_mibs[i].db_field); switch (db_id) { case SNMP_DB_ID_BAN: snmp_mibs[i].mib_enabled = TRUE; break; } } } return 0; }
END_TEST START_TEST (module_exists_test) { unsigned char res; module m; res = pr_module_exists(NULL); fail_unless(res == FALSE, "Failed to handle null argument"); fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, strerror(errno), errno); res = pr_module_exists("mod_foo.c"); fail_unless(res == FALSE, "Failed to handle nonexistent module"); fail_unless(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT, strerror(errno), errno); memset(&m, 0, sizeof(m)); m.name = "bar"; loaded_modules = &m; res = pr_module_exists("mod_foo.c"); fail_unless(res == FALSE, "Failed to handle nonexistent module"); fail_unless(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT, strerror(errno), errno); res = pr_module_exists("mod_bar.c"); fail_unless(res == TRUE, "Failed to detect existing module"); res = pr_module_exists("mod_BAR.c"); fail_unless(res == FALSE, "Failed to handle nonexistent module"); fail_unless(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT, strerror(errno), errno); loaded_modules = NULL; }
static int counter_sess_init(void) { config_rec *c; c = find_config(main_server->conf, CONF_PARAM, "CounterEngine", FALSE); if (c != NULL) { counter_engine = *((int *) c->argv[0]); } if (counter_engine == FALSE) { return 0; } c = find_config(main_server->conf, CONF_PARAM, "CounterLog", FALSE); if (c != NULL) { const char *path = c->argv[0]; if (strcasecmp(path, "none") != 0) { int res, xerrno; PRIVS_ROOT res = pr_log_openfile(path, &counter_logfd, 0660); xerrno = errno; PRIVS_RELINQUISH; if (res < 0) { pr_log_debug(DEBUG2, MOD_COUNTER_VERSION ": error opening CounterLog '%s': %s", path, strerror(xerrno)); counter_logfd = -1; } } } /* Find all CounterFile directives for this vhost, and make sure they * have open handles. We need to do this here, and not in a POST_CMD * PASS handler because of the need to open handles that may be outside * of a chroot. */ c = find_config(main_server->conf, CONF_PARAM, "CounterFile", TRUE); while (c != NULL) { int xerrno = 0; const char *area = NULL, *path; pr_fh_t *fh; struct counter_fh *cfh; pr_signals_handle(); path = c->argv[0]; if (c->parent != NULL) { if (c->parent->config_type == CONF_ANON || c->parent->config_type == CONF_DIR) { area = c->parent->name; } else { (void) pr_log_writefile(counter_logfd, MOD_COUNTER_VERSION, "unhandled configuration parent type (%d) for CounterFile, skipping", c->parent->config_type); c = find_config_next(c, c->next, CONF_PARAM, "CounterFile", TRUE); continue; } } else { /* Toplevel CounterFile directive, in "server config" or <VirtualHost> * sections. */ area = "/"; } PRIVS_ROOT fh = pr_fsio_open(path, O_RDWR|O_CREAT); xerrno = errno; PRIVS_RELINQUISH if (fh == NULL) { pr_log_debug(DEBUG1, MOD_COUNTER_VERSION ": error opening CounterFile '%s': %s", path, strerror(xerrno)); counter_engine = FALSE; if (counter_fhs != NULL) { for (cfh = (struct counter_fh *) counter_fhs->xas_list; cfh; cfh = cfh->next) { (void) pr_fsio_close(cfh->fh); } } return 0; } (void) pr_log_writefile(counter_logfd, MOD_COUNTER_VERSION, "opened CounterFile '%s'", path); if (counter_fhs == NULL) { counter_fhs = xaset_create(counter_pool, NULL); } cfh = pcalloc(counter_pool, sizeof(struct counter_fh)); /* Ignore any trailing slash. */ cfh->arealen = strlen(area); if (cfh->arealen > 1 && area[cfh->arealen-1] == '/') { cfh->arealen--; } cfh->area = pstrndup(counter_pool, area, cfh->arealen); /* Mark any areas that use glob(3) characters. */ if (strpbrk(cfh->area, "[*?") != NULL) { cfh->isglob = TRUE; } cfh->fh = fh; xaset_insert(counter_fhs, (xasetmember_t *) cfh); c = find_config_next(c, c->next, CONF_PARAM, "CounterFile", TRUE); } if (counter_fhs == NULL) { (void) pr_log_writefile(counter_logfd, MOD_COUNTER_VERSION, "no CounterFiles configured, disabling module"); counter_engine = FALSE; return 0; } pr_event_register(&counter_module, "core.exit", counter_exit_ev, NULL); /* If mod_vroot is present, we need to do a little more magic to counter * the mod_vroot magic. */ if (pr_module_exists("mod_vroot.c") == TRUE) { pr_event_register(&counter_module, "core.chroot", counter_chroot_ev, NULL); } return 0; }
static int log_failure_sess_init(void) { config_rec *c; c = find_config(main_server->conf, CONF_PARAM, "FailureLog", FALSE); if (c == NULL) { return 0; } /* XXX Open FailureLog */ /* "Authentication" class */ pr_event_register(&log_failure_module, "mod_auth.authentication-code", log_failure_auth_code_ev, NULL); pr_event_register(&log_failure_module, "mod_auth.empty-password", log_failure_empty_passwd_ev, NULL); pr_event_register(&log_failure_module, "mod_auth.max-login-attempts", log_failure_max_logins_ev, NULL); /* XXX Include AnonRejectPassword? */ /* "Connection" class */ pr_event_register(&log_failure_module, "mod_auth.max-clients", log_failure_max_clients_ev, NULL); pr_event_register(&log_failure_module, "mod_auth.max-clients-per-class", log_failure_max_clients_per_class_ev, NULL); pr_event_register(&log_failure_module, "mod_auth.max-clients-per-host", log_failure_max_clients_per_host_ev, NULL); pr_event_register(&log_failure_module, "mod_auth.max-clients-per-user", log_failure_max_clients_per_user_ev, NULL); pr_event_register(&log_failure_module, "mod_auth.max-connections-per-host", log_failure_max_conns_per_host_ev, NULL); pr_event_register(&log_failure_module, "mod_auth.max-hosts-per-user", log_failure_max_hosts_per_user_ev, NULL); /* XXX "Transfer" class, for failed uploads/downloads/dirlists */ /* "Timeout" class */ pr_event_register(&log_failure_module, "core.timeout-idle", log_failure_timeout_idle_ev, NULL); pr_event_register(&log_failure_module, "core.timeout-login", log_failure_timeout_login_ev, NULL); pr_event_register(&log_failure_module, "core.timeout-no-transfer", log_failure_timeout_noxfer_ev, NULL); pr_event_register(&log_failure_module, "core.timeout-session", log_failure_timeout_session_ev, NULL); pr_event_register(&log_failure_module, "core.timeout-stalled", log_failure_timeout_stalled_ev, NULL); if (pr_module_exists("mod_tls.c") == TRUE) { /* "Connection" class */ pr_event_register(&log_failure_module, "mod_tls.ctrl-handshake-failed", log_failure_tls_ctrl_handshake_err_ev, NULL); pr_event_register(&log_failure_module, "mod_tls.data-handshake-failed", log_failure_tls_data_handshake_err_ev, NULL); pr_event_register(&log_failure_module, "mod_tls.verify-client-failed", log_failure_tls_verify_client_err_ev, NULL); } if (pr_module_exists("mod_sftp.c") == TRUE) { /* "Authentication" class */ pr_event_register(&log_failure_module, "mod_sftp.ssh2.auth-publickey.failed", log_failure_sftp_auth_pubkey_err_ev, NULL); pr_event_register(&log_failure_module, "mod_sftp.ssh2.auth-kbdint.failed", log_failure_sftp_auth_kbdint_err_ev, NULL); pr_event_register(&log_failure_module, "mod_sftp.ssh2.auth-password.failed", log_failure_sftp_auth_passwd_err_ev, NULL); /* "Connection" class */ pr_event_register(&log_failure_module, "mod_sftp.ssh2.kex.failed", log_failure_sftp_kex_err_ev, NULL); } if (pr_module_exists("mod_ban.c") == TRUE) { /* "Connection" class */ pr_event_register(&log_failure_module, "mod_ban.ban-user", log_failure_ban_ban_user_ev, NULL); pr_event_register(&log_failure_module, "mod_ban.ban-host", log_failure_ban_ban_host_ev, NULL); pr_event_register(&log_failure_module, "mod_ban.ban-class", log_failure_ban_ban_class_ev, NULL); } if (pr_module_exists("mod_geoip.c") == TRUE) { /* "Connection" class */ pr_event_register(&log_failure_module, "mod_geoip.connection-denied", log_failure_geoip_denied_ev, NULL); } if (pr_module_exists("mod_wrap.c") == TRUE || pr_module_exists("mod_wrap2.c") == TRUE) { /* "Connection" class */ pr_event_register(&log_failure_module, "mod_wrap.connection-denied", log_failure_wrap_denied_ev, NULL); } return 0; }