1 /* @(#) $Id: ./src/analysisd/alerts/getloglocation.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
14 /* Get the log directory/file based on the day/month/year */
17 /* analysisd headers */
18 #include "getloglocation.h"
21 char __elogfile[OS_FLSIZE+1];
22 char __alogfile[OS_FLSIZE+1];
23 char __flogfile[OS_FLSIZE+1];
32 /* alerts and events log file */
33 memset(__alogfile,'\0',OS_FLSIZE +1);
34 memset(__elogfile,'\0',OS_FLSIZE +1);
35 memset(__flogfile,'\0',OS_FLSIZE +1);
41 /* Setting the umask */
47 int OS_CompressLog(int yesterday, char *prev_month, int prev_year)
55 /* OS_GetLogLocation: v0.1, 2005/04/25 */
56 int OS_GetLogLocation(Eventinfo *lf)
58 /* Checking what directories to create
59 * Checking if the year directory is there.
60 * If not, create it. Same for the month directory.
66 if(ftell(_eflog) == 0)
72 snprintf(__elogfile,OS_FLSIZE,"%s/%d/", EVENTS, lf->year);
73 if(IsDir(__elogfile) == -1)
74 if(mkdir(__elogfile,0770) == -1)
76 ErrorExit(MKDIR_ERROR,ARGV0,__elogfile);
79 snprintf(__elogfile,OS_FLSIZE,"%s/%d/%s", EVENTS, lf->year,lf->mon);
81 if(IsDir(__elogfile) == -1)
82 if(mkdir(__elogfile,0770) == -1)
84 ErrorExit(MKDIR_ERROR,ARGV0,__elogfile);
88 /* Creating the logfile name */
89 snprintf(__elogfile,OS_FLSIZE,"%s/%d/%s/ossec-%s-%02d.log",
97 _eflog = fopen(__elogfile,"a");
99 ErrorExit("%s: Error opening logfile: '%s'",ARGV0,__elogfile);
101 /* Creating a symlink */
102 unlink(EVENTS_DAILY);
103 link(__elogfile, EVENTS_DAILY);
106 /* for the alerts logs */
109 if(ftell(_aflog) == 0)
115 snprintf(__alogfile,OS_FLSIZE,"%s/%d/", ALERTS, lf->year);
116 if(IsDir(__alogfile) == -1)
117 if(mkdir(__alogfile,0770) == -1)
119 ErrorExit(MKDIR_ERROR,ARGV0,__alogfile);
122 snprintf(__alogfile,OS_FLSIZE,"%s/%d/%s", ALERTS, lf->year,lf->mon);
124 if(IsDir(__alogfile) == -1)
125 if(mkdir(__alogfile,0770) == -1)
127 ErrorExit(MKDIR_ERROR,ARGV0,__alogfile);
131 /* Creating the logfile name */
132 snprintf(__alogfile,OS_FLSIZE,"%s/%d/%s/ossec-%s-%02d.log",
139 _aflog = fopen(__alogfile,"a");
142 ErrorExit("%s: Error opening logfile: '%s'",ARGV0,__alogfile);
144 /* Creating a symlink */
145 unlink(ALERTS_DAILY);
146 link(__alogfile, ALERTS_DAILY);
149 /* For the firewall events */
152 if(ftell(_fflog) == 0)
158 snprintf(__flogfile,OS_FLSIZE,"%s/%d/", FWLOGS, lf->year);
159 if(IsDir(__flogfile) == -1)
160 if(mkdir(__flogfile,0770) == -1)
162 ErrorExit(MKDIR_ERROR,ARGV0,__flogfile);
165 snprintf(__flogfile,OS_FLSIZE,"%s/%d/%s", FWLOGS, lf->year,lf->mon);
167 if(IsDir(__flogfile) == -1)
168 if(mkdir(__flogfile,0770) == -1)
170 ErrorExit(MKDIR_ERROR,ARGV0,__flogfile);
174 /* Creating the logfile name */
175 snprintf(__flogfile,OS_FLSIZE,"%s/%d/%s/ossec-%s-%02d.log",
182 _fflog = fopen(__flogfile,"a");
185 ErrorExit("%s: Error opening logfile: '%s'",ARGV0,__flogfile);
188 /* Creating a symlink */
189 unlink(FWLOGS_DAILY);
190 link(__flogfile, FWLOGS_DAILY);
193 /* Setting the new day */