1 /* @(#) $Id: add-localfile.c,v 1.13 2009/06/24 18:53:10 dcid Exp $ */
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 3) 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);
125 printf("%s: Continue? (y/n):", name);
129 memset(u_buffer, '\0', 256);
130 if((fgets(u_buffer, 254, stdin) != NULL) &&
131 (strlen(u_buffer) < 250))
133 if((u_buffer[0] == 'y') || (u_buffer[0] == 'Y'))
138 else if((u_buffer[0] == 'n') || (u_buffer[0] == 'N'))
144 printf("%s: Continue? (y/n):", name);
149 printf("%s: Action not taken.\n", name);
156 "<!-- Extra log file -->\r\n"
159 " <location>%s</location>\r\n"
160 " <log_format>syslog</log_format>\r\n"
162 "</ossec_config>\r\n\r\n", file);
165 printf("%s: Action completed.\n", name);
172 /* Setup windows after install */
173 int main(int argc, char **argv)
179 printf("%s: Invalid syntax.\n", argv[0]);
180 printf("Try: '%s <file_name>'\n\n", argv[0]);
183 /* Looking for the quiet option */
184 if((argc == 3) && (strcmp(argv[2],"--quiet") == 0))
190 /* Checking if ossec was installed already */
191 if(!fileexist(OSSECCONF))
193 printf("%s: Unable to find ossec config: '%s'.\n", argv[0], OSSECCONF);
198 config_file(argv[0], argv[1], quiet);