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
39 * @param s_time The set time
40 * @param d The duration of the xline
41 * @param src The sender of the xline
42 * @param re The reason of the xline
44 XLine(time_t s_time, long d, const char* src, const char* re)
45 : set_time(s_time), duration(d)
49 expiry = set_time + duration;
60 /** Returns true whether or not the given user is covered by this line.
62 virtual bool Matches(User *u) = 0;
64 virtual bool Matches(const std::string &str);
66 /** The time the line was added.
70 /** The duration of the ban, or 0 if permenant
74 /** Source of the ban. This can be a servername or an oper nickname
78 /** Reason for the ban
86 /** Q, K, etc. Don't change this. Constructors set it.
93 class CoreExport KLine : public XLine
97 * @param s_time The set time
98 * @param d The duration of the xline
99 * @param src The sender of the xline
100 * @param re The reason of the xline
101 * @param ident Ident to match
102 * @param host Host to match
104 KLine(time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(s_time, d, src, re)
106 identmask = strdup(ident);
107 hostmask = strdup(host);
119 virtual bool Matches(User *u);
131 class CoreExport GLine : public XLine
135 * @param s_time The set time
136 * @param d The duration of the xline
137 * @param src The sender of the xline
138 * @param re The reason of the xline
139 * @param ident Ident to match
140 * @param host Host to match
142 GLine(time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(s_time, d, src, re)
144 identmask = strdup(ident);
145 hostmask = strdup(host);
157 virtual bool Matches(User *u);
169 class CoreExport ELine : public XLine
172 /** Create an E-Line.
173 * @param s_time The set time
174 * @param d The duration of the xline
175 * @param src The sender of the xline
176 * @param re The reason of the xline
177 * @param ident Ident to match
178 * @param host Host to match
180 ELine(time_t s_time, long d, const char* src, const char* re, const char* ident, const char* host) : XLine(s_time, d, src, re)
182 identmask = strdup(ident);
183 hostmask = strdup(host);
193 virtual bool Matches(User *u);
205 class CoreExport ZLine : public XLine
209 * @param s_time The set time
210 * @param d The duration of the xline
211 * @param src The sender of the xline
212 * @param re The reason of the xline
213 * @param ip IP to match
215 ZLine(time_t s_time, long d, const char* src, const char* re, const char* ip) : XLine(s_time, d, src, re)
228 virtual bool Matches(User *u);
230 virtual bool Matches(const std::string &str);
239 class CoreExport QLine : public XLine
243 * @param s_time The set time
244 * @param d The duration of the xline
245 * @param src The sender of the xline
246 * @param re The reason of the xline
247 * @param nickname Nickname to match
249 QLine(time_t s_time, long d, const char* src, const char* re, const char* nickname) : XLine(s_time, d, src, re)
251 nick = strdup(nickname);
262 virtual bool Matches(User *u);
264 virtual bool Matches(const std::string &str);
271 /* Required forward declarations
276 /** Initialize x line
278 bool InitXLine(ServerConfig* conf, const char* tag);
280 /** Done adding zlines from the config
282 bool DoneZLine(ServerConfig* conf, const char* tag);
283 /** Done adding qlines from the config
285 bool DoneQLine(ServerConfig* conf, const char* tag);
286 /** Done adding klines from the config
288 bool DoneKLine(ServerConfig* conf, const char* tag);
289 /** Done adding elines from the config
291 bool DoneELine(ServerConfig* conf, const char* tag);
293 /** Add a config-defined zline
295 bool DoZLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
296 /** Add a config-defined qline
298 bool DoQLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
299 /** Add a config-defined kline
301 bool DoKLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
302 /** Add a config-defined eline
304 bool DoELine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
306 /** Contains an ident and host split into two strings
308 typedef std::pair<std::string, std::string> IdentHostPair;
310 /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines.
312 class CoreExport XLineManager
315 /** The owner/creator of this class
317 InspIRCd* ServerInstance;
319 /** This functor is used by the std::sort() function to keep all lines in order
321 static bool XSortComparison (const XLine *one, const XLine *two);
323 /** Used to hold XLines which have not yet been applied.
325 std::vector<XLine *> pending_lines;
327 /* Lists for temporary lines with an expiry time */
329 /** Temporary KLines */
330 std::vector<KLine*> klines;
332 /** Temporary Glines */
333 std::vector<GLine*> glines;
335 /** Temporary Zlines */
336 std::vector<ZLine*> zlines;
338 /** Temporary QLines */
339 std::vector<QLine*> qlines;
341 /** Temporary ELines */
342 std::vector<ELine*> elines;
345 * @param Instance A pointer to the creator object
347 XLineManager(InspIRCd* Instance);
349 /** Split an ident and host into two seperate strings.
350 * This allows for faster matching.
352 IdentHostPair IdentSplit(const std::string &ident_and_host);
355 * @param duration The duration of the line
356 * @param source The source of the line
357 * @param reason The reason for the line
358 * @param hostmask The hostmask
359 * @return True if the line was added successfully
361 bool AddGLine(long duration, const char* source, const char* reason, const char* hostmask);
364 * @param duration The duration of the line
365 * @param source The source of the line
366 * @param reason The reason for the line
367 * @param nickname The nickmask
368 * @return True if the line was added successfully
370 bool AddQLine(long duration, const char* source, const char* reason, const char* nickname);
373 * @param duration The duration of the line
374 * @param source The source of the line
375 * @param reason The reason for the line
376 * @param ipaddr The IP mask
377 * @return True if the line was added successfully
379 bool AddZLine(long duration, const char* source, const char* reason, const char* ipaddr);
382 * @param duration The duration of the line
383 * @param source The source of the line
384 * @param reason The reason for the line
385 * @param hostmask The hostmask
386 * @return True if the line was added successfully
388 bool AddKLine(long duration, const char* source, const char* reason, const char* hostmask);
391 * @param duration The duration of the line
392 * @param source The source of the line
393 * @param reason The reason for the line
394 * @param hostmask The hostmask
395 * @return True if the line was added successfully
397 bool AddELine(long duration, const char* source, const char* reason, const char* hostmask);
400 * @param hostmask The host 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 DelGLine(const char* hostmask, bool simulate = false);
407 * @param nickname The nick to remove
408 * @param simulate If this is true, don't actually remove the line, just return
409 * @return True if the line was deleted successfully
411 bool DelQLine(const char* nickname, bool simulate = false);
414 * @param ipaddr The IP to remove
415 * @param simulate If this is true, don't actually remove the line, just return
416 * @return True if the line was deleted successfully
418 bool DelZLine(const char* ipaddr, bool simulate = false);
421 * @param hostmask The host 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 DelKLine(const char* hostmask, bool simulate = false);
428 * @param hostmask The host to remove
429 * @param simulate If this is true, don't actually remove the line, just return
430 * @return True if the line was deleted successfully
432 bool DelELine(const char* hostmask, bool simulate = false);
434 /** Check if a nickname matches a QLine
435 * @return nick The nick to check against
436 * @return The reason for the line if there is a match, or NULL if there is no match
438 QLine* matches_qline(const char* nick);
440 /** Check if a hostname matches a GLine
441 * @param user The user to check against
442 * @return The reason for the line if there is a match, or NULL if there is no match
444 GLine* matches_gline(User* user);
446 /** Check if a user's IP matches a ZLine
447 * @param user The user to check against
448 * @return The reason for the line if there is a match, or NULL if there is no match
450 ZLine* matches_zline(User *user);
452 /** Check if a hostname matches a KLine
453 * @param user The user to check against
454 * @return The reason for the line if there is a match, or NULL if there is no match
456 KLine* matches_kline(User* user);
458 /** Check if a hostname matches a ELine
459 * @param user The user to check against
460 * @return The reason for the line if there is a match, or NULL if there is no match
462 ELine* matches_exception(User* user);
464 /** Expire any lines that should be expired.
468 /** Apply any new lines that are pending to be applied
473 * @param user The username making the query
474 * @param results The string_list to receive the results
476 void stats_k(User* user, string_list &results);
479 * @param user The username making the query
480 * @param results The string_list to receive the results
482 void stats_g(User* user, string_list &results);
485 * @param user The username making the query
486 * @param results The string_list to receive the results
488 void stats_q(User* user, string_list &results);
491 * @param user The username making the query
492 * @param results The string_list to receive the results
494 void stats_z(User* user, string_list &results);
497 * @param user The username making the query
498 * @param results The string_list to receive the results
500 void stats_e(User* user, string_list &results);
502 /** Change creation time of a GLine
503 * @param host The hostname to change
504 * @param create_Time The new creation time
506 void gline_set_creation_time(const char* host, time_t create_time);
508 /** Change creation time of a QLine
509 * @param nick The nickmask to change
510 * @param create_Time The new creation time
512 void qline_set_creation_time(const char* nick, time_t create_time);
514 /** Change creation time of a ZLine
515 * @param ip The ipmask to change
516 * @param create_Time The new creation time
518 void zline_set_creation_time(const char* ip, time_t create_time);
520 /** Change creation time of a ELine
521 * @param host The hostname to change
522 * @param create_Time The new creation time
524 void eline_set_creation_time(const char* host, time_t create_time);