1 /* @(#) $Id: ./src/win32/add-localfile.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2009 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 2) as published by the FSF - Free Software
19 #include "os_regex/os_regex.h"
21 #define OSSECCONF "ossec.conf"
22 #define OS_MAXSTR 1024
26 int fileexist(char *file)
31 fp = fopen(file, "r");
39 int dogrep(char *file, char *str)
41 char line[OS_MAXSTR +1];
45 fp = fopen(file, "r");
50 memset(line, '\0', OS_MAXSTR +1);
52 /* Reading file and looking for str */
53 while(fgets(line, OS_MAXSTR, fp) != NULL)
55 if(OS_Match(str, line))
68 /* Check is syscheck is present in the config */
69 int config_file(char *name, char *file, int quiet)
77 /* Checking if the file has a variable format */
78 if(strchr(file, '%') != NULL)
86 if(strftime(ffile, 255, file, p) == 0)
93 strncpy(ffile, file, 255);
97 /* Looking for ffile */
102 printf("%s: Log file not existent: '%s'.\n", name, file);
107 if(dogrep(OSSECCONF, file))
109 printf("%s: Log file already configured: '%s'.\n",
115 /* Add iis config config */
116 fp = fopen(OSSECCONF, "a");
119 printf("%s: Unable to edit configuration file.\n", name);
123 printf("%s: Adding log file to be monitored: '%s'.\n", name,file);
126 "<!-- Extra log file -->\r\n"
129 " <location>%s</location>\r\n"
130 " <log_format>syslog</log_format>\r\n"
132 "</ossec_config>\r\n\r\n", file);
135 printf("%s: Action completed.\n", name);
142 /* Setup windows after install */
143 int main(int argc, char **argv)
149 printf("%s: Invalid syntax.\n", argv[0]);
150 printf("Try: '%s <file_name>'\n\n", argv[0]);
153 /* Looking for the quiet option */
154 if((argc == 3) && (strcmp(argv[2],"--quiet") == 0))
160 /* Checking if ossec was installed already */
161 if(!fileexist(OSSECCONF))
163 printf("%s: Unable to find ossec config: '%s'.\n", argv[0], OSSECCONF);
168 config_file(argv[0], argv[1], quiet);