]>
Commit | Line | Data |
---|---|---|
c86edd1d Q |
1 | #ifndef __trojanscan_H |
2 | #define __trojanscan_H | |
3 | ||
4 | #include "../core/config.h" | |
5 | #include "../core/schedule.h" | |
6 | #include "../lib/irc_string.h" | |
7 | #include "../lib/splitline.h" | |
31f37482 | 8 | #include "../lib/strlfunc.h" |
c86edd1d Q |
9 | #include "../localuser/localuserchannel.h" |
10 | ||
11 | #include <assert.h> | |
12 | #include <mysql/mysql.h> | |
13 | #include <mysql/mysql_version.h> | |
14 | #include <pcre.h> | |
15 | #include <stdarg.h> | |
16 | #include <stdio.h> | |
17 | #include <string.h> | |
c8fdcfa5 CP |
18 | #include <ctype.h> |
19 | #include <strings.h> | |
c86edd1d | 20 | |
8f619fe4 | 21 | #define TROJANSCAN_VERSION "2.65" |
c86edd1d | 22 | |
052247fa CP |
23 | #define TROJANSCAN_MAX_HOST_GLINE 5 |
24 | ||
f49909c3 CP |
25 | #define TROJANSCAN_CLONE_MAX 75 |
26 | #define TROJANSCAN_WATCHCLONE_MAX 75 | |
c86edd1d Q |
27 | #define TROJANSCAN_CLONE_TOTAL TROJANSCAN_CLONE_MAX + TROJANSCAN_WATCHCLONE_MAX |
28 | ||
29 | #define TROJANSCAN_POOLSIZE 1000 | |
20b84796 | 30 | #define TROJANSCAN_MINPOOLSIZE 500 /* 500 */ |
c86edd1d | 31 | |
1fbd040c | 32 | #define TROJANSCAN_MINIMUM_HOSTS_BEFORE_POOL 5000 /* 5000 */ |
c86edd1d | 33 | |
31f37482 | 34 | #define TROJANSCAN_DEFAULT_MAXCHANS 750 |
f49909c3 | 35 | #define TROJANSCAN_DEFAULT_CYCLETIME 1600 |
c86edd1d | 36 | |
20b84796 | 37 | #define TROJANSCAN_DEFAULT_MINIMUM_CHANNEL_SIZE 100 /* 100 */ |
c86edd1d Q |
38 | |
39 | #define TROJANSCAN_NICKCHANGE_ODDS 8 | |
40 | #define TROJANSCAN_INVISIBLE_ODDS 8 | |
41 | ||
f49909c3 | 42 | #define TROJANSCAN_DEFAULT_PARTTIME 150 |
c86edd1d Q |
43 | #define TROJANSCAN_DEFAULT_MAXUSERS 20 |
44 | ||
45 | #define TROJANSCAN_POOL_REGENERATION 3600 | |
46 | ||
378cf1b9 CP |
47 | #define TROJANSCAN_HOST_POOL 0x00 |
48 | #define TROJANSCAN_STEAL_HOST 0x01 | |
49 | ||
31f37482 | 50 | #define TROJANSCAN_EPIDEMIC_MULTIPLIER 40 |
378cf1b9 CP |
51 | |
52 | #define TROJANSCAN_HOST_MODE TROJANSCAN_STEAL_HOST | |
53 | ||
707e6470 CP |
54 | #define TROJANSCAN_MAX_CLONE_COUNT 5 |
55 | ||
c86edd1d Q |
56 | #define TROJANSCAN_CAT "./trojanscan/cat.txt" |
57 | ||
e3448309 | 58 | #define TROJANSCAN_CHANNEL "#qnet.trj" |
c86edd1d Q |
59 | #define TROJANSCAN_OPERCHANNEL "#twilightzone" |
60 | ||
61 | #define TROJANSCAN_URL_PREFIX "http://trojanscan.quakenet.org/?" | |
62 | ||
63 | #define TROJANSCAN_MMAX(a, b) a > b ? a : b | |
64 | #define TROJANSCAN_MMIN(a, b) a > b ? b : a | |
65 | ||
66 | #define TROJANSCAN_NORMAL_CLONES 0 | |
67 | #define TROJANSCAN_WATCH_CLONES 1 | |
68 | ||
69 | #define TROJANSCAN_QUERY_TEMP_BUF_SIZE 1040 | |
70 | #define TROJANSCAN_QUERY_BUF_SIZE 5040 | |
71 | ||
31f37482 | 72 | #define TROJANSCAN_FIRST_OFFENSE 12 |
c86edd1d Q |
73 | #define TROJANSCAN_IPLEN 20 |
74 | ||
75 | #define TROJANSCAN_VERSION_DETECT "\001VERSION" | |
8f619fe4 | 76 | #define TROJANSCAN_DEFAULT_VERSION_REPLY "mIRC v6.31 Khaled Mardam-Bey" |
c86edd1d Q |
77 | |
78 | typedef struct trojanscan_clones { | |
79 | int remaining, sitting, index; | |
80 | nick *clone; | |
21ec3379 | 81 | patricia_node_t *fakeipnode; |
c86edd1d Q |
82 | } trojanscan_clones; |
83 | ||
84 | typedef struct trojanscan_channels { | |
85 | sstring *name; | |
86 | unsigned exempt : 1; | |
87 | } trojanscan_channels; | |
88 | ||
89 | typedef struct trojanscan_worms { | |
90 | int id; | |
91 | sstring *name; | |
92 | unsigned glinehost : 1; | |
93 | unsigned glineuser : 1; | |
94 | unsigned monitor : 1; | |
95 | unsigned datalen : 1; | |
96 | unsigned hitpriv : 1; | |
97 | unsigned hitchans : 1; | |
378cf1b9 | 98 | unsigned epidemic : 1; |
c86edd1d Q |
99 | } trojanscan_worms; |
100 | ||
101 | typedef struct trojanscan_phrases { | |
102 | int id; | |
103 | pcre *phrase; | |
104 | pcre_extra *hint; | |
105 | trojanscan_worms *worm; | |
106 | } trojanscan_phrases; | |
107 | ||
108 | typedef struct trojanscan_db { | |
109 | int total_channels, total_phrases, total_worms, detections, glines; | |
110 | trojanscan_channels *channels; | |
111 | trojanscan_phrases *phrases; | |
112 | trojanscan_worms *worms; | |
113 | } trojanscan_db; | |
114 | ||
115 | typedef struct trojanscan_prechannels { | |
116 | sstring *name; | |
117 | int size; | |
378cf1b9 | 118 | struct trojanscan_clones *watch_clone; |
c86edd1d Q |
119 | struct trojanscan_prechannels *next; |
120 | unsigned exempt : 1; | |
121 | } trojanscan_prechannels; | |
122 | ||
123 | typedef struct trojanscan_realchannels { | |
124 | channel *chan; | |
125 | struct trojanscan_clones *clone; | |
126 | struct trojanscan_realchannels *next; | |
127 | void *schedule; | |
128 | char donotpart; | |
129 | int kickedout; | |
130 | } trojanscan_realchannels; | |
131 | ||
132 | typedef struct trojanscan_userflags { | |
133 | unsigned unauthed : 1; | |
134 | unsigned cat : 1; | |
135 | unsigned website : 1; | |
136 | unsigned staff : 1; | |
137 | unsigned teamleader : 1; | |
138 | unsigned developer : 1; | |
139 | } trojanscan_userflags; | |
140 | ||
141 | typedef union trojanscan_userlevel { | |
142 | char number; | |
143 | struct trojanscan_userflags values; | |
144 | } trojanscan_userlevel; | |
145 | ||
146 | typedef struct trojanscan_flagmodification { | |
147 | char addition; | |
148 | char flag; | |
149 | } trojanscan_flagmodification; | |
150 | ||
151 | typedef struct trojanscan_rejoinlist { | |
152 | sstring *channel; | |
2e9a528b | 153 | trojanscan_clones *clone; |
c86edd1d Q |
154 | void *schedule; |
155 | struct trojanscan_realchannels *rp; | |
156 | struct trojanscan_rejoinlist *next; | |
157 | } trojanscan_rejoinlist; | |
158 | ||
378cf1b9 CP |
159 | typedef struct trojanscan_inchannel { |
160 | sstring *channel; | |
161 | struct trojanscan_clones *watch_clone; | |
162 | } trojanscan_inchannel; | |
163 | ||
164 | typedef struct trojanscan_templist { | |
165 | struct trojanscan_clones *watch_clone; | |
166 | char active; /* required as copy of trojanscan_inchannel could be nil unfortunatly */ | |
167 | } trojanscan_templist; | |
168 | ||
c86edd1d Q |
169 | typedef MYSQL_RES trojanscan_database_res; |
170 | typedef MYSQL_ROW trojanscan_database_row; | |
171 | typedef MYSQL trojanscan_database_connection; | |
172 | ||
173 | #define TROJANSCAN_FLAG_MASK "%s%s%s%s%s" | |
174 | ||
175 | #define TrojanscanIsCat(x) (x.values.cat) | |
176 | #define TrojanscanIsWebsite(x) (x.values.website) | |
177 | #define TrojanscanIsStaff(x) (x.values.staff) | |
178 | #define TrojanscanIsDeveloper(x) (x.values.developer) | |
179 | #define TrojanscanIsTeamLeader(x) (x.values.teamleader) | |
180 | ||
181 | #define TrojanscanIsLeastTeamLeader(x) ((TrojanscanIsTeamLeader(x) | TrojanscanIsDeveloper(x))) | |
182 | #define TrojanscanIsLeastWebsite(x) ((TrojanscanIsWebsite(x) | TrojanscanIsDeveloper(x))) | |
183 | #define TrojanscanIsLeastStaff(x) ((TrojanscanIsStaff(x) | TrojanscanIsTeamLeader(x) | TrojanscanIsDeveloper(x))) | |
184 | ||
185 | #define TrojanscanFlagsInfo(flags) TrojanscanIsDeveloper(flags) ? "d" : "", TrojanscanIsTeamLeader(flags) ? "t" : "", TrojanscanIsStaff(flags) ? "s" : "", TrojanscanIsWebsite(flags) ? "w" : "", TrojanscanIsCat(flags) ? "c" : "" | |
186 | ||
187 | #define TROJANSCAN_ACL_UNAUTHED 0x01 | |
188 | #define TROJANSCAN_ACL_STAFF 0x02 | |
189 | #define TROJANSCAN_ACL_OPER 0x04 | |
190 | #define TROJANSCAN_ACL_DEVELOPER 0x08 | |
191 | #define TROJANSCAN_ACL_CAT 0x10 | |
192 | #define TROJANSCAN_ACL_WEBSITE 0x20 | |
193 | #define TROJANSCAN_ACL_TEAMLEADER 0x40 | |
194 | ||
195 | int trojanscan_status(void *sender, int cargc, char **cargv); | |
196 | int trojanscan_showcommands(void *sender, int cargc, char **cargv); | |
197 | int trojanscan_help(void *sender, int cargc, char **cargv); | |
198 | int trojanscan_hello(void *sender, int cargc, char **cargv); | |
199 | int trojanscan_userjoin(void *sender, int cargc, char **cargv); | |
200 | int trojanscan_changelev(void *sender, int cargc, char **cargv); | |
201 | int trojanscan_deluser(void *sender, int cargc, char **cargv); | |
202 | int trojanscan_rehash(void *sender, int cargc, char **cargv); | |
203 | int trojanscan_mew(void *sender, int cargc, char **cargv); | |
204 | int trojanscan_cat(void *sender, int cargc, char **cargv); | |
205 | int trojanscan_reschedule(void *sender, int cargc, char **cargv); | |
206 | int trojanscan_chanlist(void *sender, int cargc, char **cargv); | |
207 | int trojanscan_whois(void *sender, int cargc, char **cargv); | |
208 | int trojanscan_listusers(void *sender, int cargc, char **cargv); | |
209 | ||
210 | char trojanscan_getmtfrommessagetype(int input); | |
211 | ||
212 | void trojanscan_handlemessages(nick *target, int messagetype, void **args); | |
213 | void trojanscan_clonehandlemessages(nick *target, int messagetype, void **args); | |
214 | void trojanscan_mainchanmsg(char *message, ...); | |
e261c2c9 | 215 | void trojanscan_peonchanmsg(char *message, ...); |
c86edd1d Q |
216 | void trojanscan_reply(nick *target, char *message, ... ); |
217 | void trojanscan_privmsg_chan_or_nick(channel *cp, nick *np, char *text, ...); | |
218 | ||
219 | void trojanscan_connect(void *arg); | |
220 | void trojanscan_dojoin(void *arg); | |
221 | void trojanscan_dopart(void *arg); | |
222 | void trojanscan_donickchange(void *arg); | |
223 | void trojanscan_registerclones(void *arg); | |
224 | void trojanscan_fill_channels(void *arg); | |
225 | void trojanscan_rehash_schedule(void *arg); | |
226 | void trojanscan_rejoin_channel(void *arg); | |
227 | ||
228 | void trojanscan_read_database(int first_time); | |
229 | void trojanscan_free_database(void); | |
230 | ||
231 | struct trojanscan_realchannels *trojanscan_allocaterc(char *chan); | |
232 | void trojanscan_join(trojanscan_realchannels *rc); | |
233 | struct trojanscan_clones *trojanscan_selectclone(char type); | |
234 | void trojanscan_free_channels(void); | |
235 | int trojanscan_add_ll(struct trojanscan_prechannels **head, struct trojanscan_prechannels *newitem); | |
236 | int trojanscan_keysort(const void *v1, const void *v2); | |
237 | ||
238 | int trojanscan_user_level_by_authname(char *authname); | |
239 | int trojanscan_user_id_by_authname(char *authname); | |
240 | struct trojanscan_worms *trojanscan_find_worm_by_id(int id); | |
241 | char *trojanscan_getuser(int id); | |
242 | ||
243 | int trojanscan_minmaxrand(float min, float max); | |
244 | char *trojanscan_iptostr(char *buf, int buflen, unsigned int ip); | |
245 | ||
246 | int trojanscan_database_connect(char *dbhost, char *dbuser, char *dbpass, char *db, unsigned int port); | |
247 | void trojanscan_database_close(void); | |
248 | void trojanscan_database_escape_string(char *dest, char *source, size_t length); | |
249 | int trojanscan_database_query(char *format, ...); | |
250 | int trojanscan_database_num_rows(trojanscan_database_res *res); | |
251 | trojanscan_database_res *trojanscan_database_store_result(); | |
252 | trojanscan_database_row trojanscan_database_fetch_row(trojanscan_database_res *res); | |
253 | void trojanscan_database_free_result(trojanscan_database_res *res); | |
c8fdcfa5 | 254 | nick *trojanscan_selectuser(void); |
c86edd1d Q |
255 | |
256 | int trojanscan_is_not_octet(char *begin, int length); | |
257 | void trojanscan_genreal(char *ptc, char size); | |
258 | char trojanscan_genchar(int ty); | |
259 | void trojanscan_gennick(char *ptc, char size); | |
260 | void trojanscan_genident(char *ptc, char size); | |
21ec3379 | 261 | void trojanscan_genhost(char *ptc, char size, patricia_node_t **fakeipnode); |
c86edd1d Q |
262 | |
263 | int trojanscan_generatepool(void); | |
264 | void trojanscan_watch_clone_update(struct trojanscan_prechannels *hp, int count); | |
265 | void trojanscan_repool(void *arg); | |
266 | ||
21ec3379 | 267 | void trojanscan_generatehost(char *buf, int maxsize, patricia_node_t **fakeipnode); |
c86edd1d Q |
268 | void trojanscan_generatenick(char *buf, int maxsize); |
269 | void trojanscan_generateident(char *buf, int maxsize); | |
270 | void trojanscan_generaterealname(char *buf, int maxsize); | |
271 | ||
272 | sstring *trojanscan_getsstring(char *string, int length); | |
273 | int trojanscan_strip_codes(char *buf, size_t max, char *original); | |
c8fdcfa5 | 274 | int trojanscan_isip(char *host); |
c86edd1d Q |
275 | |
276 | struct trojanscan_clones trojanscan_swarm[TROJANSCAN_CLONE_TOTAL]; | |
277 | struct trojanscan_db trojanscan_database; | |
278 | ||
279 | sstring *trojanscan_hostpool[TROJANSCAN_POOLSIZE], *trojanscan_tailpool[TROJANSCAN_POOLSIZE]; | |
378cf1b9 | 280 | struct trojanscan_inchannel *trojanscan_chans = NULL; |
c86edd1d Q |
281 | |
282 | unsigned int trojanscan_cycletime, trojanscan_maxchans, trojanscan_part_time, trojanscan_activechans = 0, trojanscan_tailpoolsize = 0, trojanscan_hostpoolsize = 0, trojanscan_channumber = 0, trojanscan_maxusers; | |
283 | int trojanscan_watchclones_count = 0; | |
284 | ||
285 | int trojanscan_errorcode; | |
286 | struct trojanscan_realchannels *trojanscan_realchanlist; | |
287 | char trojanscan_hostmode; | |
288 | ||
289 | void *trojanscan_schedule, *trojanscan_connect_schedule; | |
290 | void *trojanscan_initialschedule, *trojanscan_rehashschedule, *trojanscan_poolschedule, *trojanscan_cloneschedule; | |
291 | ||
36efd3fc | 292 | int trojanscan_minchansize, trojanscan_min_hosts; |
c86edd1d Q |
293 | int trojanscan_swarm_created = 0; |
294 | ||
295 | nick *trojanscan_nick; | |
296 | CommandTree *trojanscan_cmds; | |
297 | trojanscan_database_connection trojanscan_sql; | |
298 | struct trojanscan_rejoinlist *trojanscan_schedulerejoins = NULL; | |
299 | ||
300 | #endif |