4 #include "../core/config.h"
5 #include "../core/schedule.h"
6 #include "../lib/irc_string.h"
7 #include "../lib/splitline.h"
8 #include "../localuser/localuserchannel.h"
11 #include <mysql/mysql.h>
12 #include <mysql/mysql_version.h>
20 #define TROJANSCAN_VERSION "2.52"
22 #define TROJANSCAN_CLONE_MAX 300 /* 80 */
23 #define TROJANSCAN_WATCHCLONE_MAX 75
24 #define TROJANSCAN_CLONE_TOTAL TROJANSCAN_CLONE_MAX + TROJANSCAN_WATCHCLONE_MAX
26 #define TROJANSCAN_POOLSIZE 1000
27 #define TROJANSCAN_MINPOOLSIZE 1 /* 100 */
29 #define TROJANSCAN_MINIMUM_HOSTS_BEFORE_POOL 1 /* 500 */
31 #define TROJANSCAN_DEFAULT_MAXCHANS 500
32 #define TROJANSCAN_DEFAULT_CYCLETIME 600
34 #define TROJANSCAN_DEFAULT_MINIMUM_CHANNEL_SIZE 1 /* 100 */
36 #define TROJANSCAN_NICKCHANGE_ODDS 8
37 #define TROJANSCAN_INVISIBLE_ODDS 8
39 #define TROJANSCAN_DEFAULT_PARTTIME 100
40 #define TROJANSCAN_DEFAULT_MAXUSERS 20
42 #define TROJANSCAN_POOL_REGENERATION 3600
44 #define TROJANSCAN_HOST_POOL 0x00
45 #define TROJANSCAN_STEAL_HOST 0x01
47 #define TROJANSCAN_EPIDEMIC_MULTIPLIER 20
49 #define TROJANSCAN_HOST_MODE TROJANSCAN_STEAL_HOST
51 #define TROJANSCAN_CAT "./trojanscan/cat.txt"
53 #define TROJANSCAN_CHANNEL "#qnet.sec.trj"
54 #define TROJANSCAN_OPERCHANNEL "#twilightzone"
56 #define TROJANSCAN_URL_PREFIX "http://trojanscan.quakenet.org/?"
58 #define TROJANSCAN_MMAX(a, b) a > b ? a : b
59 #define TROJANSCAN_MMIN(a, b) a > b ? b : a
61 #define TROJANSCAN_NORMAL_CLONES 0
62 #define TROJANSCAN_WATCH_CLONES 1
64 #define TROJANSCAN_QUERY_TEMP_BUF_SIZE 1040
65 #define TROJANSCAN_QUERY_BUF_SIZE 5040
67 #define TROJANSCAN_FIRST_OFFENSE 2
68 #define TROJANSCAN_IPLEN 20
70 #define TROJANSCAN_VERSION_DETECT "\001VERSION"
71 #define TROJANSCAN_CLONE_VERSION_REPLY "mIRC v6.16 Khaled Mardam-Bey"
73 typedef struct trojanscan_clones
{
74 int remaining
, sitting
, index
;
78 typedef struct trojanscan_channels
{
81 } trojanscan_channels
;
83 typedef struct trojanscan_worms
{
86 unsigned glinehost
: 1;
87 unsigned glineuser
: 1;
91 unsigned hitchans
: 1;
92 unsigned epidemic
: 1;
95 typedef struct trojanscan_phrases
{
99 trojanscan_worms
*worm
;
100 } trojanscan_phrases
;
102 typedef struct trojanscan_db
{
103 int total_channels
, total_phrases
, total_worms
, detections
, glines
;
104 trojanscan_channels
*channels
;
105 trojanscan_phrases
*phrases
;
106 trojanscan_worms
*worms
;
109 typedef struct trojanscan_prechannels
{
112 struct trojanscan_clones
*watch_clone
;
113 struct trojanscan_prechannels
*next
;
115 } trojanscan_prechannels
;
117 typedef struct trojanscan_realchannels
{
119 struct trojanscan_clones
*clone
;
120 struct trojanscan_realchannels
*next
;
124 } trojanscan_realchannels
;
126 typedef struct trojanscan_userflags
{
127 unsigned unauthed
: 1;
129 unsigned website
: 1;
131 unsigned teamleader
: 1;
132 unsigned developer
: 1;
133 } trojanscan_userflags
;
135 typedef union trojanscan_userlevel
{
137 struct trojanscan_userflags values
;
138 } trojanscan_userlevel
;
140 typedef struct trojanscan_flagmodification
{
143 } trojanscan_flagmodification
;
145 typedef struct trojanscan_rejoinlist
{
149 struct trojanscan_realchannels
*rp
;
150 struct trojanscan_rejoinlist
*next
;
151 } trojanscan_rejoinlist
;
153 typedef struct trojanscan_inchannel
{
155 struct trojanscan_clones
*watch_clone
;
156 } trojanscan_inchannel
;
158 typedef struct trojanscan_templist
{
159 struct trojanscan_clones
*watch_clone
;
160 char active
; /* required as copy of trojanscan_inchannel could be nil unfortunatly */
161 } trojanscan_templist
;
163 typedef MYSQL_RES trojanscan_database_res
;
164 typedef MYSQL_ROW trojanscan_database_row
;
165 typedef MYSQL trojanscan_database_connection
;
167 #define TROJANSCAN_FLAG_MASK "%s%s%s%s%s"
169 #define TrojanscanIsCat(x) (x.values.cat)
170 #define TrojanscanIsWebsite(x) (x.values.website)
171 #define TrojanscanIsStaff(x) (x.values.staff)
172 #define TrojanscanIsDeveloper(x) (x.values.developer)
173 #define TrojanscanIsTeamLeader(x) (x.values.teamleader)
175 #define TrojanscanIsLeastTeamLeader(x) ((TrojanscanIsTeamLeader(x) | TrojanscanIsDeveloper(x)))
176 #define TrojanscanIsLeastWebsite(x) ((TrojanscanIsWebsite(x) | TrojanscanIsDeveloper(x)))
177 #define TrojanscanIsLeastStaff(x) ((TrojanscanIsStaff(x) | TrojanscanIsTeamLeader(x) | TrojanscanIsDeveloper(x)))
179 #define TrojanscanFlagsInfo(flags) TrojanscanIsDeveloper(flags) ? "d" : "", TrojanscanIsTeamLeader(flags) ? "t" : "", TrojanscanIsStaff(flags) ? "s" : "", TrojanscanIsWebsite(flags) ? "w" : "", TrojanscanIsCat(flags) ? "c" : ""
181 #define TROJANSCAN_ACL_UNAUTHED 0x01
182 #define TROJANSCAN_ACL_STAFF 0x02
183 #define TROJANSCAN_ACL_OPER 0x04
184 #define TROJANSCAN_ACL_DEVELOPER 0x08
185 #define TROJANSCAN_ACL_CAT 0x10
186 #define TROJANSCAN_ACL_WEBSITE 0x20
187 #define TROJANSCAN_ACL_TEAMLEADER 0x40
189 int trojanscan_status(void *sender
, int cargc
, char **cargv
);
190 int trojanscan_showcommands(void *sender
, int cargc
, char **cargv
);
191 int trojanscan_help(void *sender
, int cargc
, char **cargv
);
192 int trojanscan_hello(void *sender
, int cargc
, char **cargv
);
193 int trojanscan_userjoin(void *sender
, int cargc
, char **cargv
);
194 int trojanscan_changelev(void *sender
, int cargc
, char **cargv
);
195 int trojanscan_deluser(void *sender
, int cargc
, char **cargv
);
196 int trojanscan_rehash(void *sender
, int cargc
, char **cargv
);
197 int trojanscan_mew(void *sender
, int cargc
, char **cargv
);
198 int trojanscan_cat(void *sender
, int cargc
, char **cargv
);
199 int trojanscan_reschedule(void *sender
, int cargc
, char **cargv
);
200 int trojanscan_chanlist(void *sender
, int cargc
, char **cargv
);
201 int trojanscan_whois(void *sender
, int cargc
, char **cargv
);
202 int trojanscan_listusers(void *sender
, int cargc
, char **cargv
);
204 char trojanscan_getmtfrommessagetype(int input
);
206 void trojanscan_handlemessages(nick
*target
, int messagetype
, void **args
);
207 void trojanscan_clonehandlemessages(nick
*target
, int messagetype
, void **args
);
208 void trojanscan_mainchanmsg(char *message
, ...);
209 void trojanscan_reply(nick
*target
, char *message
, ... );
210 void trojanscan_privmsg_chan_or_nick(channel
*cp
, nick
*np
, char *text
, ...);
212 void trojanscan_connect(void *arg
);
213 void trojanscan_dojoin(void *arg
);
214 void trojanscan_dopart(void *arg
);
215 void trojanscan_donickchange(void *arg
);
216 void trojanscan_registerclones(void *arg
);
217 void trojanscan_fill_channels(void *arg
);
218 void trojanscan_rehash_schedule(void *arg
);
219 void trojanscan_rejoin_channel(void *arg
);
221 void trojanscan_read_database(int first_time
);
222 void trojanscan_free_database(void);
224 struct trojanscan_realchannels
*trojanscan_allocaterc(char *chan
);
225 void trojanscan_join(trojanscan_realchannels
*rc
);
226 struct trojanscan_clones
*trojanscan_selectclone(char type
);
227 void trojanscan_free_channels(void);
228 int trojanscan_add_ll(struct trojanscan_prechannels
**head
, struct trojanscan_prechannels
*newitem
);
229 int trojanscan_keysort(const void *v1
, const void *v2
);
231 int trojanscan_user_level_by_authname(char *authname
);
232 int trojanscan_user_id_by_authname(char *authname
);
233 struct trojanscan_worms
*trojanscan_find_worm_by_id(int id
);
234 char *trojanscan_getuser(int id
);
236 int trojanscan_minmaxrand(float min
, float max
);
237 char *trojanscan_iptostr(char *buf
, int buflen
, unsigned int ip
);
239 int trojanscan_database_connect(char *dbhost
, char *dbuser
, char *dbpass
, char *db
, unsigned int port
);
240 void trojanscan_database_close(void);
241 void trojanscan_database_escape_string(char *dest
, char *source
, size_t length
);
242 int trojanscan_database_query(char *format
, ...);
243 int trojanscan_database_num_rows(trojanscan_database_res
*res
);
244 trojanscan_database_res
*trojanscan_database_store_result();
245 trojanscan_database_row
trojanscan_database_fetch_row(trojanscan_database_res
*res
);
246 void trojanscan_database_free_result(trojanscan_database_res
*res
);
247 nick
*trojanscan_selectuser(void);
249 int trojanscan_is_not_octet(char *begin
, int length
);
250 void trojanscan_genreal(char *ptc
, char size
);
251 char trojanscan_genchar(int ty
);
252 void trojanscan_gennick(char *ptc
, char size
);
253 void trojanscan_genident(char *ptc
, char size
);
254 void trojanscan_genhost(char *ptc
, char size
);
256 int trojanscan_generatepool(void);
257 void trojanscan_watch_clone_update(struct trojanscan_prechannels
*hp
, int count
);
258 void trojanscan_repool(void *arg
);
260 void trojanscan_generatehost(char *buf
, int maxsize
);
261 void trojanscan_generatenick(char *buf
, int maxsize
);
262 void trojanscan_generateident(char *buf
, int maxsize
);
263 void trojanscan_generaterealname(char *buf
, int maxsize
);
265 sstring
*trojanscan_getsstring(char *string
, int length
);
266 int trojanscan_strip_codes(char *buf
, size_t max
, char *original
);
267 int trojanscan_isip(char *host
);
269 struct trojanscan_clones trojanscan_swarm
[TROJANSCAN_CLONE_TOTAL
];
270 struct trojanscan_db trojanscan_database
;
272 sstring
*trojanscan_hostpool
[TROJANSCAN_POOLSIZE
], *trojanscan_tailpool
[TROJANSCAN_POOLSIZE
];
273 struct trojanscan_inchannel
*trojanscan_chans
= NULL
;
275 unsigned int trojanscan_cycletime
, trojanscan_maxchans
, trojanscan_part_time
, trojanscan_activechans
= 0, trojanscan_tailpoolsize
= 0, trojanscan_hostpoolsize
= 0, trojanscan_channumber
= 0, trojanscan_maxusers
;
276 int trojanscan_watchclones_count
= 0;
278 int trojanscan_errorcode
;
279 struct trojanscan_realchannels
*trojanscan_realchanlist
;
280 char trojanscan_hostmode
;
282 void *trojanscan_schedule
, *trojanscan_connect_schedule
;
283 void *trojanscan_initialschedule
, *trojanscan_rehashschedule
, *trojanscan_poolschedule
, *trojanscan_cloneschedule
;
285 int trojanscan_minchansize
;
286 int trojanscan_swarm_created
= 0;
288 nick
*trojanscan_nick
;
289 CommandTree
*trojanscan_cmds
;
290 trojanscan_database_connection trojanscan_sql
;
291 struct trojanscan_rejoinlist
*trojanscan_schedulerejoins
= NULL
;