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) = 0;
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);
112 virtual bool Matches(User *u);
124 class CoreExport GLine : public XLine
128 * @param s_time The set time
129 * @param d The duration of the xline
130 * @param src The sender of the xline
131 * @param re The reason of the xline
132 * @param ident Ident to match
133 * @param host Host to match
135 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)
137 identmask = strdup(ident);
138 hostmask = strdup(host);
149 virtual bool Matches(User *u);
161 class CoreExport ELine : public XLine
164 /** Create an E-Line.
165 * @param s_time The set time
166 * @param d The duration of the xline
167 * @param src The sender of the xline
168 * @param re The reason of the xline
169 * @param ident Ident to match
170 * @param host Host to match
172 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)
174 identmask = strdup(ident);
175 hostmask = strdup(host);
184 virtual bool Matches(User *u);
196 class CoreExport ZLine : public XLine
200 * @param s_time The set time
201 * @param d The duration of the xline
202 * @param src The sender of the xline
203 * @param re The reason of the xline
204 * @param ip IP to match
206 ZLine(time_t s_time, long d, const char* src, const char* re, const char* ip) : XLine(s_time, d, src, re)
218 virtual bool Matches(User *u);
227 class CoreExport QLine : public XLine
231 * @param s_time The set time
232 * @param d The duration of the xline
233 * @param src The sender of the xline
234 * @param re The reason of the xline
235 * @param nickname Nickname to match
237 QLine(time_t s_time, long d, const char* src, const char* re, const char* nickname) : XLine(s_time, d, src, re)
239 nick = strdup(nickname);
249 virtual bool Matches(User *u);
256 /* Required forward declarations
261 /** Initialize x line
263 bool InitXLine(ServerConfig* conf, const char* tag);
265 /** Done adding zlines from the config
267 bool DoneZLine(ServerConfig* conf, const char* tag);
268 /** Done adding qlines from the config
270 bool DoneQLine(ServerConfig* conf, const char* tag);
271 /** Done adding klines from the config
273 bool DoneKLine(ServerConfig* conf, const char* tag);
274 /** Done adding elines from the config
276 bool DoneELine(ServerConfig* conf, const char* tag);
278 /** Add a config-defined zline
280 bool DoZLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
281 /** Add a config-defined qline
283 bool DoQLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
284 /** Add a config-defined kline
286 bool DoKLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
287 /** Add a config-defined eline
289 bool DoELine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
291 /** Contains an ident and host split into two strings
293 typedef std::pair<std::string, std::string> IdentHostPair;
295 /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines.
297 class CoreExport XLineManager
300 /** The owner/creator of this class
302 InspIRCd* ServerInstance;
304 /** This functor is used by the std::sort() function to keep all lines in order
306 static bool XSortComparison (const XLine *one, const XLine *two);
308 /* Lists for temporary lines with an expiry time */
310 /** Temporary KLines */
311 std::vector<KLine*> klines;
313 /** Temporary Glines */
314 std::vector<GLine*> glines;
316 /** Temporary Zlines */
317 std::vector<ZLine*> zlines;
319 /** Temporary QLines */
320 std::vector<QLine*> qlines;
322 /** Temporary ELines */
323 std::vector<ELine*> elines;
326 * @param Instance A pointer to the creator object
328 XLineManager(InspIRCd* Instance);
330 /** Split an ident and host into two seperate strings.
331 * This allows for faster matching.
333 IdentHostPair IdentSplit(const std::string &ident_and_host);
336 * @param duration The duration of the line
337 * @param source The source of the line
338 * @param reason The reason for the line
339 * @param hostmask The hostmask
340 * @return True if the line was added successfully
342 bool AddGLine(long duration, const char* source, const char* reason, const char* hostmask);
345 * @param duration The duration of the line
346 * @param source The source of the line
347 * @param reason The reason for the line
348 * @param nickname The nickmask
349 * @return True if the line was added successfully
351 bool AddQLine(long duration, const char* source, const char* reason, const char* nickname);
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 ipaddr The IP mask
358 * @return True if the line was added successfully
360 bool AddZLine(long duration, const char* source, const char* reason, const char* ipaddr);
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 hostmask The hostmask
367 * @return True if the line was added successfully
369 bool AddKLine(long duration, const char* source, const char* reason, const char* hostmask);
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 hostmask The hostmask
376 * @return True if the line was added successfully
378 bool AddELine(long duration, const char* source, const char* reason, const char* hostmask);
381 * @param hostmask The host to remove
382 * @param simulate If this is true, don't actually remove the line, just return
383 * @return True if the line was deleted successfully
385 bool DelGLine(const char* hostmask, bool simulate = false);
388 * @param nickname The nick to remove
389 * @param simulate If this is true, don't actually remove the line, just return
390 * @return True if the line was deleted successfully
392 bool DelQLine(const char* nickname, bool simulate = false);
395 * @param ipaddr The IP to remove
396 * @param simulate If this is true, don't actually remove the line, just return
397 * @return True if the line was deleted successfully
399 bool DelZLine(const char* ipaddr, bool simulate = false);
402 * @param hostmask The host to remove
403 * @param simulate If this is true, don't actually remove the line, just return
404 * @return True if the line was deleted successfully
406 bool DelKLine(const char* hostmask, bool simulate = false);
409 * @param hostmask The host to remove
410 * @param simulate If this is true, don't actually remove the line, just return
411 * @return True if the line was deleted successfully
413 bool DelELine(const char* hostmask, bool simulate = false);
415 /** Check if a nickname matches a QLine
416 * @return nick The nick to check against
417 * @return The reason for the line if there is a match, or NULL if there is no match
419 QLine* matches_qline(const char* nick);
421 /** Check if a hostname matches a GLine
422 * @param user The user to check against
423 * @return The reason for the line if there is a match, or NULL if there is no match
425 GLine* matches_gline(User* user);
427 /** Check if a IP matches a ZLine
428 * @param ipaddr The IP to check against
429 * @return The reason for the line if there is a match, or NULL if there is no match
431 ZLine* matches_zline(const char* ipaddr);
433 /** Check if a hostname matches a KLine
434 * @param user The user to check against
435 * @return The reason for the line if there is a match, or NULL if there is no match
437 KLine* matches_kline(User* user);
439 /** Check if a hostname matches a ELine
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 ELine* matches_exception(User* user);
445 /** Expire any lines that should be expired.
449 /** Apply any new lines that are pending to be applied
454 * @param user The username making the query
455 * @param results The string_list to receive the results
457 void stats_k(User* user, string_list &results);
460 * @param user The username making the query
461 * @param results The string_list to receive the results
463 void stats_g(User* user, string_list &results);
466 * @param user The username making the query
467 * @param results The string_list to receive the results
469 void stats_q(User* user, string_list &results);
472 * @param user The username making the query
473 * @param results The string_list to receive the results
475 void stats_z(User* user, string_list &results);
478 * @param user The username making the query
479 * @param results The string_list to receive the results
481 void stats_e(User* user, string_list &results);
483 /** Change creation time of a GLine
484 * @param host The hostname to change
485 * @param create_Time The new creation time
487 void gline_set_creation_time(const char* host, time_t create_time);
489 /** Change creation time of a QLine
490 * @param nick The nickmask to change
491 * @param create_Time The new creation time
493 void qline_set_creation_time(const char* nick, time_t create_time);
495 /** Change creation time of a ZLine
496 * @param ip The ipmask to change
497 * @param create_Time The new creation time
499 void zline_set_creation_time(const char* ip, time_t create_time);
501 /** Change creation time of a ELine
502 * @param host The hostname to change
503 * @param create_Time The new creation time
505 void eline_set_creation_time(const char* host, time_t create_time);