summaryrefslogtreecommitdiff
path: root/modules/m_kline.c
diff options
context:
space:
mode:
Diffstat (limited to 'modules/m_kline.c')
-rw-r--r--modules/m_kline.c322
1 files changed, 161 insertions, 161 deletions
diff --git a/modules/m_kline.c b/modules/m_kline.c
index 0753f30..28ce68b 100644
--- a/modules/m_kline.c
+++ b/modules/m_kline.c
@@ -1,8 +1,7 @@
/*
- * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
- * m_kline.c: Bans a user.
+ * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
*
- * Copyright (C) 2002 by the past and present ircd coders, and others.
+ * Copyright (c) 2002-2014 ircd-hybrid development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,8 +17,11 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
- *
- * $Id$
+ */
+
+/*! \file m_kline.c
+ * \brief Includes required functions for processing the KLINE/UNKLINE command.
+ * \version $Id$
*/
#include "stdinc.h"
@@ -44,12 +46,138 @@
#include "conf_db.h"
#include "memory.h"
-static int already_placed_kline(struct Client *, const char *, const char *, int);
-static void m_kline_add_kline(struct Client *, struct MaskItem *, time_t);
-static char buffer[IRCD_BUFSIZE];
-static int remove_kline_match(const char *, const char *);
+/* apply_tkline()
+ *
+ * inputs -
+ * output - NONE
+ * side effects - tkline as given is placed
+ */
+static void
+m_kline_add_kline(struct Client *source_p, struct MaskItem *conf,
+ time_t tkline_time)
+{
+ if (tkline_time)
+ {
+ conf->until = CurrentTime + tkline_time;
+ sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
+ "%s added temporary %d min. K-Line for [%s@%s] [%s]",
+ get_oper_name(source_p), tkline_time/60,
+ conf->user, conf->host,
+ conf->reason);
+ sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. K-Line [%s@%s]",
+ MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
+ source_p->name, tkline_time/60, conf->user, conf->host);
+ ilog(LOG_TYPE_KLINE, "%s added temporary %d min. K-Line for [%s@%s] [%s]",
+ get_oper_name(source_p), tkline_time/60,
+ conf->user, conf->host, conf->reason);
+ }
+ else
+ {
+ sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
+ "%s added K-Line for [%s@%s] [%s]",
+ get_oper_name(source_p),
+ conf->user, conf->host, conf->reason);
+ sendto_one(source_p, ":%s NOTICE %s :Added K-Line [%s@%s]",
+ MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
+ source_p->name, conf->user, conf->host);
+ ilog(LOG_TYPE_KLINE, "%s added K-Line for [%s@%s] [%s]",
+ get_oper_name(source_p), conf->user, conf->host, conf->reason);
+ }
+
+ conf->setat = CurrentTime;
+ SetConfDatabase(conf);
+
+ add_conf_by_address(CONF_KLINE, conf);
+ rehashed_klines = 1;
+}
+
+/* static int remove_tkline_match(const char *host, const char *user)
+ * Input: A hostname, a username to unkline.
+ * Output: returns YES on success, NO if no tkline removed.
+ * Side effects: Any matching tklines are removed.
+ */
+static int
+remove_kline_match(const char *host, const char *user)
+{
+ struct irc_ssaddr iphost, *piphost;
+ struct MaskItem *conf;
+ int t = 0;
+ int aftype = 0;
+
+ if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
+ {
+#ifdef IPV6
+ if (t == HM_IPV6)
+ aftype = AF_INET6;
+ else
+#endif
+ aftype = AF_INET;
+ piphost = &iphost;
+ }
+ else
+ piphost = NULL;
+
+ if ((conf = find_conf_by_address(host, piphost, CONF_KLINE, aftype, user, NULL, 0)))
+ {
+ if (IsConfDatabase(conf))
+ {
+ delete_one_address_conf(host, conf);
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+/* already_placed_kline()
+ * inputs - user to complain to, username & host to check for
+ * outputs - returns 1 on existing K-line, 0 if doesn't exist
+ * side effects - notifies source_p if the K-line already exists
+ */
+/*
+ * Note: This currently works if the new K-line is a special case of an
+ * existing K-line, but not the other way round. To do that we would
+ * have to walk the hash and check every existing K-line. -A1kmm.
+ */
+static int
+already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int warn)
+{
+ const char *reason;
+ struct irc_ssaddr iphost, *piphost;
+ struct MaskItem *conf = NULL;
+ int t = 0;
+ int aftype = 0;
+
+ if ((t = parse_netmask(lhost, &iphost, NULL)) != HM_HOST)
+ {
+#ifdef IPV6
+ if (t == HM_IPV6)
+ aftype = AF_INET6;
+ else
+#endif
+ aftype = AF_INET;
+ piphost = &iphost;
+ }
+ else
+ piphost = NULL;
+
+ if ((conf = find_conf_by_address(lhost, piphost, CONF_KLINE, aftype, luser, NULL, 0)))
+ {
+ if (warn)
+ {
+ reason = conf->reason ? conf->reason : CONF_NOREASON;
+ sendto_one(source_p,
+ ":%s NOTICE %s :[%s@%s] already K-Lined by [%s@%s] - %s",
+ me.name, source_p->name, luser, lhost, conf->user,
+ conf->host, reason);
+ }
+
+ return 1;
+ }
+ return 0;
+}
/* mo_kline()
*
@@ -64,6 +192,7 @@ static void
mo_kline(struct Client *client_p, struct Client *source_p,
int parc, char *parv[])
{
+ char buffer[IRCD_BUFSIZE];
char *reason = NULL;
char *user = NULL;
char *host = NULL;
@@ -75,13 +204,13 @@ mo_kline(struct Client *client_p, struct Client *source_p,
if (!HasOFlag(source_p, OPER_FLAG_K))
{
- sendto_one(source_p, form_str(ERR_NOPRIVS),
- me.name, source_p->name, "kline");
+ sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
+ source_p->name, "kline");
return;
}
- if (parse_aline("KLINE", source_p, parc, parv,
- AWILD, &user, &host, &tkline_time, &target_server, &reason) < 0)
+ if (parse_aline("KLINE", source_p, parc, parv, AWILD, &user, &host,
+ &tkline_time, &target_server, &reason) < 0)
return;
if (target_server != NULL)
@@ -123,9 +252,10 @@ static void
me_kline(struct Client *client_p, struct Client *source_p,
int parc, char *parv[])
{
+ char buffer[IRCD_BUFSIZE];
struct MaskItem *conf = NULL;
int tkline_time = 0;
- const char* current_date;
+ const char *current_date;
time_t cur_time;
char *kuser, *khost, *kreason;
@@ -143,7 +273,8 @@ me_kline(struct Client *client_p, struct Client *source_p,
cur_time = CurrentTime;
current_date = smalldate(cur_time);
- if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
+ if (HasFlag(source_p, FLAGS_SERVICE) ||
+ find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
source_p->username, source_p->host,
SHARED_KLINE))
{
@@ -182,100 +313,6 @@ ms_kline(struct Client *client_p, struct Client *source_p,
me_kline(client_p, source_p, parc, parv);
}
-/* apply_tkline()
- *
- * inputs -
- * output - NONE
- * side effects - tkline as given is placed
- */
-static void
-m_kline_add_kline(struct Client *source_p, struct MaskItem *conf,
- time_t tkline_time)
-{
- if (tkline_time)
- {
- conf->until = CurrentTime + tkline_time;
- sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
- "%s added temporary %d min. K-Line for [%s@%s] [%s]",
- get_oper_name(source_p), tkline_time/60,
- conf->user, conf->host,
- conf->reason);
- sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. K-Line [%s@%s]",
- MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
- source_p->name, tkline_time/60, conf->user, conf->host);
- ilog(LOG_TYPE_KLINE, "%s added temporary %d min. K-Line for [%s@%s] [%s]",
- get_oper_name(source_p), tkline_time/60,
- conf->user, conf->host, conf->reason);
- }
- else
- {
- sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
- "%s added K-Line for [%s@%s] [%s]",
- get_oper_name(source_p),
- conf->user, conf->host, conf->reason);
- sendto_one(source_p, ":%s NOTICE %s :Added K-Line [%s@%s]",
- MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
- source_p->name, conf->user, conf->host);
- ilog(LOG_TYPE_KLINE, "%s added K-Line for [%s@%s] [%s]",
- get_oper_name(source_p), conf->user, conf->host, conf->reason);
- }
-
- conf->setat = CurrentTime;
- SetConfDatabase(conf);
-
- add_conf_by_address(CONF_KLINE, conf);
- rehashed_klines = 1;
-}
-
-/* already_placed_kline()
- * inputs - user to complain to, username & host to check for
- * outputs - returns 1 on existing K-line, 0 if doesn't exist
- * side effects - notifies source_p if the K-line already exists
- */
-/*
- * Note: This currently works if the new K-line is a special case of an
- * existing K-line, but not the other way round. To do that we would
- * have to walk the hash and check every existing K-line. -A1kmm.
- */
-static int
-already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int warn)
-{
- const char *reason;
- struct irc_ssaddr iphost, *piphost;
- struct MaskItem *conf = NULL;
- int t = 0;
- int aftype = 0;
-
- if ((t = parse_netmask(lhost, &iphost, NULL)) != HM_HOST)
- {
-#ifdef IPV6
- if (t == HM_IPV6)
- aftype = AF_INET6;
- else
-#endif
- aftype = AF_INET;
- piphost = &iphost;
- }
- else
- piphost = NULL;
-
- if ((conf = find_conf_by_address(lhost, piphost, CONF_KLINE, aftype, luser, NULL, 0)))
- {
- if (warn)
- {
- reason = conf->reason ? conf->reason : CONF_NOREASON;
- sendto_one(source_p,
- ":%s NOTICE %s :[%s@%s] already K-Lined by [%s@%s] - %s",
- me.name, source_p->name, luser, lhost, conf->user,
- conf->host, reason);
- }
-
- return 1;
- }
-
- return 0;
-}
-
/*
** mo_unkline
** Added Aug 31, 1997
@@ -295,8 +332,8 @@ mo_unkline(struct Client *client_p,struct Client *source_p,
if (!HasOFlag(source_p, OPER_FLAG_UNKLINE))
{
- sendto_one(source_p, form_str(ERR_NOPRIVS),
- me.name, source_p->name, "unkline");
+ sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
+ source_p->name, "unkline");
return;
}
@@ -327,8 +364,7 @@ mo_unkline(struct Client *client_p,struct Client *source_p,
if (remove_kline_match(host, user))
{
- sendto_one(source_p,
- ":%s NOTICE %s :K-Line for [%s@%s] is removed",
+ sendto_one(source_p, ":%s NOTICE %s :K-Line for [%s@%s] is removed",
me.name, source_p->name, user, host);
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
"%s has removed the K-Line for: [%s@%s]",
@@ -366,15 +402,14 @@ me_unkline(struct Client *client_p, struct Client *source_p,
if (!IsClient(source_p) || match(parv[1], me.name))
return;
- if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE,
- source_p->servptr->name,
- source_p->username, source_p->host,
- SHARED_UNKLINE))
+ if (HasFlag(source_p, FLAGS_SERVICE) ||
+ find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
+ source_p->username, source_p->host,
+ SHARED_UNKLINE))
{
if (remove_kline_match(khost, kuser))
{
- sendto_one(source_p,
- ":%s NOTICE %s :K-Line for [%s@%s] is removed",
+ sendto_one(source_p, ":%s NOTICE %s :K-Line for [%s@%s] is removed",
me.name, source_p->name, kuser, khost);
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
"%s has removed the K-Line for: [%s@%s]",
@@ -403,52 +438,16 @@ ms_unkline(struct Client *client_p, struct Client *source_p,
me_unkline(client_p, source_p, parc, parv);
}
-/* static int remove_tkline_match(const char *host, const char *user)
- * Input: A hostname, a username to unkline.
- * Output: returns YES on success, NO if no tkline removed.
- * Side effects: Any matching tklines are removed.
- */
-static int
-remove_kline_match(const char *host, const char *user)
+static struct Message kline_msgtab =
{
- struct irc_ssaddr iphost, *piphost;
- struct MaskItem *conf;
- int t = 0;
- int aftype = 0;
-
- if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
- {
-#ifdef IPV6
- if (t == HM_IPV6)
- aftype = AF_INET6;
- else
-#endif
- aftype = AF_INET;
- piphost = &iphost;
- }
- else
- piphost = NULL;
-
- if ((conf = find_conf_by_address(host, piphost, CONF_KLINE, aftype, user, NULL, 0)))
- {
- if (IsConfDatabase(conf))
- {
- delete_one_address_conf(host, conf);
- return 1;
- }
- }
-
- return 0;
-}
-
-static struct Message kline_msgtab = {
"KLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
- {m_unregistered, m_not_oper, ms_kline, me_kline, mo_kline, m_ignore}
+ { m_unregistered, m_not_oper, ms_kline, me_kline, mo_kline, m_ignore }
};
-static struct Message unkline_msgtab = {
+static struct Message unkline_msgtab =
+{
"UNKLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
- {m_unregistered, m_not_oper, ms_unkline, me_unkline, mo_unkline, m_ignore}
+ { m_unregistered, m_not_oper, ms_unkline, me_unkline, mo_unkline, m_ignore }
};
static void
@@ -469,7 +468,8 @@ module_exit(void)
delete_capability("KLN");
}
-struct module module_entry = {
+struct module module_entry =
+{
.node = { NULL, NULL, NULL },
.name = NULL,
.version = "$Revision$",