-/* @(#) $Id: config.c,v 1.25 2009/08/27 18:17:41 dcid Exp $ */
+/* @(#) $Id: ./src/config/config.c, 2011/11/01 dcid Exp $
+ */
/* Copyright (C) 2009 Trend Micro Inc.
* All right reserved.
*
* This program is a free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public
- * License (version 3) as published by the FSF - Free Software
+ * License (version 2) as published by the FSF - Free Software
* Foundation
*/
/* Read the main elements of the configuration.
*/
-int read_main_elements(OS_XML xml, int modules,
- XML_NODE node,
- void *d1,
+int read_main_elements(OS_XML xml, int modules,
+ XML_NODE node,
+ void *d1,
void *d2)
{
int i = 0;
- char *osglobal = "global";
- char *osrules = "rules";
- char *ossyscheck = "syscheck";
- char *osrootcheck = "rootcheck";
- char *osalerts = "alerts";
- char *osemailalerts = "email_alerts";
- char *osdbd = "database_output";
- char *oscsyslogd = "syslog_output";
- char *oscagentless = "agentless";
- char *oslocalfile = "localfile";
- char *osremote = "remote";
- char *osclient = "client";
- char *oscommand = "command";
- char *osactive_response = "active-response";
-
-
+ char *osglobal = "global"; /*Server Config*/
+ char *osrules = "rules"; /*Server Config*/
+ char *ossyscheck = "syscheck"; /*Agent Config*/
+ char *osrootcheck = "rootcheck"; /*Agent Config*/
+ char *osalerts = "alerts"; /*Server Config*/
+ char *osemailalerts = "email_alerts"; /*Server Config*/
+ char *osdbd = "database_output"; /*Server Config*/
+ char *oscsyslogd = "syslog_output"; /*Server Config*/
+ char *oscagentless = "agentless"; /*Server Config*/
+ char *oslocalfile = "localfile"; /*Agent Config*/
+ char *osremote = "remote"; /*Agent Config*/
+ char *osclient = "client"; /*Agent Config*/
+ char *oscommand = "command"; /*? Config*/
+ char *osreports = "reports"; /*Server Config*/
+ char *osactive_response = "active-response"; /*Agent Config*/
+
+
while(node[i])
{
XML_NODE chld_node = NULL;
-
+
chld_node = OS_GetElementsbyNode(&xml,node[i]);
-
+
if(!node[i]->element)
{
merror(XML_ELEMNULL, ARGV0);
}
else if(strcmp(node[i]->element, osglobal) == 0)
{
- if(((modules & CGLOBAL) || (modules & CMAIL))
+ if(((modules & CGLOBAL) || (modules & CMAIL))
&& (Read_Global(chld_node, d1, d2) < 0))
return(OS_INVALID);
}
if((modules & CSYSCHECK) && (Read_Syscheck(chld_node, d1,d2) < 0))
return(OS_INVALID);
if((modules & CGLOBAL) && (Read_GlobalSK(chld_node, d1, d2) < 0))
- return(OS_INVALID);
+ return(OS_INVALID);
}
else if(strcmp(node[i]->element, osrootcheck) == 0)
{
if((modules & CAR)&&(ReadActiveResponses(chld_node, d1, d2)<0))
return(OS_INVALID);
}
+ else if(strcmp(node[i]->element, osreports) == 0)
+ {
+ if((modules & CREPORTS)&&(Read_CReports(chld_node, d1, d2)<0))
+ return(OS_INVALID);
+ }
else
{
merror(XML_INVELEM, ARGV0, node[i]->element);
return(OS_INVALID);
}
-
+
+ //printf("before\n");
OS_ClearNode(chld_node);
+ //printf("after\n");
i++;
}
/* ReadConfig(int modules, char *cfgfile)
* Read the config files
*/
-int ReadConfig(int modules, char *cfgfile, void *d1, void *d2)
+int ReadConfig(int modules, char *cfgfile, void *d1, void *d2)
{
int i;
OS_XML xml;
char *xml_start_ossec = "ossec_config";
char *xml_start_agent = "agent_config";
+ /* Attributes of the <agent_config> tag */
char *xml_agent_name = "name";
char *xml_agent_os = "os";
char *xml_agent_overwrite = "overwrite";
-
+ /* cmoraes */
+ char *xml_agent_profile = "profile";
+
if(OS_ReadXML(cfgfile,&xml) < 0)
{
if(modules & CAGENT_CONFIG)
{
+ #ifndef CLIENT
+ merror(XML_ERROR, ARGV0, cfgfile, xml.err, xml.err_line);
+ #endif
}
else
{
}
return(OS_INVALID);
}
-
+
node = OS_GetElementsbyNode(&xml, NULL);
if(!node)
return(OS_INVALID);
}
- OS_ClearNode(chld_node);
+ OS_ClearNode(chld_node);
}
}
else if((modules & CAGENT_CONFIG) &&
/* Checking if this is specific to any agent. */
if(node[i]->attributes && node[i]->values)
- {
+ {
while(node[i]->attributes[attrs] && node[i]->values[attrs])
{
+ /* Checking if there is an "name=" attribute */
if(strcmp(xml_agent_name, node[i]->attributes[attrs]) == 0)
{
+ #ifdef CLIENT
char *agentname = os_read_agent_name();
if(!agentname)
}
free(agentname);
}
+ #endif
}
else if(strcmp(xml_agent_os, node[i]->attributes[attrs]) == 0)
{
+ #ifdef CLIENT
char *agentos = getuname();
if(agentos)
passed_agent_test = 0;
merror("%s: ERROR: Unable to retrieve uname.", ARGV0);
}
+ #endif
}
+ else if(strcmp(xml_agent_profile, node[i]->attributes[attrs]) == 0)
+ {
+ #ifdef CLIENT
+ char *agentprofile = os_read_agent_profile();
+ debug2("Read agent config profile name [%s]", agentprofile);
+
+ if(!agentprofile)
+ {
+ passed_agent_test = 0;
+ }
+ else
+ {
+ /* match the profile name of this <agent_config> section
+ * with a comma separated list of values in agent's
+ * <config-profile> tag.
+ */
+ if(!OS_Match2(node[i]->values[attrs], agentprofile))
+ {
+ passed_agent_test = 0;
+ debug2("[%s] did not match agent config profile name [%s]",
+ node[i]->values[attrs], agentprofile);
+ }
+ else
+ {
+ debug2("Matched agent config profile name [%s]", agentprofile);
+ }
+ free(agentprofile);
+ }
+ #endif
+ }
+ /* cmoraes: end add */
else if(strcmp(xml_agent_overwrite, node[i]->attributes[attrs]) == 0)
{
}
attrs++;
}
}
+ #ifdef CLIENT
+ else
+ {
+ debug2("agent_config element does not have any attributes.");
+
+ /* if node does not have any attributes, it is a generic config block.
+ * check if agent has a profile name
+ * if agent does not have profile name, then only read this generic
+ * agent_config block
+ */
+
+ if (!os_read_agent_profile())
+ {
+ debug2("but agent has a profile name.");
+ passed_agent_test = 0;
+ }
+ }
+ #endif
-
/* Main element does not need to have any child */
if(chld_node)
{
return(OS_INVALID);
}
- OS_ClearNode(chld_node);
+ OS_ClearNode(chld_node);
}
}
else
}
i++;
}
-
+
/* Clearing node and xml */
OS_ClearNode(node);
OS_ClearXML(&xml);