Imported Upstream version 2.5.1
[ossec-hids.git] / src / monitord / manage_files.c
1 /* @(#) $Id$ */
2
3 /* Copyright (C) 2009 Trend Micro Inc.
4  * All right reserved.
5  *
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 2) as published by the FSF - Free Software 
9  * Foundation
10  */
11
12
13 #include "shared.h"
14 #include "monitord.h"
15
16 char *(months[])={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug",
17                   "Sep","Oct","Nov","Dec"};
18
19
20 /* OS_GetLogLocation: v0.1, 2005/04/25 */
21 void manage_files(int cday, int cmon, int cyear)
22 {
23     time_t tm_old;
24
25     struct tm *pp_old;
26
27     #ifndef SOLARIS
28     struct tm p_old;
29     #endif
30             
31     char elogfile[OS_FLSIZE +1];
32     char elogfile_old[OS_FLSIZE +1];
33     
34     char alogfile[OS_FLSIZE +1];
35     char alogfile_old[OS_FLSIZE +1];
36     
37     char flogfile[OS_FLSIZE +1];
38     char flogfile_old[OS_FLSIZE +1];
39
40
41     /* Getting time from the day before (for log signing) */
42     tm_old = time(NULL);
43     tm_old -= 93500;
44     #ifndef SOLARIS
45     pp_old = localtime_r(&tm_old, &p_old);
46     #else
47     pp_old = localtime(&tm_old);
48     #endif
49     
50
51     memset(elogfile, '\0', OS_FLSIZE +1);
52     memset(elogfile_old, '\0', OS_FLSIZE +1);
53     memset(alogfile, '\0', OS_FLSIZE +1);
54     memset(alogfile_old, '\0', OS_FLSIZE +1);
55     memset(flogfile, '\0', OS_FLSIZE +1);
56     memset(flogfile_old, '\0', OS_FLSIZE +1);
57
58
59     /* When the day changes, we wait up to day_wait
60      * before compressing the file.
61      */
62     sleep(mond.day_wait);
63     
64
65     /* Event logfile */
66     snprintf(elogfile, OS_FLSIZE, "%s/%d/%s/ossec-%s-%02d.log",
67             EVENTS,
68             cyear,
69             months[cmon],
70             "archive",
71             cday);
72     /* Event log file old */
73     snprintf(elogfile_old, OS_FLSIZE, "%s/%d/%s/ossec-%s-%02d.log",
74             EVENTS,
75             pp_old->tm_year+1900,
76             months[pp_old->tm_mon],
77             "archive",
78             pp_old->tm_mday);
79
80     OS_SignLog(elogfile, elogfile_old, 0);
81     OS_CompressLog(elogfile);
82
83
84     /* alert logfile  */
85     snprintf(alogfile, OS_FLSIZE, "%s/%d/%s/ossec-%s-%02d.log",
86             ALERTS,
87             cyear,
88             months[cmon],
89             "alerts",
90             cday);
91     /* alert logfile old  */ 
92     snprintf(alogfile_old, OS_FLSIZE, "%s/%d/%s/ossec-%s-%02d.log",
93             ALERTS,
94             pp_old->tm_year+1900,
95             months[pp_old->tm_mon],
96             "alerts",
97             pp_old->tm_mday);
98     OS_SignLog(alogfile, alogfile_old, 1);
99     OS_CompressLog(alogfile);
100
101
102     /* firewall events */
103     snprintf(flogfile, OS_FLSIZE, "%s/%d/%s/ossec-%s-%02d.log",
104             FWLOGS,
105             cyear,
106             months[cmon],
107             "firewall",
108             cday);
109     /* firewall events old */
110     snprintf(flogfile_old, OS_FLSIZE, "%s/%d/%s/ossec-%s-%02d.log",
111             FWLOGS,
112             pp_old->tm_year+1900,
113             months[pp_old->tm_mon],
114             "firewall",
115             pp_old->tm_mday);
116     OS_SignLog(flogfile, flogfile_old, 0);
117     OS_CompressLog(flogfile);
118
119     return;
120 }
121
122 /* EOF */