1 /* @(#) $Id: getloglocation.c,v 1.14 2009/06/24 17:06:22 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
13 /* Get the log directory/file based on the day/month/year */
16 /* analysisd headers */
17 #include "getloglocation.h"
20 char __elogfile[OS_FLSIZE+1];
21 char __alogfile[OS_FLSIZE+1];
22 char __flogfile[OS_FLSIZE+1];
31 /* alerts and events log file */
32 memset(__alogfile,'\0',OS_FLSIZE +1);
33 memset(__elogfile,'\0',OS_FLSIZE +1);
34 memset(__flogfile,'\0',OS_FLSIZE +1);
40 /* Setting the umask */
46 int OS_CompressLog(int yesterday, char *prev_month, int prev_year)
54 /* OS_GetLogLocation: v0.1, 2005/04/25 */
55 int OS_GetLogLocation(Eventinfo *lf)
57 /* Checking what directories to create
58 * Checking if the year directory is there.
59 * If not, create it. Same for the month directory.
65 if(ftell(_eflog) == 0)
71 snprintf(__elogfile,OS_FLSIZE,"%s/%d/", EVENTS, lf->year);
72 if(IsDir(__elogfile) == -1)
73 if(mkdir(__elogfile,0770) == -1)
75 ErrorExit(MKDIR_ERROR,ARGV0,__elogfile);
78 snprintf(__elogfile,OS_FLSIZE,"%s/%d/%s", EVENTS, lf->year,lf->mon);
80 if(IsDir(__elogfile) == -1)
81 if(mkdir(__elogfile,0770) == -1)
83 ErrorExit(MKDIR_ERROR,ARGV0,__elogfile);
87 /* Creating the logfile name */
88 snprintf(__elogfile,OS_FLSIZE,"%s/%d/%s/ossec-%s-%02d.log",
96 _eflog = fopen(__elogfile,"a");
98 ErrorExit("%s: Error opening logfile: '%s'",ARGV0,__elogfile);
100 /* Creating a symlink */
101 unlink(EVENTS_DAILY);
102 link(__elogfile, EVENTS_DAILY);
105 /* for the alerts logs */
108 if(ftell(_aflog) == 0)
114 snprintf(__alogfile,OS_FLSIZE,"%s/%d/", ALERTS, lf->year);
115 if(IsDir(__alogfile) == -1)
116 if(mkdir(__alogfile,0770) == -1)
118 ErrorExit(MKDIR_ERROR,ARGV0,__alogfile);
121 snprintf(__alogfile,OS_FLSIZE,"%s/%d/%s", ALERTS, lf->year,lf->mon);
123 if(IsDir(__alogfile) == -1)
124 if(mkdir(__alogfile,0770) == -1)
126 ErrorExit(MKDIR_ERROR,ARGV0,__alogfile);
130 /* Creating the logfile name */
131 snprintf(__alogfile,OS_FLSIZE,"%s/%d/%s/ossec-%s-%02d.log",
138 _aflog = fopen(__alogfile,"a");
141 ErrorExit("%s: Error opening logfile: '%s'",ARGV0,__alogfile);
143 /* Creating a symlink */
144 unlink(ALERTS_DAILY);
145 link(__alogfile, ALERTS_DAILY);
148 /* For the firewall events */
151 if(ftell(_fflog) == 0)
157 snprintf(__flogfile,OS_FLSIZE,"%s/%d/", FWLOGS, lf->year);
158 if(IsDir(__flogfile) == -1)
159 if(mkdir(__flogfile,0770) == -1)
161 ErrorExit(MKDIR_ERROR,ARGV0,__flogfile);
164 snprintf(__flogfile,OS_FLSIZE,"%s/%d/%s", FWLOGS, lf->year,lf->mon);
166 if(IsDir(__flogfile) == -1)
167 if(mkdir(__flogfile,0770) == -1)
169 ErrorExit(MKDIR_ERROR,ARGV0,__flogfile);
173 /* Creating the logfile name */
174 snprintf(__flogfile,OS_FLSIZE,"%s/%d/%s/ossec-%s-%02d.log",
181 _fflog = fopen(__flogfile,"a");
184 ErrorExit("%s: Error opening logfile: '%s'",ARGV0,__flogfile);
187 /* Creating a symlink */
188 unlink(FWLOGS_DAILY);
189 link(__flogfile, FWLOGS_DAILY);
192 /* Setting the new day */