4 #include "../core/config.h"
5 #include "../core/schedule.h"
6 #include "../lib/irc_string.h"
7 #include "../lib/splitline.h"
8 #include "../lib/strlfunc.h"
9 #include "../localuser/localuserchannel.h"
12 #include <mysql/mysql.h>
13 #include <mysql/mysql_version.h>
21 #define TROJANSCAN_VERSION "2.69"
23 #define TROJANSCAN_MAX_HOST_GLINE 5
25 #define TROJANSCAN_CLONE_MAX 75
26 #define TROJANSCAN_WATCHCLONE_MAX 75
27 #define TROJANSCAN_CLONE_TOTAL TROJANSCAN_CLONE_MAX + TROJANSCAN_WATCHCLONE_MAX
29 #define TROJANSCAN_POOLSIZE 1000
30 #define TROJANSCAN_MINPOOLSIZE 500 /* 500 */
32 #define TROJANSCAN_MINIMUM_HOSTS_BEFORE_POOL 5000 /* 5000 */
34 #define TROJANSCAN_DEFAULT_MAXCHANS 750
35 #define TROJANSCAN_DEFAULT_CYCLETIME 1600
37 #define TROJANSCAN_DEFAULT_MINIMUM_CHANNEL_SIZE 100 /* 100 */
39 #define TROJANSCAN_NICKCHANGE_ODDS 8
40 #define TROJANSCAN_INVISIBLE_ODDS 8
42 #define TROJANSCAN_DEFAULT_PARTTIME 150
43 #define TROJANSCAN_DEFAULT_MAXUSERS 20
45 #define TROJANSCAN_POOL_REGENERATION 3600
47 #define TROJANSCAN_HOST_POOL 0x00
48 #define TROJANSCAN_STEAL_HOST 0x01
50 #define TROJANSCAN_EPIDEMIC_MULTIPLIER 40
52 #define TROJANSCAN_HOST_MODE TROJANSCAN_STEAL_HOST
54 #define TROJANSCAN_MAX_CLONE_COUNT 5
56 #define TROJANSCAN_CAT "./trojanscan/cat.txt"
58 #define TROJANSCAN_CHANNEL "#qnet.trj"
59 #define TROJANSCAN_OPERCHANNEL "#twilightzone"
61 #define TROJANSCAN_URL_PREFIX "http://trojanscan.quakenet.org/?"
63 #define TROJANSCAN_MMAX(a, b) a > b ? a : b
64 #define TROJANSCAN_MMIN(a, b) a > b ? b : a
66 #define TROJANSCAN_NORMAL_CLONES 0
67 #define TROJANSCAN_WATCH_CLONES 1
69 #define TROJANSCAN_QUERY_TEMP_BUF_SIZE 1040
70 #define TROJANSCAN_QUERY_BUF_SIZE 5040
72 #define TROJANSCAN_FIRST_OFFENSE 12
73 #define TROJANSCAN_IPLEN 20
75 #define TROJANSCAN_VERSION_DETECT "\001VERSION"
76 #define TROJANSCAN_DEFAULT_VERSION_REPLY "mIRC v6.31 Khaled Mardam-Bey"
78 typedef struct trojanscan_clones
{
79 int remaining
, sitting
, index
;
81 patricia_node_t
*fakeipnode
;
84 typedef struct trojanscan_channels
{
87 } trojanscan_channels
;
89 typedef struct trojanscan_worms
{
92 unsigned glinehost
: 1;
93 unsigned glineuser
: 1;
97 unsigned hitchans
: 1;
98 unsigned epidemic
: 1;
101 typedef struct trojanscan_phrases
{
105 trojanscan_worms
*worm
;
106 } trojanscan_phrases
;
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
;
115 typedef struct trojanscan_prechannels
{
118 struct trojanscan_clones
*watch_clone
;
119 struct trojanscan_prechannels
*next
;
121 } trojanscan_prechannels
;
123 typedef struct trojanscan_realchannels
{
125 struct trojanscan_clones
*clone
;
126 struct trojanscan_realchannels
*next
;
130 } trojanscan_realchannels
;
132 typedef struct trojanscan_userflags
{
133 unsigned unauthed
: 1;
135 unsigned website
: 1;
137 unsigned teamleader
: 1;
138 unsigned developer
: 1;
139 } trojanscan_userflags
;
141 typedef union trojanscan_userlevel
{
143 struct trojanscan_userflags values
;
144 } trojanscan_userlevel
;
146 typedef struct trojanscan_flagmodification
{
149 } trojanscan_flagmodification
;
151 typedef struct trojanscan_rejoinlist
{
153 trojanscan_clones
*clone
;
155 struct trojanscan_realchannels
*rp
;
156 struct trojanscan_rejoinlist
*next
;
157 } trojanscan_rejoinlist
;
159 typedef struct trojanscan_inchannel
{
161 struct trojanscan_clones
*watch_clone
;
162 } trojanscan_inchannel
;
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
;
169 typedef MYSQL_RES trojanscan_database_res
;
170 typedef MYSQL_ROW trojanscan_database_row
;
171 typedef MYSQL trojanscan_database_connection
;
173 #define TROJANSCAN_FLAG_MASK "%s%s%s%s%s"
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)
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)))
185 #define TrojanscanFlagsInfo(flags) TrojanscanIsDeveloper(flags) ? "d" : "", TrojanscanIsTeamLeader(flags) ? "t" : "", TrojanscanIsStaff(flags) ? "s" : "", TrojanscanIsWebsite(flags) ? "w" : "", TrojanscanIsCat(flags) ? "c" : ""
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
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
);
210 char trojanscan_getmtfrommessagetype(int input
);
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
, ...);
215 void trojanscan_peonchanmsg(char *message
, ...);
216 void trojanscan_reply(nick
*target
, char *message
, ... );
217 void trojanscan_privmsg_chan_or_nick(channel
*cp
, nick
*np
, char *text
, ...);
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
);
228 void trojanscan_read_database(int first_time
);
229 void trojanscan_free_database(void);
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
);
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
);
243 int trojanscan_minmaxrand(float min
, float max
);
244 char *trojanscan_iptostr(char *buf
, int buflen
, unsigned int ip
);
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
);
254 nick
*trojanscan_selectuser(void);
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
);
261 void trojanscan_genhost(char *ptc
, char size
, patricia_node_t
**fakeipnode
);
263 int trojanscan_generatepool(void);
264 void trojanscan_watch_clone_update(struct trojanscan_prechannels
*hp
, int count
);
265 void trojanscan_repool(void *arg
);
267 void trojanscan_generatehost(char *buf
, int maxsize
, patricia_node_t
**fakeipnode
);
268 void trojanscan_generatenick(char *buf
, int maxsize
);
269 void trojanscan_generateident(char *buf
, int maxsize
);
270 void trojanscan_generaterealname(char *buf
, int maxsize
);
272 sstring
*trojanscan_getsstring(char *string
, int length
);
273 int trojanscan_strip_codes(char *buf
, size_t max
, char *original
);
274 int trojanscan_isip(char *host
);
276 struct trojanscan_clones trojanscan_swarm
[TROJANSCAN_CLONE_TOTAL
];
277 struct trojanscan_db trojanscan_database
;
279 sstring
*trojanscan_hostpool
[TROJANSCAN_POOLSIZE
], *trojanscan_tailpool
[TROJANSCAN_POOLSIZE
];
280 struct trojanscan_inchannel
*trojanscan_chans
= NULL
;
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;
285 int trojanscan_errorcode
;
286 struct trojanscan_realchannels
*trojanscan_realchanlist
;
287 char trojanscan_hostmode
;
289 void *trojanscan_schedule
, *trojanscan_connect_schedule
;
290 void *trojanscan_initialschedule
, *trojanscan_rehashschedule
, *trojanscan_poolschedule
, *trojanscan_cloneschedule
;
292 int trojanscan_minchansize
, trojanscan_min_hosts
;
293 int trojanscan_swarm_created
= 0;
295 nick
*trojanscan_nick
;
296 CommandTree
*trojanscan_cmds
;
297 trojanscan_database_connection trojanscan_sql
;
298 struct trojanscan_rejoinlist
*trojanscan_schedulerejoins
= NULL
;