ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_kline.c
Revision: 1793
Committed: Sun Mar 31 14:06:08 2013 UTC (13 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 13881 byte(s)
Log Message:
- Replaced all occurrences of ircsprintf with sprintf/snprintf
  and killed sprintf_irc.(c|h)

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

Properties

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