new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / config / alerts-config.c
old mode 100755 (executable)
new mode 100644 (file)
index 353ba46..7b86126
@@ -1,5 +1,3 @@
-/*   $OSSEC, alerts-config.c, v0.1, 2005/04/02, Daniel B. Cid$   */
-
 /* Copyright (C) 2009 Trend Micro Inc.
  * All right reserved.
  *
@@ -9,90 +7,77 @@
  * Foundation
  */
 
-/* Functions to handle the configuration files
- */
-
-
 #include "shared.h"
 #include "global-config.h"
+#include "config.h"
 
 
-int Read_Alerts(XML_NODE node, void *configp, void *mailp)
+int Read_Alerts(XML_NODE node, void *configp, __attribute__((unused)) void *mailp)
 {
     int i = 0;
 
     /* XML definitions */
-    char *xml_email_level = "email_alert_level";
-    char *xml_log_level = "log_alert_level";
+    const char *xml_email_level = "email_alert_level";
+    const char *xml_log_level = "log_alert_level";
 
-#ifdef GEOIP
+#ifdef LIBGEOIP_ENABLED
     /* GeoIP */
-    char *xml_log_geoip = "use_geoip";
+    const char *xml_log_geoip = "use_geoip";
 #endif
 
     _Config *Config;
-
     Config = (_Config *)configp;
 
+    if (!Config) {
+        merror("%s: ERROR: Configuration handle is NULL.", __local_name);
+        return (OS_INVALID);
+    }
 
-    while(node[i])
-    {
-        if(!node[i]->element)
-        {
-            merror(XML_ELEMNULL, ARGV0);
-            return(OS_INVALID);
-        }
-        else if(!node[i]->content)
-        {
-            merror(XML_VALUENULL, ARGV0, node[i]->element);
-            return(OS_INVALID);
+    while (node[i]) {
+        if (!node[i]->element) {
+            merror(XML_ELEMNULL, __local_name);
+            return (OS_INVALID);
+        } else if (!node[i]->content) {
+            merror(XML_VALUENULL, __local_name, node[i]->element);
+            return (OS_INVALID);
         }
         /* Mail notification */
-        else if(strcmp(node[i]->element, xml_email_level) == 0)
-        {
-            if(!OS_StrIsNum(node[i]->content))
-            {
-                merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
-                return(OS_INVALID);
+        else if (strcmp(node[i]->element, xml_email_level) == 0) {
+            if (!OS_StrIsNum(node[i]->content)) {
+                merror(XML_VALUEERR, __local_name, node[i]->element, node[i]->content);
+                return (OS_INVALID);
             }
 
-            Config->mailbylevel = atoi(node[i]->content);
+            Config->mailbylevel = (u_int8_t) atoi(node[i]->content);
         }
         /* Log alerts */
-        else if(strcmp(node[i]->element, xml_log_level) == 0)
-        {
-            if(!OS_StrIsNum(node[i]->content))
-            {
-                merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
-                return(OS_INVALID);
+        else if (strcmp(node[i]->element, xml_log_level) == 0) {
+            if (!OS_StrIsNum(node[i]->content)) {
+                merror(XML_VALUEERR, __local_name, node[i]->element, node[i]->content);
+                return (OS_INVALID);
             }
-            Config->logbylevel  = atoi(node[i]->content);
+            Config->logbylevel  = (u_int8_t) atoi(node[i]->content);
         }
-#ifdef GEOIP
-       /* Enable GeoIP */
-       else if(strcmp(node[i]->element, xml_log_geoip) == 0)
-       {
-            if(strcmp(node[i]->content, "yes") == 0)
-                { if(Config) Config->loggeoip = 1;}
-            else if(strcmp(node[i]->content, "no") == 0)
-                {if(Config) Config->loggeoip = 0;}
-            else
-            {
-                merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
-                return(OS_INVALID);
+#ifdef LIBGEOIP_ENABLED
+        /* Enable GeoIP */
+        else if (strcmp(node[i]->element, xml_log_geoip) == 0) {
+            if (strcmp(node[i]->content, "yes") == 0) {
+                Config->loggeoip = 1;
+            } else if (strcmp(node[i]->content, "no") == 0) {
+                Config->loggeoip = 0;
+            } else {
+                merror(XML_VALUEERR, __local_name, node[i]->element, node[i]->content);
+                return (OS_INVALID);
             }
 
-       }
+        }
 #endif
-        else
-        {
-            merror(XML_INVELEM, ARGV0, node[i]->element);
-            return(OS_INVALID);
+        else {
+            merror(XML_INVELEM, __local_name, node[i]->element);
+            return (OS_INVALID);
         }
         i++;
     }
-    return(0);
+    return (0);
 }
 
-
-/* EOF */