| 1 |
adx |
30 |
/* |
| 2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
adx |
30 |
* |
| 4 |
michael |
7924 |
* Copyright (c) 2003-2017 ircd-hybrid development team |
| 5 |
adx |
30 |
* |
| 6 |
|
|
* This program is free software; you can redistribute it and/or modify |
| 7 |
|
|
* it under the terms of the GNU General Public License as published by |
| 8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
|
|
* (at your option) any later version. |
| 10 |
|
|
* |
| 11 |
|
|
* This program is distributed in the hope that it will be useful, |
| 12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
|
|
* GNU General Public License for more details. |
| 15 |
|
|
* |
| 16 |
|
|
* You should have received a copy of the GNU General Public License |
| 17 |
|
|
* along with this program; if not, write to the Free Software |
| 18 |
michael |
4565 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
adx |
30 |
* USA |
| 20 |
|
|
*/ |
| 21 |
|
|
|
| 22 |
michael |
2820 |
/*! \file m_xline.c |
| 23 |
michael |
3352 |
* \brief Includes required functions for processing the XLINE command. |
| 24 |
michael |
2820 |
* \version $Id$ |
| 25 |
|
|
*/ |
| 26 |
|
|
|
| 27 |
adx |
30 |
#include "stdinc.h" |
| 28 |
michael |
1011 |
#include "list.h" |
| 29 |
adx |
30 |
#include "client.h" |
| 30 |
|
|
#include "irc_string.h" |
| 31 |
|
|
#include "ircd.h" |
| 32 |
michael |
1632 |
#include "conf.h" |
| 33 |
michael |
7209 |
#include "conf_cluster.h" |
| 34 |
michael |
7304 |
#include "conf_gecos.h" |
| 35 |
michael |
7209 |
#include "conf_shared.h" |
| 36 |
adx |
30 |
#include "numeric.h" |
| 37 |
michael |
1309 |
#include "log.h" |
| 38 |
michael |
5823 |
#include "misc.h" |
| 39 |
adx |
30 |
#include "send.h" |
| 40 |
michael |
3347 |
#include "server.h" |
| 41 |
adx |
30 |
#include "parse.h" |
| 42 |
|
|
#include "modules.h" |
| 43 |
michael |
1666 |
#include "memory.h" |
| 44 |
adx |
30 |
|
| 45 |
|
|
|
| 46 |
michael |
2877 |
static void |
| 47 |
michael |
7435 |
xline_check(const struct GecosItem *gecos) |
| 48 |
michael |
2877 |
{ |
| 49 |
michael |
8026 |
dlink_node *node, *node_next; |
| 50 |
michael |
2877 |
|
| 51 |
michael |
4815 |
DLINK_FOREACH_SAFE(node, node_next, local_client_list.head) |
| 52 |
michael |
2877 |
{ |
| 53 |
michael |
4815 |
struct Client *client_p = node->data; |
| 54 |
michael |
2877 |
|
| 55 |
|
|
if (IsDead(client_p)) |
| 56 |
|
|
continue; |
| 57 |
|
|
|
| 58 |
michael |
7304 |
if (!match(gecos->mask, client_p->info)) |
| 59 |
|
|
conf_try_ban(client_p, CLIENT_BAN_XLINE, gecos->reason); |
| 60 |
michael |
2877 |
} |
| 61 |
|
|
} |
| 62 |
|
|
|
| 63 |
michael |
7415 |
/* xline_handle() |
| 64 |
michael |
2974 |
* |
| 65 |
|
|
* inputs - client taking credit for xline, gecos, reason, xline type |
| 66 |
|
|
* outputs - none |
| 67 |
|
|
* side effects - when successful, adds an xline to the conf |
| 68 |
|
|
*/ |
| 69 |
|
|
static void |
| 70 |
michael |
7673 |
xline_handle(struct Client *source_p, const char *mask, const char *reason, uintmax_t duration) |
| 71 |
michael |
2974 |
{ |
| 72 |
michael |
5865 |
char buf[IRCD_BUFSIZE]; |
| 73 |
michael |
2974 |
|
| 74 |
michael |
7415 |
if (!HasFlag(source_p, FLAGS_SERVICE)) |
| 75 |
|
|
{ |
| 76 |
|
|
if (!valid_wild_card_simple(mask)) |
| 77 |
|
|
{ |
| 78 |
|
|
if (IsClient(source_p)) |
| 79 |
|
|
sendto_one_notice(source_p, &me, ":Please include at least %u non-wildcard characters with the xline", |
| 80 |
|
|
ConfigGeneral.min_nonwildcard_simple); |
| 81 |
|
|
return; |
| 82 |
|
|
} |
| 83 |
|
|
} |
| 84 |
|
|
|
| 85 |
michael |
8026 |
struct GecosItem *gecos = gecos_find(mask, match); |
| 86 |
|
|
if (gecos) |
| 87 |
michael |
7415 |
{ |
| 88 |
|
|
if (IsClient(source_p)) |
| 89 |
|
|
sendto_one_notice(source_p, &me, ":[%s] already X-Lined by [%s] - %s", |
| 90 |
|
|
mask, gecos->mask, gecos->reason); |
| 91 |
|
|
return; |
| 92 |
|
|
} |
| 93 |
|
|
|
| 94 |
michael |
6458 |
if (duration) |
| 95 |
michael |
6782 |
snprintf(buf, sizeof(buf), "Temporary X-line %ju min. - %.*s (%s)", |
| 96 |
|
|
duration / 60, REASONLEN, reason, date_iso8601(0)); |
| 97 |
michael |
5865 |
else |
| 98 |
michael |
6422 |
snprintf(buf, sizeof(buf), "%.*s (%s)", REASONLEN, reason, date_iso8601(0)); |
| 99 |
michael |
5865 |
|
| 100 |
michael |
7415 |
gecos = gecos_make(); |
| 101 |
michael |
7304 |
gecos->mask = xstrdup(mask); |
| 102 |
|
|
gecos->reason = xstrdup(buf); |
| 103 |
|
|
gecos->setat = CurrentTime; |
| 104 |
|
|
gecos->in_database = 1; |
| 105 |
michael |
2974 |
|
| 106 |
michael |
6458 |
if (duration) |
| 107 |
michael |
2974 |
{ |
| 108 |
michael |
7304 |
gecos->expire = CurrentTime + duration; |
| 109 |
michael |
5875 |
|
| 110 |
michael |
4646 |
if (IsClient(source_p)) |
| 111 |
michael |
6782 |
sendto_one_notice(source_p, &me, ":Added temporary %ju min. X-Line [%s]", |
| 112 |
michael |
7304 |
duration / 60, gecos->mask); |
| 113 |
michael |
4890 |
|
| 114 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
| 115 |
michael |
6782 |
"%s added temporary %ju min. X-Line for [%s] [%s]", |
| 116 |
|
|
get_oper_name(source_p), duration / 60, |
| 117 |
michael |
7304 |
gecos->mask, gecos->reason); |
| 118 |
michael |
6782 |
ilog(LOG_TYPE_XLINE, "%s added temporary %ju min. X-Line for [%s] [%s]", |
| 119 |
michael |
7304 |
get_oper_name(source_p), duration / 60, gecos->mask, gecos->reason); |
| 120 |
michael |
2974 |
} |
| 121 |
|
|
else |
| 122 |
|
|
{ |
| 123 |
michael |
4646 |
if (IsClient(source_p)) |
| 124 |
|
|
sendto_one_notice(source_p, &me, ":Added X-Line [%s] [%s]", |
| 125 |
michael |
7304 |
gecos->mask, gecos->reason); |
| 126 |
michael |
4890 |
|
| 127 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
| 128 |
michael |
2974 |
"%s added X-Line for [%s] [%s]", |
| 129 |
michael |
7304 |
get_oper_name(source_p), gecos->mask, |
| 130 |
|
|
gecos->reason); |
| 131 |
michael |
2974 |
ilog(LOG_TYPE_XLINE, "%s added X-Line for [%s] [%s]", |
| 132 |
michael |
7304 |
get_oper_name(source_p), gecos->mask, gecos->reason); |
| 133 |
michael |
2974 |
} |
| 134 |
|
|
|
| 135 |
michael |
7304 |
xline_check(gecos); |
| 136 |
michael |
2974 |
} |
| 137 |
|
|
|
| 138 |
adx |
30 |
/* mo_xline() |
| 139 |
|
|
* |
| 140 |
|
|
* inputs - pointer to server |
| 141 |
|
|
* - pointer to client |
| 142 |
|
|
* - parameter count |
| 143 |
|
|
* - parameter list |
| 144 |
|
|
* output - |
| 145 |
|
|
* side effects - x line is added |
| 146 |
|
|
* |
| 147 |
|
|
*/ |
| 148 |
michael |
2820 |
static int |
| 149 |
michael |
3156 |
mo_xline(struct Client *source_p, int parc, char *parv[]) |
| 150 |
adx |
30 |
{ |
| 151 |
|
|
char *reason = NULL; |
| 152 |
michael |
7304 |
char *mask = NULL; |
| 153 |
adx |
30 |
char *target_server = NULL; |
| 154 |
michael |
7330 |
uintmax_t duration = 0; |
| 155 |
adx |
30 |
|
| 156 |
michael |
2852 |
if (!HasOFlag(source_p, OPER_FLAG_XLINE)) |
| 157 |
adx |
30 |
{ |
| 158 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "xline"); |
| 159 |
michael |
2820 |
return 0; |
| 160 |
adx |
30 |
} |
| 161 |
|
|
|
| 162 |
michael |
7429 |
if (!parse_aline("XLINE", source_p, parc, parv, &mask, NULL, |
| 163 |
michael |
6458 |
&duration, &target_server, &reason)) |
| 164 |
michael |
2820 |
return 0; |
| 165 |
adx |
30 |
|
| 166 |
michael |
3368 |
if (target_server) |
| 167 |
adx |
30 |
{ |
| 168 |
michael |
6782 |
sendto_match_servs(source_p, target_server, CAPAB_CLUSTER, "XLINE %s %s %ju :%s", |
| 169 |
michael |
7304 |
target_server, mask, duration, reason); |
| 170 |
adx |
30 |
|
| 171 |
|
|
/* Allow ON to apply local xline as well if it matches */ |
| 172 |
michael |
1652 |
if (match(target_server, me.name)) |
| 173 |
michael |
2820 |
return 0; |
| 174 |
adx |
30 |
} |
| 175 |
michael |
2820 |
else |
| 176 |
michael |
7209 |
cluster_distribute(source_p, "XLINE", CAPAB_CLUSTER, CLUSTER_XLINE, "%s %ju :%s", |
| 177 |
michael |
7304 |
mask, duration, reason); |
| 178 |
adx |
30 |
|
| 179 |
michael |
7415 |
xline_handle(source_p, mask, reason, duration); |
| 180 |
michael |
2820 |
return 0; |
| 181 |
adx |
30 |
} |
| 182 |
|
|
|
| 183 |
michael |
5870 |
/*! \brief XLINE command handler |
| 184 |
adx |
30 |
* |
| 185 |
michael |
5870 |
* \param source_p Pointer to allocated Client struct from which the message |
| 186 |
|
|
* originally comes from. This can be a local or remote client. |
| 187 |
|
|
* \param parc Integer holding the number of supplied arguments. |
| 188 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 189 |
|
|
* pointers. |
| 190 |
|
|
* \note Valid arguments for this command are: |
| 191 |
|
|
* - parv[0] = command |
| 192 |
michael |
7094 |
* - parv[1] = target server mask |
| 193 |
michael |
5870 |
* - parv[2] = gecos |
| 194 |
michael |
7094 |
* - parv[3] = duration in seconds |
| 195 |
michael |
5870 |
* - parv[4] = reason |
| 196 |
adx |
30 |
*/ |
| 197 |
michael |
2820 |
static int |
| 198 |
michael |
3156 |
ms_xline(struct Client *source_p, int parc, char *parv[]) |
| 199 |
adx |
30 |
{ |
| 200 |
|
|
if (parc != 5 || EmptyString(parv[4])) |
| 201 |
michael |
2820 |
return 0; |
| 202 |
adx |
30 |
|
| 203 |
michael |
6354 |
sendto_match_servs(source_p, parv[1], CAPAB_CLUSTER, "XLINE %s %s %s :%s", |
| 204 |
michael |
4646 |
parv[1], parv[2], parv[3], parv[4]); |
| 205 |
|
|
|
| 206 |
|
|
if (match(parv[1], me.name)) |
| 207 |
michael |
2820 |
return 0; |
| 208 |
adx |
30 |
|
| 209 |
michael |
7413 |
if (HasFlag(source_p, FLAGS_SERVICE) || |
| 210 |
|
|
shared_find(SHARED_XLINE, source_p->servptr->name, |
| 211 |
|
|
source_p->username, source_p->host)) |
| 212 |
michael |
7415 |
xline_handle(source_p, parv[2], parv[4], strtoumax(parv[3], NULL, 10)); |
| 213 |
adx |
30 |
|
| 214 |
michael |
2820 |
return 0; |
| 215 |
adx |
30 |
} |
| 216 |
|
|
|
| 217 |
michael |
2820 |
static struct Message xline_msgtab = |
| 218 |
|
|
{ |
| 219 |
michael |
5881 |
.cmd = "XLINE", |
| 220 |
|
|
.args_min = 2, |
| 221 |
|
|
.args_max = MAXPARA, |
| 222 |
|
|
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
| 223 |
|
|
.handlers[CLIENT_HANDLER] = m_not_oper, |
| 224 |
|
|
.handlers[SERVER_HANDLER] = ms_xline, |
| 225 |
michael |
6850 |
.handlers[ENCAP_HANDLER] = m_ignore, |
| 226 |
michael |
5881 |
.handlers[OPER_HANDLER] = mo_xline |
| 227 |
michael |
1230 |
}; |
| 228 |
|
|
|
| 229 |
|
|
static void |
| 230 |
|
|
module_init(void) |
| 231 |
|
|
{ |
| 232 |
|
|
mod_add_cmd(&xline_msgtab); |
| 233 |
|
|
} |
| 234 |
|
|
|
| 235 |
|
|
static void |
| 236 |
|
|
module_exit(void) |
| 237 |
|
|
{ |
| 238 |
|
|
mod_del_cmd(&xline_msgtab); |
| 239 |
|
|
} |
| 240 |
|
|
|
| 241 |
michael |
2820 |
struct module module_entry = |
| 242 |
|
|
{ |
| 243 |
michael |
1230 |
.version = "$Revision$", |
| 244 |
|
|
.modinit = module_init, |
| 245 |
|
|
.modexit = module_exit, |
| 246 |
|
|
}; |