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