void hs_load_output_plugins(hs_output_plugins *plugins, const hs_config *cfg, bool dynamic) { char lpath[HS_MAX_PATH]; char rpath[HS_MAX_PATH]; if (!hs_get_fqfn(cfg->load_path, hs_output_dir, lpath, sizeof(lpath))) { hs_log(NULL, g_module, 0, "load path too long"); exit(EXIT_FAILURE); } if (!hs_get_fqfn(cfg->run_path, hs_output_dir, rpath, sizeof(rpath))) { hs_log(NULL, g_module, 0, "run path too long"); exit(EXIT_FAILURE); } const char *dir = dynamic ? lpath : rpath; DIR *dp = opendir(dir); if (dp == NULL) { hs_log(NULL, g_module, 0, "%s: %s", dir, strerror(errno)); exit(EXIT_FAILURE); } if (dynamic) process_lua(plugins, lpath, rpath, dp); struct dirent *entry; while ((entry = readdir(dp))) { if (dynamic) { int ret = hs_process_load_cfg(lpath, rpath, entry->d_name); switch (ret) { case 0: remove_from_output_plugins(plugins, entry->d_name); break; case 1: // proceed to load break; default: // ignore continue; } } hs_sandbox_config sbc; if (hs_load_sandbox_config(rpath, entry->d_name, &sbc, &cfg->opd, 'o')) { hs_output_plugin *p = create_output_plugin(plugins->mmb, cfg, &sbc); if (p) { p->plugins = plugins; hs_init_input(&p->input, cfg->max_message_size, cfg->output_path, p->name); hs_init_input(&p->analysis, cfg->max_message_size, cfg->output_path, p->name); add_to_output_plugins(plugins, p); } else { hs_log(NULL, g_module, 3, "%s create_output_plugin failed", sbc.cfg_name); } hs_free_sandbox_config(&sbc); } } closedir(dp); }
static void init_analysis_thread(hs_analysis_plugins* plugins, int tid) { hs_analysis_thread* at = &plugins->list[tid]; at->plugins = plugins; at->list = NULL; at->msg = NULL; if (pthread_mutex_init(&at->list_lock, NULL)) { perror("list_lock pthread_mutex_init failed"); exit(EXIT_FAILURE); } if (pthread_mutex_init(&at->cp_lock, NULL)) { perror("cp_lock pthread_mutex_init failed"); exit(EXIT_FAILURE); } at->cp.id = 0; at->cp.offset = 0; at->current_t = 0; at->list_cap = 0; at->list_cnt = 0; at->tid = tid; at->matched = false; char name[255]; int n = snprintf(name, sizeof name, "%s%d", hs_analysis_dir, tid); if (n < 0 || n >= (int)sizeof name) { hs_log(g_module, 0, "name exceeded the buffer length: %s%d", hs_analysis_dir, tid); exit(EXIT_FAILURE); } hs_init_input(&at->input, plugins->cfg->max_message_size, plugins->cfg->output_path, name); }
void hs_load_output_plugins(hs_output_plugins* plugins, const hs_config* cfg, bool dynamic) { char lpath[HS_MAX_PATH]; char rpath[HS_MAX_PATH]; if (!hs_get_fqfn(cfg->load_path, hs_output_dir, lpath, sizeof(lpath))) { hs_log(g_module, 0, "load path too long"); exit(EXIT_FAILURE); } if (!hs_get_fqfn(cfg->run_path, hs_output_dir, rpath, sizeof(rpath))) { hs_log(g_module, 0, "run path too long"); exit(EXIT_FAILURE); } const char* dir = dynamic ? lpath : rpath; DIR* dp = opendir(dir); if (dp == NULL) { hs_log(g_module, 0, "%s: %s", dir, strerror(errno)); exit(EXIT_FAILURE); } if (dynamic) process_lua(plugins, lpath, rpath, dp); struct dirent* entry; while ((entry = readdir(dp))) { if (dynamic) { int ret = hs_process_load_cfg(lpath, rpath, entry->d_name); switch (ret) { case 0: remove_from_output_plugins(plugins, entry->d_name); break; case 1: // proceed to load break; default: // ignore continue; } } hs_sandbox_config sbc; if (hs_load_sandbox_config(rpath, entry->d_name, &sbc, &cfg->opd, HS_SB_TYPE_OUTPUT)) { hs_output_plugin* p = create_output_plugin(cfg, &sbc); if (p) { p->plugins = plugins; hs_init_input(&p->input, cfg->max_message_size, cfg->output_path, p->sb->name); hs_init_input(&p->analysis, cfg->max_message_size, cfg->output_path, p->sb->name); p->sb->mm = hs_create_message_matcher(plugins->mmb, sbc.message_matcher); int ret = hs_init_output_sandbox(p->sb); if (!p->sb->mm || ret) { if (!p->sb->mm) { hs_log(g_module, 3, "file: %s invalid message_matcher: %s", p->sb->name, sbc.message_matcher); } else { hs_log(g_module, 3, "lsb_init() file: %s received: %d %s", p->sb->name, ret, lsb_get_error(p->sb->lsb)); } free_output_plugin(p); free(p); p = NULL; hs_free_sandbox_config(&sbc); continue; } add_to_output_plugins(plugins, p); } hs_free_sandbox_config(&sbc); } } closedir(dp); }