Changeset 265
- Timestamp:
- Dec 21, 2009, 8:54:07 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 6 added
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Makefile.in
r264 r265 123 123 sh_mounts.h sh_userfiles.h sh_static.h sh_prelink.h \ 124 124 sh_processcheck.h sh_portcheck.h sh_pthread.h sh_string.h \ 125 sh_log_check.h sh_log_evalrule.h sh_inotify.h 125 sh_log_check.h sh_log_evalrule.h sh_log_correlate.h \ 126 sh_log_mark.h sh_log_repeat.h sh_inotify.h 126 127 127 128 … … 161 162 $(srcsrc)/sh_log_parse_samba.c \ 162 163 $(srcsrc)/sh_log_parse_apache.c $(srcsrc)/sh_log_evalrule.c \ 164 $(srcsrc)/sh_log_correlate.c $(srcsrc)/sh_log_mark.c \ 163 165 $(srcsrc)/sh_log_check.c $(srcsrc)/dnmalloc.c \ 164 $(srcsrc)/sh_inotify.c \166 $(srcsrc)/sh_inotify.c $(srcsrc)/sh_log_repeat.c \ 165 167 $(srcsrc)/t-test1.c 166 168 … … 179 181 sh_log_parse_syslog.o sh_log_parse_pacct.o sh_log_parse_apache.o \ 180 182 sh_log_parse_samba.o sh_log_evalrule.o sh_log_check.o \ 183 sh_log_correlate.o sh_log_mark.o sh_log_repeat.o \ 181 184 sh_pthread.o sh_string.o sh_inotify.o dnmalloc.o 182 185 … … 1665 1668 sh_files.o: $(srcsrc)/sh_files.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_error.h $(srcinc)/sh_utils.h $(srcinc)/sh_unix.h $(srcinc)/sh_files.h $(srcinc)/sh_tiger.h $(srcinc)/sh_hash.h $(srcinc)/sh_ignore.h $(srcinc)/zAVLTree.h 1666 1669 sh_getopt.o: $(srcsrc)/sh_getopt.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_error.h $(srcinc)/sh_getopt.h $(srcinc)/sh_files.h $(srcinc)/sh_utils.h $(srcinc)/sh_mail.h $(srcinc)/sh_forward.h $(srcinc)/sh_hash.h $(srcinc)/sh_extern.h 1667 sh_readconf.o: $(srcsrc)/sh_readconf.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_ error.h $(srcinc)/sh_database.h $(srcinc)/sh_unix.h $(srcinc)/sh_utils.h $(srcinc)/sh_files.h $(srcinc)/sh_mail.h $(srcinc)/sh_nmail.h $(srcinc)/sh_calls.h $(srcinc)/sh_tiger.h $(srcinc)/sh_forward.h $(srcinc)/sh_modules.h $(srcinc)/sh_gpg.h $(srcinc)/sh_hash.h $(srcinc)/sh_ignore.h $(srcinc)/sh_prelink.h $(srcinc)/sh_extern.h $(srcinc)/sh_tools.h $(srcinc)/sh_database.h $(srcinc)/sh_prelude.h1670 sh_readconf.o: $(srcsrc)/sh_readconf.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_calls.h $(srcinc)/sh_error.h $(srcinc)/sh_extern.h $(srcinc)/sh_files.h $(srcinc)/sh_forward.h $(srcinc)/sh_gpg.h $(srcinc)/sh_hash.h $(srcinc)/sh_ignore.h $(srcinc)/sh_database.h $(srcinc)/sh_mail.h $(srcinc)/sh_modules.h $(srcinc)/sh_nmail.h $(srcinc)/sh_prelink.h $(srcinc)/sh_prelude.h $(srcinc)/sh_tiger.h $(srcinc)/sh_tools.h $(srcinc)/sh_unix.h $(srcinc)/sh_utils.h 1668 1671 sh_tiger0.o: $(srcsrc)/sh_tiger0.c Makefile config_xor.h $(srcinc)/sh_tiger.h $(srcinc)/sh_unix.h $(srcinc)/sh_error.h $(srcinc)/sh_utils.h $(srcinc)/sh_pthread.h $(srcinc)/sh_string.h 1669 1672 sh_tiger1.o: $(srcsrc)/sh_tiger1.c Makefile config_xor.h … … 1728 1731 sh_log_parse_pacct.o: $(srcsrc)/sh_log_parse_pacct.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_log_check.h $(srcinc)/sh_utils.h $(srcinc)/sh_string.h 1729 1732 sh_log_parse_apache.o: $(srcsrc)/sh_log_parse_apache.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_log_check.h $(srcinc)/sh_utils.h $(srcinc)/sh_string.h 1730 sh_log_evalrule.o: $(srcsrc)/sh_log_evalrule.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_string.h $(srcinc)/sh_log_check.h $(srcinc)/sh_log_evalrule.h $(srcinc)/ zAVLTree.h1731 sh_log_check.o: $(srcsrc)/sh_log_check.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_ string.h $(srcinc)/sh_log_check.h $(srcinc)/sh_log_evalrule.h $(srcinc)/sh_modules.h1733 sh_log_evalrule.o: $(srcsrc)/sh_log_evalrule.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_string.h $(srcinc)/sh_log_check.h $(srcinc)/sh_log_evalrule.h $(srcinc)/sh_log_correlate.h $(srcinc)/sh_log_mark.h $(srcinc)/sh_log_repeat.h $(srcinc)/zAVLTree.h 1734 sh_log_check.o: $(srcsrc)/sh_log_check.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_unix.h $(srcinc)/sh_string.h $(srcinc)/sh_log_check.h $(srcinc)/sh_log_evalrule.h $(srcinc)/sh_log_correlate.h $(srcinc)/sh_log_mark.h $(srcinc)/sh_log_repeat.h $(srcinc)/sh_modules.h 1732 1735 sh_log_parse_samba.o: $(srcsrc)/sh_log_parse_samba.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_log_check.h $(srcinc)/sh_string.h 1733 1736 sh_nmail.o: $(srcsrc)/sh_nmail.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_mem.h $(srcinc)/sh_mail.h $(srcinc)/sh_tiger.h $(srcinc)/sh_string.h $(srcinc)/sh_utils.h $(srcinc)/sh_fifo.h $(srcinc)/sh_filter.h $(srcinc)/sh_mail_int.h $(srcinc)/zAVLTree.h 1734 1737 sh_filter.o: $(srcsrc)/sh_filter.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_utils.h $(srcinc)/sh_mem.h $(srcinc)/sh_filter.h 1735 1738 sh_inotify.o: $(srcsrc)/sh_inotify.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_calls.h $(srcinc)/sh_inotify.h $(srcinc)/sh_mem.h $(srcinc)/slib.h $(srcinc)/sh_calls.h 1739 sh_log_correlate.o: $(srcsrc)/sh_log_correlate.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_string.h $(srcinc)/sh_log_check.h $(srcinc)/sh_log_evalrule.h 1740 sh_log_mark.o: $(srcsrc)/sh_log_mark.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_mem.h $(srcinc)/sh_string.h $(srcinc)/sh_error_min.h $(srcinc)/sh_log_check.h $(srcinc)/sh_log_evalrule.h $(srcinc)/zAVLTree.h 1741 sh_log_repeat.o: $(srcsrc)/sh_log_repeat.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_string.h $(srcinc)/sh_log_check.h $(srcinc)/sh_log_evalrule.h -
trunk/acconfig.h
r156 r265 342 342 /* Define if UINT64 is 32 bits. */ 343 343 #undef UINT64_IS_32 344 345 /* Define if you have uint64_t. */ 346 #undef HAVE_UINT16_T 344 347 345 348 /* Define if you have uint64_t. */ -
trunk/configure.ac
r259 r265 495 495 AC_C_LONG_DOUBLE 496 496 SH_CHECK_TYPEDEF(long long, HAVE_LONG_LONG) 497 SH_CHECK_TYPEDEF(uint16_t, HAVE_UINT16_T) 497 498 SH_CHECK_TYPEDEF(uint64_t, HAVE_UINT64_T) 498 499 if test "$sh_HAVE_LONG_LONG" = "yes"; then -
trunk/depend.dep
r264 r265 7 7 sh_files.o: $(srcsrc)/sh_files.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_error.h $(srcinc)/sh_utils.h $(srcinc)/sh_unix.h $(srcinc)/sh_files.h $(srcinc)/sh_tiger.h $(srcinc)/sh_hash.h $(srcinc)/sh_ignore.h $(srcinc)/zAVLTree.h 8 8 sh_getopt.o: $(srcsrc)/sh_getopt.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_error.h $(srcinc)/sh_getopt.h $(srcinc)/sh_files.h $(srcinc)/sh_utils.h $(srcinc)/sh_mail.h $(srcinc)/sh_forward.h $(srcinc)/sh_hash.h $(srcinc)/sh_extern.h 9 sh_readconf.o: $(srcsrc)/sh_readconf.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_ error.h $(srcinc)/sh_database.h $(srcinc)/sh_unix.h $(srcinc)/sh_utils.h $(srcinc)/sh_files.h $(srcinc)/sh_mail.h $(srcinc)/sh_nmail.h $(srcinc)/sh_calls.h $(srcinc)/sh_tiger.h $(srcinc)/sh_forward.h $(srcinc)/sh_modules.h $(srcinc)/sh_gpg.h $(srcinc)/sh_hash.h $(srcinc)/sh_ignore.h $(srcinc)/sh_prelink.h $(srcinc)/sh_extern.h $(srcinc)/sh_tools.h $(srcinc)/sh_database.h $(srcinc)/sh_prelude.h9 sh_readconf.o: $(srcsrc)/sh_readconf.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_calls.h $(srcinc)/sh_error.h $(srcinc)/sh_extern.h $(srcinc)/sh_files.h $(srcinc)/sh_forward.h $(srcinc)/sh_gpg.h $(srcinc)/sh_hash.h $(srcinc)/sh_ignore.h $(srcinc)/sh_database.h $(srcinc)/sh_mail.h $(srcinc)/sh_modules.h $(srcinc)/sh_nmail.h $(srcinc)/sh_prelink.h $(srcinc)/sh_prelude.h $(srcinc)/sh_tiger.h $(srcinc)/sh_tools.h $(srcinc)/sh_unix.h $(srcinc)/sh_utils.h 10 10 sh_tiger0.o: $(srcsrc)/sh_tiger0.c Makefile config_xor.h $(srcinc)/sh_tiger.h $(srcinc)/sh_unix.h $(srcinc)/sh_error.h $(srcinc)/sh_utils.h $(srcinc)/sh_pthread.h $(srcinc)/sh_string.h 11 11 sh_tiger1.o: $(srcsrc)/sh_tiger1.c Makefile config_xor.h … … 72 72 sh_log_parse_pacct.o: $(srcsrc)/sh_log_parse_pacct.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_log_check.h $(srcinc)/sh_utils.h $(srcinc)/sh_string.h 73 73 sh_log_parse_apache.o: $(srcsrc)/sh_log_parse_apache.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_log_check.h $(srcinc)/sh_utils.h $(srcinc)/sh_string.h 74 sh_log_evalrule.o: $(srcsrc)/sh_log_evalrule.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_string.h $(srcinc)/sh_log_check.h $(srcinc)/sh_log_evalrule.h $(srcinc)/ zAVLTree.h75 sh_log_check.o: $(srcsrc)/sh_log_check.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_ string.h $(srcinc)/sh_log_check.h $(srcinc)/sh_log_evalrule.h $(srcinc)/sh_modules.h74 sh_log_evalrule.o: $(srcsrc)/sh_log_evalrule.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_string.h $(srcinc)/sh_log_check.h $(srcinc)/sh_log_evalrule.h $(srcinc)/sh_log_correlate.h $(srcinc)/sh_log_mark.h $(srcinc)/sh_log_repeat.h $(srcinc)/zAVLTree.h 75 sh_log_check.o: $(srcsrc)/sh_log_check.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_unix.h $(srcinc)/sh_string.h $(srcinc)/sh_log_check.h $(srcinc)/sh_log_evalrule.h $(srcinc)/sh_log_correlate.h $(srcinc)/sh_log_mark.h $(srcinc)/sh_log_repeat.h $(srcinc)/sh_modules.h 76 76 sh_log_parse_samba.o: $(srcsrc)/sh_log_parse_samba.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_log_check.h $(srcinc)/sh_string.h 77 77 sh_nmail.o: $(srcsrc)/sh_nmail.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_mem.h $(srcinc)/sh_mail.h $(srcinc)/sh_tiger.h $(srcinc)/sh_string.h $(srcinc)/sh_utils.h $(srcinc)/sh_fifo.h $(srcinc)/sh_filter.h $(srcinc)/sh_mail_int.h $(srcinc)/zAVLTree.h 78 78 sh_filter.o: $(srcsrc)/sh_filter.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_utils.h $(srcinc)/sh_mem.h $(srcinc)/sh_filter.h 79 79 sh_inotify.o: $(srcsrc)/sh_inotify.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_calls.h $(srcinc)/sh_inotify.h $(srcinc)/sh_mem.h $(srcinc)/slib.h $(srcinc)/sh_calls.h 80 sh_log_correlate.o: $(srcsrc)/sh_log_correlate.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_string.h $(srcinc)/sh_log_check.h $(srcinc)/sh_log_evalrule.h 81 sh_log_mark.o: $(srcsrc)/sh_log_mark.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_mem.h $(srcinc)/sh_string.h $(srcinc)/sh_error_min.h $(srcinc)/sh_log_check.h $(srcinc)/sh_log_evalrule.h $(srcinc)/zAVLTree.h 82 sh_log_repeat.o: $(srcsrc)/sh_log_repeat.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_string.h $(srcinc)/sh_log_check.h $(srcinc)/sh_log_evalrule.h -
trunk/depend.sum
r264 r265 1 188553029 1 968635974 -
trunk/docs/Changelog
r263 r265 1 2.6.1: 1 2.6.1 (21-12-2009): 2 * add a routine to log monitoring module to guess the proper year 3 for timestamps without year (standard syslog) 4 * add feature to automatically detect and report bursts of 5 similar messages in log monitoring module 6 * add feature to check for missing heartbeat messages in 7 log monitoring module 8 * cache UIDs/GIDs to reduce the number of lookups 2 9 * use inotify to track login/logout (sh_inotify.c, sh_utmp.c) 3 10 * support event correlation in log monitoring module … … 7 14 sh_unix_count_mlock() (reported by Remco Landegge). 8 15 9 2.6.0 :16 2.6.0 (01-11-2009): 10 17 * don't use statvfs() for process checking on FreeBSD 11 18 * fix bug with parallel compilation of cutest in Makefile -
trunk/include/samhain.h
r256 r265 106 106 #ifdef HAVE_STDINT_H 107 107 #include <stdint.h> 108 #endif 109 110 #if !defined(HAVE_UINT16_T) 111 #define UINT16 unsigned short 112 #else 113 #define UINT16 uint16_t 108 114 #endif 109 115 -
trunk/include/sh_cat.h
r260 r265 168 168 MSG_LOGMON_SUM, 169 169 MSG_LOGMON_COR, 170 MSG_LOGMON_MARK, 171 MSG_LOGMON_BURST, 170 172 #endif 171 173 -
trunk/include/sh_error.h
r170 r265 109 109 void sh_error_fixup(void); 110 110 111 /* convert a string to a numeric priority112 */113 int sh_error_convert_level (const char * str_s);114 115 111 /* only to stderr (GOOD/BAD) 116 112 */ -
trunk/include/sh_error_min.h
r170 r265 25 25 long errnum, unsigned long msg_index, ...); 26 26 27 /* convert a string to a numeric priority 28 */ 29 int sh_error_convert_level (const char * str_s); 30 27 31 #endif -
trunk/include/sh_log_evalrule.h
r260 r265 39 39 int sh_eval_process_msg(struct sh_logrecord * record); 40 40 41 /* Match correlated rules 42 */ 43 void sh_keep_match(); 41 enum policies { 42 EVAL_REPORT, 43 EVAL_SUM 44 }; 45 46 struct sh_qeval /* Queue with definitions */ 47 { 48 sh_string * label; 49 enum policies policy; 50 int severity; 51 time_t interval; /* if EVAL_SUM, interval */ 52 struct sh_qeval * next; 53 }; 54 55 struct sh_qeval * sh_log_find_queue(const char * str); 56 57 int sh_log_lookup_severity(const char * str); 44 58 45 59 #endif -
trunk/include/sh_string.h
r260 r265 2 2 #define SH_STRING_H 3 3 4 #include <stdio.h> 4 5 5 6 /* String definition and utility functions. … … 84 85 char ** split_array_list(char *line, unsigned int * nfields, size_t * lengths); 85 86 87 /* Same as above, but split on delimiter list (token) 88 */ 89 char ** split_array_token (char *line, 90 unsigned int * nfields, size_t * lengths, 91 const char * token); 92 86 93 /* Return a split_array_list() of a list contained in 'PREFIX\s*( list ).*' 87 94 */ -
trunk/include/sh_unix.h
r264 r265 219 219 void sh_unix_closeall (int fd, int except, int inchild); 220 220 221 /* Check whether directory for pid file exists 222 */ 223 int sh_unix_check_piddir (char * pidpath); 221 224 222 225 /* write lock for filename -
trunk/src/samhain.c
r264 r265 753 753 #endif 754 754 delete_cache(); 755 sh_userid_destroy (); 755 756 sh_mem_stat(); 756 757 #endif -
trunk/src/sh_cat.c
r260 r265 159 159 { MSG_LOGMON_REP, SH_ERR_SEVERE, EVENT, N_("msg=\"POLICY [Logfile] %s\" time=\"%s\" host=\"%s\" path=\"%s\"") }, 160 160 { MSG_LOGMON_SUM, SH_ERR_SEVERE, EVENT, N_("msg=\"POLICY [Logfile] %s\" host=\"%s\" path=\"%s\"") }, 161 { MSG_LOGMON_COR, SH_ERR_SEVERE, EVENT, N_("msg=\"POLICY [Logfile] Correlated events %s\"") }, 161 { MSG_LOGMON_COR, SH_ERR_SEVERE, EVENT, N_("msg=\"POLICY [Logfile] Correlation event %s occured %d time(s)\"") }, 162 { MSG_LOGMON_MARK, SH_ERR_SEVERE, EVENT, N_("msg=\"POLICY [Logfile] Event %s missing for %lu seconds\"") }, 163 { MSG_LOGMON_BURST, SH_ERR_SEVERE, EVENT, N_("msg=\"POLICY [Logfile] Repeated %d times: %s\" host=\"%s\"") }, 162 164 #endif 163 165 … … 487 489 { MSG_LOGMON_EOPEN,SH_ERR_ERR, RUN, N_("msg=<Cannot open logfile %s>") }, 488 490 { MSG_LOGMON_EREAD,SH_ERR_ERR, RUN, N_("msg=<Error while reading logfile %s>") }, 489 { MSG_LOGMON_REP, SH_ERR_SEVERE, EVENT, N_("msg=<POLICY [Logfile] %s> time=<%s> host=<%s>path=<%s>") },491 { MSG_LOGMON_REP, SH_ERR_SEVERE, EVENT, N_("msg=<POLICY [Logfile] %s> time=<%s>, host=<%s>, path=<%s>") }, 490 492 { MSG_LOGMON_SUM, SH_ERR_SEVERE, EVENT, N_("msg=<POLICY [Logfile] %s> host=<%s> path=<%s>") }, 491 { MSG_LOGMON_COR, SH_ERR_SEVERE, EVENT, N_("msg=<POLICY [Logfile] Correlated events %s>") }, 493 { MSG_LOGMON_COR, SH_ERR_SEVERE, EVENT, N_("msg=<POLICY [Logfile] Correlation event %s occured %d time(s)>") }, 494 { MSG_LOGMON_MARK, SH_ERR_SEVERE, EVENT, N_("msg=<POLICY [Logfile] Event %s missing for %lu seconds>") }, 495 { MSG_LOGMON_BURST, SH_ERR_SEVERE, EVENT, N_("msg=<POLICY [Logfile] Repeated %d times: %s>, host=<%s> ") }, 492 496 #endif 493 497 -
trunk/src/sh_inotify.c
r261 r265 304 304 } while (len < 0 || errno == EINTR); 305 305 306 fprintf (stderr, "FIXME buflen=%ld\n", (long int) len);307 308 306 if (len > 0) 309 307 { … … 317 315 event = (struct inotify_event *) &buffer[i]; 318 316 319 fprintf (stderr, "FIXME wd=%d mask=%u cookie=%u len=%u\n",320 event->wd, event->mask,321 event->cookie, event->len);322 323 if (event->len > 0)324 fprintf (stderr, "FIXME name=%s\n", event->name);325 326 317 for (j = 0; j < watches->count; ++j) 327 318 { 328 fprintf (stderr, "FIXME %d watch=%d file=%s\n",329 j, watches->watch[j], watches->file[j]);330 331 319 if (watches->watch[j] == event->wd) 332 320 { 333 334 fprintf (stderr, "FIXME wd=%d mask=%u\n",335 event->wd, event->mask);336 337 321 if (event->mask & IN_MODIFY) 338 322 { -
trunk/src/sh_log_check.c
r260 r265 23 23 #include "sh_pthread.h" 24 24 #include "sh_utils.h" 25 #include "sh_unix.h" 25 26 #include "sh_string.h" 26 27 #include "sh_log_check.h" 27 28 #include "sh_log_evalrule.h" 29 #include "sh_log_correlate.h" 30 #include "sh_log_mark.h" 31 #include "sh_log_repeat.h" 28 32 29 33 /* List of supported logfile types, format is … … 52 56 ino_t inode; 53 57 fpos_t offset; 54 /* FIXME include filename hash */55 58 }; 56 59 57 constchar * save_dir = NULL;60 static char * save_dir = NULL; 58 61 59 62 static void * sh_dummy_path = NULL; … … 105 108 if (path) 106 109 { 110 if (0 != sh_unix_check_piddir (path)) 111 { 112 SH_FREE(path); 113 return; 114 } 115 107 116 fd = fopen(path, "wb"); 108 117 if (fd) … … 771 780 **********************************************************/ 772 781 782 /* Return current year, unless that would result 783 * in a date far in the future. If that happens, 784 * return last year. 785 */ 786 static int year_guess (struct tm * btime) 787 { 788 int year; 789 struct tm ts; 790 time_t now = time(NULL); 791 time_t check; 792 793 memcpy(&ts, localtime(&now), sizeof(struct tm)); 794 year = ts.tm_year; 795 796 /* Check result to detect year wrap 797 * (logfile entry from last year). 798 */ 799 btime->tm_year = year; 800 check = mktime(btime); 801 if (check > (now + (86400*30))) 802 --year; 803 804 return year; 805 } 806 773 807 time_t conv_timestamp (struct tm * btime, 774 808 struct tm * old_tm, time_t * old_time) … … 776 810 time_t timestamp; 777 811 long offtime; 812 778 813 779 814 /* timestamp - mktime is slooow, thus cache result … … 788 823 (btime->tm_min - old_tm->tm_min) * 60 + 789 824 (btime->tm_sec - old_tm->tm_sec); 825 790 826 *old_time += offtime; 791 827 memcpy(old_tm, btime, sizeof(struct tm)); … … 794 830 else 795 831 { 832 int year_btime = btime->tm_year; 833 834 if (btime->tm_year == 0) 835 btime->tm_year = year_guess(btime); 796 836 timestamp = mktime(btime); 837 btime->tm_year = year_btime; 838 797 839 *old_time = timestamp; 798 840 memcpy(old_tm, btime, sizeof(struct tm)); … … 866 908 sh_check_watches(); 867 909 sh_keep_match(); 910 sh_log_mark_check(); 868 911 } 869 912 SH_MUTEX_UNLOCK(mutex_logmon_check); … … 892 935 int sh_log_check_cleanup(void) 893 936 { 937 sh_log_mark_destroy(); 894 938 return sh_log_check_reconf(); 895 939 } … … 907 951 static int sh_logmon_add_rule (const char * str); 908 952 extern int sh_set_hidepid(const char *s); 953 static int sh_logmon_set_save_dir(const char *s); 909 954 910 955 sh_rconf sh_log_check_table[] = { … … 948 993 N_("logmonhidepid"), 949 994 sh_set_hidepid, 995 }, 996 { 997 N_("logmonsavedir"), 998 sh_logmon_set_save_dir, 999 }, 1000 { 1001 N_("logmonmarkseverity"), 1002 sh_logmon_set_save_dir, 1003 }, 1004 { 1005 N_("logmonburstthreshold"), 1006 sh_repeat_set_trigger, 1007 }, 1008 { 1009 N_("logmonburstqueue"), 1010 sh_repeat_set_queue, 1011 }, 1012 { 1013 N_("logmonburstcron"), 1014 sh_repeat_set_cron, 950 1015 }, 951 1016 { … … 966 1031 967 1032 SL_RETURN((value), _("sh_logmon_set_active")); 1033 } 1034 1035 static int sh_logmon_set_save_dir(const char *str) 1036 { 1037 int retval = -1; 1038 1039 SL_ENTER(_("sh_logmon_set_save_dir")); 1040 1041 if (str && str[0] == '/') 1042 { 1043 if (save_dir) 1044 { 1045 SH_FREE(save_dir); 1046 save_dir = NULL; 1047 } 1048 save_dir = sh_util_strdup(str); 1049 retval = 0; 1050 } 1051 1052 SL_RETURN((retval), _("sh_logmon_set_save_dir")); 968 1053 } 969 1054 -
trunk/src/sh_log_evalrule.c
r262 r265 5 5 #include <stdarg.h> 6 6 #include <string.h> 7 #include <ctype.h> 7 8 #include <time.h> 8 9 #include <limits.h> … … 31 32 #include "sh_log_check.h" 32 33 #include "sh_log_evalrule.h" 34 #include "sh_log_correlate.h" 35 #include "sh_log_mark.h" 36 #include "sh_log_repeat.h" 33 37 #include "zAVLTree.h" 34 38 … … 38 42 39 43 #ifdef DEBUG_EVALRULES 40 void DEBUG(const char *fmt, ...)44 static void DEBUG(const char *fmt, ...) 41 45 { 42 46 va_list ap; … … 47 51 } 48 52 #else 49 void DEBUG(const char *fmt, ...)53 static void DEBUG(const char *fmt, ...) 50 54 { 51 55 (void) fmt; … … 53 57 } 54 58 #endif 55 56 enum policies {57 EVAL_REPORT,58 EVAL_SUM59 };60 59 61 60 struct sh_ceval /* Counter for summarizing */ … … 80 79 } 81 80 82 struct sh_qeval /* Queue with definitions */83 {84 sh_string * label;85 enum policies policy;86 int severity;87 time_t interval; /* if EVAL_SUM, interval */88 struct sh_qeval * next;89 };90 91 81 enum { 92 82 RFL_ISRULE = 1 << 0, 93 83 RFL_ISGROUP = 1 << 1, 94 RFL_KEEP = 1 << 2 84 RFL_KEEP = 1 << 2, 85 RFL_MARK = 1 << 3 95 86 }; 96 87 97 /*--------------------------------------------------------------*/ 98 99 struct sh_keep 100 { 101 sh_string * label; /* label of keep rule */ 102 unsigned long delay; /* valid delay */ 103 time_t last; /* seen at */ 104 struct sh_keep * next; 105 }; 106 107 static struct sh_keep * keeplist = NULL; 108 static struct sh_keep * keeplast = NULL; 109 static unsigned long keepcount = 0; 110 111 static void sh_keep_free(void * item) 112 { 113 struct sh_keep * keep = (struct sh_keep *) item; 114 if (!keep) 115 return; 116 sh_string_destroy(&(keep->label)); 117 SH_FREE(keep); 118 } 119 120 static void sh_keep_destroy() 121 { 122 struct sh_keep * keep; 123 124 while (keeplist) 125 { 126 keep = keeplist; 127 keeplist = keep->next; 128 sh_keep_free(keep); 129 --keepcount; 130 } 131 keeplist = NULL; 132 keeplast = NULL; 133 keepcount = 0; 134 } 135 136 static int sh_keep_add(sh_string * label, unsigned long delay, time_t last) 137 { 138 struct sh_keep * keep = SH_ALLOC(sizeof(struct sh_keep)); 139 140 keep->label = sh_string_copy(label); 141 keep->delay = delay; 142 keep->last = last; 143 keep->next = NULL; 144 145 if (keeplast && keeplist) 146 { 147 keeplast->next = keep; 148 keeplast = keep; 149 } 150 else 151 { 152 keeplist = keep; 153 keeplast = keeplist; 154 } 155 ++keepcount; 156 return 0; 157 } 158 159 int sh_keep_comp(const void * a, const void * b) 160 { 161 return ( (int)(((struct sh_keep *)a)->last) - 162 (int)(((struct sh_keep *)b)->last) ); 163 } 164 165 static sh_string * sh_keep_eval() 166 { 167 unsigned long count = 0; 168 sh_string * res = NULL; 169 time_t now = time(NULL); 170 struct sh_keep * keep = keeplist; 171 struct sh_keep * prev = keeplist; 172 struct sh_keep * arr; 173 174 if (keepcount > 0) 175 { 176 arr = SH_ALLOC (keepcount * sizeof(struct sh_keep)); 177 178 while (count < keepcount && keep) 179 { 180 if ((now > keep->last) && ((unsigned long)(now - keep->last) <= keep->delay)) 181 { 182 memcpy(&(arr[count]), keep, sizeof(struct sh_keep)); 183 ++count; 184 prev = keep; 185 keep = keep->next; 186 } 187 else /* Too old or in future, delete it */ 188 { 189 if (keep != keeplist) 190 { 191 prev->next = keep->next; 192 sh_keep_free(keep); 193 keep = prev->next; 194 --keepcount; 195 } 196 else /* list head */ 197 { 198 keeplist = keep->next; 199 prev = keeplist; 200 sh_keep_free(keep); 201 keep = keeplist; 202 --keepcount; 203 } 204 } 205 } 206 207 if (count > 0) 208 { 209 unsigned long i; 210 qsort(arr, count, sizeof(struct sh_keep), sh_keep_comp); 211 res = sh_string_copy(arr[0].label); 212 for (i = 1; i < count; ++i) 213 res = sh_string_add(res, arr[i].label); 214 } 215 SH_FREE(arr); 216 } 217 return res; 218 } 219 220 struct sh_mkeep 221 { 222 sh_string * label; /* label of match rule */ 223 pcre * rule; /* compiled regex for rule */ 224 struct sh_qeval * queue; /* assigned queue */ 225 struct sh_mkeep * next; 226 }; 227 228 struct sh_mkeep * mkeep_list = NULL; 229 230 static struct sh_qeval * find_queue(const char * str); 231 232 static int sh_keep_match_add(const char * str, const char * queue, const char * pattern) 233 { 234 unsigned int nfields = 1; /* seconds:label */ 235 size_t lengths[1]; 236 char * new = sh_util_strdup(str); 237 char ** splits = split_array_braced(new, _("CORRELATE"), &nfields, lengths); 238 239 if (nfields == 1 && lengths[0] > 0) 240 { 241 struct sh_mkeep * mkeep = SH_ALLOC(sizeof(struct sh_mkeep)); 242 const char * error; 243 int erroffset; 244 struct sh_qeval * rqueue = NULL; 245 246 mkeep->rule = pcre_compile(pattern, PCRE_NO_AUTO_CAPTURE, 247 &error, &erroffset, NULL); 248 if (!(mkeep->rule)) 249 { 250 sh_string * msg = sh_string_new(0); 251 sh_string_add_from_char(msg, _("Bad regex: ")); 252 sh_string_add_from_char(msg, pattern); 253 254 SH_MUTEX_LOCK(mutex_thread_nolog); 255 sh_error_handle(SH_ERR_ERR, FIL__, __LINE__, 0, MSG_E_SUBGEN, 256 sh_string_str(msg), 257 _("sh_keep_match_add")); 258 SH_MUTEX_UNLOCK(mutex_thread_nolog); 259 sh_string_destroy(&msg); 260 261 SH_FREE(splits); 262 SH_FREE(mkeep); 263 SH_FREE(new); 264 return -1; 265 } 266 267 if (0 != strcmp(queue, _("trash"))) 268 { 269 270 rqueue = find_queue(queue); 271 if (!rqueue) 272 { 273 pcre_free(mkeep->rule); 274 SH_FREE(splits); 275 SH_FREE(mkeep); 276 SH_FREE(new); 277 return -1; 278 } 279 } 280 281 mkeep->queue = rqueue; 282 mkeep->label = sh_string_new_from_lchar(splits[0], strlen(splits[0])); 283 mkeep->next = mkeep_list; 284 mkeep_list = mkeep; 285 } 286 SH_FREE(new); 287 return 0; 288 } 289 290 static void sh_keep_match_del() 291 { 292 struct sh_mkeep * mkeep = mkeep_list; 293 while (mkeep) 294 { 295 mkeep_list = mkeep->next; 296 sh_string_destroy(&(mkeep->label)); 297 pcre_free(mkeep->rule); 298 mkeep = mkeep_list; 299 } 300 mkeep_list = NULL; 301 } 302 303 static struct sh_mkeep ** dummy_mkeep; 304 305 void sh_keep_match() 306 { 307 if (mkeep_list) 308 { 309 sh_string * res = sh_keep_eval(); 310 311 if (res) 312 { 313 struct sh_mkeep * mkeep = mkeep_list; 314 315 dummy_mkeep = &mkeep; 316 317 while (mkeep) 318 { 319 int val = pcre_exec(mkeep->rule, NULL, 320 sh_string_str(res), (int)sh_string_len(res), 321 0, 0, NULL, 0); 322 if (val >= 0) 323 { 324 char * tmp; 325 SH_MUTEX_LOCK(mutex_thread_nolog); 326 tmp = sh_util_safe_name (sh_string_str(mkeep->label)); 327 sh_error_handle (mkeep->queue->severity, FIL__, __LINE__, 0, 328 MSG_LOGMON_COR, tmp); 329 SH_FREE(tmp); 330 SH_MUTEX_UNLOCK(mutex_thread_nolog); 331 } 332 mkeep = mkeep->next; 333 } 334 sh_string_destroy(&res); 335 } 336 } 337 return; 338 } 339 340 /*--------------------------------------------------------------*/ 88 89 /*-------------------------------------------------------------- 90 * 91 * Adding rules/groups/hosts 92 * 93 *--------------------------------------------------------------*/ 341 94 342 95 struct sh_geval /* Group of rules (may be a single rule) */ … … 623 376 } 624 377 625 st atic struct sh_qeval *find_queue(const char * str)378 struct sh_qeval * sh_log_find_queue(const char * str) 626 379 { 627 380 struct sh_qeval * retval = queuelist; … … 639 392 } 640 393 641 char * get_keep(char * str, unsigned long * seconds) 394 int sh_log_lookup_severity(const char * str) 395 { 396 struct sh_qeval * queue; 397 398 if (str) 399 { 400 if (0 != strcmp(str, _("trash"))) 401 { 402 queue = sh_log_find_queue(str); 403 404 if (queue) 405 return queue->severity; 406 } 407 } 408 return SH_ERR_SEVERE; 409 } 410 411 static char * get_label_and_time(const char * inprefix, char * str, 412 unsigned long * seconds) 642 413 { 643 414 char * res = NULL; … … 646 417 unsigned int nfields = 2; /* seconds:label */ 647 418 size_t lengths[2]; 419 char * prefix = sh_util_strdup(inprefix); 648 420 char * new = sh_util_strdup(str); 649 char ** splits = split_array_braced(new, _("KEEP"), &nfields, lengths);650 651 if ( nfields == 2 && lengths[0] > 0 && lengths[1] > 0)421 char ** splits = split_array_braced(new, prefix, &nfields, lengths); 422 423 if (splits && nfields == 2 && lengths[0] > 0 && lengths[1] > 0) 652 424 { 653 425 *seconds = strtoul(splits[0], &endptr, 10); … … 660 432 SH_FREE(splits); 661 433 SH_FREE(new); 434 SH_FREE(prefix); 662 435 return res; 663 436 } … … 677 450 int captures = 0; 678 451 unsigned int nfields = 2; /* queue:regex */ 679 size_t lengths[ 2];452 size_t lengths[3]; 680 453 char * new = sh_util_strdup(str); 681 char ** splits = split_array(new, &nfields, ':', lengths); 682 683 int qpos = 0; 684 volatile int rpos = 1; 685 unsigned long dsec = 0; 686 char * dstr = NULL; 454 char ** splits; 455 456 int qpos = 0; 457 volatile int rpos = 1; 458 unsigned long dsec = 0; 459 char * dstr = NULL; 460 char * s = new; 461 volatile char pflag = '-'; 462 463 while ( *s && isspace((int)*s) ) ++s; 464 if (0 == strncmp(s, _("KEEP"), 4) || 465 0 == strncmp(s, _("CORRELATE"), 9) || 466 0 == strncmp(s, _("MARK"), 4)) 467 { 468 pflag = s[0]; 469 nfields = 3; 470 } 471 472 splits = split_array(new, &nfields, ':', lengths); 687 473 688 474 dummy_queue = &queue; … … 698 484 if (nfields == 3) 699 485 { 700 /* KEEP(nsec):queue:regex 701 */ 702 dstr = get_keep(splits[0], &dsec); 703 if (!dstr) 704 { 705 /* CORRELATE:queue:regex 486 if (pflag == 'K') 487 { 488 /* KEEP(nsec,label):queue:regex 489 */ 490 dstr = get_label_and_time(_("KEEP"), splits[0], &dsec); 491 if (!dstr) 492 { 493 SH_FREE(splits); 494 SH_FREE(new); 495 return -1; 496 } 497 } 498 else if (pflag == 'C') 499 { 500 /* CORRELATE(description):queue:regex 706 501 */ 707 502 int retval = sh_keep_match_add(splits[0], splits[1], splits[2]); … … 710 505 return retval; 711 506 } 507 else if (pflag == 'M') 508 { 509 /* MARK(description, interval):queue:regex 510 */ 511 int retval = -1; 512 513 dstr = get_label_and_time(_("MARK"), splits[0], &dsec); 514 if (dstr) 515 { 516 retval = sh_log_mark_add(dstr, dsec, splits[1]); 517 } 518 if (retval != 0) 519 { 520 SH_FREE(splits); 521 SH_FREE(new); 522 return retval; 523 } 524 } 712 525 ++qpos; ++rpos; 713 526 } … … 715 528 if (0 != strcmp(splits[qpos], _("trash"))) 716 529 { 717 queue = find_queue(splits[qpos]);530 queue = sh_log_find_queue(splits[qpos]); 718 531 if (!queue) 719 532 { … … 784 597 785 598 786 if ( dstr)599 if (pflag == 'K') 787 600 { 788 601 nr->label = sh_string_new_from_lchar(dstr, strlen(dstr)); 789 602 nr->flags |= RFL_KEEP; 603 nr->delay = dsec; 604 SH_FREE(dstr); 605 } 606 else if (pflag == 'M') 607 { 608 nr->label = sh_string_new_from_lchar(dstr, strlen(dstr)); 609 nr->flags |= RFL_MARK; 790 610 nr->delay = dsec; 791 611 SH_FREE(dstr); … … 1005 825 sl_snprintf(emsg, SH_ERRBUF_SIZE, _("Rule %d matches, result = %d (keep)"), 1006 826 count, res); 827 else if ( rule->flags & RFL_MARK ) 828 sl_snprintf(emsg, SH_ERRBUF_SIZE, _("Rule %d matches, result = %d (mark)"), 829 count, res); 1007 830 else 1008 831 sl_snprintf(emsg, SH_ERRBUF_SIZE, _("Rule %d matches, result = %d"), … … 1020 843 sh_keep_add(rule->label, rule->delay, 1021 844 timestamp == 0 ? time(NULL) : timestamp); 845 } 846 847 else if ( rule->flags & RFL_MARK ) 848 { 849 DEBUG("debug: rule %d matches (mark)\n", count); 850 sh_log_mark_update(rule->label, 851 timestamp == 0 ? time(NULL) : timestamp); 1022 852 } 1023 853 … … 1349 1179 msg_report(DEFAULT_SEVERITY, NULL, record); 1350 1180 } 1181 1182 sh_repeat_message_check(record->host, 1183 record->message, 1184 record->timestamp); 1185 1351 1186 return 0; 1352 1187 } -
trunk/src/sh_log_parse_syslog.c
r199 r265 72 72 73 73 74 if ( sh_string_len(logline) > 0 && flag_err_debug == SL_TRUE)74 if (flag_err_debug == SL_TRUE && sh_string_len(logline) > 0) 75 75 { 76 76 SH_MUTEX_LOCK(mutex_thread_nolog); -
trunk/src/sh_readconf.c
r254 r265 28 28 29 29 #include "samhain.h" 30 #include "sh_calls.h" 30 31 #include "sh_error.h" 31 #include "sh_database.h" 32 #include "sh_unix.h" 33 #include "sh_utils.h" 32 #include "sh_extern.h" 34 33 #include "sh_files.h" 35 #include "sh_mail.h"36 #include "sh_nmail.h"37 #include "sh_calls.h"38 #include "sh_tiger.h"39 34 #include "sh_forward.h" 40 #include "sh_modules.h"41 35 #include "sh_gpg.h" 42 36 #include "sh_hash.h" 43 37 #include "sh_ignore.h" 38 #include "sh_database.h" 39 #include "sh_mail.h" 40 #include "sh_modules.h" 41 #include "sh_nmail.h" 44 42 #include "sh_prelink.h" 45 #include "sh_extern.h"46 #include "sh_tools.h"47 48 #ifdef WITH_DATABASE49 #include "sh_database.h"50 #endif51 52 43 #ifdef HAVE_LIBPRELUDE 53 44 #include "sh_prelude.h" 54 45 #endif 46 #include "sh_tiger.h" 47 #include "sh_tools.h" 48 #include "sh_unix.h" 49 #include "sh_utils.h" 50 55 51 56 52 extern int set_reverse_lookup (const char * c); -
trunk/src/sh_socket.c
r264 r265 385 385 } 386 386 387 if (0 != sh_unix_check_piddir (sh_sockname)) 388 { 389 SH_FREE(sh_sockname); 390 SL_RETURN((-1),_("sh_socket_open_int")); 391 } 387 392 388 393 pf_unix_fd = socket (PF_UNIX, SOCK_STREAM, 0); -
trunk/src/sh_string.c
r260 r265 133 133 char ** split_array_ws_int (char *line, 134 134 unsigned int * nfields, size_t * lengths, 135 int isList)135 const char *delim, int isList) 136 136 { 137 137 char *a, *e, *s; … … 161 161 else 162 162 { 163 if ( *s && (*s == ' ' || *s == '\t' || *s == ',')) 164 { 165 do { 166 ++s; 167 } while ( *s && (*s == ' ' || *s == '\t' || *s == ',')); 168 } 163 if ( *s && strchr(delim, (int)*s)) 164 { 165 do { 166 ++s; 167 } while ( *s && strchr(delim, (int)*s)); 168 } 169 169 170 } 170 171 … … 183 184 else 184 185 { 185 186 187 } while ( *a && (*a != ' ' && *a != '\t' && *a != ','));186 do { 187 a++; 188 } while ( *a && NULL == strchr(delim, (int)*a)); 188 189 } 189 190 … … 231 232 unsigned int * nfields, size_t * lengths) 232 233 { 233 return split_array_ws_int (line, nfields, lengths, SH_SPLIT_WS);234 return split_array_ws_int (line, nfields, lengths, NULL, SH_SPLIT_WS); 234 235 } 235 236 … … 237 238 unsigned int * nfields, size_t * lengths) 238 239 { 239 return split_array_ws_int (line, nfields, lengths, SH_SPLIT_LIST); 240 return split_array_ws_int (line, nfields, lengths, ", \t", SH_SPLIT_LIST); 241 } 242 243 char ** split_array_token (char *line, 244 unsigned int * nfields, size_t * lengths, 245 const char * token) 246 { 247 return split_array_ws_int (line, nfields, lengths, token, SH_SPLIT_LIST); 240 248 } 241 249 -
trunk/src/sh_unix.c
r264 r265 4235 4235 } 4236 4236 4237 int sh_unix_check_piddir (char * pid file)4237 int sh_unix_check_piddir (char * pidpath) 4238 4238 { 4239 4239 static struct stat buf; … … 4243 4243 SL_ENTER(_("sh_unix_check_piddir")); 4244 4244 4245 pid_dir = sh_util_dirname (pid file);4245 pid_dir = sh_util_dirname (pidpath); 4246 4246 4247 4247 status = retry_lstat (FIL__, __LINE__, pid_dir, &buf);
Note:
See TracChangeset
for help on using the changeset viewer.