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;
59 /** The time the line was added.
63 /** The duration of the ban, or 0 if permenant
67 /** Source of the ban. This can be a servername or an oper nickname
71 /** Reason for the ban
82 class CoreExport KLine : public XLine
86 * @param s_time The set time
87 * @param d The duration of the xline
88 * @param src The sender of the xline
89 * @param re The reason of the xline
90 * @param ident Ident to match
91 * @param host Host to match
93 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)
95 identmask = strdup(ident);
96 hostmask = strdup(host);
117 class CoreExport GLine : public XLine
121 * @param s_time The set time
122 * @param d The duration of the xline
123 * @param src The sender of the xline
124 * @param re The reason of the xline
125 * @param ident Ident to match
126 * @param host Host to match
128 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)
130 identmask = strdup(ident);
131 hostmask = strdup(host);
152 class CoreExport ELine : public XLine
155 /** Create an E-Line.
156 * @param s_time The set time
157 * @param d The duration of the xline
158 * @param src The sender of the xline
159 * @param re The reason of the xline
160 * @param ident Ident to match
161 * @param host Host to match
163 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)
165 identmask = strdup(ident);
166 hostmask = strdup(host);
185 class CoreExport ZLine : public XLine
189 * @param s_time The set time
190 * @param d The duration of the xline
191 * @param src The sender of the xline
192 * @param re The reason of the xline
193 * @param ip IP to match
195 ZLine(time_t s_time, long d, const char* src, const char* re, const char* ip) : XLine(s_time, d, src, re)
214 class CoreExport QLine : public XLine
218 * @param s_time The set time
219 * @param d The duration of the xline
220 * @param src The sender of the xline
221 * @param re The reason of the xline
222 * @param nickname Nickname to match
224 QLine(time_t s_time, long d, const char* src, const char* re, const char* nickname) : XLine(s_time, d, src, re)
226 nick = strdup(nickname);
241 /* Required forward declarations
246 /** Initialize x line
248 bool InitXLine(ServerConfig* conf, const char* tag);
250 /** Done adding zlines from the config
252 bool DoneZLine(ServerConfig* conf, const char* tag);
253 /** Done adding qlines from the config
255 bool DoneQLine(ServerConfig* conf, const char* tag);
256 /** Done adding klines from the config
258 bool DoneKLine(ServerConfig* conf, const char* tag);
259 /** Done adding elines from the config
261 bool DoneELine(ServerConfig* conf, const char* tag);
263 /** Add a config-defined zline
265 bool DoZLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
266 /** Add a config-defined qline
268 bool DoQLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
269 /** Add a config-defined kline
271 bool DoKLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
272 /** Add a config-defined eline
274 bool DoELine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
276 /** Contains an ident and host split into two strings
278 typedef std::pair<std::string, std::string> IdentHostPair;
280 /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines.
282 class CoreExport XLineManager
285 /** The owner/creator of this class
287 InspIRCd* ServerInstance;
289 /** This functor is used by the std::sort() function to keep glines in order
291 static bool GSortComparison ( const GLine* one, const GLine* two );
293 /** This functor is used by the std::sort() function to keep elines in order
295 static bool ESortComparison ( const ELine* one, const ELine* two );
297 /** This functor is used by the std::sort() function to keep zlines in order
299 static bool ZSortComparison ( const ZLine* one, const ZLine* two );
301 /** This functor is used by the std::sort() function to keep klines in order
303 static bool KSortComparison ( const KLine* one, const KLine* two );
305 /** This functor is used by the std::sort() function to keep qlines in order
307 static bool QSortComparison ( const QLine* one, const QLine* two );
309 /* Lists for temporary lines with an expiry time */
311 /** Temporary KLines */
312 std::vector<KLine*> klines;
314 /** Temporary Glines */
315 std::vector<GLine*> glines;
317 /** Temporary Zlines */
318 std::vector<ZLine*> zlines;
320 /** Temporary QLines */
321 std::vector<QLine*> qlines;
323 /** Temporary ELines */
324 std::vector<ELine*> elines;
326 /* Seperate lists for perm XLines that isnt checked by expiry functions */
328 /** Permenant KLines */
329 std::vector<KLine*> pklines;
331 /** Permenant GLines */
332 std::vector<GLine*> pglines;
334 /** Permenant ZLines */
335 std::vector<ZLine*> pzlines;
337 /** Permenant QLines */
338 std::vector<QLine*> pqlines;
340 /** Permenant ELines */
341 std::vector<ELine*> pelines;
344 * @param Instance A pointer to the creator object
346 XLineManager(InspIRCd* Instance);
348 /** Split an ident and host into two seperate strings.
349 * This allows for faster matching.
351 IdentHostPair IdentSplit(const std::string &ident_and_host);
354 * @param duration The duration of the line
355 * @param source The source of the line
356 * @param reason The reason for the line
357 * @param hostmask The hostmask
358 * @return True if the line was added successfully
360 bool add_gline(long duration, const char* source, const char* reason, const char* hostmask);
363 * @param duration The duration of the line
364 * @param source The source of the line
365 * @param reason The reason for the line
366 * @param nickname The nickmask
367 * @return True if the line was added successfully
369 bool add_qline(long duration, const char* source, const char* reason, const char* nickname);
372 * @param duration The duration of the line
373 * @param source The source of the line
374 * @param reason The reason for the line
375 * @param ipaddr The IP mask
376 * @return True if the line was added successfully
378 bool add_zline(long duration, const char* source, const char* reason, const char* ipaddr);
381 * @param duration The duration of the line
382 * @param source The source of the line
383 * @param reason The reason for the line
384 * @param hostmask The hostmask
385 * @return True if the line was added successfully
387 bool add_kline(long duration, const char* source, const char* reason, const char* hostmask);
390 * @param duration The duration of the line
391 * @param source The source of the line
392 * @param reason The reason for the line
393 * @param hostmask The hostmask
394 * @return True if the line was added successfully
396 bool add_eline(long duration, const char* source, const char* reason, const char* hostmask);
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 del_gline(const char* hostmask, bool simulate = false);
406 * @param nickname The nick to remove
407 * @param simulate If this is true, don't actually remove the line, just return
408 * @return True if the line was deleted successfully
410 bool del_qline(const char* nickname, bool simulate = false);
413 * @param ipaddr The IP to remove
414 * @param simulate If this is true, don't actually remove the line, just return
415 * @return True if the line was deleted successfully
417 bool del_zline(const char* ipaddr, bool simulate = false);
420 * @param hostmask The host to remove
421 * @param simulate If this is true, don't actually remove the line, just return
422 * @return True if the line was deleted successfully
424 bool del_kline(const char* hostmask, bool simulate = false);
427 * @param hostmask The host to remove
428 * @param simulate If this is true, don't actually remove the line, just return
429 * @return True if the line was deleted successfully
431 bool del_eline(const char* hostmask, bool simulate = false);
433 /** Check if a nickname matches a QLine
434 * @return nick The nick to check against
435 * @return The reason for the line if there is a match, or NULL if there is no match
437 QLine* matches_qline(const char* nick, bool permonly = false);
439 /** Check if a hostname matches a GLine
440 * @param user The user to check against
441 * @return The reason for the line if there is a match, or NULL if there is no match
443 GLine* matches_gline(userrec* user, bool permonly = false);
445 /** Check if a IP matches a ZLine
446 * @param ipaddr The IP to check against
447 * @return The reason for the line if there is a match, or NULL if there is no match
449 ZLine* matches_zline(const char* ipaddr, bool permonly = false);
451 /** Check if a hostname matches a KLine
452 * @param user The user to check against
453 * @return The reason for the line if there is a match, or NULL if there is no match
455 KLine* matches_kline(userrec* user, bool permonly = false);
457 /** Check if a hostname matches a ELine
458 * @param user The user to check against
459 * @return The reason for the line if there is a match, or NULL if there is no match
461 ELine* matches_exception(userrec* user, bool permonly = false);
463 /** Expire any pending non-permenant lines
467 /** Apply any new lines
468 * @param What The types of lines to apply, from the set
469 * APPLY_GLINES | APPLY_KLINES | APPLY_QLINES | APPLY_ZLINES | APPLY_ALL
472 void apply_lines(const int What);
475 * @param user The username making the query
476 * @param results The string_list to receive the results
478 void stats_k(userrec* user, string_list &results);
481 * @param user The username making the query
482 * @param results The string_list to receive the results
484 void stats_g(userrec* user, string_list &results);
487 * @param user The username making the query
488 * @param results The string_list to receive the results
490 void stats_q(userrec* user, string_list &results);
493 * @param user The username making the query
494 * @param results The string_list to receive the results
496 void stats_z(userrec* user, string_list &results);
499 * @param user The username making the query
500 * @param results The string_list to receive the results
502 void stats_e(userrec* user, string_list &results);
504 /** Change creation time of a GLine
505 * @param host The hostname to change
506 * @param create_Time The new creation time
508 void gline_set_creation_time(const char* host, time_t create_time);
510 /** Change creation time of a QLine
511 * @param nick The nickmask to change
512 * @param create_Time The new creation time
514 void qline_set_creation_time(const char* nick, time_t create_time);
516 /** Change creation time of a ZLine
517 * @param ip The ipmask to change
518 * @param create_Time The new creation time
520 void zline_set_creation_time(const char* ip, time_t create_time);
522 /** Change creation time of a ELine
523 * @param host The hostname to change
524 * @param create_Time The new creation time
526 void eline_set_creation_time(const char* host, time_t create_time);