Load host OS info from the configuration.

remotes/origin/master-1.0.x
Jason Ish 15 years ago committed by Victor Julien
parent 297001c6d9
commit 5c3ab2b73f

@ -629,6 +629,9 @@ int main(int argc, char **argv)
* logging module. */
SCLogLoadConfig();
/* Load the Host-OS lookup. */
SCHInfoLoadFromConfig();
if (run_mode == MODE_UNKNOWN) {
usage(argv[0]);
exit(EXIT_FAILURE);

@ -10,6 +10,8 @@
#include "stream-tcp-private.h"
#include "stream-tcp-reassemble.h"
#include "conf.h"
#include "util-enum.h"
#include "util-unittest.h"
@ -366,6 +368,32 @@ void SCHInfoCleanResources(void)
return;
}
/**
* \brief Load the host os policy information from the configuration.
*/
void SCHInfoLoadFromConfig(void)
{
ConfNode *root = ConfGetNode("host-os-policy");
if (root == NULL)
return;
ConfNode *policy;
TAILQ_FOREACH(policy, &root->head, next) {
ConfNode *host;
TAILQ_FOREACH(host, &policy->head, next) {
int is_ipv4 = 1;
if (index(host->val, ':') != NULL)
is_ipv4 = 0;
if (SCHInfoAddHostOSInfo(policy->name, host->val, is_ipv4) == -1) {
SCLogError(SC_ERR_INVALID_ARGUMENT,
"Failed to add host \"%s\" with policy \"%s\" to host "
"info database", host->val, policy->name);
exit(EXIT_FAILURE);
}
}
}
}
/*------------------------------------Unit_Tests------------------------------*/
#ifdef UNITTESTS
@ -954,6 +982,36 @@ int SCHInfoTestValidIPV4Address09(void)
return result;
}
/**
* \test Check the loading of host info from a configuration file.
*/
int SCHInfoTestLoadFromConfig01(void)
{
char config[] = "\
%YAML 1.1\n\
---\n\
host-os-policy:\n\
windows: [10.0.0.0/8, 192.168.1.0/24]\n\
linux: [10.0.0.5/32]\n\
\n";
ConfCreateContextBackup();
ConfInit();
ConfYamlLoadString(config, strlen(config));
SCHInfoLoadFromConfig();
if (SCHInfoGetHostOSFlavour("10.0.0.4") != OS_POLICY_WINDOWS)
return 0;
if (SCHInfoGetHostOSFlavour("10.0.0.5") != OS_POLICY_LINUX)
return 0;
if (SCHInfoGetHostOSFlavour("192.168.1.1") != OS_POLICY_WINDOWS)
return 0;
ConfDeInit();
ConfRestoreContextBackup();
return 1;
}
#endif /* UNITTESTS */
@ -980,6 +1038,8 @@ void SCHInfoRegisterTests(void)
SCHInfoTestValidIPV6Address08, 1);
UtRegisterTest("SCHInfoTestValidIPV4Address09",
SCHInfoTestValidIPV4Address09, 1);
UtRegisterTest("SCHInfoTestLoadFromConfig01",
SCHInfoTestLoadFromConfig01, 1);
#endif /* UNITTESTS */

@ -13,6 +13,7 @@ int SCHInfoGetHostOSFlavour(char *);
int SCHInfoGetIPv4HostOSFlavour(uint8_t *);
int SCHInfoGetIPv6HostOSFlavour(uint8_t *);
void SCHInfoCleanResources(void);
void SCHInfoLoadFromConfig(void);
void SCHInfoRegisterTests(void);
#endif /* __UTIL_HOST_OS_INFO_H__ */

@ -364,3 +364,17 @@ vars:
ORACLE_PORTS: 1521
SSH_PORTS: 22
host-os-policy:
bsd: []
old_linux: []
linux: [10.0.0.0/8, 192.168.1.100, "8762:2352:6241:7245:E000:0000:0000:0000"]
solaris: ["::1"]
hpux10: []
hpux11: []
irix: []
macos: []
windows: [192.168.1.0/24, 192.168.2.0/24]
vista: []
windows2k3: []

Loading…
Cancel
Save