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, const char t)
50 : ServerInstance(Instance), set_time(s_time), duration(d), type(t)
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 /** Returns true wether or not the given string exactly matches the gline
70 * (no wildcard use in this method) -- used for removal of a line
72 virtual bool MatchesLiteral(std::string &str) = 0;
74 virtual bool Matches(const std::string &str);
76 virtual void Apply(User* u);
78 virtual void Unset() { }
80 virtual void DisplayExpiry() = 0;
82 virtual void OnAdd() { }
84 /** The time the line was added.
88 /** The duration of the ban, or 0 if permenant
92 /** Source of the ban. This can be a servername or an oper nickname
96 /** Reason for the ban
104 /** Q, K, etc. Don't change this. Constructors set it.
111 class CoreExport KLine : public XLine
115 * @param s_time The set time
116 * @param d The duration of the xline
117 * @param src The sender of the xline
118 * @param re The reason of the xline
119 * @param ident Ident to match
120 * @param host Host to match
122 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, 'K')
124 identmask = strdup(ident);
125 hostmask = strdup(host);
136 virtual bool Matches(User *u);
138 virtual bool MatchesLiteral(const std::string &str);
140 virtual void Apply(User* u);
142 virtual void DisplayExpiry();
154 class CoreExport GLine : public XLine
158 * @param s_time The set time
159 * @param d The duration of the xline
160 * @param src The sender of the xline
161 * @param re The reason of the xline
162 * @param ident Ident to match
163 * @param host Host to match
165 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, 'G')
167 identmask = strdup(ident);
168 hostmask = strdup(host);
179 virtual bool Matches(User *u);
181 virtual bool MatchesLiteral(const std::string &str);
183 virtual void Apply(User* u);
185 virtual void DisplayExpiry();
197 class CoreExport ELine : public XLine
200 /** Create an E-Line.
201 * @param s_time The set time
202 * @param d The duration of the xline
203 * @param src The sender of the xline
204 * @param re The reason of the xline
205 * @param ident Ident to match
206 * @param host Host to match
208 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, 'E')
210 identmask = strdup(ident);
211 hostmask = strdup(host);
220 virtual bool Matches(User *u);
222 virtual bool MatchesLiteral(const std::string &str);
224 virtual void Unset();
226 virtual void DisplayExpiry();
228 virtual void OnAdd();
240 class CoreExport ZLine : public XLine
244 * @param s_time The set time
245 * @param d The duration of the xline
246 * @param src The sender of the xline
247 * @param re The reason of the xline
248 * @param ip IP to match
250 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, 'Z')
262 virtual bool Matches(User *u);
264 virtual bool Matches(const std::string &str);
266 virtual bool MatchesLiteral(const std::string &str);
268 virtual void Apply(User* u);
270 virtual void DisplayExpiry();
279 class CoreExport QLine : public XLine
283 * @param s_time The set time
284 * @param d The duration of the xline
285 * @param src The sender of the xline
286 * @param re The reason of the xline
287 * @param nickname Nickname to match
289 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, 'Q')
291 nick = strdup(nickname);
301 virtual bool Matches(User *u);
303 virtual bool Matches(const std::string &str);
305 virtual bool MatchesLiteral(const std::string &str);
307 virtual void Apply(User* u);
309 virtual void DisplayExpiry();
316 /* Required forward declarations
321 /** Done adding elines from the config
323 bool DoneELine(ServerConfig* conf, const char* tag);
325 /** Contains an ident and host split into two strings
327 typedef std::pair<std::string, std::string> IdentHostPair;
329 /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines.
331 class CoreExport XLineManager
334 /** The owner/creator of this class
336 InspIRCd* ServerInstance;
338 /** This functor is used by the std::sort() function to keep all lines in order
340 static bool XSortComparison (const XLine *one, const XLine *two);
342 /** Used to hold XLines which have not yet been applied.
344 std::vector<XLine *> pending_lines;
346 std::vector<XLine *> active_lines;
350 std::map<char, std::map<std::string, XLine *> > lookup_lines;
353 * @param Instance A pointer to the creator object
355 XLineManager(InspIRCd* Instance);
357 /** Split an ident and host into two seperate strings.
358 * This allows for faster matching.
360 IdentHostPair IdentSplit(const std::string &ident_and_host);
362 /** Checks what users match a given list of ELines and sets their ban exempt flag accordingly.
363 * @param ELines List of E:Lines to check.
365 void CheckELines(std::map<std::string, XLine *> &ELines);
368 * @param duration The duration of the line
369 * @param source The source of the line
370 * @param reason The reason for the line
371 * @param hostmask The hostmask
372 * @return True if the line was added successfully
374 bool AddLine(XLine* line);
377 * @param hostmask The host to remove
378 * @param type Type of line to remove
379 * @param simulate If this is true, don't actually remove the line, just return
380 * @return True if the line was deleted successfully
382 bool DelLine(const char* hostmask, char type, bool simulate = false);
384 /** Check if a nickname matches a QLine
385 * @return nick The nick to check against
386 * @return The reason for the line if there is a match, or NULL if there is no match
388 QLine* matches_qline(const char* nick);
390 /** Check if a hostname matches a GLine
391 * @param user The user to check against
392 * @return The reason for the line if there is a match, or NULL if there is no match
394 GLine* matches_gline(User* user);
396 /** Check if a user's IP matches a ZLine
397 * @param user The user to check against
398 * @return The reason for the line if there is a match, or NULL if there is no match
400 ZLine* matches_zline(User *user);
402 /** Check if a hostname matches a KLine
403 * @param user The user to check against
404 * @return The reason for the line if there is a match, or NULL if there is no match
406 KLine* matches_kline(User* user);
408 /** Check if a hostname matches a ELine
409 * @param user The user to check against
410 * @return The reason for the line if there is a match, or NULL if there is no match
412 ELine* matches_exception(User* user);
414 /** Expire any lines that should be expired.
418 /** Apply any new lines that are pending to be applied
423 * @param user The username making the query
424 * @param results The string_list to receive the results
426 void stats_k(User* user, string_list &results);
429 * @param user The username making the query
430 * @param results The string_list to receive the results
432 void stats_g(User* user, string_list &results);
435 * @param user The username making the query
436 * @param results The string_list to receive the results
438 void stats_q(User* user, string_list &results);
441 * @param user The username making the query
442 * @param results The string_list to receive the results
444 void stats_z(User* user, string_list &results);
447 * @param user The username making the query
448 * @param results The string_list to receive the results
450 void stats_e(User* user, string_list &results);
452 /** Change creation time of a GLine
453 * @param host The hostname to change
454 * @param create_Time The new creation time
456 void gline_set_creation_time(const char* host, time_t create_time);
458 /** Change creation time of a QLine
459 * @param nick The nickmask to change
460 * @param create_Time The new creation time
462 void qline_set_creation_time(const char* nick, time_t create_time);
464 /** Change creation time of a ZLine
465 * @param ip The ipmask to change
466 * @param create_Time The new creation time
468 void zline_set_creation_time(const char* ip, time_t create_time);
470 /** Change creation time of a ELine
471 * @param host The hostname to change
472 * @param create_Time The new creation time
474 void eline_set_creation_time(const char* host, time_t create_time);