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 /** Done adding elines from the config
309 bool DoneELine(ServerConfig* conf, const char* tag);
311 /** Contains an ident and host split into two strings
313 typedef std::pair<std::string, std::string> IdentHostPair;
315 /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines.
317 class CoreExport XLineManager
320 /** The owner/creator of this class
322 InspIRCd* ServerInstance;
324 /** This functor is used by the std::sort() function to keep all lines in order
326 static bool XSortComparison (const XLine *one, const XLine *two);
328 /** Used to hold XLines which have not yet been applied.
330 std::vector<XLine *> pending_lines;
332 std::vector<XLine *> active_lines;
336 std::map<char, std::map<std::string, XLine *> > lookup_lines;
339 * @param Instance A pointer to the creator object
341 XLineManager(InspIRCd* Instance);
343 /** Split an ident and host into two seperate strings.
344 * This allows for faster matching.
346 IdentHostPair IdentSplit(const std::string &ident_and_host);
348 /** Checks what users match a given list of ELines and sets their ban exempt flag accordingly.
349 * @param ELines List of E:Lines to check.
351 void CheckELines(std::map<std::string, XLine *> &ELines);
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 AddGLine(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 AddQLine(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 AddZLine(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 AddKLine(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 AddELine(long duration, const char* source, const char* reason, const char* hostmask);
399 * @param hostmask The host to remove
400 * @param type Type of line to remove
401 * @param simulate If this is true, don't actually remove the line, just return
402 * @return True if the line was deleted successfully
404 bool DelLine(const char* hostmask, char type, bool simulate = false);
406 /** Check if a nickname matches a QLine
407 * @return nick The nick to check against
408 * @return The reason for the line if there is a match, or NULL if there is no match
410 QLine* matches_qline(const char* nick);
412 /** Check if a hostname matches a GLine
413 * @param user The user to check against
414 * @return The reason for the line if there is a match, or NULL if there is no match
416 GLine* matches_gline(User* user);
418 /** Check if a user's IP matches a ZLine
419 * @param user The user to check against
420 * @return The reason for the line if there is a match, or NULL if there is no match
422 ZLine* matches_zline(User *user);
424 /** Check if a hostname matches a KLine
425 * @param user The user to check against
426 * @return The reason for the line if there is a match, or NULL if there is no match
428 KLine* matches_kline(User* user);
430 /** Check if a hostname matches a ELine
431 * @param user The user to check against
432 * @return The reason for the line if there is a match, or NULL if there is no match
434 ELine* matches_exception(User* user);
436 /** Expire any lines that should be expired.
440 /** Apply any new lines that are pending to be applied
445 * @param user The username making the query
446 * @param results The string_list to receive the results
448 void stats_k(User* user, string_list &results);
451 * @param user The username making the query
452 * @param results The string_list to receive the results
454 void stats_g(User* user, string_list &results);
457 * @param user The username making the query
458 * @param results The string_list to receive the results
460 void stats_q(User* user, string_list &results);
463 * @param user The username making the query
464 * @param results The string_list to receive the results
466 void stats_z(User* user, string_list &results);
469 * @param user The username making the query
470 * @param results The string_list to receive the results
472 void stats_e(User* user, string_list &results);
474 /** Change creation time of a GLine
475 * @param host The hostname to change
476 * @param create_Time The new creation time
478 void gline_set_creation_time(const char* host, time_t create_time);
480 /** Change creation time of a QLine
481 * @param nick The nickmask to change
482 * @param create_Time The new creation time
484 void qline_set_creation_time(const char* nick, time_t create_time);
486 /** Change creation time of a ZLine
487 * @param ip The ipmask to change
488 * @param create_Time The new creation time
490 void zline_set_creation_time(const char* ip, time_t create_time);
492 /** Change creation time of a ELine
493 * @param host The hostname to change
494 * @param create_Time The new creation time
496 void eline_set_creation_time(const char* host, time_t create_time);