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(const std::string &str) = 0;
74 virtual bool Matches(const std::string &str) = 0;
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);
126 matchtext = this->identmask;
127 matchtext.append("@").append(this->hostmask);
138 virtual bool Matches(User *u);
140 virtual bool Matches(const std::string &str);
142 virtual bool MatchesLiteral(const std::string &str);
144 virtual void Apply(User* u);
146 virtual void DisplayExpiry();
155 std::string matchtext;
160 class CoreExport GLine : public XLine
164 * @param s_time The set time
165 * @param d The duration of the xline
166 * @param src The sender of the xline
167 * @param re The reason of the xline
168 * @param ident Ident to match
169 * @param host Host to match
171 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')
173 identmask = strdup(ident);
174 hostmask = strdup(host);
175 matchtext = this->identmask;
176 matchtext.append("@").append(this->hostmask);
187 virtual bool Matches(User *u);
189 virtual bool Matches(const std::string &str);
191 virtual bool MatchesLiteral(const std::string &str);
193 virtual void Apply(User* u);
195 virtual void DisplayExpiry();
204 std::string matchtext;
209 class CoreExport ELine : public XLine
212 /** Create an E-Line.
213 * @param s_time The set time
214 * @param d The duration of the xline
215 * @param src The sender of the xline
216 * @param re The reason of the xline
217 * @param ident Ident to match
218 * @param host Host to match
220 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')
222 identmask = strdup(ident);
223 hostmask = strdup(host);
224 matchtext = this->identmask;
225 matchtext.append("@").append(this->hostmask);
234 virtual bool Matches(User *u);
236 virtual bool Matches(const std::string &str);
238 virtual bool MatchesLiteral(const std::string &str);
240 virtual void Unset();
242 virtual void DisplayExpiry();
244 virtual void OnAdd();
253 std::string matchtext;
258 class CoreExport ZLine : public XLine
262 * @param s_time The set time
263 * @param d The duration of the xline
264 * @param src The sender of the xline
265 * @param re The reason of the xline
266 * @param ip IP to match
268 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')
280 virtual bool Matches(User *u);
282 virtual bool Matches(const std::string &str);
284 virtual bool MatchesLiteral(const std::string &str);
286 virtual void Apply(User* u);
288 virtual void DisplayExpiry();
297 class CoreExport QLine : public XLine
301 * @param s_time The set time
302 * @param d The duration of the xline
303 * @param src The sender of the xline
304 * @param re The reason of the xline
305 * @param nickname Nickname to match
307 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')
309 nick = strdup(nickname);
319 virtual bool Matches(User *u);
321 virtual bool Matches(const std::string &str);
323 virtual bool MatchesLiteral(const std::string &str);
325 virtual void Apply(User* u);
327 virtual void DisplayExpiry();
334 /* Required forward declarations
339 /** Done adding elines from the config
341 bool DoneELine(ServerConfig* conf, const char* tag);
343 /** Contains an ident and host split into two strings
345 typedef std::pair<std::string, std::string> IdentHostPair;
347 /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines.
349 class CoreExport XLineManager
352 /** The owner/creator of this class
354 InspIRCd* ServerInstance;
356 /** This functor is used by the std::sort() function to keep all lines in order
358 static bool XSortComparison (const XLine *one, const XLine *two);
360 /** Used to hold XLines which have not yet been applied.
362 std::vector<XLine *> pending_lines;
364 std::vector<XLine *> active_lines;
368 std::map<char, std::map<std::string, XLine *> > lookup_lines;
371 * @param Instance A pointer to the creator object
373 XLineManager(InspIRCd* Instance);
375 /** Split an ident and host into two seperate strings.
376 * This allows for faster matching.
378 IdentHostPair IdentSplit(const std::string &ident_and_host);
380 /** Checks what users match a given list of ELines and sets their ban exempt flag accordingly.
381 * @param ELines List of E:Lines to check.
383 void CheckELines(std::map<std::string, XLine *> &ELines);
386 * @param duration The duration of the line
387 * @param source The source of the line
388 * @param reason The reason for the line
389 * @param hostmask The hostmask
390 * @return True if the line was added successfully
392 bool AddLine(XLine* line);
395 * @param hostmask The host to remove
396 * @param type Type of line to remove
397 * @param simulate If this is true, don't actually remove the line, just return
398 * @return True if the line was deleted successfully
400 bool DelLine(const char* hostmask, char type, bool simulate = false);
402 /** Check if a nickname matches a QLine
403 * @return nick The nick to check against
404 * @return The reason for the line if there is a match, or NULL if there is no match
406 QLine* matches_qline(const char* nick);
408 /** Check if a hostname matches a GLine
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 GLine* matches_gline(User* user);
414 /** Check if a user's IP matches a ZLine
415 * @param user The user to check against
416 * @return The reason for the line if there is a match, or NULL if there is no match
418 ZLine* matches_zline(User *user);
420 /** Check if a hostname matches a KLine
421 * @param user The user to check against
422 * @return The reason for the line if there is a match, or NULL if there is no match
424 KLine* matches_kline(User* user);
426 /** Check if a hostname matches a ELine
427 * @param user The user to check against
428 * @return The reason for the line if there is a match, or NULL if there is no match
430 ELine* matches_exception(User* user);
432 /** Expire any lines that should be expired.
436 /** Apply any new lines that are pending to be applied
441 * @param user The username making the query
442 * @param results The string_list to receive the results
444 void stats_k(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_g(User* user, string_list &results);
453 * @param user The username making the query
454 * @param results The string_list to receive the results
456 void stats_q(User* user, string_list &results);
459 * @param user The username making the query
460 * @param results The string_list to receive the results
462 void stats_z(User* user, string_list &results);
465 * @param user The username making the query
466 * @param results The string_list to receive the results
468 void stats_e(User* user, string_list &results);
470 /** Change creation time of a GLine
471 * @param host The hostname to change
472 * @param create_Time The new creation time
474 void gline_set_creation_time(const char* host, time_t create_time);
476 /** Change creation time of a QLine
477 * @param nick The nickmask to change
478 * @param create_Time The new creation time
480 void qline_set_creation_time(const char* nick, time_t create_time);
482 /** Change creation time of a ZLine
483 * @param ip The ipmask to change
484 * @param create_Time The new creation time
486 void zline_set_creation_time(const char* ip, time_t create_time);
488 /** Change creation time of a ELine
489 * @param host The hostname to change
490 * @param create_Time The new creation time
492 void eline_set_creation_time(const char* host, time_t create_time);