1 |
adx |
30 |
/* |
2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
7925 |
* Copyright (c) 2001-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 |
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 |
michael |
7208 |
#include "conf_cluster.h" |
38 |
michael |
7235 |
#include "conf_resv.h" |
39 |
michael |
7208 |
#include "conf_shared.h" |
40 |
michael |
1309 |
#include "log.h" |
41 |
adx |
30 |
|
42 |
|
|
|
43 |
michael |
3560 |
/* parse_resv() |
44 |
|
|
* |
45 |
michael |
7281 |
* inputs - source_p |
46 |
michael |
3560 |
* - thing to resv |
47 |
michael |
7329 |
* - !0 if temporary |
48 |
michael |
3560 |
* - reason |
49 |
|
|
* outputs - none |
50 |
|
|
* side effects - parse resv, create if valid |
51 |
|
|
*/ |
52 |
|
|
static void |
53 |
michael |
7329 |
resv_handle(struct Client *source_p, const char *mask, uintmax_t duration, const char *reason) |
54 |
michael |
3560 |
{ |
55 |
michael |
7408 |
if (!HasFlag(source_p, FLAGS_SERVICE)) |
56 |
michael |
6330 |
{ |
57 |
michael |
7408 |
if (!HasUMode(source_p, UMODE_ADMIN) && has_wildcards(mask)) |
58 |
|
|
{ |
59 |
|
|
if (IsClient(source_p)) |
60 |
|
|
sendto_one_notice(source_p, &me, ":You must be an admin to perform a wildcard RESV"); |
61 |
michael |
4889 |
|
62 |
michael |
7408 |
return; |
63 |
|
|
} |
64 |
michael |
3560 |
|
65 |
michael |
7408 |
if (!valid_wild_card_simple(mask + !!IsChanPrefix(*mask))) |
66 |
|
|
{ |
67 |
|
|
if (IsClient(source_p)) |
68 |
|
|
sendto_one_notice(source_p, &me, ":Please include at least %u non-wildcard characters with the RESV", |
69 |
|
|
ConfigGeneral.min_nonwildcard_simple); |
70 |
michael |
4889 |
|
71 |
michael |
7408 |
return; |
72 |
|
|
} |
73 |
michael |
5826 |
} |
74 |
michael |
3560 |
|
75 |
michael |
7291 |
struct ResvItem *resv = resv_make(mask, reason, NULL); |
76 |
|
|
if (!resv) |
77 |
michael |
5826 |
{ |
78 |
|
|
if (IsClient(source_p)) |
79 |
michael |
7287 |
sendto_one_notice(source_p, &me, ":A RESV has already been placed on: %s", mask); |
80 |
michael |
4889 |
|
81 |
michael |
5826 |
return; |
82 |
|
|
} |
83 |
michael |
3560 |
|
84 |
michael |
7281 |
resv->setat = CurrentTime; |
85 |
|
|
resv->in_database = 1; |
86 |
michael |
3560 |
|
87 |
michael |
6457 |
if (duration) |
88 |
michael |
5826 |
{ |
89 |
michael |
7281 |
resv->expire = CurrentTime + duration; |
90 |
michael |
7074 |
|
91 |
michael |
5826 |
if (IsClient(source_p)) |
92 |
michael |
7074 |
sendto_one_notice(source_p, &me, ":Added temporary %ju min. RESV [%s]", |
93 |
michael |
7281 |
duration / 60, resv->mask); |
94 |
michael |
4889 |
|
95 |
michael |
6317 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
96 |
michael |
7074 |
"%s added temporary %ju min. RESV for [%s] [%s]", |
97 |
|
|
get_oper_name(source_p), duration / 60, |
98 |
michael |
7281 |
resv->mask, resv->reason); |
99 |
michael |
6781 |
ilog(LOG_TYPE_RESV, "%s added temporary %ju min. RESV for [%s] [%s]", |
100 |
michael |
7281 |
get_oper_name(source_p), duration / 60, resv->mask, resv->reason); |
101 |
michael |
5826 |
} |
102 |
|
|
else |
103 |
|
|
{ |
104 |
|
|
if (IsClient(source_p)) |
105 |
michael |
7074 |
sendto_one_notice(source_p, &me, ":Added RESV [%s] [%s]", |
106 |
michael |
7281 |
resv->mask, resv->reason); |
107 |
michael |
4889 |
|
108 |
michael |
6317 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
109 |
michael |
7074 |
"%s added RESV for [%s] [%s]", |
110 |
michael |
7281 |
get_oper_name(source_p), resv->mask, |
111 |
|
|
resv->reason); |
112 |
michael |
5826 |
ilog(LOG_TYPE_RESV, "%s added RESV for [%s] [%s]", |
113 |
michael |
7281 |
get_oper_name(source_p), resv->mask, resv->reason); |
114 |
michael |
3560 |
} |
115 |
|
|
} |
116 |
|
|
|
117 |
adx |
30 |
/* mo_resv() |
118 |
michael |
3096 |
* parv[0] = command |
119 |
adx |
30 |
* parv[1] = channel/nick to forbid |
120 |
|
|
*/ |
121 |
michael |
2820 |
static int |
122 |
michael |
3156 |
mo_resv(struct Client *source_p, int parc, char *parv[]) |
123 |
adx |
30 |
{ |
124 |
michael |
7281 |
char *mask = NULL; |
125 |
adx |
30 |
char *reason = NULL; |
126 |
|
|
char *target_server = NULL; |
127 |
michael |
7329 |
uintmax_t duration = 0; |
128 |
adx |
30 |
|
129 |
michael |
6453 |
if (!HasOFlag(source_p, OPER_FLAG_RESV)) |
130 |
|
|
{ |
131 |
|
|
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "resv"); |
132 |
|
|
return 0; |
133 |
|
|
} |
134 |
|
|
|
135 |
michael |
7428 |
if (!parse_aline("RESV", source_p, parc, parv, &mask, NULL, |
136 |
michael |
6457 |
&duration, &target_server, &reason)) |
137 |
michael |
2820 |
return 0; |
138 |
adx |
30 |
|
139 |
michael |
3368 |
if (target_server) |
140 |
adx |
30 |
{ |
141 |
michael |
7063 |
sendto_match_servs(source_p, target_server, CAPAB_CLUSTER, |
142 |
|
|
"RESV %s %ju %s :%s", |
143 |
michael |
7281 |
target_server, duration, mask, reason); |
144 |
michael |
5958 |
|
145 |
adx |
30 |
/* Allow ON to apply local resv as well if it matches */ |
146 |
michael |
1652 |
if (match(target_server, me.name)) |
147 |
michael |
2820 |
return 0; |
148 |
adx |
30 |
} |
149 |
|
|
else |
150 |
michael |
7208 |
cluster_distribute(source_p, "RESV", CAPAB_KLN, CLUSTER_RESV, |
151 |
michael |
7281 |
"%ju %s :%s", duration, mask, reason); |
152 |
adx |
30 |
|
153 |
michael |
7291 |
resv_handle(source_p, mask, duration, reason); |
154 |
michael |
2820 |
return 0; |
155 |
adx |
30 |
} |
156 |
|
|
|
157 |
michael |
7093 |
/*! \brief RESV command handler |
158 |
|
|
* |
159 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
160 |
|
|
* originally comes from. This can be a local or remote client. |
161 |
|
|
* \param parc Integer holding the number of supplied arguments. |
162 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
163 |
|
|
* pointers. |
164 |
|
|
* \note Valid arguments for this command are: |
165 |
|
|
* - parv[0] = command |
166 |
|
|
* - parv[1] = target server mask |
167 |
|
|
* - parv[2] = duration in seconds |
168 |
|
|
* - parv[3] = name mask |
169 |
|
|
* - parv[4] = reason |
170 |
adx |
30 |
*/ |
171 |
michael |
2820 |
static int |
172 |
michael |
3156 |
ms_resv(struct Client *source_p, int parc, char *parv[]) |
173 |
adx |
30 |
{ |
174 |
michael |
6352 |
if (parc != 5 || EmptyString(parv[4])) |
175 |
michael |
2820 |
return 0; |
176 |
adx |
30 |
|
177 |
michael |
6353 |
sendto_match_servs(source_p, parv[1], CAPAB_CLUSTER, "RESV %s %s %s :%s", |
178 |
michael |
6352 |
parv[1], parv[2], parv[3], parv[4]); |
179 |
adx |
30 |
|
180 |
michael |
4649 |
if (match(parv[1], me.name)) |
181 |
michael |
2820 |
return 0; |
182 |
adx |
30 |
|
183 |
michael |
4649 |
if (HasFlag(source_p, FLAGS_SERVICE) || |
184 |
michael |
7208 |
shared_find(SHARED_RESV, source_p->servptr->name, |
185 |
|
|
source_p->username, source_p->host)) |
186 |
michael |
7360 |
resv_handle(source_p, parv[3], strtoumax(parv[2], NULL, 10), parv[4]); |
187 |
michael |
2820 |
return 0; |
188 |
adx |
30 |
} |
189 |
|
|
|
190 |
michael |
2820 |
static struct Message resv_msgtab = |
191 |
|
|
{ |
192 |
michael |
5880 |
.cmd = "RESV", |
193 |
|
|
.args_min = 3, |
194 |
|
|
.args_max = MAXPARA, |
195 |
michael |
5892 |
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
196 |
michael |
5880 |
.handlers[CLIENT_HANDLER] = m_not_oper, |
197 |
|
|
.handlers[SERVER_HANDLER] = ms_resv, |
198 |
michael |
7063 |
.handlers[ENCAP_HANDLER] = m_ignore, |
199 |
michael |
5880 |
.handlers[OPER_HANDLER] = mo_resv |
200 |
michael |
1230 |
}; |
201 |
|
|
|
202 |
|
|
static void |
203 |
|
|
module_init(void) |
204 |
|
|
{ |
205 |
|
|
mod_add_cmd(&resv_msgtab); |
206 |
|
|
} |
207 |
|
|
|
208 |
|
|
static void |
209 |
|
|
module_exit(void) |
210 |
|
|
{ |
211 |
|
|
mod_del_cmd(&resv_msgtab); |
212 |
|
|
} |
213 |
|
|
|
214 |
michael |
2820 |
struct module module_entry = |
215 |
|
|
{ |
216 |
michael |
1230 |
.version = "$Revision$", |
217 |
|
|
.modinit = module_init, |
218 |
|
|
.modexit = module_exit, |
219 |
|
|
}; |