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 virtual void Unset() { };
75 virtual void DisplayExpiry() = 0;
77 /** The time the line was added.
81 /** The duration of the ban, or 0 if permenant
85 /** Source of the ban. This can be a servername or an oper nickname
89 /** Reason for the ban
97 /** Q, K, etc. Don't change this. Constructors set it.
104 class CoreExport KLine : public XLine
108 * @param s_time The set time
109 * @param d The duration of the xline
110 * @param src The sender of the xline
111 * @param re The reason of the xline
112 * @param ident Ident to match
113 * @param host Host to match
115 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)
117 identmask = strdup(ident);
118 hostmask = strdup(host);
130 virtual bool Matches(User *u);
132 virtual void Apply(User* u);
134 virtual void DisplayExpiry();
146 class CoreExport GLine : public XLine
150 * @param s_time The set time
151 * @param d The duration of the xline
152 * @param src The sender of the xline
153 * @param re The reason of the xline
154 * @param ident Ident to match
155 * @param host Host to match
157 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)
159 identmask = strdup(ident);
160 hostmask = strdup(host);
172 virtual bool Matches(User *u);
174 virtual void Apply(User* u);
176 virtual void DisplayExpiry();
188 class CoreExport ELine : public XLine
191 /** Create an E-Line.
192 * @param s_time The set time
193 * @param d The duration of the xline
194 * @param src The sender of the xline
195 * @param re The reason of the xline
196 * @param ident Ident to match
197 * @param host Host to match
199 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)
201 identmask = strdup(ident);
202 hostmask = strdup(host);
212 virtual bool Matches(User *u);
214 virtual void Unset();
216 virtual void DisplayExpiry();
228 class CoreExport ZLine : public XLine
232 * @param s_time The set time
233 * @param d The duration of the xline
234 * @param src The sender of the xline
235 * @param re The reason of the xline
236 * @param ip IP to match
238 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)
251 virtual bool Matches(User *u);
253 virtual bool Matches(const std::string &str);
255 virtual void Apply(User* u);
257 virtual void DisplayExpiry();
266 class CoreExport QLine : public XLine
270 * @param s_time The set time
271 * @param d The duration of the xline
272 * @param src The sender of the xline
273 * @param re The reason of the xline
274 * @param nickname Nickname to match
276 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)
278 nick = strdup(nickname);
289 virtual bool Matches(User *u);
291 virtual bool Matches(const std::string &str);
293 virtual void Apply(User* u);
295 virtual void DisplayExpiry();
302 /* Required forward declarations
307 /** Initialize x line
309 bool InitXLine(ServerConfig* conf, const char* tag);
311 /** Done adding zlines from the config
313 bool DoneZLine(ServerConfig* conf, const char* tag);
314 /** Done adding qlines from the config
316 bool DoneQLine(ServerConfig* conf, const char* tag);
317 /** Done adding klines from the config
319 bool DoneKLine(ServerConfig* conf, const char* tag);
320 /** Done adding elines from the config
322 bool DoneELine(ServerConfig* conf, const char* tag);
324 /** Add a config-defined zline
326 bool DoZLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
327 /** Add a config-defined qline
329 bool DoQLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
330 /** Add a config-defined kline
332 bool DoKLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
333 /** Add a config-defined eline
335 bool DoELine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
337 /** Contains an ident and host split into two strings
339 typedef std::pair<std::string, std::string> IdentHostPair;
341 /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines.
343 class CoreExport XLineManager
346 /** The owner/creator of this class
348 InspIRCd* ServerInstance;
350 /** This functor is used by the std::sort() function to keep all lines in order
352 static bool XSortComparison (const XLine *one, const XLine *two);
354 /** Used to hold XLines which have not yet been applied.
356 std::vector<XLine *> pending_lines;
358 std::vector<XLine *> active_lines;
362 std::map<std::string, ELine *> elines;
365 * @param Instance A pointer to the creator object
367 XLineManager(InspIRCd* Instance);
369 /** Split an ident and host into two seperate strings.
370 * This allows for faster matching.
372 IdentHostPair IdentSplit(const std::string &ident_and_host);
375 * @param duration The duration of the line
376 * @param source The source of the line
377 * @param reason The reason for the line
378 * @param hostmask The hostmask
379 * @return True if the line was added successfully
381 bool AddGLine(long duration, const char* source, const char* reason, const char* hostmask);
384 * @param duration The duration of the line
385 * @param source The source of the line
386 * @param reason The reason for the line
387 * @param nickname The nickmask
388 * @return True if the line was added successfully
390 bool AddQLine(long duration, const char* source, const char* reason, const char* nickname);
393 * @param duration The duration of the line
394 * @param source The source of the line
395 * @param reason The reason for the line
396 * @param ipaddr The IP mask
397 * @return True if the line was added successfully
399 bool AddZLine(long duration, const char* source, const char* reason, const char* ipaddr);
402 * @param duration The duration of the line
403 * @param source The source of the line
404 * @param reason The reason for the line
405 * @param hostmask The hostmask
406 * @return True if the line was added successfully
408 bool AddKLine(long duration, const char* source, const char* reason, const char* hostmask);
411 * @param duration The duration of the line
412 * @param source The source of the line
413 * @param reason The reason for the line
414 * @param hostmask The hostmask
415 * @return True if the line was added successfully
417 bool AddELine(long duration, const char* source, const char* reason, const char* hostmask);
420 * @param hostmask The host to remove
421 * @param type Type of line to remove
422 * @param simulate If this is true, don't actually remove the line, just return
423 * @return True if the line was deleted successfully
425 bool DelLine(const char* hostmask, char type, bool simulate = false);
427 /** Check if a nickname matches a QLine
428 * @return nick The nick to check against
429 * @return The reason for the line if there is a match, or NULL if there is no match
431 QLine* matches_qline(const char* nick);
433 /** Check if a hostname matches a GLine
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 GLine* matches_gline(User* user);
439 /** Check if a user's IP matches a ZLine
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 ZLine* matches_zline(User *user);
445 /** Check if a hostname matches a KLine
446 * @param user The user to check against
447 * @return The reason for the line if there is a match, or NULL if there is no match
449 KLine* matches_kline(User* user);
451 /** Check if a hostname matches a ELine
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 ELine* matches_exception(User* user);
457 /** Expire any lines that should be expired.
461 /** Apply any new lines that are pending to be applied
466 * @param user The username making the query
467 * @param results The string_list to receive the results
469 void stats_k(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_g(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_q(User* user, string_list &results);
484 * @param user The username making the query
485 * @param results The string_list to receive the results
487 void stats_z(User* user, string_list &results);
490 * @param user The username making the query
491 * @param results The string_list to receive the results
493 void stats_e(User* user, string_list &results);
495 /** Change creation time of a GLine
496 * @param host The hostname to change
497 * @param create_Time The new creation time
499 void gline_set_creation_time(const char* host, time_t create_time);
501 /** Change creation time of a QLine
502 * @param nick The nickmask to change
503 * @param create_Time The new creation time
505 void qline_set_creation_time(const char* nick, time_t create_time);
507 /** Change creation time of a ZLine
508 * @param ip The ipmask to change
509 * @param create_Time The new creation time
511 void zline_set_creation_time(const char* ip, time_t create_time);
513 /** Change creation time of a ELine
514 * @param host The hostname to change
515 * @param create_Time The new creation time
517 void eline_set_creation_time(const char* host, time_t create_time);