return 0;
}
+bool AppInfoManager::configured()
+{
+ return !app_info_table.empty();
+}
+
AppInfoTableEntry* AppInfoManager::get_app_info_entry(AppId appId, const
AppInfoTable& lookup_table)
{
if (entry)
entry->flags |= APPINFO_FLAG_ACTIVE;
else
- WarningMessage("AppInfo: AppId %d has no entry in application info table\n", appId);
+ ParseWarning(WARN_PLUGINS, "appid: no entry in %s for %d", APP_MAPPING_FILE, appId);
}
void AppInfoManager::load_appid_config(AppIdModuleConfig* config, const char* path)
void AppInfoManager::init_appid_info_table(AppIdModuleConfig* mod_config)
{
+ if ( !mod_config->app_detector_dir )
+ {
+ AppIdPegCounts::set_detectors_configured();
+ return; // no lua detectors, no rule support, already warned
+ }
+
char filepath[PATH_MAX];
snprintf(filepath, sizeof(filepath), "%s/odp/%s", mod_config->app_detector_dir,
APP_MAPPING_FILE);
FILE* tableFile = fopen(filepath, "r");
- if ( tableFile )
+ if ( !tableFile )
+ {
+ ParseError("appid: could not open %s", filepath);
+ }
+ else
{
char buf[MAX_TABLE_LINE_LEN];
USR_CONFIG_FILE);
load_appid_config (mod_config, filepath);
}
- else
- {
- ParseWarning(WARN_RULES,
- "Could not open AppMapping Table file: %s, no AppId rule support", filepath);
- }
AppIdPegCounts::set_detectors_configured();
}
void set_app_info_active(AppId);
const char* get_app_name(AppId);
int32_t get_appid_by_name(const char* app_name);
+ bool configured();
void set_app_info_flags(AppId appId, unsigned flags)
{
bool AppIdModule::end(const char*, int, SnortConfig*)
{
- if ( (config == nullptr) || (config->app_detector_dir == nullptr) )
- ParseWarning(WARN_CONF,"no app_detector_dir present. No support for appid in rules.\n");
+ assert(config);
+ if ( !config->app_detector_dir )
+ {
+ ParseWarning(WARN_CONF,
+ "appid: app_detector_dir not configured; no support for appids in rules.\n");
+ }
return true;
}
AppInfoTableEntry* pEntry = AppInfoManager::get_instance().get_app_info_entry(appId);
if (!pEntry)
{
- ParseWarning(WARN_RULES,
- "AppId: ID to Name mapping entry missing for AppId: %d. No rule support for this ID.",
- appId);
+ if ( AppInfoManager::get_instance().configured() )
+ {
+ ParseWarning(WARN_RULES,
+ "appid: no entry for %d in appMapping.data; no rule support for this ID.",
+ appId);
+ }
return;
}
extractsInfo &= (APPINFO_FLAG_CLIENT_ADDITIONAL | APPINFO_FLAG_CLIENT_USER);
// release the reference of the userdata on the lua side
if ( detector_user_data_ref != LUA_REFNIL )
luaL_unref(my_lua_state, LUA_REGISTRYINDEX, detector_user_data_ref);
+ lua_close(my_lua_state);
}
int LuaStateDescriptor::lua_validate(AppIdDiscoveryArgs& args)
static bool logged = false;
if ( !logged )
{
- ErrorMessage("Error can not create new luaState\n");
+ ErrorMessage("Error - appid: can not create new luaState\n");
logged = true;
}
return;
if ( luaL_loadfile(L, detector_filename) || lua_pcall(L, 0, 0, 0) )
{
- ErrorMessage("Error loading Lua detector: %s : %s\n", detector_filename, lua_tostring(L,
- -1));
+ ErrorMessage("Error - appid: loading Lua detector: %s : %s\n",
+ detector_filename, lua_tostring(L, -1));
lua_close(L);
return;
}
globfree(&globs);
}
else if (rval == GLOB_NOMATCH)
- ParseWarning(WARN_CONF, "No lua detectors found in directory '%s'\n", pattern);
+ ParseWarning(WARN_CONF, "appid: no lua detectors found in directory '%s'", pattern);
else
- ParseWarning(WARN_CONF, "Error reading lua detectors directory '%s'. Error Code: %d\n",
+ ParseWarning(WARN_CONF,
+ "appid: error reading lua detectors directory '%s'. Error Code: %d",
pattern, rval);
}
void LuaDetectorManager::initialize_lua_detectors()
{
char path[PATH_MAX];
+ const char* dir = config.mod_config->app_detector_dir;
- snprintf(path, sizeof(path), "%s/odp/lua", config.mod_config->app_detector_dir);
+ if ( !dir )
+ return;
+
+ snprintf(path, sizeof(path), "%s/odp/lua", dir);
load_lua_detectors(path, false);
- snprintf(path, sizeof(path), "%s/custom/lua", config.mod_config->app_detector_dir);
+
+ snprintf(path, sizeof(path), "%s/custom/lua", dir);
load_lua_detectors(path, true);
}
AppInfoTableEntry* pEntry = AppInfoManager::get_instance().get_app_info_entry(appId);
if (!pEntry)
{
- ParseWarning(WARN_RULES,
- "AppId: ID to Name mapping entry missing for AppId: %d. No rule support for this ID.",
- appId);
+ if ( AppInfoManager::get_instance().configured() )
+ {
+ ParseWarning(WARN_RULES,
+ "appid: no entry for %d in appMapping.data; no rule support for this ID.",
+ appId);
+ }
return;
}
extractsInfo &= (APPINFO_FLAG_SERVICE_ADDITIONAL | APPINFO_FLAG_SERVICE_UDP_REVERSED);
return nullptr;
}
+bool AppInfoManager::configured()
+{ return false; }
+
// Stubs for service_state.h
ServiceDiscoveryState* AppIdServiceState::get(SfIp const*, IpProtocol, unsigned short, bool)
{
EstimateNumEntries(conf);
if (conf->numEntries <= 0)
{
- ParseWarning(WARN_CONF, "Can't find any whitelist/blacklist entries. "
- "Reputation Preprocessor disabled.\n");
+ ParseWarning(WARN_CONF,
+ "reputation: can't find any whitelist/blacklist entries; disabled.");
return true;
}