1 /* Copyright (C) 2009 Trend Micro Inc.
4 * This program is a free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License (version 2) as published by the FSF - Free Software
16 #include "os_regex/os_regex.h"
18 #define OSSECCONF "ossec.conf"
19 #define OS_MAXSTR 1024
24 int fileexist(char *file)
29 fp = fopen(file, "r");
38 int dogrep(char *file, char *str)
40 char line[OS_MAXSTR + 1];
44 fp = fopen(file, "r");
50 memset(line, '\0', OS_MAXSTR + 1);
52 /* Read file and look for str */
53 while (fgets(line, OS_MAXSTR, fp) != NULL) {
54 if (OS_Match(str, line)) {
64 /* Check if syscheck is present in the config */
65 int config_file(char *name, char *file, int quiet)
72 /* Check if the file has a variable format */
73 if (strchr(file, '%') != NULL) {
80 if (strftime(ffile, 255, file, p) == 0) {
84 strncpy(ffile, file, 255);
88 if (!fileexist(ffile)) {
90 printf("%s: Log file not existent: '%s'.\n", name, file);
95 if (dogrep(OSSECCONF, file)) {
96 printf("%s: Log file already configured: '%s'.\n",
102 fp = fopen(OSSECCONF, "a");
104 printf("%s: Unable to edit configuration file.\n", name);
108 printf("%s: Adding log file to be monitored: '%s'.\n", name, file);
111 "<!-- Extra log file -->\r\n"
114 " <location>%s</location>\r\n"
115 " <log_format>syslog</log_format>\r\n"
117 "</ossec_config>\r\n\r\n", file);
119 printf("%s: Action completed.\n", name);
125 /* Setup Windows after install */
126 int main(int argc, char **argv)
131 printf("%s: Invalid syntax.\n", argv[0]);
132 printf("Try: '%s <file_name>'\n\n", argv[0]);
135 /* Look for the quiet option */
136 if ((argc == 3) && (strcmp(argv[2], "--quiet") == 0)) {
140 /* Check if OSSEC-HIDS was installed already */
141 if (!fileexist(OSSECCONF)) {
142 printf("%s: Unable to find ossec config: '%s'.\n", argv[0], OSSECCONF);
144 config_file(argv[0], argv[1], quiet);