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); }
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); }