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
38 InspIRCd* ServerInstance;
39 void DefaultApply(User* u, char line);
44 * @param s_time The set time
45 * @param d The duration of the xline
46 * @param src The sender of the xline
47 * @param re The reason of the xline
49 XLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re)
50 : ServerInstance(Instance), set_time(s_time), duration(d)
54 expiry = set_time + duration;
65 /** Returns true whether or not the given user is covered by this line.
67 virtual bool Matches(User *u) = 0;
69 virtual bool Matches(const std::string &str);
71 virtual void Apply(User* u);
73 /** The time the line was added.
77 /** The duration of the ban, or 0 if permenant
81 /** Source of the ban. This can be a servername or an oper nickname
85 /** Reason for the ban
93 /** Q, K, etc. Don't change this. Constructors set it.
100 class CoreExport KLine : public XLine
104 * @param s_time The set time
105 * @param d The duration of the xline
106 * @param src The sender of the xline
107 * @param re The reason of the xline
108 * @param ident Ident to match
109 * @param host Host to match
111 KLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(Instance, s_time, d, src, re)
113 identmask = strdup(ident);
114 hostmask = strdup(host);
126 virtual bool Matches(User *u);
128 virtual void Apply(User* u);
140 class CoreExport GLine : public XLine
144 * @param s_time The set time
145 * @param d The duration of the xline
146 * @param src The sender of the xline
147 * @param re The reason of the xline
148 * @param ident Ident to match
149 * @param host Host to match
151 GLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(Instance, s_time, d, src, re)
153 identmask = strdup(ident);
154 hostmask = strdup(host);
166 virtual bool Matches(User *u);
168 virtual void Apply(User* u);
180 class CoreExport ELine : public XLine
183 /** Create an E-Line.
184 * @param s_time The set time
185 * @param d The duration of the xline
186 * @param src The sender of the xline
187 * @param re The reason of the xline
188 * @param ident Ident to match
189 * @param host Host to match
191 ELine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(Instance, s_time, d, src, re)
193 identmask = strdup(ident);
194 hostmask = strdup(host);
204 virtual bool Matches(User *u);
216 class CoreExport ZLine : public XLine
220 * @param s_time The set time
221 * @param d The duration of the xline
222 * @param src The sender of the xline
223 * @param re The reason of the xline
224 * @param ip IP to match
226 ZLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* ip) : XLine(Instance, s_time, d, src, re)
239 virtual bool Matches(User *u);
241 virtual bool Matches(const std::string &str);
243 virtual void Apply(User* u);
252 class CoreExport QLine : public XLine
256 * @param s_time The set time
257 * @param d The duration of the xline
258 * @param src The sender of the xline
259 * @param re The reason of the xline
260 * @param nickname Nickname to match
262 QLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* nickname) : XLine(Instance, s_time, d, src, re)
264 nick = strdup(nickname);
275 virtual bool Matches(User *u);
277 virtual bool Matches(const std::string &str);
279 virtual void Apply(User* u);
286 /* Required forward declarations
291 /** Initialize x line
293 bool InitXLine(ServerConfig* conf, const char* tag);
295 /** Done adding zlines from the config
297 bool DoneZLine(ServerConfig* conf, const char* tag);
298 /** Done adding qlines from the config
300 bool DoneQLine(ServerConfig* conf, const char* tag);
301 /** Done adding klines from the config
303 bool DoneKLine(ServerConfig* conf, const char* tag);
304 /** Done adding elines from the config
306 bool DoneELine(ServerConfig* conf, const char* tag);
308 /** Add a config-defined zline
310 bool DoZLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
311 /** Add a config-defined qline
313 bool DoQLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
314 /** Add a config-defined kline
316 bool DoKLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
317 /** Add a config-defined eline
319 bool DoELine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
321 /** Contains an ident and host split into two strings
323 typedef std::pair<std::string, std::string> IdentHostPair;
325 /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines.
327 class CoreExport XLineManager
330 /** The owner/creator of this class
332 InspIRCd* ServerInstance;
334 /** This functor is used by the std::sort() function to keep all lines in order
336 static bool XSortComparison (const XLine *one, const XLine *two);
338 /** Used to hold XLines which have not yet been applied.
340 std::vector<XLine *> pending_lines;
342 /* Lists for temporary lines with an expiry time */
344 /** Temporary KLines */
345 std::vector<KLine*> klines;
347 /** Temporary Glines */
348 std::vector<GLine*> glines;
350 /** Temporary Zlines */
351 std::vector<ZLine*> zlines;
353 /** Temporary QLines */
354 std::vector<QLine*> qlines;
356 /** Temporary ELines */
357 std::vector<ELine*> elines;
360 * @param Instance A pointer to the creator object
362 XLineManager(InspIRCd* Instance);
364 /** Split an ident and host into two seperate strings.
365 * This allows for faster matching.
367 IdentHostPair IdentSplit(const std::string &ident_and_host);
370 * @param duration The duration of the line
371 * @param source The source of the line
372 * @param reason The reason for the line
373 * @param hostmask The hostmask
374 * @return True if the line was added successfully
376 bool AddGLine(long duration, const char* source, const char* reason, const char* hostmask);
379 * @param duration The duration of the line
380 * @param source The source of the line
381 * @param reason The reason for the line
382 * @param nickname The nickmask
383 * @return True if the line was added successfully
385 bool AddQLine(long duration, const char* source, const char* reason, const char* nickname);
388 * @param duration The duration of the line
389 * @param source The source of the line
390 * @param reason The reason for the line
391 * @param ipaddr The IP mask
392 * @return True if the line was added successfully
394 bool AddZLine(long duration, const char* source, const char* reason, const char* ipaddr);
397 * @param duration The duration of the line
398 * @param source The source of the line
399 * @param reason The reason for the line
400 * @param hostmask The hostmask
401 * @return True if the line was added successfully
403 bool AddKLine(long duration, const char* source, const char* reason, const char* hostmask);
406 * @param duration The duration of the line
407 * @param source The source of the line
408 * @param reason The reason for the line
409 * @param hostmask The hostmask
410 * @return True if the line was added successfully
412 bool AddELine(long duration, const char* source, const char* reason, const char* hostmask);
415 * @param hostmask The host to remove
416 * @param simulate If this is true, don't actually remove the line, just return
417 * @return True if the line was deleted successfully
419 bool DelGLine(const char* hostmask, bool simulate = false);
422 * @param nickname The nick to remove
423 * @param simulate If this is true, don't actually remove the line, just return
424 * @return True if the line was deleted successfully
426 bool DelQLine(const char* nickname, bool simulate = false);
429 * @param ipaddr The IP to remove
430 * @param simulate If this is true, don't actually remove the line, just return
431 * @return True if the line was deleted successfully
433 bool DelZLine(const char* ipaddr, bool simulate = false);
436 * @param hostmask The host to remove
437 * @param simulate If this is true, don't actually remove the line, just return
438 * @return True if the line was deleted successfully
440 bool DelKLine(const char* hostmask, bool simulate = false);
443 * @param hostmask The host to remove
444 * @param simulate If this is true, don't actually remove the line, just return
445 * @return True if the line was deleted successfully
447 bool DelELine(const char* hostmask, bool simulate = false);
449 /** Check if a nickname matches a QLine
450 * @return nick The nick to check against
451 * @return The reason for the line if there is a match, or NULL if there is no match
453 QLine* matches_qline(const char* nick);
455 /** Check if a hostname matches a GLine
456 * @param user The user to check against
457 * @return The reason for the line if there is a match, or NULL if there is no match
459 GLine* matches_gline(User* user);
461 /** Check if a user's IP matches a ZLine
462 * @param user The user to check against
463 * @return The reason for the line if there is a match, or NULL if there is no match
465 ZLine* matches_zline(User *user);
467 /** Check if a hostname matches a KLine
468 * @param user The user to check against
469 * @return The reason for the line if there is a match, or NULL if there is no match
471 KLine* matches_kline(User* user);
473 /** Check if a hostname matches a ELine
474 * @param user The user to check against
475 * @return The reason for the line if there is a match, or NULL if there is no match
477 ELine* matches_exception(User* user);
479 /** Expire any lines that should be expired.
483 /** Apply any new lines that are pending to be applied
488 * @param user The username making the query
489 * @param results The string_list to receive the results
491 void stats_k(User* user, string_list &results);
494 * @param user The username making the query
495 * @param results The string_list to receive the results
497 void stats_g(User* user, string_list &results);
500 * @param user The username making the query
501 * @param results The string_list to receive the results
503 void stats_q(User* user, string_list &results);
506 * @param user The username making the query
507 * @param results The string_list to receive the results
509 void stats_z(User* user, string_list &results);
512 * @param user The username making the query
513 * @param results The string_list to receive the results
515 void stats_e(User* user, string_list &results);
517 /** Change creation time of a GLine
518 * @param host The hostname to change
519 * @param create_Time The new creation time
521 void gline_set_creation_time(const char* host, time_t create_time);
523 /** Change creation time of a QLine
524 * @param nick The nickmask to change
525 * @param create_Time The new creation time
527 void qline_set_creation_time(const char* nick, time_t create_time);
529 /** Change creation time of a ZLine
530 * @param ip The ipmask to change
531 * @param create_Time The new creation time
533 void zline_set_creation_time(const char* ip, time_t create_time);
535 /** Change creation time of a ELine
536 * @param host The hostname to change
537 * @param create_Time The new creation time
539 void eline_set_creation_time(const char* host, time_t create_time);