ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/branches/ircd-hybrid-20110809/modules/m_rkline.c
Revision: 1154
Committed: Tue Aug 9 20:07:34 2011 UTC (12 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 16043 byte(s)
Log Message:
- move directories

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_kline.c: Bans a user.
4 *
5 * Copyright (C) 2005 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "list.h"
27 #include "channel.h"
28 #include "client.h"
29 #include "common.h"
30 #include "irc_string.h"
31 #include "sprintf_irc.h"
32 #include "ircd.h"
33 #include "hostmask.h"
34 #include "numeric.h"
35 #include "fdlist.h"
36 #include "s_bsd.h"
37 #include "s_conf.h"
38 #include "s_log.h"
39 #include "s_misc.h"
40 #include "send.h"
41 #include "hash.h"
42 #include "handlers.h"
43 #include "s_serv.h"
44 #include "msg.h"
45 #include "s_gline.h"
46 #include "parse.h"
47 #include "modules.h"
48
49 static void me_rkline(struct Client *, struct Client *, int, char *[]);
50 static void mo_rkline(struct Client *, struct Client *, int, char *[]);
51 static void ms_rkline(struct Client *, struct Client *, int, char *[]);
52
53 static void me_unrkline(struct Client *, struct Client *, int, char *[]);
54 static void mo_unrkline(struct Client *, struct Client *, int, char *[]);
55 static void ms_unrkline(struct Client *, struct Client *, int, char *[]);
56 /* Local function prototypes */
57 static int already_placed_rkline(struct Client *, const char *, const char *);
58 static void apply_rkline(struct Client *, struct ConfItem *, const char *, time_t);
59 static void apply_trkline(struct Client *, struct ConfItem *, int);
60
61 static char buffer[IRCD_BUFSIZE];
62 static int remove_trkline_match(const char *, const char *);
63
64 struct Message rkline_msgtab = {
65 "RKLINE", 0, 0, 2, 0, MFLG_SLOW, 0,
66 {m_unregistered, m_not_oper, ms_rkline, me_rkline, mo_rkline, m_ignore}
67 };
68
69 struct Message unrkline_msgtab = {
70 "UNRKLINE", 0, 0, 2, 0, MFLG_SLOW, 0,
71 {m_unregistered, m_not_oper, ms_unrkline, me_unrkline, mo_unrkline, m_ignore}
72 };
73
74 #ifndef STATIC_MODULES
75 void
76 _modinit(void)
77 {
78 mod_add_cmd(&rkline_msgtab);
79 mod_add_cmd(&unrkline_msgtab);
80 }
81
82 void
83 _moddeinit(void)
84 {
85 mod_del_cmd(&rkline_msgtab);
86 mod_del_cmd(&unrkline_msgtab);
87 }
88
89 const char *_version = "$Revision$";
90 #endif
91
92 /* mo_rkline()
93 *
94 * inputs - pointer to server
95 * - pointer to client
96 * - parameter count
97 * - parameter list
98 * output -
99 * side effects - rk line is added
100 */
101 static void
102 mo_rkline(struct Client *client_p, struct Client *source_p,
103 int parc, char *parv[])
104 {
105 void *exp_user = NULL, *exp_host = NULL;
106 const char *errptr = NULL;
107 char *reason = NULL;
108 char *oper_reason = NULL;
109 char *user = NULL;
110 char *host = NULL;
111 const char *current_date = NULL;
112 char *target_server = NULL;
113 struct ConfItem *conf = NULL;
114 struct AccessItem *aconf = NULL;
115 time_t tkline_time = 0;
116 time_t cur_time = 0;
117
118 if (!IsAdmin(source_p) || !IsOperK(source_p))
119 {
120 sendto_one(source_p, form_str(ERR_NOPRIVS),
121 me.name, source_p->name, "rkline");
122 return;
123 }
124
125 if (parse_aline("RKLINE", source_p, parc, parv, NOUSERLOOKUP, &user,
126 &host, &tkline_time, &target_server, &reason) < 0)
127 return;
128
129 if (target_server != NULL)
130 {
131 if (HasID(source_p))
132 {
133 sendto_server(NULL, NULL, CAP_KLN|CAP_TS6, NOCAPS,
134 ":%s RKLINE %s %lu %s %s :%s",
135 source_p->id, target_server, (unsigned long)tkline_time,
136 user, host, reason);
137 sendto_server(NULL, NULL, CAP_KLN, CAP_TS6,
138 ":%s RKLINE %s %lu %s %s :%s",
139 source_p->name, target_server, (unsigned long)tkline_time,
140 user, host, reason);
141 }
142 else
143 sendto_server(NULL, NULL, CAP_KLN, NOCAPS,
144 ":%s RKLINE %s %lu %s %s :%s",
145 source_p->name, target_server, (unsigned long)tkline_time,
146 user, host, reason);
147
148 /* Allow ON to apply local kline as well if it matches */
149 if (!match(target_server, me.name))
150 return;
151 }
152 #if 0
153 else
154 cluster_a_line(source_p, "RKLINE", CAP_KLN, SHARED_KLINE,
155 "%d %s %s :%s", tkline_time, user, host, reason);
156 #endif
157
158 if (already_placed_rkline(source_p, user, host))
159 return;
160
161 /* Look for an oper reason */
162 if ((oper_reason = strchr(reason, '|')) != NULL)
163 *oper_reason++ = '\0';
164
165 if (!(exp_user = ircd_pcre_compile(user, &errptr)) ||
166 !(exp_host = ircd_pcre_compile(host, &errptr)))
167 {
168 sendto_realops_flags(UMODE_ALL, L_ALL,
169 "Failed to add regular expression based K-Line: %s", errptr);
170 return;
171 }
172
173 cur_time = CurrentTime;
174 current_date = smalldate(cur_time);
175 conf = make_conf_item(RKLINE_TYPE);
176 aconf = map_to_conf(conf);
177
178 DupString(aconf->host, host);
179 DupString(aconf->user, user);
180
181 aconf->regexuser = exp_user;
182 aconf->regexhost = exp_host;
183
184 if (tkline_time != 0)
185 {
186 ircsprintf(buffer, "Temporary RK-line %d min. - %s (%s)",
187 (int)(tkline_time/60), reason, current_date);
188 DupString(aconf->reason, buffer);
189
190 if (oper_reason != NULL)
191 DupString(aconf->oper_reason, oper_reason);
192 apply_trkline(source_p, conf, tkline_time);
193 }
194 else
195 {
196 ircsprintf(buffer, "%s (%s)", reason, current_date);
197 DupString(aconf->reason, buffer);
198
199 if (oper_reason != NULL)
200 DupString(aconf->oper_reason, oper_reason);
201 apply_rkline(source_p, conf, current_date, cur_time);
202 }
203 }
204
205 /* me_rkline - handle remote rkline. no propagation */
206 static void
207 me_rkline(struct Client *client_p, struct Client *source_p,
208 int parc, char *parv[])
209 {
210 struct ConfItem *conf = NULL;
211 struct AccessItem *aconf = NULL;
212 int tkline_time;
213 const char *current_date = NULL;
214 time_t cur_time;
215 char *kuser, *khost, *kreason, *oper_reason;
216
217 if (parc != 6 || EmptyString(parv[5]))
218 return;
219
220 if (!match(parv[1], me.name))
221 return;
222
223 tkline_time = valid_tkline(parv[2], TK_SECONDS);
224 kuser = parv[3];
225 khost = parv[4];
226 kreason = parv[5];
227
228 if ((oper_reason = strchr(kreason, '|')) != NULL)
229 *oper_reason++ = '\0';
230
231 cur_time = CurrentTime;
232 current_date = smalldate(cur_time);
233
234 if (find_matching_name_conf(ULINE_TYPE, source_p->servptr->name,
235 source_p->username, source_p->host,
236 SHARED_KLINE))
237 {
238 void *exp_user = NULL, *exp_host = NULL;
239 const char *errptr = NULL;
240
241 if (!IsClient(source_p) ||
242 already_placed_rkline(source_p, kuser, khost))
243 return;
244
245 if (!(exp_user = ircd_pcre_compile(kuser, &errptr)) ||
246 !(exp_host = ircd_pcre_compile(khost, &errptr)))
247 {
248 sendto_realops_flags(UMODE_ALL, L_ALL,
249 "Failed to add regular expression based K-Line: %s", errptr);
250 return;
251 }
252
253 conf = make_conf_item(RKLINE_TYPE);
254 aconf = map_to_conf(conf);
255 DupString(aconf->host, khost);
256 DupString(aconf->user, kuser);
257
258 aconf->regexuser = exp_user;
259 aconf->regexhost = exp_host;
260
261 if (tkline_time)
262 {
263 ircsprintf(buffer, "Temporary RK-line %d min. - %s (%s)",
264 (int)(tkline_time/60), kreason, current_date);
265 DupString(aconf->reason, buffer);
266
267 if (oper_reason != NULL)
268 DupString(aconf->oper_reason, oper_reason);
269 apply_trkline(source_p, conf, tkline_time);
270 }
271 else
272 {
273 ircsprintf(buffer, "%s (%s)", kreason, current_date);
274 DupString(aconf->reason, buffer);
275
276 if (oper_reason != NULL)
277 DupString(aconf->oper_reason, oper_reason);
278 apply_rkline(source_p, conf, current_date, cur_time);
279 }
280 }
281 }
282
283 static void
284 ms_rkline(struct Client *client_p, struct Client *source_p,
285 int parc, char *parv[])
286 {
287 if (parc != 6 || EmptyString(parv[5]))
288 return;
289
290 /* parv[0] parv[1] parv[2] parv[3] parv[4] parv[5] */
291 /* oper target_server tkline_time user host reason */
292 sendto_match_servs(source_p, parv[1], CAP_KLN,
293 "RKLINE %s %s %s %s :%s",
294 parv[1], parv[2], parv[3], parv[4], parv[5]);
295
296 me_rkline(client_p, source_p, parc, parv);
297 }
298
299 /* apply_rkline()
300 *
301 * inputs -
302 * output - NONE
303 * side effects - kline as given, is added to the hashtable
304 * and conf file
305 */
306 static void
307 apply_rkline(struct Client *source_p, struct ConfItem *conf,
308 const char *current_date, time_t cur_time)
309 {
310 write_conf_line(source_p, conf, current_date, cur_time);
311 /* Now, activate kline against current online clients */
312 rehashed_klines = 1;
313 }
314
315 /* apply_trkline()
316 *
317 * inputs -
318 * output - NONE
319 * side effects - tkline as given is placed
320 */
321 static void
322 apply_trkline(struct Client *source_p, struct ConfItem *conf,
323 int tkline_time)
324 {
325 struct AccessItem *aconf = map_to_conf(conf);
326
327 aconf->hold = CurrentTime + tkline_time;
328 add_temp_line(conf);
329 sendto_realops_flags(UMODE_ALL, L_ALL,
330 "%s added temporary %d min. RK-Line for [%s@%s] [%s]",
331 get_oper_name(source_p), tkline_time/60,
332 aconf->user, aconf->host,
333 aconf->reason);
334 sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. RK-Line [%s@%s]",
335 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
336 source_p->name, tkline_time/60, aconf->user, aconf->host);
337 ilog(L_TRACE, "%s added temporary %d min. RK-Line for [%s@%s] [%s]",
338 source_p->name, tkline_time/60,
339 aconf->user, aconf->host, aconf->reason);
340 rehashed_klines = 1;
341 }
342
343 /* already_placed_rkline()
344 * inputs - user to complain to, username & host to check for
345 * outputs - returns 1 on existing K-line, 0 if doesn't exist
346 * side effects - notifies source_p if the K-line already exists
347 */
348 static int
349 already_placed_rkline(struct Client *source_p, const char *user, const char *host)
350 {
351 const dlink_node *ptr = NULL;
352
353 DLINK_FOREACH(ptr, rkconf_items.head)
354 {
355 struct AccessItem *aptr = map_to_conf(ptr->data);
356
357 if (!strcmp(user, aptr->user) &&
358 !strcmp(aptr->host, host))
359 {
360 sendto_one(source_p,
361 ":%s NOTICE %s :[%s@%s] already RK-Lined by [%s@%s] - %s",
362 me.name, source_p->name, user, host, aptr->user,
363 aptr->host, aptr->reason ? aptr->reason : "No reason");
364 return 1;
365 }
366 }
367
368 return 0;
369 }
370
371 /*
372 * mo_unrkline
373 * parv[0] = sender
374 * parv[1] = address to remove
375 */
376 static void
377 mo_unrkline(struct Client *client_p,struct Client *source_p,
378 int parc, char *parv[])
379 {
380 char *target_server = NULL;
381 char *user, *host;
382
383 if (!IsAdmin(source_p) || !IsOperUnkline(source_p))
384 {
385 sendto_one(source_p, form_str(ERR_NOPRIVS),
386 me.name, source_p->name, "unrkline");
387 return;
388 }
389
390 if (parc < 2 || *parv[1] == '\0')
391 {
392 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
393 me.name, source_p->name, "UNRKLINE");
394 return;
395 }
396
397 if (parse_aline("UNRKLINE", source_p, parc, parv, NOUSERLOOKUP, &user,
398 &host, NULL, &target_server, NULL) < 0)
399 return;
400
401 if (target_server != NULL)
402 {
403 sendto_match_servs(source_p, target_server, CAP_UNKLN,
404 "UNRKLINE %s %s %s",
405 target_server, user, host);
406
407 /* Allow ON to apply local unkline as well if it matches */
408 if (!match(target_server, me.name))
409 return;
410 }
411 #if 0
412 else
413 cluster_a_line(source_p, "UNRKLINE", CAP_UNKLN, SHARED_UNKLINE,
414 "%s %s", user, host);
415 #endif
416
417 if (remove_trkline_match(host, user))
418 {
419 sendto_one(source_p,
420 ":%s NOTICE %s :Un-klined [%s@%s] from temporary RK-Lines",
421 me.name, source_p->name, user, host);
422 sendto_realops_flags(UMODE_ALL, L_ALL,
423 "%s has removed the temporary RK-Line for: [%s@%s]",
424 get_oper_name(source_p), user, host);
425 ilog(L_NOTICE, "%s removed temporary RK-Line for [%s@%s]",
426 source_p->name, user, host);
427 return;
428 }
429
430 if (remove_conf_line(RKLINE_TYPE, source_p, user, host) > 0)
431 {
432 sendto_one(source_p, ":%s NOTICE %s :RK-Line for [%s@%s] is removed",
433 me.name, source_p->name, user,host);
434 sendto_realops_flags(UMODE_ALL, L_ALL,
435 "%s has removed the RK-Line for: [%s@%s]",
436 get_oper_name(source_p), user, host);
437 ilog(L_NOTICE, "%s removed RK-Line for [%s@%s]",
438 source_p->name, user, host);
439 }
440 else
441 sendto_one(source_p, ":%s NOTICE %s :No RK-Line for [%s@%s] found",
442 me.name, source_p->name, user, host);
443 }
444
445 /* me_unrkline()
446 *
447 * inputs - server
448 * - client
449 * - parc
450 * - parv
451 * outputs - none
452 * side effects - if server is authorized, rkline is removed
453 * does not propagate message
454 */
455 static void
456 me_unrkline(struct Client *client_p, struct Client *source_p,
457 int parc, char *parv[])
458 {
459 const char *user = NULL, *host = NULL;
460
461 if (parc != 4 || EmptyString(parv[3]))
462 return;
463
464 user = parv[2];
465 host = parv[3];
466
467 if (!IsClient(source_p) || !match(parv[1], me.name))
468 return;
469
470 if (find_matching_name_conf(ULINE_TYPE, source_p->servptr->name,
471 source_p->username, source_p->host,
472 SHARED_UNKLINE))
473 {
474 if (remove_trkline_match(host, user))
475 {
476 sendto_one(source_p,
477 ":%s NOTICE %s :Un-klined [%s@%s] from temporary RK-Lines",
478 me.name, source_p->name, user, host);
479 sendto_realops_flags(UMODE_ALL, L_ALL,
480 "%s has removed the temporary RK-Line for: [%s@%s]",
481 get_oper_name(source_p), user, host);
482 ilog(L_NOTICE, "%s removed temporary RK-Line for [%s@%s]",
483 source_p->name, user, host);
484 return;
485 }
486
487 if (remove_conf_line(RKLINE_TYPE, source_p, user, host) > 0)
488 {
489 sendto_one(source_p, ":%s NOTICE %s :RK-Line for [%s@%s] is removed",
490 me.name, source_p->name, user, host);
491 sendto_realops_flags(UMODE_ALL, L_ALL,
492 "%s has removed the RK-Line for: [%s@%s]",
493 get_oper_name(source_p), user, host);
494
495 ilog(L_NOTICE, "%s removed RK-Line for [%s@%s]",
496 source_p->name, user, host);
497 }
498 else
499 sendto_one(source_p, ":%s NOTICE %s :No RK-Line for [%s@%s] found",
500 me.name, source_p->name, user, host);
501 }
502 }
503
504 /* ms_unrkline - propagates and handles a remote unrkline message */
505 static void
506 ms_unrkline(struct Client *client_p, struct Client *source_p,
507 int parc, char *parv[])
508 {
509 if (parc != 4 || EmptyString(parv[3]))
510 return;
511
512 sendto_match_servs(source_p, parv[1], CAP_UNKLN,
513 "UNRKLINE %s %s %s",
514 parv[1], parv[2], parv[3]);
515
516 me_unrkline(client_p, source_p, parc, parv);
517 }
518
519 /* static int remove_rtkline_match(const char *host, const char *user)
520 * Input: A hostname, a username to unrkline.
521 * Output: returns YES on success, NO if no trkline removed.
522 * Side effects: Any matching trklines are removed.
523 */
524 static int
525 remove_trkline_match(const char *const host,
526 const char *const user)
527 {
528 dlink_node *ptr = NULL;
529
530 DLINK_FOREACH(ptr, temporary_rklines.head)
531 {
532 struct ConfItem *conf = ptr->data;
533 struct AccessItem *aptr = map_to_conf(ptr->data);
534
535 if (!strcmp(user, aptr->user) &&
536 !strcmp(aptr->host, host))
537 {
538 dlinkDelete(ptr, &temporary_rklines);
539 free_dlink_node(ptr);
540 delete_conf_item(conf);
541 return 1;
542 }
543 }
544
545 return 0;
546 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision