2
** Copyright (C) 2009-2011 Softwink, Inc.
3
** Copyright (C) 2009-2011 Champ Clark III <champ@softwink.com>
5
** This program is free software; you can redistribute it and/or modify
6
** it under the terms of the GNU General Public License Version 2 as
7
** published by the Free Software Foundation. You may not use, modify or
8
** distribute this program under any other version of the GNU General
11
** This program is distributed in the hope that it will be useful,
12
** but WITHOUT ANY WARRANTY; without even the implied warranty of
13
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
** GNU General Public License for more details.
16
** You should have received a copy of the GNU General Public License
17
** along with this program; if not, write to the Free Software
18
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
* This runs as a thread for signal processing.
28
#include "config.h" /* From autoconf */
40
#ifdef HAVE_LIBLOGNORM
41
#include <liblognorm.h>
48
#ifdef HAVE_LIBPRELUDE
49
#include <libprelude/prelude.h>
50
char sagan_prelude_profile[255];
51
sbool sagan_prelude_flag;
52
prelude_client_t *preludeclient;
56
#include "output-plugins/sagan-unified2.h"
57
sbool sagan_unified2_flag;
60
#if defined(HAVE_LIBMYSQLCLIENT_R) || defined(HAVE_LIBPQ)
61
#include "output-plugins/sagan-snort.h"
62
#include "output-plugins/sagan-logzilla.h"
66
struct _SaganConfig *config;
67
struct _SaganCounters *counters;
69
struct rule_struct *rulestruct;
70
struct class_struct *classstruct;
71
struct ref_struct *refstruct;
74
char sagan_extern[255];
75
char sagan_esmtp_server[255];
83
uint64_t threshold_total;
85
pthread_mutex_t sig_mutex = PTHREAD_MUTEX_INITIALIZER;
87
void sig_handler(int sigargs ) {
93
/* wait for any and all signals */
94
sigfillset( &signal_set );
95
sigwait( &signal_set, &sig );
107
sagan_log(0, "\n\n[Received signal %d. Sagan version %s shutting down]-------\n", sig, VERSION);
110
#if defined(HAVE_LIBMYSQLCLIENT_R) || defined(HAVE_LIBPQ)
111
if ( config->dbtype != 0 ) record_last_cid();
114
#ifdef HAVE_LIBPRELUDE
116
/* This comment is from the Snort source code. "Sensor reporting to Prelude
117
shall never go offline, which is why we use the
118
PRELUDE_CLIENT_EXIT_STATUS_FAILURE. */
120
if ( sagan_prelude_flag != 0 ) {
121
prelude_client_destroy(preludeclient, PRELUDE_CLIENT_EXIT_STATUS_FAILURE);
128
if ( sagan_unified2_flag ) Unified2CleanExit();
131
fflush(config->sagan_alert_stream);
132
fclose(config->sagan_alert_stream); /* Close Sagan alert file */
134
fflush(config->sagan_log_stream); /* Close the sagan.log */
135
fclose(config->sagan_log_stream);
142
pthread_mutex_lock(&sig_mutex);
143
sagan_log(0, "[Reloading Sagan version %s.]-------", VERSION);
146
counters->refcount=0; counters->classcount=0; counters->rulecount=0; counters->ruletotal=0;
148
/* Re-load everything */
153
pthread_mutex_unlock(&sig_mutex);
155
sagan_log(0, "Configuration reloaded.");
158
/* Signals to ignore */
159
case 17: /* Child process has exited. */
160
case 28: /* Terminal 'resize'/alarm. */
168
sagan_log(0, "[Received signal %d. Sagan doesn't know how to deal with]", sig);
174
/****************************************************************************/
175
/* sig_handler_daemon, for handling signals when the --daemon flag is used */
176
/* We don't spawn a sig_handler() thread in the event --daemon is used. */
177
/* Signals must be handled differently. This is really redundant code and */
178
/* I don't like it, but oh well. */
179
/****************************************************************************/
181
void sig_handler_daemon( int sig ) {
191
sagan_log(0, "\n\n[Received signal %d. Sagan version %s shutting down]-------\n", sig, VERSION);
194
#if defined(HAVE_LIBMYSQLCLIENT_R) || defined(HAVE_LIBPQ)
195
if ( config->dbtype != 0 ) record_last_cid();
198
#ifdef HAVE_LIBPRELUDE
200
/* This comment is from the Snort source code. "Sensor reporting to Prelude
201
shall never go offline, which is why we use the
202
PRELUDE_CLIENT_EXIT_STATUS_FAILURE. */
204
if ( sagan_prelude_flag != 0 ) {
205
prelude_client_destroy(preludeclient, PRELUDE_CLIENT_EXIT_STATUS_FAILURE);
212
if ( sagan_unified2_flag ) Unified2CleanExit();
216
fflush(config->sagan_alert_stream);
217
fclose(config->sagan_alert_stream); /* Close Sagan alert file */
219
fflush(config->sagan_log_stream); /* Close the sagan.log */
220
fclose(config->sagan_log_stream);
228
pthread_mutex_lock(&sig_mutex);
229
sagan_log(0, "[Reloading Sagan version %s.]-------", VERSION);
232
counters->refcount=0; counters->classcount=0; counters->rulecount=0; counters->ruletotal=0;
234
/* Re-load everything */
239
pthread_mutex_unlock(&sig_mutex);
241
sagan_log(0, "Configuration reloaded.");
244
case 17: /* Child process has exited. */
245
case 28: /* Terminal 'resize'/alarm. */
253
sagan_log(0, "[Received signal %d. Sagan doesn't know how to deal with]", sig);