1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-10 19:03:12 +02:00

Rewrite/cleanup huge portion of TKL handling (16 files updated, but

src/modules/tkl.c is the main one).
Also move DB writing/reading functions to src/misc.c so they can be
removed out of channeldb and tkldb.

Important note to current tkldb users:
Unfortunately due to the major cleanup I had to remove upgrading
for previously saved tkl db files. That seemed not worth the effort
for maybe <15 current users or so. It also makes the tkldb code
a lot more cleaner. Otherwise it would be a huge mess.

Currently a FIXME item: spamfilter support in RMTKL.
This commit is contained in:
Bram Matthys
2019-08-31 15:24:52 +02:00
parent 0116c4f0d6
commit 8a6c84876e
16 changed files with 1391 additions and 1200 deletions
+22 -2
View File
@@ -645,8 +645,20 @@ extern MODVAR int (*tkl_hash)(unsigned int c);
extern MODVAR char (*tkl_typetochar)(int type);
extern MODVAR int (*tkl_chartotype)(char c);
extern MODVAR char *(*tkl_type_string)(aTKline *tk);
extern MODVAR aTKline *(*tkl_add_line)(int type, char *usermask, char *hostmask, char *reason, char *setby,
time_t expire_at, time_t set_at, time_t spamf_tkl_duration, char *spamf_tkl_reason, MatchType spamf_match_type, int soft, int flags);
extern MODVAR aTKline *(*tkl_add_serverban)(int type, char *usermask, char *hostmask, char *reason, char *setby,
time_t expire_at, time_t set_at, int soft, int flags);
extern MODVAR aTKline *(*tkl_add_nameban)(int type, char *name, int hold, char *reason, char *setby,
time_t expire_at, time_t set_at, int flags);
extern MODVAR aTKline *(*tkl_add_spamfilter)(int type, unsigned short target, unsigned short action, aMatch *match, char *setby,
time_t expire_at, time_t set_at,
time_t spamf_tkl_duration, char *spamf_tkl_reason,
int flags);
extern MODVAR aTKline *(*find_tkl_serverban)(int type, char *usermask, char *hostmask, int softban);
extern MODVAR aTKline *(*find_tkl_nameban)(int type, char *name, int hold);
extern MODVAR aTKline *(*find_tkl_spamfilter)(int type, char *match_string, unsigned short action, unsigned short target);
extern MODVAR void (*sendnotice_tkl_del)(char *removed_by, aTKline *tkl);
extern MODVAR void (*sendnotice_tkl_add)(aTKline *tkl);
extern MODVAR void (*free_tkl)(aTKline *tkl);
extern MODVAR aTKline *(*tkl_del_line)(aTKline *tkl);
extern MODVAR void (*tkl_check_local_remove_shun)(aTKline *tmp);
extern MODVAR int (*find_tkline_match)(aClient *cptr, int skip_soft);
@@ -861,3 +873,11 @@ extern int history_request(aClient *acptr, char *object, HistoryFilter *filter);
extern int history_del(char *object, int max_lines, long max_time);
extern int history_destroy(char *object);
extern void special_delayed_unloading(void);
extern int write_int64(FILE *fd, uint64_t t);
extern int write_int32(FILE *fd, uint32_t t);
extern int read_int64(FILE *fd, uint64_t *t);
extern int read_int32(FILE *fd, uint32_t *t);
extern int read_data(FILE *fd, void *buf, size_t len);
extern int write_data(FILE *fd, const void *buf, size_t len);
extern int write_str(FILE *fd, char *x);
extern int read_str(FILE *fd, char **x);
+9 -1
View File
@@ -1170,7 +1170,7 @@ _UNREAL_ERROR(_hook_error_incompatible, "Incompatible hook function. Check argum
#define EFUNC_REGISTER_USER 7
#define EFUNC_TKL_HASH 8
#define EFUNC_TKL_TYPETOCHAR 9
#define EFUNC_TKL_ADD_LINE 10
#define EFUNC_TKL_ADD_SERVERBAN 10
#define EFUNC_TKL_DEL_LINE 11
#define EFUNC_TKL_CHECK_LOCAL_REMOVE_SHUN 12
#define EFUNC_TKL_EXPIRE 13
@@ -1227,6 +1227,14 @@ _UNREAL_ERROR(_hook_error_incompatible, "Incompatible hook function. Check argum
#define EFUNC_BROADCAST_MD_GLOBALVAR_CMD 67
#define EFUNC_TKL_IP_HASH 68
#define EFUNC_TKL_IP_HASH_TYPE 69
#define EFUNC_TKL_ADD_NAMEBAN 70
#define EFUNC_TKL_ADD_SPAMFILTER 71
#define EFUNC_SENDNOTICE_TKL_ADD 72
#define EFUNC_SENDNOTICE_TKL_DEL 73
#define EFUNC_FREE_TKL 74
#define EFUNC_FIND_TKL_SERVERBAN 75
#define EFUNC_FIND_TKL_NAMEBAN 76
#define EFUNC_FIND_TKL_SPAMFILTER 77
/* Module flags */
#define MODFLAG_NONE 0x0000
+35 -14
View File
@@ -67,8 +67,9 @@ typedef struct aloopStruct LoopStruct;
typedef struct ConfItem aConfItem;
typedef struct t_kline aTKline;
typedef struct _spamfilter Spamfilter;
typedef struct _serverban ServerBan;
typedef struct _nameban NameBan;
typedef struct _spamexcept SpamExcept;
/* New Config Stuff */
typedef struct _conditionalconfig ConditionalConfig;
typedef struct _configentry ConfigEntry;
typedef struct _configfile ConfigFile;
@@ -711,11 +712,17 @@ struct Server {
#define TKL_ZAP 0x0002
#define TKL_GLOBAL 0x0004
#define TKL_SHUN 0x0008
#define TKL_QUIET 0x0010
#define TKL_SPAMF 0x0020
#define TKL_NICK 0x0040
#define TKL_NAME 0x0040
#define TKL_EXCEPT 0x0080
#define TKLIsServerBan(tkl) ((tkl)->type & (TKL_KILL|TKL_ZAP|TKL_SHUN))
#define TKLIsServerBanType(tpe) ((tpe) & (TKL_KILL|TKL_ZAP|TKL_SHUN))
#define TKLIsSpamfilter(tkl) ((tkl)->type & TKL_SPAMF)
#define TKLIsSpamfilterType(tpe) ((tpe) & TKL_SPAMF)
#define TKLIsNameBan(tkl) ((tkl)->type & TKL_NAME)
#define TKLIsNameBanType(tpe) ((tpe) & TKL_NAME)
#define SPAMF_CHANMSG 0x0001 /* c */
#define SPAMF_USERMSG 0x0002 /* p */
#define SPAMF_USERNOTICE 0x0004 /* n */
@@ -730,14 +737,30 @@ struct Server {
/* Other flags only for function calls: */
#define SPAMFLAG_NOWARN 0x0001
/** Spamfilter sub-struct of TKL entry */
/** Spamfilter sub-struct of TKL entry (Spamfilter) */
struct _spamfilter {
unsigned short target;
unsigned short action; /**< Ban action, see BAN_ACT* */
aMatch *expr; /**< Spamfilter matcher */
aMatch *match; /**< Spamfilter matcher */
char *tkl_reason; /**< Reason to use for bans placed by this spamfilter, escaped by unreal_encodespace(). */
time_t tkl_duration; /**< Duration of bans placed by this spamfilter */
};
/** Server ban sub-struct of TKL entry (KLINE/GLINE/ZLINE/GZLINE/SHUN) */
struct _serverban {
char *usermask; /**< User mask */
char *hostmask; /**< Host mask */
unsigned short subtype; /**< See TKL_SUBTYPE_* */
char *reason; /**< Reason */
};
/* Name ban sub-struct of TKL entry (QLINE) */
struct _nameban {
char hold; /**< nickname hold is used by services */
char *name; /**< the nick or channel that is banned */
char *reason; /**< Reason */
};
#define TKL_SUBTYPE_NONE 0x0000
#define TKL_SUBTYPE_SOFT 0x0001 /* (require SASL) */
@@ -747,17 +770,15 @@ struct _spamfilter {
struct t_kline {
aTKline *prev, *next;
unsigned int type; /**< TKL type. One of TKL_*, such as TKL_KILL|TKL_GLOBAL for gline */
unsigned short subtype; /* TKL subtype. For spamfilter one of SPAMF_*, otherwise TKL_SUBTYPE_* */
unsigned short flags; /**< One of TKL_FLAG_*, such as TKL_FLAG_CONFIG */
union {
Spamfilter *spamf;
} ptr;
char usermask[USERLEN + 3]; /**< User mask [different for spamfilter] */
char *hostmask; /**< Host mask [different for spamfilter] */
char *reason; /**< Reason [different for spamfilter] */
char *setby; /**< By who was this entry added */
time_t expire_at; /**< When this entry will expire */
char *set_by; /**< By who was this entry added */
time_t set_at; /**< When this entry was added */
time_t expire_at; /**< When this entry will expire */
union {
Spamfilter *spamfilter;
ServerBan *serverban;
NameBan *nameban;
} ptr;
};
/** A spamfilter except entry */