ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/branches/newio/modules/m_kline.c
Revision: 2805
Committed: Sun Jan 12 16:56:10 2014 UTC (12 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 13423 byte(s)
Log Message:
- m_kline.c:mo_kline(). if a target server exists, use sendto_match_servs()
  instead of sendto_server()

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) 2002 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 "irc_string.h"
30 #include "ircd.h"
31 #include "conf.h"
32 #include "hostmask.h"
33 #include "numeric.h"
34 #include "s_bsd.h"
35 #include "log.h"
36 #include "s_misc.h"
37 #include "send.h"
38 #include "hash.h"
39 #include "s_serv.h"
40 #include "parse.h"
41 #include "modules.h"
42 #include "conf_db.h"
43 #include "memory.h"
44 #include "xsnprintf.h"
45
46 static int already_placed_kline(struct Client *, const char *, const char *, int);
47 static void m_kline_add_kline(struct Client *, struct MaskItem *, time_t);
48
49 static char buffer[IRCD_BUFSIZE];
50 static int remove_kline_match(const char *, const char *);
51
52
53 /* mo_kline()
54 *
55 * inputs - pointer to server
56 * - pointer to client
57 * - parameter count
58 * - parameter list
59 * output -
60 * side effects - k line is added
61 */
62 static int
63 mo_kline(struct Client *client_p, struct Client *source_p,
64 int parc, char *parv[])
65 {
66 char *reason = NULL;
67 char *user = NULL;
68 char *host = NULL;
69 const char *current_date;
70 char *target_server = NULL;
71 struct MaskItem *conf;
72 time_t tkline_time = 0;
73 time_t cur_time;
74
75 if (!HasOFlag(source_p, OPER_FLAG_K))
76 {
77 sendto_one(source_p, form_str(ERR_NOPRIVS),
78 me.name, source_p->name, "kline");
79 return 0;
80 }
81
82 if (parse_aline("KLINE", source_p, parc, parv,
83 AWILD, &user, &host, &tkline_time, &target_server, &reason) < 0)
84 return 0;
85
86 if (target_server != NULL)
87 {
88 sendto_match_servs(source_p, target_server, CAP_KLN, "KLINE %s %Tu %s %s :%s",
89 target_server, tkline_time, user, host, reason);
90
91 /* Allow ON to apply local kline as well if it matches */
92 if (match(target_server, me.name))
93 return 0;
94 }
95 else
96 cluster_a_line(source_p, "KLINE", CAP_KLN, SHARED_KLINE,
97 "%d %s %s :%s", tkline_time, user, host, reason);
98
99 if (already_placed_kline(source_p, user, host, 1))
100 return 0;
101
102 cur_time = CurrentTime;
103 current_date = smalldate(cur_time);
104 conf = conf_make(CONF_KLINE);
105
106 conf->host = xstrdup(host);
107 conf->user = xstrdup(user);
108
109 if (tkline_time != 0)
110 xsnprintf(NULL, buffer, sizeof(buffer), "Temporary K-line %Tu min. - %s (%s)",
111 (tkline_time/60), reason, current_date);
112 else
113 xsnprintf(NULL, buffer, sizeof(buffer), "%s (%s)", reason, current_date);
114
115 conf->reason = xstrdup(buffer);
116 m_kline_add_kline(source_p, conf, tkline_time);
117 return 0;
118 }
119
120 /* me_kline - handle remote kline. no propagation */
121 static int
122 me_kline(struct Client *client_p, struct Client *source_p,
123 int parc, char *parv[])
124 {
125 struct MaskItem *conf = NULL;
126 int tkline_time = 0;
127 const char* current_date;
128 time_t cur_time;
129 char *kuser, *khost, *kreason;
130
131 if (parc != 6 || EmptyString(parv[5]))
132 return 0;
133
134 if (match(parv[1], me.name))
135 return 0;
136
137 tkline_time = valid_tkline(parv[2], TK_SECONDS);
138 kuser = parv[3];
139 khost = parv[4];
140 kreason = parv[5];
141
142 cur_time = CurrentTime;
143 current_date = smalldate(cur_time);
144
145 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
146 source_p->username, source_p->host,
147 SHARED_KLINE))
148 {
149 if (!IsClient(source_p) ||
150 already_placed_kline(source_p, kuser, khost, 1))
151 return 0;
152
153 conf = conf_make(CONF_KLINE);
154 conf->host = xstrdup(khost);
155 conf->user = xstrdup(kuser);
156
157 if (tkline_time != 0)
158 snprintf(buffer, sizeof(buffer), "Temporary K-line %d min. - %s (%s)",
159 (int)(tkline_time/60), kreason, current_date);
160 else
161 snprintf(buffer, sizeof(buffer), "%s (%s)", kreason, current_date);
162
163 conf->reason = xstrdup(buffer);
164 m_kline_add_kline(source_p, conf, tkline_time);
165 }
166
167 return 0;
168 }
169
170 static int
171 ms_kline(struct Client *client_p, struct Client *source_p,
172 int parc, char *parv[])
173 {
174 if (parc != 6 || EmptyString(parv[5]))
175 return 0;
176
177 /* parv[0] parv[1] parv[2] parv[3] parv[4] parv[5] */
178 /* oper target_server tkline_time user host reason */
179 sendto_match_servs(source_p, parv[1], CAP_KLN,
180 "KLINE %s %s %s %s :%s",
181 parv[1], parv[2], parv[3], parv[4], parv[5]);
182
183 return me_kline(client_p, source_p, parc, parv);
184 }
185
186 /* apply_tkline()
187 *
188 * inputs -
189 * output - NONE
190 * side effects - tkline as given is placed
191 */
192 static void
193 m_kline_add_kline(struct Client *source_p, struct MaskItem *conf,
194 time_t tkline_time)
195 {
196 if (tkline_time)
197 {
198 conf->until = CurrentTime + tkline_time;
199 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
200 "%s added temporary %d min. K-Line for [%s@%s] [%s]",
201 get_oper_name(source_p), tkline_time/60,
202 conf->user, conf->host,
203 conf->reason);
204 sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. K-Line [%s@%s]",
205 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
206 source_p->name, tkline_time/60, conf->user, conf->host);
207 ilog(LOG_TYPE_KLINE, "%s added temporary %d min. K-Line for [%s@%s] [%s]",
208 get_oper_name(source_p), tkline_time/60,
209 conf->user, conf->host, conf->reason);
210 }
211 else
212 {
213 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
214 "%s added K-Line for [%s@%s] [%s]",
215 get_oper_name(source_p),
216 conf->user, conf->host, conf->reason);
217 sendto_one(source_p, ":%s NOTICE %s :Added K-Line [%s@%s]",
218 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
219 source_p->name, conf->user, conf->host);
220 ilog(LOG_TYPE_KLINE, "%s added K-Line for [%s@%s] [%s]",
221 get_oper_name(source_p), conf->user, conf->host, conf->reason);
222 }
223
224 conf->setat = CurrentTime;
225 SetConfDatabase(conf);
226
227 add_conf_by_address(CONF_KLINE, conf);
228 rehashed_klines = 1;
229 }
230
231 /* already_placed_kline()
232 * inputs - user to complain to, username & host to check for
233 * outputs - returns 1 on existing K-line, 0 if doesn't exist
234 * side effects - notifies source_p if the K-line already exists
235 */
236 /*
237 * Note: This currently works if the new K-line is a special case of an
238 * existing K-line, but not the other way round. To do that we would
239 * have to walk the hash and check every existing K-line. -A1kmm.
240 */
241 static int
242 already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int warn)
243 {
244 const char *reason;
245 struct irc_ssaddr iphost, *piphost;
246 struct MaskItem *conf = NULL;
247 int t = 0;
248 int aftype = 0;
249
250 if ((t = parse_netmask(lhost, &iphost, NULL)) != HM_HOST)
251 {
252 if (t == HM_IPV6)
253 aftype = AF_INET6;
254 else
255 aftype = AF_INET;
256 piphost = &iphost;
257 }
258 else
259 piphost = NULL;
260
261 if ((conf = find_conf_by_address(lhost, piphost, CONF_KLINE, aftype, luser, NULL, 0)))
262 {
263 if (warn)
264 {
265 reason = conf->reason ? conf->reason : CONF_NOREASON;
266 sendto_one(source_p,
267 ":%s NOTICE %s :[%s@%s] already K-Lined by [%s@%s] - %s",
268 me.name, source_p->name, luser, lhost, conf->user,
269 conf->host, reason);
270 }
271
272 return 1;
273 }
274
275 return 0;
276 }
277
278 /*
279 ** mo_unkline
280 ** Added Aug 31, 1997
281 ** common (Keith Fralick) fralick@gate.net
282 **
283 ** parv[0] = sender
284 ** parv[1] = address to remove
285 *
286 *
287 */
288 static int
289 mo_unkline(struct Client *client_p,struct Client *source_p,
290 int parc, char *parv[])
291 {
292 char *target_server = NULL;
293 char *user, *host;
294
295 if (!HasOFlag(source_p, OPER_FLAG_UNKLINE))
296 {
297 sendto_one(source_p, form_str(ERR_NOPRIVS),
298 me.name, source_p->name, "unkline");
299 return 0;
300 }
301
302 if (EmptyString(parv[1]))
303 {
304 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
305 me.name, source_p->name, "UNKLINE");
306 return 0;
307 }
308
309 if (parse_aline("UNKLINE", source_p, parc, parv, 0, &user,
310 &host, NULL, &target_server, NULL) < 0)
311 return 0;
312
313 if (target_server != NULL)
314 {
315 sendto_match_servs(source_p, target_server, CAP_UNKLN,
316 "UNKLINE %s %s %s",
317 target_server, user, host);
318
319 /* Allow ON to apply local unkline as well if it matches */
320 if (match(target_server, me.name))
321 return 0;
322 }
323 else
324 cluster_a_line(source_p, "UNKLINE", CAP_UNKLN, SHARED_UNKLINE,
325 "%s %s", user, host);
326
327 if (remove_kline_match(host, user))
328 {
329 sendto_one(source_p,
330 ":%s NOTICE %s :K-Line for [%s@%s] is removed",
331 me.name, source_p->name, user, host);
332 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
333 "%s has removed the K-Line for: [%s@%s]",
334 get_oper_name(source_p), user, host);
335 ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]",
336 get_oper_name(source_p), user, host);
337 }
338 else
339 sendto_one(source_p, ":%s NOTICE %s :No K-Line for [%s@%s] found",
340 me.name, source_p->name, user, host);
341 return 0;
342 }
343
344 /* me_unkline()
345 *
346 * inputs - server
347 * - client
348 * - parc
349 * - parv
350 * outputs - none
351 * side effects - if server is authorized, kline is removed
352 * does not propagate message
353 */
354 static int
355 me_unkline(struct Client *client_p, struct Client *source_p,
356 int parc, char *parv[])
357 {
358 const char *kuser, *khost;
359
360 if (parc != 4)
361 return 0;
362
363 kuser = parv[2];
364 khost = parv[3];
365
366 if (!IsClient(source_p) || match(parv[1], me.name))
367 return 0;
368
369 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE,
370 source_p->servptr->name,
371 source_p->username, source_p->host,
372 SHARED_UNKLINE))
373 {
374 if (remove_kline_match(khost, kuser))
375 {
376 sendto_one(source_p,
377 ":%s NOTICE %s :K-Line for [%s@%s] is removed",
378 me.name, source_p->name, kuser, khost);
379 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
380 "%s has removed the K-Line for: [%s@%s]",
381 get_oper_name(source_p), kuser, khost);
382 ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]",
383 get_oper_name(source_p), kuser, khost);
384 }
385 else
386 sendto_one(source_p, ":%s NOTICE %s :No K-Line for [%s@%s] found",
387 me.name, source_p->name, kuser, khost);
388 }
389
390 return 0;
391 }
392
393 /* ms_unkline - propagates and handles a remote unkline message */
394 static int
395 ms_unkline(struct Client *client_p, struct Client *source_p,
396 int parc, char *parv[])
397 {
398 if (parc != 4)
399 return 0;
400
401 sendto_match_servs(source_p, parv[1], CAP_UNKLN,
402 "UNKLINE %s %s %s",
403 parv[1], parv[2], parv[3]);
404
405 return me_unkline(client_p, source_p, parc, parv);
406 }
407
408 /* static int remove_tkline_match(const char *host, const char *user)
409 * Input: A hostname, a username to unkline.
410 * Output: returns YES on success, NO if no tkline removed.
411 * Side effects: Any matching tklines are removed.
412 */
413 static int
414 remove_kline_match(const char *host, const char *user)
415 {
416 struct irc_ssaddr iphost, *piphost;
417 struct MaskItem *conf;
418 int t = 0;
419 int aftype = 0;
420
421 if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
422 {
423 if (t == HM_IPV6)
424 aftype = AF_INET6;
425 else
426 aftype = AF_INET;
427 piphost = &iphost;
428 }
429 else
430 piphost = NULL;
431
432 if ((conf = find_conf_by_address(host, piphost, CONF_KLINE, aftype, user, NULL, 0)))
433 {
434 if (IsConfDatabase(conf))
435 {
436 delete_one_address_conf(host, conf);
437 return 1;
438 }
439 }
440
441 return 0;
442 }
443
444 static struct Message kline_msgtab =
445 {
446 "KLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
447 {m_unregistered, m_not_oper, ms_kline, me_kline, mo_kline, m_ignore}
448 };
449
450 static struct Message unkline_msgtab =
451 {
452 "UNKLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
453 {m_unregistered, m_not_oper, ms_unkline, me_unkline, mo_unkline, m_ignore}
454 };
455
456 static void
457 module_init(void)
458 {
459 mod_add_cmd(&kline_msgtab);
460 mod_add_cmd(&unkline_msgtab);
461 add_capability("KLN", CAP_KLN, 1);
462 add_capability("UNKLN", CAP_UNKLN, 1);
463 }
464
465 static void
466 module_exit(void)
467 {
468 mod_del_cmd(&kline_msgtab);
469 mod_del_cmd(&unkline_msgtab);
470 delete_capability("UNKLN");
471 delete_capability("KLN");
472 }
473
474 struct module module_entry =
475 {
476 .node = { NULL, NULL, NULL },
477 .name = NULL,
478 .version = "$Revision$",
479 .handle = NULL,
480 .modinit = module_init,
481 .modexit = module_exit,
482 .flags = 0
483 };

Properties

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