1 |
adx |
30 |
/* |
2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
|
|
* |
4 |
|
|
* Copyright (C) 2002 by the past and present ircd coders, and others. |
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
|
|
* USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
michael |
1008 |
/*! \file m_gline.c |
23 |
|
|
* \brief Includes required functions for processing the GLINE command. |
24 |
|
|
* \version $Id$ |
25 |
|
|
*/ |
26 |
|
|
|
27 |
adx |
30 |
#include "stdinc.h" |
28 |
|
|
#include "tools.h" |
29 |
|
|
#include "handlers.h" |
30 |
|
|
#include "s_gline.h" |
31 |
|
|
#include "channel.h" |
32 |
|
|
#include "client.h" |
33 |
|
|
#include "common.h" |
34 |
|
|
#include "irc_string.h" |
35 |
|
|
#include "sprintf_irc.h" |
36 |
|
|
#include "ircd.h" |
37 |
|
|
#include "hostmask.h" |
38 |
|
|
#include "numeric.h" |
39 |
|
|
#include "fdlist.h" |
40 |
|
|
#include "s_bsd.h" |
41 |
|
|
#include "s_conf.h" |
42 |
|
|
#include "s_misc.h" |
43 |
|
|
#include "send.h" |
44 |
|
|
#include "msg.h" |
45 |
|
|
#include "fileio.h" |
46 |
|
|
#include "s_serv.h" |
47 |
|
|
#include "hash.h" |
48 |
|
|
#include "parse.h" |
49 |
|
|
#include "modules.h" |
50 |
|
|
#include "list.h" |
51 |
|
|
#include "s_log.h" |
52 |
|
|
|
53 |
|
|
#define GLINE_NOT_PLACED 0 |
54 |
|
|
#define GLINE_ALREADY_VOTED -1 |
55 |
|
|
#define GLINE_PLACED 1 |
56 |
|
|
|
57 |
|
|
|
58 |
michael |
958 |
static void me_gline(struct Client *, struct Client *, int, char *[]); |
59 |
|
|
static void ms_gline(struct Client *, struct Client *, int, char *[]); |
60 |
|
|
static void mo_gline(struct Client *, struct Client *, int, char *[]); |
61 |
|
|
static void me_gungline(struct Client *, struct Client *, int, char *[]); |
62 |
|
|
static void mo_gungline(struct Client *, struct Client *, int, char *[]); |
63 |
db |
937 |
|
64 |
adx |
30 |
/* |
65 |
|
|
* gline enforces 3 parameters to force operator to give a reason |
66 |
|
|
* a gline is not valid with "No reason" |
67 |
|
|
* -db |
68 |
|
|
*/ |
69 |
|
|
struct Message gline_msgtab = { |
70 |
|
|
"GLINE", 0, 0, 3, 0, MFLG_SLOW, 0, |
71 |
michael |
1008 |
{ m_unregistered, m_not_oper, ms_gline, me_gline, mo_gline, m_ignore } |
72 |
adx |
30 |
}; |
73 |
|
|
|
74 |
db |
937 |
struct Message ungline_msgtab = { |
75 |
db |
940 |
"GUNGLINE", 0, 0, 3, 0, MFLG_SLOW, 0, |
76 |
michael |
1008 |
{ m_unregistered, m_not_oper, m_ignore, me_gungline, mo_gungline, m_ignore } |
77 |
db |
937 |
}; |
78 |
|
|
|
79 |
michael |
958 |
|
80 |
adx |
30 |
void |
81 |
|
|
_modinit(void) |
82 |
|
|
{ |
83 |
michael |
957 |
mod_add_cmd(&gline_msgtab); |
84 |
|
|
mod_add_cmd(&ungline_msgtab); |
85 |
|
|
add_capability("GLN", CAP_GLN, 1); |
86 |
adx |
30 |
} |
87 |
|
|
|
88 |
|
|
void |
89 |
|
|
_moddeinit(void) |
90 |
|
|
{ |
91 |
|
|
mod_del_cmd(&gline_msgtab); |
92 |
db |
937 |
mod_del_cmd(&ungline_msgtab); |
93 |
adx |
30 |
delete_capability("GLN"); |
94 |
|
|
} |
95 |
|
|
|
96 |
knight |
31 |
const char *_version = "$Revision$"; |
97 |
adx |
30 |
|
98 |
michael |
1009 |
/*! \brief Adds a GLINE to the configuration subsystem. |
99 |
|
|
* |
100 |
|
|
* \param source_p Operator requesting gline |
101 |
|
|
* \param user Username covered by the gline |
102 |
|
|
* \param host Hostname covered by the gline |
103 |
|
|
* \param reason Reason for the gline |
104 |
|
|
*/ |
105 |
|
|
static void |
106 |
|
|
set_local_gline(const struct Client *source_p, const char *user, |
107 |
|
|
const char *host, const char *reason) |
108 |
|
|
{ |
109 |
|
|
char buffer[IRCD_BUFSIZE]; |
110 |
|
|
struct ConfItem *conf; |
111 |
|
|
struct AccessItem *aconf; |
112 |
michael |
1008 |
|
113 |
|
|
|
114 |
michael |
1009 |
conf = make_conf_item(GLINE_TYPE); |
115 |
|
|
aconf = map_to_conf(conf); |
116 |
|
|
|
117 |
|
|
snprintf(buffer, sizeof(buffer), "%s (%s)", reason, smalldate(CurrentTime)); |
118 |
|
|
DupString(aconf->reason, buffer); |
119 |
|
|
DupString(aconf->user, user); |
120 |
|
|
DupString(aconf->host, host); |
121 |
|
|
|
122 |
|
|
aconf->hold = CurrentTime + ConfigFileEntry.gline_time; |
123 |
|
|
add_temp_line(conf); |
124 |
|
|
|
125 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
126 |
|
|
"%s added G-Line for [%s@%s] [%s]", |
127 |
|
|
get_oper_name(source_p), |
128 |
|
|
aconf->user, aconf->host, aconf->reason); |
129 |
|
|
ilog(L_TRACE, "%s added G-Line for [%s@%s] [%s]", |
130 |
|
|
get_oper_name(source_p), aconf->user, aconf->host, aconf->reason); |
131 |
|
|
log_oper_action(LOG_GLINE_TYPE, source_p, "[%s@%s] [%s]\n", |
132 |
|
|
aconf->user, aconf->host, aconf->reason); |
133 |
|
|
/* Now, activate gline against current online clients */ |
134 |
|
|
rehashed_klines = 1; |
135 |
|
|
} |
136 |
|
|
|
137 |
|
|
/*! \brief Removes a GLINE from the configuration subsystem. |
138 |
|
|
* |
139 |
|
|
* \param user Username covered by the gline |
140 |
|
|
* \param host Hostname covered by the gline |
141 |
|
|
*/ |
142 |
|
|
static int |
143 |
|
|
remove_gline_match(const char *user, const char *host) |
144 |
|
|
{ |
145 |
|
|
struct AccessItem *aconf; |
146 |
|
|
dlink_node *ptr = NULL; |
147 |
|
|
struct irc_ssaddr addr, caddr; |
148 |
|
|
int nm_t, cnm_t, bits, cbits; |
149 |
|
|
|
150 |
|
|
nm_t = parse_netmask(host, &addr, &bits); |
151 |
|
|
|
152 |
|
|
DLINK_FOREACH(ptr, temporary_glines.head) |
153 |
|
|
{ |
154 |
|
|
aconf = map_to_conf(ptr->data); |
155 |
|
|
cnm_t = parse_netmask(aconf->host, &caddr, &cbits); |
156 |
|
|
|
157 |
|
|
if (cnm_t != nm_t || irccmp(user, aconf->user)) |
158 |
|
|
continue; |
159 |
|
|
|
160 |
|
|
if ((nm_t == HM_HOST && !irccmp(aconf->host, host)) || |
161 |
|
|
(nm_t == HM_IPV4 && bits == cbits && match_ipv4(&addr, &caddr, bits)) |
162 |
|
|
#ifdef IPV6 |
163 |
|
|
|| (nm_t == HM_IPV6 && bits == cbits && match_ipv6(&addr, &caddr, bits)) |
164 |
|
|
#endif |
165 |
|
|
) |
166 |
|
|
{ |
167 |
|
|
dlinkDelete(ptr, &temporary_glines); |
168 |
|
|
delete_one_address_conf(aconf->host, aconf); |
169 |
|
|
return 1; |
170 |
|
|
} |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
return 0; |
174 |
|
|
} |
175 |
|
|
|
176 |
michael |
1008 |
/*! \brief This function is called once a majority of opers have agreed on a |
177 |
|
|
* GLINE/GUNGLINE, and it can be placed. The information about an |
178 |
|
|
* operator being passed to us happens to be the operator who pushed us |
179 |
|
|
* over the "majority" level needed. See check_majority() for more |
180 |
|
|
* information. |
181 |
adx |
30 |
* |
182 |
michael |
1008 |
* \param source_p Operator requesting gline |
183 |
|
|
* \param user Username covered by the gline |
184 |
|
|
* \param host Hostname covered by the gline |
185 |
|
|
* \param reason Reason for the gline |
186 |
|
|
* \param type Valid values are either GLINE_PENDING_ADD_TYPE, or |
187 |
|
|
* GLINE_PENDING_DEL_TYPE |
188 |
adx |
30 |
*/ |
189 |
michael |
1008 |
static void |
190 |
|
|
add_new_majority(const struct Client *source_p, const char *user, |
191 |
|
|
const char *host, const char *reason, const unsigned int type) |
192 |
|
|
{ |
193 |
|
|
struct gline_pending *pending = MyMalloc(sizeof(struct gline_pending)); |
194 |
|
|
|
195 |
|
|
strlcpy(pending->vote_1.oper_nick, source_p->name, sizeof(pending->vote_1.oper_nick)); |
196 |
|
|
strlcpy(pending->vote_1.oper_user, source_p->username, sizeof(pending->vote_1.oper_user)); |
197 |
|
|
strlcpy(pending->vote_1.oper_host, source_p->host, sizeof(pending->vote_1.oper_host)); |
198 |
|
|
strlcpy(pending->vote_1.oper_server, source_p->servptr->name, sizeof(pending->vote_1.oper_server)); |
199 |
|
|
|
200 |
|
|
strlcpy(pending->user, user, sizeof(pending->user)); |
201 |
|
|
strlcpy(pending->host, host, sizeof(pending->host)); |
202 |
|
|
strlcpy(pending->vote_1.reason, reason, sizeof(pending->vote_1.reason)); |
203 |
|
|
|
204 |
|
|
pending->last_gline_time = CurrentTime; |
205 |
|
|
pending->vote_1.time_request = CurrentTime; |
206 |
|
|
|
207 |
|
|
dlinkAdd(pending, &pending->node, &pending_glines[type]); |
208 |
|
|
} |
209 |
|
|
|
210 |
|
|
/*! \brief See if there is a majority agreement on a GLINE on the given user. |
211 |
|
|
* There must be at least 3 different opers agreeing on this |
212 |
|
|
* GLINE/GUNGLINE |
213 |
adx |
30 |
* |
214 |
michael |
1008 |
* \param source_p Operator requesting gline |
215 |
|
|
* \param user Username covered by the gline |
216 |
|
|
* \param host Hostname covered by the gline |
217 |
|
|
* \param reason Reason for the gline |
218 |
|
|
* \param type Valid values are either GLINE_PENDING_ADD_TYPE, or |
219 |
|
|
* GLINE_PENDING_DEL_TYPE |
220 |
|
|
* |
221 |
|
|
* \return |
222 |
|
|
* - GLINE_ALREADY_VOTED returned if oper/server has already voted |
223 |
|
|
* - GLINE_PLACED returned if this triggers a gline |
224 |
|
|
* - GLINE_NOT_PLACED returned if not triggered |
225 |
adx |
30 |
*/ |
226 |
michael |
1008 |
static int |
227 |
|
|
check_majority(const struct Client *source_p, const char *user, |
228 |
|
|
const char *host, const char *reason, const int type) |
229 |
adx |
30 |
{ |
230 |
michael |
1008 |
dlink_node *dn_ptr = NULL; |
231 |
adx |
30 |
|
232 |
michael |
1008 |
cleanup_glines(NULL); |
233 |
adx |
30 |
|
234 |
michael |
1008 |
/* if its already glined, why bother? :) -- fl_ */ |
235 |
|
|
if ((type == GLINE_PENDING_ADD_TYPE) && find_is_glined(host, user)) |
236 |
|
|
return GLINE_NOT_PLACED; |
237 |
|
|
|
238 |
|
|
DLINK_FOREACH(dn_ptr, pending_glines[type].head) |
239 |
adx |
30 |
{ |
240 |
michael |
1008 |
struct gline_pending *gp_ptr = dn_ptr->data; |
241 |
adx |
30 |
|
242 |
michael |
1008 |
if (irccmp(gp_ptr->user, user) || |
243 |
|
|
irccmp(gp_ptr->host, host)) |
244 |
|
|
continue; |
245 |
adx |
30 |
|
246 |
michael |
1008 |
if ((!irccmp(gp_ptr->vote_1.oper_user, source_p->username) && |
247 |
|
|
!irccmp(gp_ptr->vote_1.oper_host, source_p->host)) || |
248 |
|
|
!irccmp(gp_ptr->vote_1.oper_server, source_p->servptr->name)) |
249 |
|
|
return GLINE_ALREADY_VOTED; |
250 |
|
|
|
251 |
|
|
if (gp_ptr->vote_2.oper_user[0] != '\0') |
252 |
adx |
30 |
{ |
253 |
michael |
1008 |
/* if two other opers on two different servers have voted yes */ |
254 |
|
|
if ((!irccmp(gp_ptr->vote_2.oper_user, source_p->username) && |
255 |
|
|
!irccmp(gp_ptr->vote_2.oper_host, source_p->host)) || |
256 |
|
|
!irccmp(gp_ptr->vote_2.oper_server, source_p->servptr->name)) |
257 |
|
|
return GLINE_ALREADY_VOTED; |
258 |
|
|
|
259 |
|
|
if (type == GLINE_PENDING_DEL_TYPE) |
260 |
|
|
{ |
261 |
|
|
if (remove_gline_match(user, host)) |
262 |
|
|
{ |
263 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
264 |
|
|
"%s has removed the G-Line for: [%s@%s]", |
265 |
|
|
get_oper_name(source_p), user, host); |
266 |
|
|
ilog(L_NOTICE, "%s removed G-Line for [%s@%s]", |
267 |
|
|
get_oper_name(source_p), user, host); |
268 |
|
|
} |
269 |
|
|
} |
270 |
|
|
else |
271 |
|
|
/* trigger the gline using the original reason --fl */ |
272 |
|
|
set_local_gline(source_p, user, host, gp_ptr->vote_1.reason); |
273 |
|
|
|
274 |
|
|
cleanup_glines(gp_ptr); |
275 |
|
|
return GLINE_PLACED; |
276 |
adx |
30 |
} |
277 |
michael |
1008 |
|
278 |
|
|
strlcpy(gp_ptr->vote_2.oper_nick, source_p->name, |
279 |
|
|
sizeof(gp_ptr->vote_2.oper_nick)); |
280 |
|
|
strlcpy(gp_ptr->vote_2.oper_user, source_p->username, |
281 |
|
|
sizeof(gp_ptr->vote_2.oper_user)); |
282 |
|
|
strlcpy(gp_ptr->vote_2.oper_host, source_p->host, |
283 |
|
|
sizeof(gp_ptr->vote_2.oper_host)); |
284 |
|
|
strlcpy(gp_ptr->vote_2.reason, reason, |
285 |
|
|
sizeof(gp_ptr->vote_2.reason)); |
286 |
|
|
strlcpy(gp_ptr->vote_2.oper_server, source_p->servptr->name, |
287 |
|
|
sizeof(gp_ptr->vote_2.oper_server)); |
288 |
|
|
gp_ptr->last_gline_time = CurrentTime; |
289 |
|
|
gp_ptr->vote_2.time_request = CurrentTime; |
290 |
|
|
return GLINE_NOT_PLACED; |
291 |
adx |
30 |
} |
292 |
|
|
|
293 |
michael |
552 |
/* |
294 |
michael |
1008 |
* Didn't find this user@host gline in pending gline list |
295 |
|
|
* so add it. |
296 |
adx |
30 |
*/ |
297 |
michael |
1008 |
add_new_majority(source_p, user, host, reason, type); |
298 |
|
|
return GLINE_NOT_PLACED; |
299 |
adx |
30 |
} |
300 |
|
|
|
301 |
|
|
static void |
302 |
michael |
1008 |
do_sgline(struct Client *source_p, int parc, char *parv[], int prop) |
303 |
adx |
30 |
{ |
304 |
|
|
const char *reason = NULL; /* reason for "victims" demise */ |
305 |
|
|
char *user = NULL; |
306 |
|
|
char *host = NULL; /* user and host of GLINE "victim" */ |
307 |
michael |
1008 |
int var_offset = 0, logged = 0; |
308 |
adx |
30 |
dlink_node *ptr; |
309 |
michael |
1008 |
struct Client *target_p = NULL; |
310 |
adx |
30 |
|
311 |
michael |
1008 |
switch (parc) |
312 |
adx |
30 |
{ |
313 |
michael |
1008 |
case 4: /* hyb-7 style */ |
314 |
|
|
if (!IsClient(source_p)) |
315 |
|
|
return; |
316 |
|
|
break; |
317 |
|
|
case 8: /* hyb-6 style */ |
318 |
|
|
if (!IsServer(source_p)) |
319 |
|
|
return; |
320 |
|
|
target_p = find_person(source_p->from, parv[1]); |
321 |
|
|
if (target_p == NULL || target_p->servptr != source_p) |
322 |
|
|
return; |
323 |
|
|
source_p = target_p, var_offset = 4; |
324 |
|
|
break; |
325 |
|
|
default: |
326 |
adx |
30 |
return; |
327 |
|
|
} |
328 |
|
|
|
329 |
|
|
assert(source_p->servptr != NULL); |
330 |
|
|
|
331 |
michael |
1008 |
user = parv[++var_offset]; |
332 |
|
|
host = parv[++var_offset]; |
333 |
|
|
reason = parv[++var_offset]; |
334 |
adx |
30 |
|
335 |
|
|
DLINK_FOREACH(ptr, gdeny_items.head) |
336 |
|
|
{ |
337 |
michael |
1008 |
struct ConfItem *conf = ptr->data; |
338 |
|
|
struct AccessItem *aconf = map_to_conf(conf); |
339 |
adx |
30 |
|
340 |
|
|
if (match(conf->name, source_p->servptr->name) && |
341 |
|
|
match(aconf->user, source_p->username) && |
342 |
|
|
match(aconf->host, source_p->host)) |
343 |
|
|
{ |
344 |
|
|
var_offset = aconf->flags; |
345 |
|
|
break; |
346 |
|
|
} |
347 |
|
|
} |
348 |
|
|
|
349 |
|
|
if (prop && !(var_offset & GDENY_BLOCK)) |
350 |
|
|
{ |
351 |
michael |
1008 |
sendto_server(source_p->from, NULL, CAP_GLN, NOCAPS, |
352 |
adx |
30 |
":%s GLINE %s %s :%s", |
353 |
|
|
source_p->name, user, host, reason); |
354 |
|
|
/* hyb-6 version to the rest */ |
355 |
michael |
1008 |
sendto_server(source_p->from, NULL, NOCAPS, CAP_GLN, |
356 |
adx |
30 |
":%s GLINE %s %s %s %s %s %s :%s", |
357 |
|
|
source_p->servptr->name, |
358 |
|
|
source_p->name, source_p->username, source_p->host, |
359 |
|
|
source_p->servptr->name, |
360 |
|
|
user, host, reason); |
361 |
|
|
} |
362 |
|
|
else if (ConfigFileEntry.gline_logging & GDENY_BLOCK && ServerInfo.hub) |
363 |
|
|
{ |
364 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, "Blocked G-Line %s requested on [%s@%s] [%s]", |
365 |
|
|
get_oper_name(source_p), user, host, reason); |
366 |
|
|
ilog(L_TRACE, "Blocked G-Line %s requested on [%s@%s] [%s]", |
367 |
|
|
get_oper_name(source_p), user, host, reason); |
368 |
|
|
logged = 1; |
369 |
|
|
} |
370 |
|
|
|
371 |
|
|
if (var_offset & GDENY_REJECT) |
372 |
|
|
{ |
373 |
|
|
if (ConfigFileEntry.gline_logging & GDENY_REJECT && !logged) |
374 |
|
|
{ |
375 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, "Rejected G-Line %s requested on [%s@%s] [%s]", |
376 |
|
|
get_oper_name(source_p), user, host, reason); |
377 |
|
|
ilog(L_TRACE, "Rejected G-Line %s requested on [%s@%s] [%s]", |
378 |
|
|
get_oper_name(source_p), user, host, reason); |
379 |
|
|
} |
380 |
michael |
958 |
|
381 |
adx |
30 |
return; |
382 |
|
|
} |
383 |
|
|
|
384 |
|
|
if (ConfigFileEntry.glines) |
385 |
|
|
{ |
386 |
|
|
if (!valid_wild_card(source_p, YES, 2, user, host)) |
387 |
|
|
return; |
388 |
|
|
|
389 |
|
|
if (IsClient(source_p)) |
390 |
|
|
{ |
391 |
|
|
const char *p = NULL; |
392 |
michael |
958 |
|
393 |
adx |
30 |
if ((p = strchr(host, '/'))) |
394 |
|
|
{ |
395 |
|
|
int bitlen = strtol(++p, NULL, 10); |
396 |
|
|
int min_bitlen = strchr(host, ':') ? ConfigFileEntry.gline_min_cidr6 : |
397 |
|
|
ConfigFileEntry.gline_min_cidr; |
398 |
|
|
|
399 |
|
|
if (bitlen < min_bitlen) |
400 |
|
|
{ |
401 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, "%s!%s@%s on %s is requesting " |
402 |
|
|
"a GLINE with a CIDR mask < %d for [%s@%s] [%s]", |
403 |
|
|
source_p->name, source_p->username, source_p->host, |
404 |
|
|
source_p->servptr->name, min_bitlen, user, host, reason); |
405 |
|
|
return; |
406 |
|
|
} |
407 |
|
|
} |
408 |
|
|
} |
409 |
|
|
|
410 |
|
|
/* If at least 3 opers agree this user should be G lined then do it */ |
411 |
michael |
988 |
if (check_majority(source_p, user, host, reason, GLINE_PENDING_ADD_TYPE) == |
412 |
adx |
30 |
GLINE_ALREADY_VOTED) |
413 |
|
|
{ |
414 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, "oper or server has already voted"); |
415 |
|
|
return; |
416 |
|
|
} |
417 |
|
|
|
418 |
michael |
554 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
419 |
|
|
"%s requesting G-Line for [%s@%s] [%s]", |
420 |
|
|
get_oper_name(source_p), |
421 |
|
|
user, host, reason); |
422 |
adx |
30 |
ilog(L_TRACE, "#gline for %s@%s [%s] requested by %s", |
423 |
|
|
user, host, reason, get_oper_name(source_p)); |
424 |
|
|
} |
425 |
|
|
} |
426 |
|
|
|
427 |
michael |
1008 |
|
428 |
|
|
/*! \brief GLINE command handler (called by operators) |
429 |
adx |
30 |
* |
430 |
michael |
1008 |
* \param client_p Pointer to allocated Client struct with physical connection |
431 |
|
|
* to this server, i.e. with an open socket connected. |
432 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
433 |
|
|
* originally comes from. This can be a local or remote client. |
434 |
|
|
* \param parc Integer holding the number of supplied arguments. |
435 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
436 |
|
|
* pointers. |
437 |
|
|
* \note Valid arguments for this command are: |
438 |
|
|
* - parv[0] = sender prefix |
439 |
|
|
* - parv[1] = user\@host mask |
440 |
|
|
* - parv[2] = reason |
441 |
adx |
30 |
*/ |
442 |
|
|
static void |
443 |
michael |
1008 |
mo_gline(struct Client *client_p, struct Client *source_p, |
444 |
|
|
int parc, char *parv[]) |
445 |
adx |
30 |
{ |
446 |
michael |
1008 |
char *user = NULL; |
447 |
|
|
char *host = NULL; |
448 |
|
|
char *reason = NULL; |
449 |
|
|
char *p; |
450 |
adx |
30 |
|
451 |
michael |
1008 |
if (!ConfigFileEntry.glines) |
452 |
|
|
{ |
453 |
|
|
sendto_one(source_p, ":%s NOTICE %s :GLINE disabled", |
454 |
|
|
me.name, source_p->name); |
455 |
|
|
return; |
456 |
|
|
} |
457 |
adx |
30 |
|
458 |
michael |
1008 |
if (!IsOperGline(source_p)) |
459 |
|
|
{ |
460 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS), |
461 |
|
|
me.name, source_p->name, "gline"); |
462 |
|
|
return; |
463 |
|
|
} |
464 |
adx |
30 |
|
465 |
michael |
1008 |
if (parse_aline("GLINE", source_p, parc, parv, AWILD, |
466 |
|
|
&user, &host, NULL, NULL, &reason) < 0) |
467 |
|
|
return; |
468 |
adx |
30 |
|
469 |
michael |
1008 |
if ((p = strchr(host, '/')) != NULL) |
470 |
adx |
30 |
{ |
471 |
michael |
1008 |
int bitlen = strtol(++p, NULL, 10); |
472 |
|
|
int min_bitlen = strchr(host, ':') ? ConfigFileEntry.gline_min_cidr6 : |
473 |
|
|
ConfigFileEntry.gline_min_cidr; |
474 |
|
|
if (bitlen < min_bitlen) |
475 |
adx |
30 |
{ |
476 |
michael |
1008 |
sendto_one(source_p, ":%s NOTICE %s :Cannot set G-Lines with CIDR length < %d", |
477 |
|
|
me.name, source_p->name, min_bitlen); |
478 |
|
|
return; |
479 |
michael |
957 |
} |
480 |
adx |
30 |
} |
481 |
michael |
1008 |
|
482 |
|
|
/* If at least 3 opers agree this user should be G lined then do it */ |
483 |
|
|
if (check_majority(source_p, user, host, reason, GLINE_PENDING_ADD_TYPE) == |
484 |
|
|
GLINE_ALREADY_VOTED) |
485 |
|
|
{ |
486 |
|
|
sendto_one(source_p, |
487 |
|
|
":%s NOTICE %s :This server or oper has already voted", |
488 |
|
|
me.name, source_p->name); |
489 |
|
|
return; |
490 |
|
|
} |
491 |
adx |
30 |
|
492 |
michael |
957 |
/* |
493 |
michael |
1008 |
* call these two functions first so the 'requesting' notice always comes |
494 |
|
|
* before the 'has triggered' notice. -bill |
495 |
adx |
30 |
*/ |
496 |
michael |
1008 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
497 |
|
|
"%s requesting G-Line for [%s@%s] [%s]", |
498 |
|
|
get_oper_name(source_p), |
499 |
|
|
user, host, reason); |
500 |
|
|
ilog(L_TRACE, "#gline for %s@%s [%s] requested by %s!%s@%s", |
501 |
|
|
user, host, reason, source_p->name, source_p->username, |
502 |
|
|
source_p->host); |
503 |
adx |
30 |
|
504 |
michael |
1008 |
/* 4 param version for hyb-7 servers */ |
505 |
|
|
sendto_server(NULL, NULL, CAP_GLN|CAP_TS6, NOCAPS, |
506 |
|
|
":%s GLINE %s %s :%s", |
507 |
|
|
ID(source_p), user, host, reason); |
508 |
|
|
sendto_server(NULL, NULL, CAP_GLN, CAP_TS6, |
509 |
|
|
":%s GLINE %s %s :%s", |
510 |
|
|
source_p->name, user, host, reason); |
511 |
adx |
30 |
|
512 |
michael |
1008 |
/* 8 param for hyb-6 */ |
513 |
|
|
sendto_server(NULL, NULL, CAP_TS6, CAP_GLN, |
514 |
|
|
":%s GLINE %s %s %s %s %s %s :%s", |
515 |
|
|
ID(&me), |
516 |
|
|
ID(source_p), source_p->username, |
517 |
|
|
source_p->host, source_p->servptr->name, user, host, |
518 |
|
|
reason); |
519 |
|
|
sendto_server(NULL, NULL, NOCAPS, CAP_GLN|CAP_TS6, |
520 |
|
|
":%s GLINE %s %s %s %s %s %s :%s", |
521 |
|
|
me.name, source_p->name, source_p->username, |
522 |
|
|
source_p->host, source_p->servptr->name, user, host, |
523 |
|
|
reason); |
524 |
adx |
30 |
} |
525 |
|
|
|
526 |
michael |
1008 |
/* ms_gline() |
527 |
|
|
* me_gline() |
528 |
|
|
* do_sgline() |
529 |
db |
937 |
* |
530 |
|
|
* inputs - The usual for a m_ function |
531 |
|
|
* output - |
532 |
|
|
* side effects - |
533 |
|
|
* |
534 |
michael |
1008 |
* Place a G line if 3 opers agree on the identical user@host |
535 |
db |
937 |
* |
536 |
michael |
1008 |
* Allow this server to pass along GLINE if received and |
537 |
|
|
* GLINES is not defined. |
538 |
|
|
* |
539 |
|
|
* ENCAP'd GLINES are propagated by encap code. |
540 |
db |
937 |
*/ |
541 |
|
|
|
542 |
|
|
static void |
543 |
michael |
1008 |
ms_gline(struct Client *client_p, struct Client *source_p, |
544 |
|
|
int parc, char *parv[]) |
545 |
db |
937 |
{ |
546 |
michael |
1008 |
do_sgline(source_p, parc, parv, 1); |
547 |
db |
937 |
} |
548 |
|
|
|
549 |
|
|
static void |
550 |
michael |
1008 |
me_gline(struct Client *client_p, struct Client *source_p, |
551 |
|
|
int parc, char *parv[]) |
552 |
|
|
{ |
553 |
|
|
do_sgline(source_p, parc, parv, 0); |
554 |
|
|
} |
555 |
|
|
|
556 |
|
|
static void |
557 |
michael |
1006 |
do_sungline(struct Client *source_p, const char *user, |
558 |
|
|
const char *host, const char *reason, int prop) |
559 |
db |
937 |
{ |
560 |
|
|
assert(source_p->servptr != NULL); |
561 |
|
|
|
562 |
michael |
957 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
563 |
|
|
"%s requesting UNG-Line for [%s@%s] [%s]", |
564 |
michael |
1006 |
get_oper_name(source_p), user, host, reason); |
565 |
michael |
957 |
ilog(L_TRACE, "#ungline for %s@%s [%s] requested by %s", |
566 |
|
|
user, host, reason, get_oper_name(source_p)); |
567 |
db |
937 |
|
568 |
michael |
957 |
/* If at least 3 opers agree this user should be un G lined then do it */ |
569 |
michael |
958 |
if (check_majority(source_p, user, host, reason, GLINE_PENDING_DEL_TYPE) == |
570 |
michael |
957 |
GLINE_ALREADY_VOTED) |
571 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, "oper or server has already voted"); |
572 |
michael |
1006 |
|
573 |
|
|
if (prop) |
574 |
|
|
{ |
575 |
|
|
sendto_server(source_p->from, NULL, CAP_ENCAP|CAP_TS6, NOCAPS, |
576 |
|
|
":%s ENCAP * GUNGLINE %s %s :%s", |
577 |
|
|
ID(source_p), user, host, reason); |
578 |
|
|
sendto_server(source_p->from, NULL, CAP_ENCAP, CAP_TS6, |
579 |
|
|
":%s ENCAP * GUNGLINE %s %s :%s", |
580 |
|
|
source_p->name, user, host, reason); |
581 |
|
|
} |
582 |
db |
937 |
} |
583 |
|
|
|
584 |
michael |
1008 |
/*! \brief GUNGLINE command handler (called in response to an encapsulated |
585 |
|
|
* GUNGLINE command) |
586 |
db |
937 |
* |
587 |
michael |
1008 |
* \param client_p Pointer to allocated Client struct with physical connection |
588 |
|
|
* to this server, i.e. with an open socket connected. |
589 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
590 |
|
|
* originally comes from. This can be a local or remote client. |
591 |
|
|
* \param parc Integer holding the number of supplied arguments. |
592 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
593 |
|
|
* pointers. |
594 |
|
|
* \note Valid arguments for this command are: |
595 |
|
|
* - parv[0] = sender prefix |
596 |
|
|
* - parv[1] = username |
597 |
|
|
* - parv[2] = hostname |
598 |
|
|
* - parv[3] = reason |
599 |
db |
937 |
*/ |
600 |
michael |
1008 |
static void |
601 |
|
|
me_gungline(struct Client *client_p, struct Client *source_p, |
602 |
|
|
int parc, char *parv[]) |
603 |
|
|
{ |
604 |
|
|
if (ConfigFileEntry.glines) |
605 |
|
|
do_sungline(source_p, parv[1], parv[2], parv[3], 0); |
606 |
|
|
} |
607 |
|
|
|
608 |
|
|
/*! \brief GUNGLINE command handler (called by operators) |
609 |
db |
937 |
* |
610 |
michael |
1008 |
* \param client_p Pointer to allocated Client struct with physical connection |
611 |
|
|
* to this server, i.e. with an open socket connected. |
612 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
613 |
|
|
* originally comes from. This can be a local or remote client. |
614 |
|
|
* \param parc Integer holding the number of supplied arguments. |
615 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
616 |
|
|
* pointers. |
617 |
|
|
* \note Valid arguments for this command are: |
618 |
|
|
* - parv[0] = sender prefix |
619 |
|
|
* - parv[1] = user\@host mask |
620 |
|
|
* - parv[2] = reason |
621 |
db |
937 |
*/ |
622 |
|
|
static void |
623 |
db |
940 |
mo_gungline(struct Client *client_p, struct Client *source_p, |
624 |
michael |
957 |
int parc, char *parv[]) |
625 |
db |
937 |
{ |
626 |
|
|
char *user = NULL; |
627 |
michael |
1008 |
char *host = NULL; |
628 |
|
|
char *reason = NULL; |
629 |
db |
937 |
|
630 |
|
|
if (!ConfigFileEntry.glines) |
631 |
|
|
{ |
632 |
michael |
957 |
sendto_one(source_p, ":%s NOTICE %s :GUNGLINE disabled", |
633 |
db |
937 |
me.name, source_p->name); |
634 |
|
|
return; |
635 |
|
|
} |
636 |
|
|
|
637 |
|
|
if (!IsOperGline(source_p)) |
638 |
|
|
{ |
639 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS), |
640 |
michael |
957 |
me.name, source_p->name, "gungline"); |
641 |
db |
937 |
return; |
642 |
|
|
} |
643 |
|
|
|
644 |
michael |
957 |
if (parse_aline("GUNGLINE", source_p, parc, parv, 0, &user, |
645 |
|
|
&host, NULL, NULL, &reason) < 0) |
646 |
db |
937 |
return; |
647 |
|
|
|
648 |
michael |
1006 |
do_sungline(source_p, user, host, reason, 1); |
649 |
db |
937 |
} |