29 #define USE_SIGACTION 1 37 static pid_t pid_parent = 0;
38 static pid_t pid_filter = 0;
40 static int DONE =
FALSE;
42 static void cleanup_after_configure();
44 static time_t dt_cleanup_spool = 21600;
45 static time_t quarantine_max_age = 172800;
47 static bool foreground =
FALSE;
63 {
"regex",
"Regular expressions used in pattern matching",
FALSE,
70 {NULL, NULL,
FALSE, NULL}
79 const char *args =
"p:i:u:hvc:l:t:mnzxqfoM:CV";
88 openlog(
"ze-filter", LOG_PID | LOG_NOWAIT | LOG_NDELAY,
ze_logFacility);
115 while ((c = getopt(argc, argv, args)) != -1) {
143 if (optarg != NULL) {
173 i = PCRE_MAJOR << 16 | PCRE_MINOR << 8;
175 printf(
"pcre %d.%d\n", PCRE_MAJOR, PCRE_MINOR);
178 printf(
"%s\n", DB_VERSION_STRING);
196 if (optarg == NULL || *optarg ==
'\0') {
197 (void) fprintf(stderr,
"Erreur %s\n", optarg);
217 if (optarg == NULL || *optarg ==
'\0') {
218 (void) fprintf(stderr,
"Illegal conn: %s\n", optarg);
224 if (optarg == NULL || *optarg ==
'\0') {
225 (void) fprintf(stderr,
"Erreur %s\n", optarg);
231 if (optarg == NULL || *optarg ==
'\0') {
232 (void) fprintf(stderr,
"Erreur %s\n", optarg);
250 if (optarg == NULL || *optarg ==
'\0') {
251 (void) fprintf(stderr,
"Erreur %s\n", optarg);
264 if (optarg == NULL || *optarg ==
'\0') {
265 (void) fprintf(stderr,
"Erreur %s\n", optarg);
270 while (p->
name != NULL) {
271 if (strcasecmp(p->
name, optarg) == 0) {
278 if (p->
name == NULL) {
279 (void) fprintf(stderr,
"Unknown table : %s\n", optarg);
296 (void) fprintf(stderr,
"Error reading command line options : %c\n", c);
335 printf(
" Compiled on %s %s\n", __DATE__, __TIME__);
336 for (t = tablog; t->
name != NULL; t++) {
339 if (t->
fdump != NULL)
362 static int need_load_conf =
FALSE;
364 static int sighup_group =
FALSE;
365 static int last_cleanup = 0;
368 father_signal_handler(signo)
371 time_t now = time(NULL);
375 signal(signo, father_signal_handler);
378 ZE_MessageInfo(20,
"*** Received SIGNAL %d : %s", signo, ctime(&now));
406 ZE_MessageInfo(10,
" *** Reload configuration files command received");
408 need_load_conf =
TRUE;
409 sighup_group =
FALSE;
427 #define SET_SIG_HANDLER(handler) \ 429 struct sigaction act; \ 431 memset(&act, 0, sizeof (act)); \ 432 act.sa_handler = SIG_IGN; \ 433 sigaction(SIGPIPE, &act, NULL); \ 435 act.sa_handler = handler; \ 436 sigaction(SIGTERM, &act, NULL); \ 437 sigaction(SIGUSR1, &act, NULL); \ 438 sigaction(SIGUSR2, &act, NULL); \ 439 sigaction(SIGALRM, &act, NULL); \ 440 sigaction(SIGCHLD, &act, NULL); \ 441 sigaction(SIGHUP, &act, NULL); \ 442 sigaction(SIGCHLD, &act, NULL); \ 452 signal(SIGPIPE, SIG_IGN);
454 signal(SIGTERM, father_signal_handler);
455 signal(SIGUSR1, father_signal_handler);
456 signal(SIGUSR2, father_signal_handler);
457 signal(SIGHUP, father_signal_handler);
458 signal(SIGALRM, father_signal_handler);
459 signal(SIGCHLD, father_signal_handler);
478 uid_t uid = getuid();
479 gid_t gid = getgid();
486 if ((gr = getgrnam(group)) != NULL) {
488 if (gid == gr->gr_gid) {
491 if ((uid == 0) && (setregid(gr->gr_gid, gr->gr_gid) < 0)) {
501 if ((pw = getpwnam(user)) != NULL) {
503 if (uid == pw->pw_uid) {
506 if ((uid == 0) && (setreuid(pw->pw_uid, pw->pw_uid) < 0)) {
531 printf(
" Let's daemonize ze-filter...\n");
534 printf(
" ze-filter daemonized !\n");
537 perror(
" Error daemonizing ze-filter ");
545 if (setpgid(0, 0) < 0)
549 signal(SIGHUP, SIG_IGN);
554 perror(
" Error daemonizing ze-filter ");
565 if ((fd = open(
"/dev/null", O_RDONLY, 0)) < 0)
568 if (dup2(fd, STDIN_FILENO) < 0)
573 if ((fd = open(
"/dev/null", O_WRONLY, 0)) < 0)
576 if (dup2(fd, STDOUT_FILENO) < 0)
579 if (dup2(fd, STDERR_FILENO) < 0)
603 if (workdir == NULL || strlen(workdir) == 0)
606 if (chdir(workdir) < 0) {
622 cleanup_after_configure()
634 memset(&sh_obj, 0,
sizeof (
SHMOBJ_T));
637 open_shared_file(&sh_obj,
"/var/ze-filter/files/ze-shared", 0x10000);
639 close_shared_file(&sh_obj);
653 static time_t tlaunch[
TL_DIM];
661 now = time(NULL) -
TL_DT - 1;
662 for (i = 0; i <
TL_DIM; i++)
670 time_t now = time(NULL);
672 for (i = 0, n = 0; i <
TL_DIM; i++)
673 if (tlaunch[i] +
TL_DT > now)
684 time_t now = time(NULL);
686 for (i = 0, n = 0; i <
TL_DIM; i++)
687 if (tlaunch[i] + tm > now)
699 if (!tlaunch_check())
705 for (i = 0; i <
TL_DIM; i++) {
706 if (tlaunch[i] < tmin) {
720 #define MAX_SIG_ERR 64 722 #define FD_SET_FLAG(fd,flag) \ 725 if ((oflag = fcntl(fd, F_GETFL, 0)) < 0) \ 727 ZE_LogSysError("fcntl F_GETFL error"); \ 730 if (fcntl(fd, F_SETFL, oflag | flag) < 0) \ 731 ZE_LogSysError("fcntl F_SETFL error"); \ 738 pid_t res_filter = 0;
739 time_t now = time(NULL);
746 pid_parent = getpid();
752 cleanup_after_configure();
779 if (pid_filter == 0) {
780 if (tlaunch_register()) {
791 if ((pid_filter = fork()) == -1) {
796 if (pid_filter == 0) {
797 struct sigaction act;
805 if ((flag = fcntl(
pipe_filter[0], F_GETFL, 0)) < 0) {
808 if (fcntl(
pipe_filter[0], F_SETFL, flag | O_NONBLOCK) < 0)
832 if ((flag = fcntl(
pipe_filter[1], F_GETFL, 0)) < 0) {
838 if (fcntl(
pipe_filter[1], F_SETFL, flag | O_NONBLOCK) < 0)
843 static time_t lastlog = 0;
846 if (lastlog + 60 < now) {
848 "Spawning too fast : %d in less than %d secs (%d)",
876 if (need_load_conf) {
881 cleanup_after_configure();
885 need_load_conf =
FALSE;
891 if (pid_filter > 0) {
897 pid_filter, res_filter);
899 if (res_filter == -1) {
907 res_filter = pid_filter;
911 if (res_filter > 0) {
912 if (WIFSIGNALED(status)) {
913 int sig = WTERMSIG(status);
923 ZE_MessageInfo(9,
"Filter %d died and returned code %d", res_filter,
931 if (res_filter == pid_filter) {
941 if ((dt_cleanup_spool > 0) && (now > last_cleanup + dt_cleanup_spool)) {
945 last_cleanup = time(NULL);
950 now = time(NULL) + 5;
951 while (now > time(NULL) && pid_filter != 0) {
952 pid_t pid = pid_filter;
956 if (pid == -1 || pid == pid_filter)
974 printf(
"Usage : ze-filter options\n %s\n" 975 " Compiled on %s %s\n" 977 " inet:2000@localhost\n" 979 " -i : 2000 (AF_INET)\n" 980 " -u : /var/sock (AF_UNIX)\n" 982 " -c : configuration file\n" 984 " -m : create configuration file (running conf)\n" 985 " -n : create configuration file (default)\n" 986 " -M : create configuration file (default)\n" 987 " null : null filter configuration\n" 988 " default : configuration with minimal features enabled\n" 989 " running : current filter configuration\n" 990 " -v : version / runtime configuration\n" 991 " -vv : version / compile time configuration\n" 992 " -C : configure options\n" 993 " -x : compile time X-FILES definition\n" 994 " -t tablename, where tablename choosen between : \n",
1003 while (p->
name != NULL) {
1004 printf(
" %-16s %s\n", p->
name, p->
desc);
1034 printf(
"ze-filter compile-time xfile definitions\n %s\n" 1035 " Compiled on %s %s\n\n",
PACKAGE, __DATE__, __TIME__);
1037 printf(
" Ext ORIGIN File Type\n" 1038 " ------------------------------------------------------\n");
1040 for (p = xfilesdef; p->
ext != NULL; p++)
#define WEXITSTATUS(stat_val)
bool setup_supervisor_signal_handler()
char * define_milter_sock(char *cf, char *p, char *u, char *i)
#define STRNCASEEQUAL(a, b, n)
bool recv_message_pipe(int, int *)
void zeLog_SetOutput(bool, bool)
#define WIFEXITED(stat_val)
void mk_cf_file(int, bool, bool)
#define ZE_LogMsgError(level,...)
#define WAIT_NOHANG(pid, stat)
#define ZE_MessageDebug(level,...)
#define FD_SET_FLAG(fd, flag)
void init_default_file_extensions()
#define ZE_LogMsgDebug(level,...)
int j_set_uid_gid(char *user, char *group)
#define ZE_MessageInfo(level,...)
#define ZE_MessageWarning(level,...)
bool create_pid_file(char *fname)
void dump_oradata_table()
#define ZE_LogSysError(...)
void remove_milter_sock()
void cleanup_spool(char *, unsigned long)
char * cf_get_str(int id)
#define ZE_LogMsgWarning(level,...)
int configure(char *, char *, bool)
#define SET_SIG_HANDLER(handler)
#define CF_CLEANUP_INTERVAL
#define CF_QUARANTINE_LIFETIME
void remove_pid_file(void)
void hardcoded_xfiles(void)
int send_msg_channel(int[], int, int)