1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-05 03:33:13 +02:00

Add spamfilter::rule (preconditions), add context to crule parser,

and add the first functions: online_time() and reputation().

The more interesting stuff will follow later...
This commit is contained in:
Bram Matthys
2023-07-06 15:43:12 +02:00
parent 1e572e25b9
commit 6bbcdfd1b3
11 changed files with 226 additions and 109 deletions
+6 -5
View File
@@ -534,7 +534,7 @@ extern void init_CommandHash(void);
/* CRULE */
extern struct CRuleNode* crule_parse(const char*);
extern void crule_free(struct CRuleNode**);
extern int crule_eval(struct CRuleNode* rule);
extern int crule_eval(crule_context *context, CRuleNode *rule);
extern int crule_test(const char *rule);
extern const char *crule_errstring(int errcode);
@@ -818,10 +818,11 @@ extern MODVAR TKL *(*tkl_add_banexception)(int type, const char *usermask, const
time_t expire_at, time_t set_at, int soft, const char *bantypes, int flags);
extern MODVAR TKL *(*tkl_add_nameban)(int type, const char *name, int hold, const char *reason, const char *setby,
time_t expire_at, time_t set_at, int flags);
extern MODVAR TKL *(*tkl_add_spamfilter)(int type, unsigned short target, BanAction *action, Match *match, const char *setby,
time_t expire_at, time_t set_at,
time_t spamf_tkl_duration, const char *spamf_tkl_reason,
int flags);
extern MODVAR TKL *(*tkl_add_spamfilter)(int type, unsigned short target, BanAction *action,
Match *match, const char *rule, const char *setby,
time_t expire_at, time_t set_at,
time_t spamf_tkl_duration, const char *spamf_tkl_reason,
int flags);
extern MODVAR TKL *(*find_tkl_serverban)(int type, const char *usermask, const char *hostmask, int softban);
extern MODVAR TKL *(*find_tkl_banexception)(int type, const char *usermask, const char *hostmask, int softban);
extern MODVAR TKL *(*find_tkl_nameban)(int type, const char *name, int hold);
+34 -26
View File
@@ -855,6 +855,7 @@ struct LoopStruct {
typedef enum {
MATCH_SIMPLE=1, /**< Simple pattern with * and ? */
MATCH_PCRE_REGEX=2, /**< PCRE2 Perl-like regex (new) */
MATCH_NONE=3, /**< No matching at all (rule-based) */
} MatchType;
/** Match struct, which allows various matching styles, see MATCH_* */
@@ -1063,6 +1064,37 @@ struct Secret {
SecretCache *cache;
};
/* CRULE stuff */
#define CRULE_ALL 0
#define CRULE_AUTO 1
/* some constants and shared data types */
#define CR_MAXARGLEN 80 /**< Maximum arg length (must be > HOSTLEN) */
#define CR_MAXARGS 3 /**< Maximum number of args for a rule */
/* context when running a crule */
typedef struct crule_context crule_context;
struct crule_context
{
Client *client;
};
/** Evaluation function for a connection rule. */
typedef int (*crule_funcptr) (crule_context *context, int, void **);
/** CRULE - Node in a connection rule tree. */
struct CRuleNode {
crule_funcptr funcptr; /**< Evaluation function for this node. */
int numargs; /**< Number of arguments. */
void *arg[CR_MAXARGS]; /**< Array of arguments. For operators, each arg
is a tree element; for functions, each arg is
a string. */
int func_test_type; /* for >, < and == */
int func_test_value; /* integer value to compare against */
};
typedef struct CRuleNode CRuleNode;
typedef struct CRuleNode* CRuleNodePtr;
/* tkl:
* TKL_KILL|TKL_GLOBAL = Global K-Line (GLINE)
@@ -1176,6 +1208,8 @@ struct Spamfilter {
unsigned short target;
BanAction *action; /**< Ban action */
Match *match; /**< Spamfilter matcher */
CRuleNode *rule; /**< parsed crule */
char *prettyrule; /**< human printable version */
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 */
};
@@ -1529,32 +1563,6 @@ struct AuthConfig {
#define crypt DES_crypt
#endif
/* CRULE stuff */
#define CRULE_ALL 0
#define CRULE_AUTO 1
/* some constants and shared data types */
#define CR_MAXARGLEN 80 /**< Maximum arg length (must be > HOSTLEN) */
#define CR_MAXARGS 3 /**< Maximum number of args for a rule */
/** Evaluation function for a connection rule. */
typedef int (*crule_funcptr) (int, void **);
/** CRULE - Node in a connection rule tree. */
struct CRuleNode {
crule_funcptr funcptr; /**< Evaluation function for this node. */
int numargs; /**< Number of arguments. */
void *arg[CR_MAXARGS]; /**< Array of arguments. For operators, each arg
is a tree element; for functions, each arg is
a string. */
int func_test_type; /* for >, < and == */
int func_test_value; /* integer value to compare against */
};
typedef struct CRuleNode CRuleNode;
typedef struct CRuleNode* CRuleNodePtr;
/*
* conf2 stuff -stskeeps
*/