3 /* Copyright (C) 2009 Trend Micro Inc.
6 * This program is a free software; you can redistribute it
7 * and/or modify it under the terms of the GNU General Public
8 * License (version 2) as published by the FSF - Free Software
18 #include "os_regex/os_regex.h"
20 #define OSSECCONF "ossec.conf"
21 #define OS_MAXSTR 1024
25 int fileexist(char *file)
30 fp = fopen(file, "r");
38 int dogrep(char *file, char *str)
40 char line[OS_MAXSTR +1];
44 fp = fopen(file, "r");
49 memset(line, '\0', OS_MAXSTR +1);
51 /* Reading file and looking for str */
52 while(fgets(line, OS_MAXSTR, fp) != NULL)
54 if(OS_Match(str, line))
67 /* Check is syscheck is present in the config */
68 int config_file(char *name, char *file, int quiet)
78 /* Checking if the file has a variable format */
79 if(strchr(file, '%') != NULL)
87 if(strftime(ffile, 255, file, p) == 0)
94 strncpy(ffile, file, 255);
98 /* Looking for ffile */
103 printf("%s: Log file not existent: '%s'.\n", name, file);
108 if(dogrep(OSSECCONF, file))
110 printf("%s: Log file already configured: '%s'.\n",
116 /* Add iis config config */
117 fp = fopen(OSSECCONF, "a");
120 printf("%s: Unable to edit configuration file.\n", name);
124 printf("%s: Adding log file to be monitored: '%s'.\n", name,file);
127 "<!-- Extra log file -->\r\n"
130 " <location>%s</location>\r\n"
131 " <log_format>syslog</log_format>\r\n"
133 "</ossec_config>\r\n\r\n", file);
136 printf("%s: Action completed.\n", name);
143 /* Setup windows after install */
144 int main(int argc, char **argv)
150 printf("%s: Invalid syntax.\n", argv[0]);
151 printf("Try: '%s <file_name>'\n\n", argv[0]);
154 /* Looking for the quiet option */
155 if((argc == 3) && (strcmp(argv[2],"--quiet") == 0))
161 /* Checking if ossec was installed already */
162 if(!fileexist(OSSECCONF))
164 printf("%s: Unable to find ossec config: '%s'.\n", argv[0], OSSECCONF);
169 config_file(argv[0], argv[1], quiet);