ze-filter  (ze-filter-0.8.0-develop-180218)
ze-log-virus.c
Go to the documentation of this file.
1 
2 /*
3  *
4  * ze-filter - Mail Server Filter for sendmail
5  *
6  * Copyright (c) 2001-2018 - Jose-Marcio Martins da Cruz
7  *
8  * Auteur : Jose Marcio Martins da Cruz
9  * jose.marcio.mc@gmail.org
10  *
11  * Historique :
12  * Creation : Tue Jan 17 14:47:33 CET 2006
13  *
14  * This program is free software, but with restricted license :
15  *
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20  *
21  * More details about ze-filter license can be found at ze-filter
22  * web site : http://foss.jose-marcio.org
23  */
24 
25 
26 #include <ze-sys.h>
27 #include <ze-filter.h>
28 #include <ze-filter-data.h>
29 #include <ze-log-virus.h>
30 
31 
32 /* ****************************************************************************
33  * *
34  * *
35  ******************************************************************************/
36 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
37 
38 static LOG_T logt = LOG_INITIALIZER;
39 
40 /* ****************************************************************************
41  * *
42  * *
43  ******************************************************************************/
44 bool
46 {
47  char *logname = cf_get_str(CF_VIRUS_LOG_FILE);
48  char path[1024];
49  char *wkdir = cf_get_str(CF_WORKDIR);
50  bool res = TRUE;
51 
52  ADJUST_LOG_NAME(path, logname, wkdir, "none:");
53 
54  MUTEX_LOCK(&mutex);
55 
56  if (!log_ready(&logt))
57  res = log_open(&logt, path);
58  else
59  res = log_reopen(&logt);
60 
62 
63  return res;
64 }
65 
66 /* ****************************************************************************
67  * *
68  * *
69  ******************************************************************************/
70 void
71 log_virus(id, ip, virus)
72  char *id;
73  char *ip;
74  char *virus;
75 {
76  time_t t = time(NULL);
77  int r;
78 
79  char *logname = cf_get_str(CF_VIRUS_LOG_FILE);
80 
81  id = STRNULL(id, "00000000.000");
82  ip = STRNULL(ip, "0.0.0.0");
83 
84  if ((logname == NULL) || (strlen(logname) == 0))
85  return;
86 
87  if (strcasecmp(logname, "NONE") == 0)
88  return;
89 
90  if (!log_ready(&logt) && !log_virus_reopen())
91  return;
92 
93  MUTEX_LOCK(&mutex);
94 
95 #if 0
96  if (!log_ready(&logt)) {
97  if (!log_open(&logt, logname))
98  goto fin;
99  }
100 #endif
101 
102  log_printf(&logt, "%10ld %-12s %s %s\n", (long) t, id, ip, virus);
103 
104 fin:
106 }
#define LOG_INITIALIZER
Definition: ze-txtlog.h:96
bool log_ready(LOG_T *)
Definition: ze-txtlog.c:130
bool log_reopen(LOG_T *)
Definition: ze-txtlog.c:275
#define MUTEX_UNLOCK(mutex)
Definition: macros.h:101
bool log_open(LOG_T *, char *)
Definition: ze-txtlog.c:146
#define STRNULL(x, r)
Definition: macros.h:81
#define MUTEX_LOCK(mutex)
Definition: macros.h:93
pthread_mutex_t mutex
Definition: ze-connopen.c:63
bool log_virus_reopen()
Definition: ze-log-virus.c:45
bool log_printf(LOG_T *, char *,...)
Definition: ze-txtlog.c:355
void log_virus(char *id, char *ip, char *virus)
Definition: ze-log-virus.c:71
#define TRUE
Definition: macros.h:157
char * cf_get_str(int id)
Definition: ze-cf.c:854
#define CF_VIRUS_LOG_FILE
Definition: cfh-defs.h:104
#define CF_WORKDIR
Definition: cfh-defs.h:67
#define ADJUST_LOG_NAME(path, fname, dir, defval)
Definition: ze-txtlog.h:133