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