| 1 |
adx |
30 |
/* |
| 2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
adx |
30 |
* |
| 4 |
michael |
5347 |
* Copyright (c) 2001-2015 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_resv.c |
| 23 |
michael |
3354 |
* \brief Includes required functions for processing the RESV command. |
| 24 |
michael |
2820 |
* \version $Id$ |
| 25 |
|
|
*/ |
| 26 |
|
|
|
| 27 |
adx |
30 |
#include "stdinc.h" |
| 28 |
|
|
#include "client.h" |
| 29 |
|
|
#include "ircd.h" |
| 30 |
|
|
#include "irc_string.h" |
| 31 |
|
|
#include "numeric.h" |
| 32 |
michael |
3347 |
#include "server.h" |
| 33 |
adx |
30 |
#include "send.h" |
| 34 |
|
|
#include "parse.h" |
| 35 |
|
|
#include "modules.h" |
| 36 |
michael |
1309 |
#include "conf.h" |
| 37 |
|
|
#include "log.h" |
| 38 |
adx |
30 |
#include "resv.h" |
| 39 |
|
|
|
| 40 |
|
|
|
| 41 |
michael |
3559 |
/* parse_resv() |
| 42 |
|
|
* |
| 43 |
|
|
* inputs - source_p, NULL supported |
| 44 |
|
|
* - thing to resv |
| 45 |
|
|
* - time_t if tkline |
| 46 |
|
|
* - reason |
| 47 |
|
|
* outputs - none |
| 48 |
|
|
* side effects - parse resv, create if valid |
| 49 |
|
|
*/ |
| 50 |
|
|
static void |
| 51 |
|
|
parse_resv(struct Client *source_p, char *name, int tkline_time, char *reason) |
| 52 |
|
|
{ |
| 53 |
michael |
5825 |
const char *type = "channel"; |
| 54 |
|
|
struct MaskItem *conf = NULL; |
| 55 |
adx |
30 |
|
| 56 |
michael |
5825 |
if (!IsChanPrefix(*name)) |
| 57 |
michael |
3559 |
{ |
| 58 |
michael |
5825 |
type = "nick"; |
| 59 |
michael |
3559 |
|
| 60 |
|
|
if (!valid_wild_card_simple(name)) |
| 61 |
|
|
{ |
| 62 |
michael |
4650 |
if (IsClient(source_p)) |
| 63 |
|
|
sendto_one_notice(source_p, &me, ":Please include at least %u non-wildcard characters with the resv", |
| 64 |
|
|
ConfigGeneral.min_nonwildcard_simple); |
| 65 |
michael |
4890 |
|
| 66 |
michael |
3559 |
return; |
| 67 |
|
|
} |
| 68 |
|
|
|
| 69 |
|
|
if (!HasUMode(source_p, UMODE_ADMIN) && has_wildcards(name)) |
| 70 |
|
|
{ |
| 71 |
michael |
4650 |
if (IsClient(source_p)) |
| 72 |
|
|
sendto_one_notice(source_p, &me, ":You must be an admin to perform a wildcard RESV"); |
| 73 |
michael |
4890 |
|
| 74 |
michael |
3559 |
return; |
| 75 |
|
|
} |
| 76 |
michael |
5825 |
} |
| 77 |
michael |
3559 |
|
| 78 |
michael |
5825 |
if ((conf = create_resv(name, reason, NULL)) == NULL) |
| 79 |
|
|
{ |
| 80 |
|
|
if (IsClient(source_p)) |
| 81 |
|
|
sendto_one_notice(source_p, &me, ":A RESV has already been placed on %s: %s", type, name); |
| 82 |
michael |
4890 |
|
| 83 |
michael |
5825 |
return; |
| 84 |
|
|
} |
| 85 |
michael |
3559 |
|
| 86 |
michael |
5825 |
conf->setat = CurrentTime; |
| 87 |
|
|
SetConfDatabase(conf); |
| 88 |
michael |
3559 |
|
| 89 |
michael |
5825 |
if (tkline_time) |
| 90 |
|
|
{ |
| 91 |
|
|
if (IsClient(source_p)) |
| 92 |
|
|
sendto_one_notice(source_p, &me, ":A %d minute %s RESV has been placed on %s: %s", |
| 93 |
|
|
tkline_time/60, (MyClient(source_p) ? "local" : "remote"), type, name); |
| 94 |
michael |
4890 |
|
| 95 |
michael |
5825 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 96 |
|
|
"%s has placed a %d minute %s RESV on %s: %s [%s]", |
| 97 |
|
|
get_oper_name(source_p), |
| 98 |
|
|
tkline_time/60, |
| 99 |
|
|
(MyClient(source_p) ? "local" : "remote"), type, |
| 100 |
|
|
conf->name, conf->reason); |
| 101 |
|
|
ilog(LOG_TYPE_RESV, "%s added temporary %d min. RESV for [%s] [%s]", |
| 102 |
|
|
get_oper_name(source_p), (int)tkline_time/60, |
| 103 |
|
|
conf->name, conf->reason); |
| 104 |
|
|
conf->until = CurrentTime + tkline_time; |
| 105 |
|
|
} |
| 106 |
|
|
else |
| 107 |
|
|
{ |
| 108 |
|
|
if (IsClient(source_p)) |
| 109 |
|
|
sendto_one_notice(source_p, &me, ":A %s RESV has been placed on %s: %s", |
| 110 |
|
|
(MyClient(source_p) ? "local" : "remote"), type, name); |
| 111 |
michael |
4890 |
|
| 112 |
michael |
5825 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 113 |
|
|
"%s has placed a %s RESV on %s: %s [%s]", |
| 114 |
|
|
get_oper_name(source_p), |
| 115 |
|
|
(MyClient(source_p) ? "local" : "remote"), type, |
| 116 |
|
|
conf->name, conf->reason); |
| 117 |
|
|
ilog(LOG_TYPE_RESV, "%s added RESV for [%s] [%s]", |
| 118 |
|
|
get_oper_name(source_p), conf->name, conf->reason); |
| 119 |
michael |
3559 |
} |
| 120 |
|
|
} |
| 121 |
|
|
|
| 122 |
adx |
30 |
/* mo_resv() |
| 123 |
michael |
3096 |
* parv[0] = command |
| 124 |
adx |
30 |
* parv[1] = channel/nick to forbid |
| 125 |
|
|
*/ |
| 126 |
michael |
2820 |
static int |
| 127 |
michael |
3156 |
mo_resv(struct Client *source_p, int parc, char *parv[]) |
| 128 |
adx |
30 |
{ |
| 129 |
|
|
char *resv = NULL; |
| 130 |
|
|
char *reason = NULL; |
| 131 |
|
|
char *target_server = NULL; |
| 132 |
|
|
time_t tkline_time = 0; |
| 133 |
|
|
|
| 134 |
|
|
/* RESV #channel ON irc.server.com :abuse |
| 135 |
|
|
* RESV kiddie ON irc.server.com :abuse |
| 136 |
|
|
*/ |
| 137 |
michael |
5776 |
if (!parse_aline("RESV", source_p, parc, parv, 0, &resv, NULL, |
| 138 |
|
|
&tkline_time, &target_server, &reason)) |
| 139 |
michael |
2820 |
return 0; |
| 140 |
adx |
30 |
|
| 141 |
michael |
3368 |
if (target_server) |
| 142 |
adx |
30 |
{ |
| 143 |
|
|
/* if a given expire time is given, ENCAP it */ |
| 144 |
michael |
3368 |
if (tkline_time) |
| 145 |
adx |
30 |
sendto_match_servs(source_p, target_server, CAP_ENCAP, |
| 146 |
michael |
2820 |
"ENCAP %s RESV %d %s 0 :%s", |
| 147 |
|
|
target_server, (int)tkline_time, resv, reason); |
| 148 |
adx |
30 |
else |
| 149 |
|
|
sendto_match_servs(source_p, target_server, CAP_CLUSTER, |
| 150 |
michael |
2820 |
"RESV %s %s :%s", |
| 151 |
|
|
target_server, resv, reason); |
| 152 |
adx |
30 |
/* Allow ON to apply local resv as well if it matches */ |
| 153 |
michael |
1652 |
if (match(target_server, me.name)) |
| 154 |
michael |
2820 |
return 0; |
| 155 |
adx |
30 |
} |
| 156 |
|
|
else |
| 157 |
|
|
{ |
| 158 |
|
|
/* RESV #channel :abuse |
| 159 |
|
|
* RESV kiddie :abuse |
| 160 |
|
|
*/ |
| 161 |
michael |
3368 |
if (tkline_time) |
| 162 |
adx |
30 |
cluster_a_line(source_p, "ENCAP", CAP_ENCAP, SHARED_RESV, |
| 163 |
michael |
4615 |
"RESV %d %s 0 :%s", (int)tkline_time, resv, reason); |
| 164 |
adx |
30 |
else |
| 165 |
|
|
cluster_a_line(source_p, "RESV", CAP_KLN, SHARED_RESV, |
| 166 |
michael |
4615 |
"%s :%s", resv, reason); |
| 167 |
adx |
30 |
} |
| 168 |
|
|
|
| 169 |
|
|
parse_resv(source_p, resv, (int)tkline_time, reason); |
| 170 |
michael |
2820 |
return 0; |
| 171 |
adx |
30 |
} |
| 172 |
|
|
|
| 173 |
|
|
/* me_resv() |
| 174 |
|
|
* |
| 175 |
|
|
* inputs - server |
| 176 |
|
|
* - client (oper) |
| 177 |
|
|
* - parc number of arguments |
| 178 |
|
|
* - parv list of arguments |
| 179 |
|
|
* via parv[] |
| 180 |
michael |
3096 |
* parv[0] = command |
| 181 |
adx |
30 |
* parv[1] = tkline_time |
| 182 |
|
|
* parv[2] = name |
| 183 |
|
|
* parv[3] = 0 |
| 184 |
|
|
* parv[4] = reason |
| 185 |
|
|
* parc should be 5 |
| 186 |
|
|
* |
| 187 |
|
|
* outputs - NONE |
| 188 |
|
|
* side effects - |
| 189 |
|
|
*/ |
| 190 |
michael |
2820 |
static int |
| 191 |
michael |
3156 |
me_resv(struct Client *source_p, int parc, char *parv[]) |
| 192 |
adx |
30 |
{ |
| 193 |
michael |
4650 |
if (parc != 5 || EmptyString(parv[4])) |
| 194 |
michael |
2820 |
return 0; |
| 195 |
adx |
30 |
|
| 196 |
|
|
parse_resv(source_p, parv[2], atoi(parv[1]), parv[4]); |
| 197 |
michael |
2820 |
return 0; |
| 198 |
adx |
30 |
} |
| 199 |
|
|
|
| 200 |
|
|
/* ms_resv() |
| 201 |
michael |
3096 |
* parv[0] = command |
| 202 |
adx |
30 |
* parv[1] = target server |
| 203 |
|
|
* parv[2] = channel/nick to resv |
| 204 |
|
|
* parv[3] = reason |
| 205 |
|
|
*/ |
| 206 |
michael |
2820 |
static int |
| 207 |
michael |
3156 |
ms_resv(struct Client *source_p, int parc, char *parv[]) |
| 208 |
adx |
30 |
{ |
| 209 |
michael |
3368 |
if (parc != 4 || EmptyString(parv[3])) |
| 210 |
michael |
2820 |
return 0; |
| 211 |
adx |
30 |
|
| 212 |
michael |
4650 |
sendto_match_servs(source_p, parv[1], CAP_CLUSTER, "RESV %s %s :%s", |
| 213 |
adx |
30 |
parv[1], parv[2], parv[3]); |
| 214 |
|
|
|
| 215 |
michael |
4650 |
if (match(parv[1], me.name)) |
| 216 |
michael |
2820 |
return 0; |
| 217 |
adx |
30 |
|
| 218 |
michael |
4650 |
if (HasFlag(source_p, FLAGS_SERVICE) || |
| 219 |
|
|
find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
| 220 |
adx |
30 |
source_p->username, source_p->host, |
| 221 |
|
|
SHARED_RESV)) |
| 222 |
|
|
parse_resv(source_p, parv[2], 0, parv[3]); |
| 223 |
michael |
2820 |
return 0; |
| 224 |
adx |
30 |
} |
| 225 |
|
|
|
| 226 |
michael |
2820 |
static struct Message resv_msgtab = |
| 227 |
|
|
{ |
| 228 |
michael |
5881 |
.cmd = "RESV", |
| 229 |
|
|
.args_min = 3, |
| 230 |
|
|
.args_max = MAXPARA, |
| 231 |
|
|
.handlers[UNREGISTERED_HANDLER] = m_ignore, |
| 232 |
|
|
.handlers[CLIENT_HANDLER] = m_not_oper, |
| 233 |
|
|
.handlers[SERVER_HANDLER] = ms_resv, |
| 234 |
|
|
.handlers[ENCAP_HANDLER] = me_resv, |
| 235 |
|
|
.handlers[OPER_HANDLER] = mo_resv |
| 236 |
michael |
1230 |
}; |
| 237 |
|
|
|
| 238 |
|
|
static void |
| 239 |
|
|
module_init(void) |
| 240 |
|
|
{ |
| 241 |
|
|
mod_add_cmd(&resv_msgtab); |
| 242 |
|
|
} |
| 243 |
|
|
|
| 244 |
|
|
static void |
| 245 |
|
|
module_exit(void) |
| 246 |
|
|
{ |
| 247 |
|
|
mod_del_cmd(&resv_msgtab); |
| 248 |
|
|
} |
| 249 |
|
|
|
| 250 |
michael |
2820 |
struct module module_entry = |
| 251 |
|
|
{ |
| 252 |
michael |
1230 |
.version = "$Revision$", |
| 253 |
|
|
.modinit = module_init, |
| 254 |
|
|
.modexit = module_exit, |
| 255 |
|
|
}; |