/*
* 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
#include "operhash.h"
#include "reject.h"
#include "hostmask.h"
+#include "logger.h"
-static int ms_ban(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
+static int m_ban(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
+static int ms_ban(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
+static const char ban_desc[] = "Provides the TS6 BAN command for propagating network-wide bans";
struct Message ban_msgtab = {
- "BAN", 0, 0, 0, MFLG_SLOW,
- {mg_unreg, mg_ignore, {ms_ban, 9}, {ms_ban, 9}, mg_ignore, mg_ignore}
+ "BAN", 0, 0, 0, 0,
+ {mg_unreg, {m_ban, 0}, {ms_ban, 9}, {ms_ban, 9}, mg_ignore, {m_ban, 0}}
};
mapi_clist_av1 ban_clist[] = { &ban_msgtab, NULL };
-DECLARE_MODULE_AV1(ban, NULL, NULL, ban_clist, NULL, NULL, "$Revision: 1349 $");
+DECLARE_MODULE_AV2(ban, NULL, NULL, ban_clist, NULL, NULL, NULL, NULL, ban_desc);
+
+static int
+m_ban(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+{
+ sendto_one_notice(source_p, ":The BAN command is not user-accessible.");
+ sendto_one_notice(source_p, ":To ban a user from a channel, see /QUOTE HELP CMODE");
+ if (IsOper(source_p))
+ sendto_one_notice(source_p, ":To ban a user from a server or from the network, see /QUOTE HELP KLINE");
+ return 0;
+}
/* ms_ban()
*
* parv[8] - reason (possibly with |operreason)
*/
static int
-ms_ban(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+ms_ban(struct MsgBuf *msgbuf_p, 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;
+ time_t now, created, hold, lifetime;
char *p;
int act;
int valid;
+ now = rb_current_time();
if (strlen(parv[1]) != 1)
{
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
ptr = find_prop_ban(ntype, parv[2], parv[3]);
if (ptr != NULL)
{
+ /* We already know about this ban mask. */
aconf = ptr->data;
if (aconf->created > created ||
(aconf->created == created &&
aconf->host);
return 0;
}
+ /* act indicates if something happened (from the oper's
+ * point of view). This is the case if the ban was
+ * previously active (not deleted) or if the new ban
+ * is not a removal and not already expired.
+ */
act = !(aconf->status & CONF_ILLEGAL) || (hold != created &&
- hold > rb_current_time());
+ hold > now);
if (lifetime > aconf->lifetime)
aconf->lifetime = lifetime;
/* already expired, hmm */
- if (aconf->lifetime <= rb_current_time())
+ if (aconf->lifetime <= now)
return 0;
- deactivate_conf(aconf, ptr);
+ /* Deactivate, it will be reactivated later if appropriate. */
+ deactivate_conf(aconf, ptr, now);
rb_free(aconf->user);
aconf->user = NULL;
rb_free(aconf->host);
}
else
{
+ /* New ban mask. */
aconf = make_conf();
aconf->status = CONF_ILLEGAL | ntype;
aconf->lifetime = lifetime;
rb_dlinkAddAlloc(aconf, &prop_bans);
- act = hold != created && hold > rb_current_time();
+ act = hold != created && hold > now;
}
aconf->flags &= ~CONF_FLAGS_MYOPER;
aconf->flags |= CONF_FLAGS_TEMPORARY;
aconf->passwd = rb_strndup(parv[parc - 1], p - parv[parc - 1] + 1);
aconf->spasswd = rb_strdup(p + 1);
}
+ /* The ban is fully filled in and in the prop_bans list
+ * but still deactivated. Now determine if it should be activated
+ * and send the server notices.
+ */
+ /* We only reject *@* and the like here.
+ * Otherwise malformed bans are fairly harmless and can be removed.
+ */
switch (ntype)
{
case CONF_KILL:
{
sendto_realops_snomask(SNO_GENERAL, L_ALL,
"Ignoring global %d min. %s from %s%s%s for [%s%s%s]: too few non-wildcard characters",
- (int)((hold - rb_current_time()) / 60),
+ (int)((hold - now) / 60),
stype,
IsServer(source_p) ? source_p->name : get_oper_name(source_p),
strcmp(parv[7], "*") ? " on behalf of " : "",
sendto_realops_snomask(SNO_GENERAL, L_ALL,
"%s added global %d min. %s%s%s for [%s%s%s] [%s]",
IsServer(source_p) ? source_p->name : get_oper_name(source_p),
- (int)((hold - rb_current_time()) / 60),
+ (int)((hold - now) / 60),
stype,
strcmp(parv[7], "*") ? " from " : "",
strcmp(parv[7], "*") ? parv[7] : "",
parv[parc - 1]);
ilog(L_KLINE, "%s %s %d %s%s%s %s", parv[1],
IsServer(source_p) ? source_p->name : get_oper_name(source_p),
- (int)((hold - rb_current_time()) / 60),
+ (int)((hold - now) / 60),
aconf->user ? aconf->user : "",
aconf->user ? " " : "",
aconf->host,
aconf->user ? " " : "",
aconf->host);
}
+ /* If CONF_ILLEGAL is still set at this point, remove entries from the
+ * reject cache (for klines and xlines).
+ * If CONF_ILLEGAL is not set, add the ban to the type-specific data
+ * structure and take action on matched clients/channels.
+ */
switch (ntype)
{
case CONF_KILL:
if(kline_queued == 0)
{
rb_event_addonce("check_klines", check_klines_event, NULL,
- ConfigFileEntry.kline_delay);
+ ConfigFileEntry.kline_delay ?
+ ConfigFileEntry.kline_delay : 1);
kline_queued = 1;
}
}
if (!(aconf->status & CONF_ILLEGAL))
{
add_to_resv_hash(aconf->host, aconf);
- resv_chan_forcepart(aconf->host, aconf->passwd, hold - rb_current_time());
+ resv_chan_forcepart(aconf->host, aconf->passwd, hold - now);
}
break;
case CONF_RESV_NICK: