1 |
adx |
30 |
/* |
2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
5346 |
* 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 |
4564 |
* 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 |
3560 |
/* 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 |
5826 |
const char *type = "channel"; |
54 |
|
|
struct MaskItem *conf = NULL; |
55 |
adx |
30 |
|
56 |
michael |
5826 |
if (!IsChanPrefix(*name)) |
57 |
michael |
3560 |
{ |
58 |
michael |
5826 |
type = "nick"; |
59 |
michael |
3560 |
|
60 |
|
|
if (!valid_wild_card_simple(name)) |
61 |
|
|
{ |
62 |
michael |
4649 |
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 |
4889 |
|
66 |
michael |
3560 |
return; |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
if (!HasUMode(source_p, UMODE_ADMIN) && has_wildcards(name)) |
70 |
|
|
{ |
71 |
michael |
4649 |
if (IsClient(source_p)) |
72 |
|
|
sendto_one_notice(source_p, &me, ":You must be an admin to perform a wildcard RESV"); |
73 |
michael |
4889 |
|
74 |
michael |
3560 |
return; |
75 |
|
|
} |
76 |
michael |
5826 |
} |
77 |
michael |
3560 |
|
78 |
michael |
5826 |
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 |
4889 |
|
83 |
michael |
5826 |
return; |
84 |
|
|
} |
85 |
michael |
3560 |
|
86 |
michael |
5826 |
conf->setat = CurrentTime; |
87 |
|
|
SetConfDatabase(conf); |
88 |
michael |
3560 |
|
89 |
michael |
5826 |
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 |
4889 |
|
95 |
michael |
5826 |
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 |
4889 |
|
112 |
michael |
5826 |
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 |
3560 |
} |
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 |
michael |
5775 |
if (!parse_aline("RESV", source_p, parc, parv, 0, &resv, NULL, |
135 |
|
|
&tkline_time, &target_server, &reason)) |
136 |
michael |
2820 |
return 0; |
137 |
adx |
30 |
|
138 |
michael |
3368 |
if (target_server) |
139 |
adx |
30 |
{ |
140 |
|
|
/* if a given expire time is given, ENCAP it */ |
141 |
michael |
3368 |
if (tkline_time) |
142 |
adx |
30 |
sendto_match_servs(source_p, target_server, CAP_ENCAP, |
143 |
michael |
2820 |
"ENCAP %s RESV %d %s 0 :%s", |
144 |
|
|
target_server, (int)tkline_time, resv, reason); |
145 |
adx |
30 |
else |
146 |
|
|
sendto_match_servs(source_p, target_server, CAP_CLUSTER, |
147 |
michael |
2820 |
"RESV %s %s :%s", |
148 |
|
|
target_server, resv, reason); |
149 |
michael |
5958 |
|
150 |
adx |
30 |
/* Allow ON to apply local resv as well if it matches */ |
151 |
michael |
1652 |
if (match(target_server, me.name)) |
152 |
michael |
2820 |
return 0; |
153 |
adx |
30 |
} |
154 |
|
|
else |
155 |
|
|
{ |
156 |
michael |
3368 |
if (tkline_time) |
157 |
adx |
30 |
cluster_a_line(source_p, "ENCAP", CAP_ENCAP, SHARED_RESV, |
158 |
michael |
4614 |
"RESV %d %s 0 :%s", (int)tkline_time, resv, reason); |
159 |
adx |
30 |
else |
160 |
|
|
cluster_a_line(source_p, "RESV", CAP_KLN, SHARED_RESV, |
161 |
michael |
4614 |
"%s :%s", resv, reason); |
162 |
adx |
30 |
} |
163 |
|
|
|
164 |
|
|
parse_resv(source_p, resv, (int)tkline_time, reason); |
165 |
michael |
2820 |
return 0; |
166 |
adx |
30 |
} |
167 |
|
|
|
168 |
|
|
/* me_resv() |
169 |
|
|
* |
170 |
|
|
* inputs - server |
171 |
|
|
* - client (oper) |
172 |
|
|
* - parc number of arguments |
173 |
|
|
* - parv list of arguments |
174 |
|
|
* via parv[] |
175 |
michael |
3096 |
* parv[0] = command |
176 |
adx |
30 |
* parv[1] = tkline_time |
177 |
|
|
* parv[2] = name |
178 |
|
|
* parv[3] = 0 |
179 |
|
|
* parv[4] = reason |
180 |
|
|
* parc should be 5 |
181 |
|
|
* |
182 |
|
|
* outputs - NONE |
183 |
|
|
* side effects - |
184 |
|
|
*/ |
185 |
michael |
2820 |
static int |
186 |
michael |
3156 |
me_resv(struct Client *source_p, int parc, char *parv[]) |
187 |
adx |
30 |
{ |
188 |
michael |
4649 |
if (parc != 5 || EmptyString(parv[4])) |
189 |
michael |
2820 |
return 0; |
190 |
adx |
30 |
|
191 |
|
|
parse_resv(source_p, parv[2], atoi(parv[1]), parv[4]); |
192 |
michael |
2820 |
return 0; |
193 |
adx |
30 |
} |
194 |
|
|
|
195 |
|
|
/* ms_resv() |
196 |
michael |
3096 |
* parv[0] = command |
197 |
adx |
30 |
* parv[1] = target server |
198 |
|
|
* parv[2] = channel/nick to resv |
199 |
|
|
* parv[3] = reason |
200 |
|
|
*/ |
201 |
michael |
2820 |
static int |
202 |
michael |
3156 |
ms_resv(struct Client *source_p, int parc, char *parv[]) |
203 |
adx |
30 |
{ |
204 |
michael |
3368 |
if (parc != 4 || EmptyString(parv[3])) |
205 |
michael |
2820 |
return 0; |
206 |
adx |
30 |
|
207 |
michael |
4649 |
sendto_match_servs(source_p, parv[1], CAP_CLUSTER, "RESV %s %s :%s", |
208 |
adx |
30 |
parv[1], parv[2], parv[3]); |
209 |
|
|
|
210 |
michael |
4649 |
if (match(parv[1], me.name)) |
211 |
michael |
2820 |
return 0; |
212 |
adx |
30 |
|
213 |
michael |
4649 |
if (HasFlag(source_p, FLAGS_SERVICE) || |
214 |
|
|
find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
215 |
adx |
30 |
source_p->username, source_p->host, |
216 |
|
|
SHARED_RESV)) |
217 |
|
|
parse_resv(source_p, parv[2], 0, parv[3]); |
218 |
michael |
2820 |
return 0; |
219 |
adx |
30 |
} |
220 |
|
|
|
221 |
michael |
2820 |
static struct Message resv_msgtab = |
222 |
|
|
{ |
223 |
michael |
5880 |
.cmd = "RESV", |
224 |
|
|
.args_min = 3, |
225 |
|
|
.args_max = MAXPARA, |
226 |
michael |
5892 |
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
227 |
michael |
5880 |
.handlers[CLIENT_HANDLER] = m_not_oper, |
228 |
|
|
.handlers[SERVER_HANDLER] = ms_resv, |
229 |
|
|
.handlers[ENCAP_HANDLER] = me_resv, |
230 |
|
|
.handlers[OPER_HANDLER] = mo_resv |
231 |
michael |
1230 |
}; |
232 |
|
|
|
233 |
|
|
static void |
234 |
|
|
module_init(void) |
235 |
|
|
{ |
236 |
|
|
mod_add_cmd(&resv_msgtab); |
237 |
|
|
} |
238 |
|
|
|
239 |
|
|
static void |
240 |
|
|
module_exit(void) |
241 |
|
|
{ |
242 |
|
|
mod_del_cmd(&resv_msgtab); |
243 |
|
|
} |
244 |
|
|
|
245 |
michael |
2820 |
struct module module_entry = |
246 |
|
|
{ |
247 |
michael |
1230 |
.version = "$Revision$", |
248 |
|
|
.modinit = module_init, |
249 |
|
|
.modexit = module_exit, |
250 |
|
|
}; |