Skip to content
This repository was archived by the owner on Jun 6, 2021. It is now read-only.

Keep propagated bans in a dictionary, not a list #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions include/s_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ struct config_file_entry

char *identifyservice;
char *identifycommand;

char *fname_userlog;
char *fname_fuserlog;
char *fname_operlog;
Expand Down Expand Up @@ -325,7 +325,7 @@ extern struct admin_info AdminInfo; /* defined in ircd.c */

extern rb_dlink_list service_list;

extern rb_dlink_list prop_bans;
extern struct Dictionary *prop_bans_dict;

typedef enum temp_list
{
Expand All @@ -344,8 +344,11 @@ extern void init_s_conf(void);
extern struct ConfItem *make_conf(void);
extern void free_conf(struct ConfItem *);

extern rb_dlink_node *find_prop_ban(unsigned int status, const char *user, const char *host);
extern void deactivate_conf(struct ConfItem *, rb_dlink_node *);
extern struct ConfItem *find_prop_ban(unsigned int status, const char *user, const char *host);
extern void add_prop_ban(struct ConfItem *);
extern void remove_prop_ban(struct ConfItem *);
extern int lookup_prop_ban(struct ConfItem *);
extern void deactivate_conf(struct ConfItem *);
extern void replace_old_ban(struct ConfItem *);

extern void read_conf_files(int cold);
Expand Down
15 changes: 8 additions & 7 deletions modules/core/m_ban.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* charybdis: An advanced ircd.
* m_ban.c: Propagates network bans across servers.
*
*
* Copyright (C) 2010 Jilles Tjoelker
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -82,14 +82,14 @@ m_ban(struct Client *client_p, struct Client *source_p, int parc, const char *pa
static int
ms_ban(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{
rb_dlink_node *ptr;
struct ConfItem *aconf;
unsigned int ntype;
const char *oper, *stype;
time_t created, hold, lifetime;
char *p;
int act;
int valid;
int new = 0;

if (strlen(parv[1]) != 1)
{
Expand Down Expand Up @@ -126,11 +126,10 @@ ms_ban(struct Client *client_p, struct Client *source_p, int parc, const char *p
oper = IsServer(source_p) ? source_p->name : get_oper_name(source_p);
else
oper = parv[7];
ptr = find_prop_ban(ntype, parv[2], parv[3]);
if (ptr != NULL)
aconf = find_prop_ban(ntype, parv[2], parv[3]);
if (aconf != NULL)
{
/* We already know about this ban mask. */
aconf = ptr->data;
if (aconf->created > created ||
(aconf->created == created &&
aconf->lifetime >= lifetime))
Expand All @@ -157,7 +156,7 @@ ms_ban(struct Client *client_p, struct Client *source_p, int parc, const char *p
if (aconf->lifetime <= rb_current_time())
return 0;
/* Deactivate, it will be reactivated later if appropriate. */
deactivate_conf(aconf, ptr);
deactivate_conf(aconf);
rb_free(aconf->user);
aconf->user = NULL;
rb_free(aconf->host);
Expand All @@ -175,8 +174,8 @@ ms_ban(struct Client *client_p, struct Client *source_p, int parc, const char *p
aconf = make_conf();
aconf->status = CONF_ILLEGAL | ntype;
aconf->lifetime = lifetime;
rb_dlinkAddAlloc(aconf, &prop_bans);
act = hold != created && hold > rb_current_time();
new = 1;
}
aconf->flags &= ~CONF_FLAGS_MYOPER;
aconf->flags |= CONF_FLAGS_TEMPORARY;
Expand All @@ -185,6 +184,8 @@ ms_ban(struct Client *client_p, struct Client *source_p, int parc, const char *p
aconf->info.oper = operhash_add(oper);
aconf->created = created;
aconf->hold = hold;
if (new)
add_prop_ban(aconf);
if (ntype != CONF_KILL || (p = strchr(parv[parc - 1], '|')) == NULL)
aconf->passwd = rb_strdup(parv[parc - 1]);
else
Expand Down
15 changes: 6 additions & 9 deletions modules/m_kline.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ mo_unkline(struct Client *client_p, struct Client *source_p, int parc, const cha
sendto_one_notice(source_p, ":No K-Line for %s@%s", user, host);
return 0;
}

if(aconf->lifetime)
{
if(propagated)
Expand Down Expand Up @@ -500,7 +500,7 @@ handle_remote_unkline(struct Client *source_p, const char *user, const char *hos

/* apply_kline()
*
* inputs -
* inputs -
* output - NONE
* side effects - kline as given, is added to the hashtable
* and conf file
Expand Down Expand Up @@ -584,7 +584,7 @@ apply_prop_kline(struct Client *source_p, struct ConfItem *aconf,

replace_old_ban(aconf);

rb_dlinkAddAlloc(aconf, &prop_bans);
add_prop_ban(aconf);
add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf);

/* no oper reason.. */
Expand Down Expand Up @@ -623,7 +623,7 @@ apply_prop_kline(struct Client *source_p, struct ConfItem *aconf,
}

/* find_user_host()
*
*
* inputs - client placing kline, user@host, user buffer, host buffer
* output - 0 if not ok to kline, 1 to kline i.e. if valid user host
* side effects -
Expand Down Expand Up @@ -839,10 +839,7 @@ remove_temp_kline(struct Client *source_p, struct ConfItem *aconf)
static void
remove_prop_kline(struct Client *source_p, struct ConfItem *aconf)
{
rb_dlink_node *ptr;

ptr = rb_dlinkFind(aconf, &prop_bans);
if (!ptr)
if (!lookup_prop_ban(aconf))
return;
sendto_one_notice(source_p,
":Un-klined [%s@%s] from global k-lines",
Expand All @@ -869,5 +866,5 @@ remove_prop_kline(struct Client *source_p, struct ConfItem *aconf)
0,
(int)(aconf->lifetime - aconf->created));
remove_reject_mask(aconf->user, aconf->host);
deactivate_conf(aconf, ptr);
deactivate_conf(aconf);
}
14 changes: 6 additions & 8 deletions modules/m_resv.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ parse_resv(struct Client *source_p, const char *name, const char *reason, int te
aconf->hold = rb_current_time() + temp_time;
aconf->lifetime = aconf->hold;
replace_old_ban(aconf);
rb_dlinkAddAlloc(aconf, &prop_bans);
add_prop_ban(aconf);

sendto_realops_snomask(SNO_GENERAL, L_ALL,
"%s added global %d min. RESV for [%s] [%s]",
Expand Down Expand Up @@ -336,7 +336,7 @@ parse_resv(struct Client *source_p, const char *name, const char *reason, int te
aconf->hold = rb_current_time() + temp_time;
aconf->lifetime = aconf->hold;
replace_old_ban(aconf);
rb_dlinkAddAlloc(aconf, &prop_bans);
add_prop_ban(aconf);

sendto_realops_snomask(SNO_GENERAL, L_ALL,
"%s added global %d min. RESV for [%s] [%s]",
Expand Down Expand Up @@ -550,8 +550,7 @@ remove_resv(struct Client *source_p, const char *name, int propagated)
sendto_one_notice(source_p, ":Cannot remove global RESV %s on specific servers", name);
return;
}
ptr = rb_dlinkFind(aconf, &prop_bans);
if(ptr == NULL)
if (!lookup_prop_ban(aconf))
return;
sendto_one_notice(source_p, ":RESV for [%s] is removed", name);
sendto_realops_snomask(SNO_GENERAL, L_ALL,
Expand All @@ -572,7 +571,7 @@ remove_resv(struct Client *source_p, const char *name, int propagated)
(unsigned long)aconf->created,
0,
(int)(aconf->lifetime - aconf->created));
deactivate_conf(aconf, ptr);
deactivate_conf(aconf);
return;
}
else if(propagated && rb_dlink_list_length(&cluster_conf_list) > 0)
Expand Down Expand Up @@ -623,8 +622,7 @@ remove_resv(struct Client *source_p, const char *name, int propagated)
sendto_one_notice(source_p, ":Cannot remove global RESV %s on specific servers", name);
return;
}
ptr = rb_dlinkFind(aconf, &prop_bans);
if(ptr == NULL)
if (!lookup_prop_ban(aconf))
return;
sendto_one_notice(source_p, ":RESV for [%s] is removed", name);
sendto_realops_snomask(SNO_GENERAL, L_ALL,
Expand All @@ -645,7 +643,7 @@ remove_resv(struct Client *source_p, const char *name, int propagated)
(unsigned long)aconf->created,
0,
(int)(aconf->lifetime - aconf->created));
deactivate_conf(aconf, ptr);
deactivate_conf(aconf);
return;
}
else if(propagated && rb_dlink_list_length(&cluster_conf_list) > 0)
Expand Down
8 changes: 3 additions & 5 deletions modules/m_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,15 +456,13 @@ static void
stats_prop_klines(struct Client *source_p)
{
struct ConfItem *aconf;
rb_dlink_node *ptr;
char *user, *host, *pass, *oper_reason;
struct DictionaryIter state;

RB_DLINK_FOREACH(ptr, prop_bans.head)
DICTIONARY_FOREACH(aconf, &state, prop_bans_dict)
{
aconf = ptr->data;

/* Skip non-klines and deactivated klines. */
if(aconf->status != CONF_KILL)
if (aconf->status != CONF_KILL)
continue;

get_printable_kline(source_p, aconf, &host, &pass,
Expand Down
9 changes: 4 additions & 5 deletions modules/m_xline.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* modules/m_xline.c
*
*
* Copyright (C) 2002-2003 Lee Hardy <[email protected]>
* Copyright (C) 2002-2005 ircd-ratbox development team
*
Expand Down Expand Up @@ -307,7 +307,7 @@ apply_xline(struct Client *source_p, const char *name, const char *reason, int t
aconf->lifetime = aconf->hold;

replace_old_ban(aconf);
rb_dlinkAddAlloc(aconf, &prop_bans);
add_prop_ban(aconf);

sendto_realops_snomask(SNO_GENERAL, L_ALL,
"%s added global %d min. X-Line for [%s] [%s]",
Expand Down Expand Up @@ -506,8 +506,7 @@ remove_xline(struct Client *source_p, const char *name, int propagated)
sendto_one_notice(source_p, ":Cannot remove global X-Line %s on specific servers", name);
return;
}
ptr = rb_dlinkFind(aconf, &prop_bans);
if(ptr == NULL)
if (!lookup_prop_ban(aconf))
return;
sendto_one_notice(source_p, ":X-Line for [%s] is removed", name);
sendto_realops_snomask(SNO_GENERAL, L_ALL,
Expand All @@ -529,7 +528,7 @@ remove_xline(struct Client *source_p, const char *name, int propagated)
0,
(int)(aconf->lifetime - aconf->created));
remove_reject_mask(aconf->host, NULL);
deactivate_conf(aconf, ptr);
deactivate_conf(aconf);
return;
}
else if(propagated && rb_dlink_list_length(&cluster_conf_list))
Expand Down
Loading