1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 // include the common header files
25 const int APPLY_GLINES = 1;
26 const int APPLY_KLINES = 2;
27 const int APPLY_QLINES = 4;
28 const int APPLY_ZLINES = 8;
29 const int APPLY_PERM_ONLY = 16;
30 const int APPLY_ALL = APPLY_GLINES | APPLY_KLINES | APPLY_QLINES | APPLY_ZLINES;
32 /** XLine is the base class for ban lines such as G lines and K lines.
34 class CoreExport XLine : public classbase
39 * @param s_time The set time
40 * @param d The duration of the xline
41 * @param src The sender of the xline
42 * @param re The reason of the xline
44 XLine(time_t s_time, long d, const char* src, const char* re)
45 : set_time(s_time), duration(d)
49 expiry = set_time + duration;
60 /** Returns true whether or not the given user is covered by this line.
62 virtual bool Matches(User *u);
64 /** The time the line was added.
68 /** The duration of the ban, or 0 if permenant
72 /** Source of the ban. This can be a servername or an oper nickname
76 /** Reason for the ban
87 class CoreExport KLine : public XLine
91 * @param s_time The set time
92 * @param d The duration of the xline
93 * @param src The sender of the xline
94 * @param re The reason of the xline
95 * @param ident Ident to match
96 * @param host Host to match
98 KLine(time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(s_time, d, src, re)
100 identmask = strdup(ident);
101 hostmask = strdup(host);
122 class CoreExport GLine : public XLine
126 * @param s_time The set time
127 * @param d The duration of the xline
128 * @param src The sender of the xline
129 * @param re The reason of the xline
130 * @param ident Ident to match
131 * @param host Host to match
133 GLine(time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(s_time, d, src, re)
135 identmask = strdup(ident);
136 hostmask = strdup(host);
157 class CoreExport ELine : public XLine
160 /** Create an E-Line.
161 * @param s_time The set time
162 * @param d The duration of the xline
163 * @param src The sender of the xline
164 * @param re The reason of the xline
165 * @param ident Ident to match
166 * @param host Host to match
168 ELine(time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(s_time, d, src, re)
170 identmask = strdup(ident);
171 hostmask = strdup(host);
190 class CoreExport ZLine : public XLine
194 * @param s_time The set time
195 * @param d The duration of the xline
196 * @param src The sender of the xline
197 * @param re The reason of the xline
198 * @param ip IP to match
200 ZLine(time_t s_time, long d, const char* src, const char* re, const char* ip) : XLine(s_time, d, src, re)
219 class CoreExport QLine : public XLine
223 * @param s_time The set time
224 * @param d The duration of the xline
225 * @param src The sender of the xline
226 * @param re The reason of the xline
227 * @param nickname Nickname to match
229 QLine(time_t s_time, long d, const char* src, const char* re, const char* nickname) : XLine(s_time, d, src, re)
231 nick = strdup(nickname);
246 /* Required forward declarations
251 /** Initialize x line
253 bool InitXLine(ServerConfig* conf, const char* tag);
255 /** Done adding zlines from the config
257 bool DoneZLine(ServerConfig* conf, const char* tag);
258 /** Done adding qlines from the config
260 bool DoneQLine(ServerConfig* conf, const char* tag);
261 /** Done adding klines from the config
263 bool DoneKLine(ServerConfig* conf, const char* tag);
264 /** Done adding elines from the config
266 bool DoneELine(ServerConfig* conf, const char* tag);
268 /** Add a config-defined zline
270 bool DoZLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
271 /** Add a config-defined qline
273 bool DoQLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
274 /** Add a config-defined kline
276 bool DoKLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
277 /** Add a config-defined eline
279 bool DoELine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
281 /** Contains an ident and host split into two strings
283 typedef std::pair<std::string, std::string> IdentHostPair;
285 /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines.
287 class CoreExport XLineManager
290 /** The owner/creator of this class
292 InspIRCd* ServerInstance;
294 /** This functor is used by the std::sort() function to keep all lines in order
296 static bool XSortComparison (const XLine *one, const XLine *two);
298 /* Lists for temporary lines with an expiry time */
300 /** Temporary KLines */
301 std::vector<KLine*> klines;
303 /** Temporary Glines */
304 std::vector<GLine*> glines;
306 /** Temporary Zlines */
307 std::vector<ZLine*> zlines;
309 /** Temporary QLines */
310 std::vector<QLine*> qlines;
312 /** Temporary ELines */
313 std::vector<ELine*> elines;
316 * @param Instance A pointer to the creator object
318 XLineManager(InspIRCd* Instance);
320 /** Split an ident and host into two seperate strings.
321 * This allows for faster matching.
323 IdentHostPair IdentSplit(const std::string &ident_and_host);
326 * @param duration The duration of the line
327 * @param source The source of the line
328 * @param reason The reason for the line
329 * @param hostmask The hostmask
330 * @return True if the line was added successfully
332 bool AddGLine(long duration, const char* source, const char* reason, const char* hostmask);
335 * @param duration The duration of the line
336 * @param source The source of the line
337 * @param reason The reason for the line
338 * @param nickname The nickmask
339 * @return True if the line was added successfully
341 bool AddQLine(long duration, const char* source, const char* reason, const char* nickname);
344 * @param duration The duration of the line
345 * @param source The source of the line
346 * @param reason The reason for the line
347 * @param ipaddr The IP mask
348 * @return True if the line was added successfully
350 bool AddZLine(long duration, const char* source, const char* reason, const char* ipaddr);
353 * @param duration The duration of the line
354 * @param source The source of the line
355 * @param reason The reason for the line
356 * @param hostmask The hostmask
357 * @return True if the line was added successfully
359 bool AddKLine(long duration, const char* source, const char* reason, const char* hostmask);
362 * @param duration The duration of the line
363 * @param source The source of the line
364 * @param reason The reason for the line
365 * @param hostmask The hostmask
366 * @return True if the line was added successfully
368 bool AddELine(long duration, const char* source, const char* reason, const char* hostmask);
371 * @param hostmask The host to remove
372 * @param simulate If this is true, don't actually remove the line, just return
373 * @return True if the line was deleted successfully
375 bool DelGLine(const char* hostmask, bool simulate = false);
378 * @param nickname The nick to remove
379 * @param simulate If this is true, don't actually remove the line, just return
380 * @return True if the line was deleted successfully
382 bool DelQLine(const char* nickname, bool simulate = false);
385 * @param ipaddr The IP to remove
386 * @param simulate If this is true, don't actually remove the line, just return
387 * @return True if the line was deleted successfully
389 bool DelZLine(const char* ipaddr, bool simulate = false);
392 * @param hostmask The host to remove
393 * @param simulate If this is true, don't actually remove the line, just return
394 * @return True if the line was deleted successfully
396 bool DelKLine(const char* hostmask, bool simulate = false);
399 * @param hostmask The host to remove
400 * @param simulate If this is true, don't actually remove the line, just return
401 * @return True if the line was deleted successfully
403 bool DelELine(const char* hostmask, bool simulate = false);
405 /** Check if a nickname matches a QLine
406 * @return nick The nick to check against
407 * @return The reason for the line if there is a match, or NULL if there is no match
409 QLine* matches_qline(const char* nick);
411 /** Check if a hostname matches a GLine
412 * @param user The user to check against
413 * @return The reason for the line if there is a match, or NULL if there is no match
415 GLine* matches_gline(User* user);
417 /** Check if a IP matches a ZLine
418 * @param ipaddr The IP to check against
419 * @return The reason for the line if there is a match, or NULL if there is no match
421 ZLine* matches_zline(const char* ipaddr);
423 /** Check if a hostname matches a KLine
424 * @param user The user to check against
425 * @return The reason for the line if there is a match, or NULL if there is no match
427 KLine* matches_kline(User* user);
429 /** Check if a hostname matches a ELine
430 * @param user The user to check against
431 * @return The reason for the line if there is a match, or NULL if there is no match
433 ELine* matches_exception(User* user);
435 /** Expire any lines that should be expired.
439 /** Apply any new lines that are pending to be applied
444 * @param user The username making the query
445 * @param results The string_list to receive the results
447 void stats_k(User* user, string_list &results);
450 * @param user The username making the query
451 * @param results The string_list to receive the results
453 void stats_g(User* user, string_list &results);
456 * @param user The username making the query
457 * @param results The string_list to receive the results
459 void stats_q(User* user, string_list &results);
462 * @param user The username making the query
463 * @param results The string_list to receive the results
465 void stats_z(User* user, string_list &results);
468 * @param user The username making the query
469 * @param results The string_list to receive the results
471 void stats_e(User* user, string_list &results);
473 /** Change creation time of a GLine
474 * @param host The hostname to change
475 * @param create_Time The new creation time
477 void gline_set_creation_time(const char* host, time_t create_time);
479 /** Change creation time of a QLine
480 * @param nick The nickmask to change
481 * @param create_Time The new creation time
483 void qline_set_creation_time(const char* nick, time_t create_time);
485 /** Change creation time of a ZLine
486 * @param ip The ipmask to change
487 * @param create_Time The new creation time
489 void zline_set_creation_time(const char* ip, time_t create_time);
491 /** Change creation time of a ELine
492 * @param host The hostname to change
493 * @param create_Time The new creation time
495 void eline_set_creation_time(const char* host, time_t create_time);