Add match_client hook

This commit is contained in:
Ed Kellett 2020-10-12 20:29:00 +01:00
parent a28599d50f
commit 4bbd1a333c
No known key found for this signature in database
GPG key ID: CB9986DEF342FABC
3 changed files with 18 additions and 10 deletions

View file

@ -45,6 +45,7 @@ extern int h_conf_read_start;
extern int h_conf_read_end;
extern int h_outbound_msgbuf;
extern int h_rehash;
extern int h_match_client;
void init_hook(void);
int register_hook(const char *name);
@ -168,4 +169,11 @@ typedef struct
bool signal;
} hook_data_rehash;
typedef struct
{
struct Client *client;
struct matchset *ms;
long mode_type;
} hook_data_match_client;
#endif

View file

@ -71,6 +71,7 @@ int h_conf_read_start;
int h_conf_read_end;
int h_outbound_msgbuf;
int h_rehash;
int h_match_client;
void
init_hook(void)
@ -95,6 +96,7 @@ init_hook(void)
h_conf_read_end = register_hook("conf_read_end");
h_outbound_msgbuf = register_hook("outbound_msgbuf");
h_rehash = register_hook("rehash");
h_match_client = register_hook("match_client");
}
/* grow_hooktable()

View file

@ -23,6 +23,7 @@
#include "ircd.h"
#include "match.h"
#include "s_assert.h"
#include "hook.h"
/*
* Compare if a given string (name) matches the given
@ -589,29 +590,24 @@ int ircncmp(const char *s1, const char *s2, int n)
void matchset_for_client(struct Client *who, struct matchset *m, long mode_type)
{
struct sockaddr_in ip4;
hook_data_match_client hdata = {.client = who, .ms = m, .mode_type = mode_type};
m->hostn = m->ipn = 0;
sprintf(m->host[m->hostn++], "%s!%s@%s", who->name, who->username, who->host);
matchset_append_host(m, "%s!%s@%s", who->name, who->username, who->host);
if (!IsIPSpoof(who))
{
sprintf(m->ip[m->ipn++], "%s!%s@%s", who->name, who->username, who->sockhost);
}
matchset_append_ip(m, "%s!%s@%s", who->name, who->username, who->sockhost);
if (who->localClient->mangledhost != NULL)
{
/* if host mangling mode enabled, also check their real host */
if (!strcmp(who->host, who->localClient->mangledhost))
{
sprintf(m->host[m->hostn++], "%s!%s@%s", who->name, who->username, who->orighost);
}
matchset_append_host(m, "%s!%s@%s", who->name, who->username, who->orighost);
/* if host mangling mode not enabled and no other spoof,
* also check the mangled form of their host */
else if (!IsDynSpoof(who))
{
sprintf(m->host[m->hostn++], "%s!%s@%s", who->name, who->username, who->localClient->mangledhost);
}
matchset_append_host(m, "%s!%s@%s", who->name, who->username, who->localClient->mangledhost);
}
if ((mode_type == CHFL_BAN || mode_type == CHFL_QUIET) &&
!IsIPSpoof(who) && GET_SS_FAMILY(&who->localClient->ip) == AF_INET6 &&
@ -622,6 +618,8 @@ void matchset_for_client(struct Client *who, struct matchset *m, long mode_type)
m->ip[m->ipn] + n, sizeof m->ip[m->ipn] - n);
}
call_hook(h_match_client, &hdata);
for (int i = m->hostn; i < ARRAY_SIZE(m->host); i++)
{
m->host[i][0] = '\0';