new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / analysisd / active-response.c
old mode 100755 (executable)
new mode 100644 (file)
index f6f2414..1613e26
@@ -1,6 +1,3 @@
-/* @(#) $Id: ./src/analysisd/active-response.c, 2011/09/08 dcid Exp $
- */
-
 /* Copyright (C) 2009 Trend Micro Inc.
  * All right reserved.
  *
  * Foundation
  */
 
-
 #include "shared.h"
 #include "active-response.h"
 
+/* Active response commands */
+static OSList *ar_commands;
+OSList *active_responses;
 
-/** void AR_Init()
- * Initializing active response.
- */
+/* Initialize active response */
 void AR_Init()
 {
     ar_commands = OSList_Create();
     active_responses = OSList_Create();
     ar_flag = 0;
 
-    if(!ar_commands || !active_responses)
-    {
+    if (!ar_commands || !active_responses) {
         ErrorExit(LIST_ERROR, ARGV0);
     }
 }
 
-
-/** int AR_ReadConfig(int test_config, char *cfgfile)
- * Reads active response configuration and write them
+/* Read active response configuration and write it
  * to the appropriate lists.
  */
-int AR_ReadConfig(int test_config, char *cfgfile)
+int AR_ReadConfig(const char *cfgfile)
 {
     FILE *fp;
     int modules = 0;
 
-    modules|= CAR;
+    modules |= CAR;
 
-
-    /* Cleaning ar file */
+    /* Clean ar file */
     fp = fopen(DEFAULTARPATH, "w");
-    if(!fp)
-    {
-        merror(FOPEN_ERROR, ARGV0, DEFAULTARPATH);
-        return(OS_INVALID);
+    if (!fp) {
+        merror(FOPEN_ERROR, ARGV0, DEFAULTARPATH, errno, strerror(errno));
+        return (OS_INVALID);
     }
     fprintf(fp, "restart-ossec0 - restart-ossec.sh - 0\n");
     fprintf(fp, "restart-ossec0 - restart-ossec.cmd - 0\n");
     fclose(fp);
 
-
-    /* Setting right permission */
-    chmod(DEFAULTARPATH, 0440);
-
-
-    /* Reading configuration */
-    if(ReadConfig(modules, cfgfile, ar_commands, active_responses) < 0)
-    {
-        return(OS_INVALID);
+    /* Set right permission */
+    if (chmod(DEFAULTARPATH, 0440) == -1) {
+        merror(CHMOD_ERROR, ARGV0, DEFAULTARPATH, errno, strerror(errno));
+        return (OS_INVALID);
     }
 
+    /* Read configuration */
+    if (ReadConfig(modules, cfgfile, ar_commands, active_responses) < 0) {
+        return (OS_INVALID);
+    }
 
-    return(0);
+    return (0);
 }
 
-/* EOF */