Add code to expire "propagated" bans.

The data structure is very simple: a dlink list of all propagated bans.
This commit is contained in:
Jilles Tjoelker 2010-03-04 00:21:22 +01:00
parent ebae0e200e
commit 12894c8888
3 changed files with 98 additions and 0 deletions

View File

@ -73,6 +73,7 @@ struct ConfItem
int port; int port;
time_t hold; /* Hold action until this time (calendar time) */ time_t hold; /* Hold action until this time (calendar time) */
time_t created; /* Creation time (for klines etc) */ time_t created; /* Creation time (for klines etc) */
time_t lifetime; /* Propagated lines: remember until this time */
char *className; /* Name of class */ char *className; /* Name of class */
struct Class *c_class; /* Class of connection */ struct Class *c_class; /* Class of connection */
rb_patricia_node_t *pnode; /* Our patricia node */ rb_patricia_node_t *pnode; /* Our patricia node */
@ -327,6 +328,8 @@ extern struct admin_info AdminInfo; /* defined in ircd.c */
extern rb_dlink_list service_list; extern rb_dlink_list service_list;
extern rb_dlink_list prop_bans;
typedef enum temp_list typedef enum temp_list
{ {
TEMP_MIN, TEMP_MIN,
@ -344,6 +347,8 @@ extern void init_s_conf(void);
extern struct ConfItem *make_conf(void); extern struct ConfItem *make_conf(void);
extern void free_conf(struct ConfItem *); extern void free_conf(struct ConfItem *);
extern void deactivate_conf(struct ConfItem *, rb_dlink_node *);
extern void read_conf_files(int cold); extern void read_conf_files(int cold);
extern int attach_conf(struct Client *, struct ConfItem *); extern int attach_conf(struct Client *, struct ConfItem *);

View File

@ -64,6 +64,8 @@ extern char linebuf[];
static rb_bh *confitem_heap = NULL; static rb_bh *confitem_heap = NULL;
rb_dlink_list prop_bans;
rb_dlink_list temp_klines[LAST_TEMP_TYPE]; rb_dlink_list temp_klines[LAST_TEMP_TYPE];
rb_dlink_list temp_dlines[LAST_TEMP_TYPE]; rb_dlink_list temp_dlines[LAST_TEMP_TYPE];
rb_dlink_list service_list; rb_dlink_list service_list;
@ -74,6 +76,7 @@ static void validate_conf(void);
static void read_conf(FILE *); static void read_conf(FILE *);
static void clear_out_old_conf(void); static void clear_out_old_conf(void);
static void expire_prop_bans(void *list);
static void expire_temp_kd(void *list); static void expire_temp_kd(void *list);
static void reorganise_temp_kd(void *list); static void reorganise_temp_kd(void *list);
@ -88,6 +91,8 @@ init_s_conf(void)
{ {
confitem_heap = rb_bh_create(sizeof(struct ConfItem), CONFITEM_HEAP_SIZE, "confitem_heap"); confitem_heap = rb_bh_create(sizeof(struct ConfItem), CONFITEM_HEAP_SIZE, "confitem_heap");
rb_event_addish("expire_prop_bans", expire_prop_bans, &prop_bans, 60);
rb_event_addish("expire_temp_klines", expire_temp_kd, &temp_klines[TEMP_MIN], 60); rb_event_addish("expire_temp_klines", expire_temp_kd, &temp_klines[TEMP_MIN], 60);
rb_event_addish("expire_temp_dlines", expire_temp_kd, &temp_dlines[TEMP_MIN], 60); rb_event_addish("expire_temp_dlines", expire_temp_kd, &temp_dlines[TEMP_MIN], 60);
@ -1002,6 +1007,87 @@ add_temp_dline(struct ConfItem *aconf)
add_conf_by_address(aconf->host, CONF_DLINE, aconf->user, NULL, aconf); add_conf_by_address(aconf->host, CONF_DLINE, aconf->user, NULL, aconf);
} }
void
deactivate_conf(struct ConfItem *aconf, rb_dlink_node *ptr)
{
int i;
s_assert(ptr->data == aconf);
switch (aconf->status)
{
case CONF_KILL:
if (aconf->lifetime == 0 &&
aconf->flags & CONF_FLAGS_TEMPORARY)
for (i = 0; i < LAST_TEMP_TYPE; i++)
rb_dlinkFindDestroy(aconf, &temp_klines[i]);
/* Make sure delete_one_address_conf() does not
* free the aconf.
*/
aconf->clients++;
delete_one_address_conf(aconf->host, aconf);
aconf->clients--;
break;
case CONF_DLINE:
if (aconf->lifetime == 0 &&
aconf->flags & CONF_FLAGS_TEMPORARY)
for (i = 0; i < LAST_TEMP_TYPE; i++)
rb_dlinkFindDestroy(aconf, &temp_dlines[i]);
aconf->clients++;
delete_one_address_conf(aconf->host, aconf);
aconf->clients--;
break;
case CONF_XLINE:
rb_dlinkFindDestroy(aconf, &xline_conf_list);
break;
case CONF_RESV_NICK:
rb_dlinkFindDestroy(aconf, &resv_conf_list);
break;
case CONF_RESV_CHANNEL:
del_from_resv_hash(aconf->host, aconf);
break;
}
if (aconf->lifetime != 0 && rb_current_time() < aconf->lifetime)
aconf->status |= CONF_ILLEGAL;
else
{
if (aconf->lifetime != 0)
rb_dlinkDestroy(ptr, &prop_bans);
free_conf(aconf);
}
}
static void
expire_prop_bans(void *list)
{
rb_dlink_node *ptr;
rb_dlink_node *next_ptr;
struct ConfItem *aconf;
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head)
{
aconf = ptr->data;
if(aconf->lifetime <= rb_current_time() ||
(aconf->hold <= rb_current_time() &&
!(aconf->status & CONF_ILLEGAL)))
{
/* Alert opers that a TKline expired - Hwy */
/* XXX show what type of ban it is */
if(ConfigFileEntry.tkline_expire_notices &&
!(aconf->status & CONF_ILLEGAL))
sendto_realops_snomask(SNO_GENERAL, L_ALL,
"Propagated ban for [%s%s%s] expired",
aconf->user ? aconf->user : "",
aconf->user ? "@" : "",
aconf->host ? aconf->host : "*");
/* will destroy or mark illegal */
deactivate_conf(aconf, ptr);
}
}
}
/* expire_tkline() /* expire_tkline()
* *
* inputs - list pointer * inputs - list pointer

View File

@ -651,6 +651,7 @@ valid_temp_time(const char *p)
return(result * 60); return(result * 60);
} }
/* Propagated bans are expired elsewhere. */
static void static void
expire_temp_rxlines(void *unused) expire_temp_rxlines(void *unused)
{ {
@ -663,6 +664,8 @@ expire_temp_rxlines(void *unused)
{ {
aconf = ptr->data; aconf = ptr->data;
if(aconf->lifetime != 0)
continue;
if(aconf->hold && aconf->hold <= rb_current_time()) if(aconf->hold && aconf->hold <= rb_current_time())
{ {
if(ConfigFileEntry.tkline_expire_notices) if(ConfigFileEntry.tkline_expire_notices)
@ -680,6 +683,8 @@ expire_temp_rxlines(void *unused)
{ {
aconf = ptr->data; aconf = ptr->data;
if(aconf->lifetime != 0)
continue;
if(aconf->hold && aconf->hold <= rb_current_time()) if(aconf->hold && aconf->hold <= rb_current_time())
{ {
if(ConfigFileEntry.tkline_expire_notices) if(ConfigFileEntry.tkline_expire_notices)
@ -695,6 +700,8 @@ expire_temp_rxlines(void *unused)
{ {
aconf = ptr->data; aconf = ptr->data;
if(aconf->lifetime != 0)
continue;
if(aconf->hold && aconf->hold <= rb_current_time()) if(aconf->hold && aconf->hold <= rb_current_time())
{ {
if(ConfigFileEntry.tkline_expire_notices) if(ConfigFileEntry.tkline_expire_notices)