Mercurial > syslog2iptables
annotate src/syslogconfig.h @ 48:ba0259c9e411 stable1011
Fixes to compile on Fedora 9 and for const correctness
author  Carl Byington <carl@fivetensg.com> 

date  Thu, 29 May 2008 11:38:42 0700 
parents  26c29da3fbdf 
children  206448c00b55 
rev  line source 

36  1 /* 
2  
3 Copyright (c) 2007 Carl Byington  510 Software Group, released under  
4 the GPL version 3 or any later version at your choice available at  
5 http://www.gnu.org/licenses/gpl3.0.txt  
6  
7 */  
1  8 
9  
10 class SYSLOGCONFIG;  
3  11 class CONFIG; 
12  
13 struct IPPAIR {  
48
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

14 int first; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

15 int last; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

16 int cidr; 
3  17 }; 
18  
19 class PATTERN {  
48
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

20 const char * pattern; // owned by the string table 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

21 regex_t re; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

22 int index; // zero based substring of the regex match that contains the ip address or hostname 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

23 int amount; // count to add to the ip address leaky bucket 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

24 const char * message; // for logging, owned by the string table 
3  25 public: 
48
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

26 ~PATTERN(); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

27 PATTERN(TOKEN &tok, const char *pattern_, int index_, int amount_, const char *msg_); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

28 bool process(char *buf, CONFIG &con, const char *file_name, int pattern_index); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

29 void dump(int level); 
3  30 }; 
1  31 
48
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

32 typedef SYSLOGCONFIG * SYSLOGCONFIGP; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

33 typedef PATTERN * PATTERNP; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

34 typedef list<SYSLOGCONFIGP> syslogconfig_list; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

35 typedef list<IPPAIR> ippair_list; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

36 typedef list<PATTERNP> pattern_list; 
2  37 const int buflen = 1024; 
1  38 
39 class SYSLOGCONFIG {  
48
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

40 TOKEN * tokp; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

41 const char * file_name; // name of the syslog file 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

42 pattern_list patterns; // owns the patterns 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

43 int fd; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

44 struct stat openfdstat; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

45 int len; // bytes in the buffer 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

46 char buf[buflen]; 
1  47 public: 
48
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

48 SYSLOGCONFIG(TOKEN &tok, const char *file_name_); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

49 ~SYSLOGCONFIG(); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

50 bool failed() { return (fd == 1); }; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

51 void open(bool msg); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

52 bool read(CONFIG &con); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

53 void close(); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

54 void add_pattern(PATTERNP pat); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

55 void process(CONFIG &con); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

56 void dump(int level); 
1  57 }; 
58  
3  59 class CONFIG { 
60 public:  
48
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

61 // the only mutable stuff once it has been loaded from the config file 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

62 int reference_count; // protected by the global config_mutex 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

63 // all the rest is constant after loading from the config file 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

64 int generation; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

65 time_t load_time; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

66 string_set config_files; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

67 int threshold; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

68 ippair_list ignore; // owns all the ippairs 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

69 const char * add_command; // owned by the string table 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

70 const char * remove_command; // "" 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

71 syslogconfig_list syslogconfigs; // owns all the syslogconfigs 
1  72 
48
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

73 CONFIG(); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

74 ~CONFIG(); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

75 void set_add(const char *add) { add_command = add; }; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

76 void set_remove(const char *remove) { remove_command = remove; }; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

77 void set_threshold(int threshold_) { threshold = threshold_; }; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

78 int get_threshold() { return threshold; }; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

79 void add_syslogconfig(SYSLOGCONFIGP con); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

80 void add_pair(IPPAIR pair); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

81 void dump(); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

82 void read(); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

83 void sleep(int duration, time_t &previous); 
36  84 void free_all(); 
48
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

85 bool looking(int ip); 
1  86 }; 
87  
48
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

88 void discard(string_set &s); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

89 const char* register_string(string_set &s, const char *name); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

90 const char* register_string(const char *name); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

91 void clear_strings(); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

92 int ip_address(const char *have); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

93 bool load_conf(CONFIG &dc, const char *fn); 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

94 void token_init(); 
1  95 
48
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

96 extern const char *token_add; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

97 extern const char *token_bucket; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

98 extern const char *token_file; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

99 extern const char *token_ignore; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

100 extern const char *token_include; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

101 extern const char *token_index; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

102 extern const char *token_lbrace; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

103 extern const char *token_pattern; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

104 extern const char *token_rbrace; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

105 extern const char *token_remove; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

106 extern const char *token_semi; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

107 extern const char *token_slash; 
ba0259c9e411
Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@fivetensg.com>
parents:
38
diff
changeset

108 extern const char *token_threshold; 
1  109 