ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_kline.c
Revision: 1832
Committed: Fri Apr 19 19:16:09 2013 UTC (13 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 13853 byte(s)
Log Message:
- Made all numeric defines use the actual string instead of the numeric value
  which allows to use gcc's printf format attribute
- Remove current message locale implementation

File Contents

# User Rev Content
1 adx 30 /*
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 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26 michael 1011 #include "list.h"
27 adx 30 #include "channel.h"
28     #include "client.h"
29     #include "irc_string.h"
30     #include "ircd.h"
31 michael 1632 #include "conf.h"
32 adx 30 #include "hostmask.h"
33     #include "numeric.h"
34     #include "fdlist.h"
35     #include "s_bsd.h"
36 michael 1309 #include "log.h"
37 adx 30 #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 michael 1622 #include "conf_db.h"
45 michael 1666 #include "memory.h"
46 adx 30
47 michael 1058 static int already_placed_kline(struct Client *, const char *, const char *, int);
48 michael 1632 static void m_kline_add_kline(struct Client *, struct MaskItem *, time_t);
49 michael 1058
50     static char buffer[IRCD_BUFSIZE];
51 michael 1622 static int remove_kline_match(const char *, const char *);
52 adx 30
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 michael 1298 int parc, char *parv[])
66 adx 30 {
67     char *reason = NULL;
68     char *user = NULL;
69     char *host = NULL;
70     const char *current_date;
71     char *target_server = NULL;
72 michael 1632 struct MaskItem *conf;
73 adx 30 time_t tkline_time = 0;
74     time_t cur_time;
75    
76 michael 1219 if (!HasOFlag(source_p, OPER_FLAG_K))
77 adx 30 {
78 michael 1832 sendto_one(source_p, ERR_NOPRIVS,
79 adx 30 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 michael 1474 sendto_server(NULL, CAP_KLN|CAP_TS6, NOCAPS,
92 adx 30 ":%s KLINE %s %lu %s %s :%s",
93     source_p->id, target_server, (unsigned long)tkline_time,
94     user, host, reason);
95 michael 1474 sendto_server(NULL, CAP_KLN, CAP_TS6,
96 adx 30 ":%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 michael 1474 sendto_server(NULL, CAP_KLN, NOCAPS,
102 adx 30 ":%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 michael 1652 if (match(target_server, me.name))
108 adx 30 return;
109     }
110     else
111     cluster_a_line(source_p, "KLINE", CAP_KLN, SHARED_KLINE,
112 michael 1058 "%d %s %s :%s", tkline_time, user, host, reason);
113 adx 30
114 michael 1243 if (already_placed_kline(source_p, user, host, 1))
115 adx 30 return;
116    
117     cur_time = CurrentTime;
118     current_date = smalldate(cur_time);
119 michael 1632 conf = conf_make(CONF_KLINE);
120 adx 30
121 michael 1646 conf->host = xstrdup(host);
122     conf->user = xstrdup(user);
123 adx 30
124     if (tkline_time != 0)
125 michael 1233 snprintf(buffer, sizeof(buffer), "Temporary K-line %d min. - %s (%s)",
126     (int)(tkline_time/60), reason, current_date);
127 adx 30 else
128 michael 1233 snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
129 adx 30
130 michael 1646 conf->reason = xstrdup(buffer);
131 michael 1632 m_kline_add_kline(source_p, conf, tkline_time);
132 adx 30 }
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 michael 1632 struct MaskItem *conf = NULL;
140 michael 1628 int tkline_time = 0;
141 adx 30 const char* current_date;
142     time_t cur_time;
143 michael 1622 char *kuser, *khost, *kreason;
144 adx 30
145 michael 352 if (parc != 6 || EmptyString(parv[5]))
146 adx 30 return;
147    
148 michael 1652 if (match(parv[1], me.name))
149 adx 30 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 michael 1632 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
160 adx 30 source_p->username, source_p->host,
161     SHARED_KLINE))
162     {
163     if (!IsClient(source_p) ||
164 michael 1243 already_placed_kline(source_p, kuser, khost, 1))
165 adx 30 return;
166    
167 michael 1632 conf = conf_make(CONF_KLINE);
168 michael 1646 conf->host = xstrdup(khost);
169     conf->user = xstrdup(kuser);
170 adx 30
171     if (tkline_time != 0)
172 michael 1233 snprintf(buffer, sizeof(buffer), "Temporary K-line %d min. - %s (%s)",
173     (int)(tkline_time/60), kreason, current_date);
174 adx 30 else
175 michael 1233 snprintf(buffer, sizeof(buffer), "%s (%s)", kreason, current_date);
176 adx 30
177 michael 1646 conf->reason = xstrdup(buffer);
178 michael 1632 m_kline_add_kline(source_p, conf, tkline_time);
179 adx 30 }
180     }
181    
182     static void
183     ms_kline(struct Client *client_p, struct Client *source_p,
184 michael 1058 int parc, char *parv[])
185 adx 30 {
186 michael 352 if (parc != 6 || EmptyString(parv[5]))
187 adx 30 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 michael 1632 m_kline_add_kline(struct Client *source_p, struct MaskItem *conf,
206 michael 1622 time_t tkline_time)
207 adx 30 {
208 michael 1622 if (tkline_time)
209     {
210 michael 1649 conf->until = CurrentTime + tkline_time;
211 michael 1622 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 michael 1632 conf->user, conf->host,
215     conf->reason);
216 michael 1622 sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. K-Line [%s@%s]",
217 michael 1632 MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
218     source_p->name, tkline_time/60, conf->user, conf->host);
219 michael 1622 ilog(LOG_TYPE_KLINE, "%s added temporary %d min. K-Line for [%s@%s] [%s]",
220     source_p->name, tkline_time/60,
221 michael 1632 conf->user, conf->host, conf->reason);
222 michael 1622 }
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 michael 1632 conf->user, conf->host, conf->reason);
229 michael 1622 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 michael 1632 source_p->name, conf->user, conf->host);
232 michael 1622 ilog(LOG_TYPE_KLINE, "%s added K-Line for [%s@%s] [%s]",
233 michael 1632 source_p->name, conf->user, conf->host, conf->reason);
234 michael 1622 }
235 michael 1247
236 michael 1632 conf->setat = CurrentTime;
237     SetConfDatabase(conf);
238 michael 1628
239 michael 1632 add_conf_by_address(CONF_KLINE, conf);
240 adx 30 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 michael 1632 struct MaskItem *conf = NULL;
259 michael 1644 int t = 0;
260     int aftype = 0;
261 adx 30
262 michael 1644 if ((t = parse_netmask(lhost, &iphost, NULL)) != HM_HOST)
263 adx 30 {
264     #ifdef IPV6
265     if (t == HM_IPV6)
266 michael 1644 aftype = AF_INET6;
267 adx 30 else
268     #endif
269 michael 1644 aftype = AF_INET;
270 adx 30 piphost = &iphost;
271     }
272     else
273     piphost = NULL;
274    
275 michael 1644 if ((conf = find_conf_by_address(lhost, piphost, CONF_KLINE, aftype, luser, NULL, 0)))
276 adx 30 {
277     if (warn)
278     {
279 michael 1794 reason = conf->reason ? conf->reason : CONF_NOREASON;
280 adx 30 sendto_one(source_p,
281     ":%s NOTICE %s :[%s@%s] already K-Lined by [%s@%s] - %s",
282 michael 1632 me.name, source_p->name, luser, lhost, conf->user,
283     conf->host, reason);
284 adx 30 }
285 michael 1298
286     return 1;
287 adx 30 }
288    
289 michael 1298 return 0;
290 adx 30 }
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 michael 1219 if (!HasOFlag(source_p, OPER_FLAG_UNKLINE))
310 adx 30 {
311 michael 1832 sendto_one(source_p, ERR_NOPRIVS,
312 adx 30 me.name, source_p->name, "unkline");
313     return;
314     }
315    
316 michael 1622 if (EmptyString(parv[1]))
317 adx 30 {
318 michael 1832 sendto_one(source_p, ERR_NEEDMOREPARAMS,
319 adx 30 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 michael 1652 if (match(target_server, me.name))
335 adx 30 return;
336     }
337     else
338     cluster_a_line(source_p, "UNKLINE", CAP_UNKLN, SHARED_UNKLINE,
339 michael 1058 "%s %s", user, host);
340 adx 30
341 michael 1622 if (remove_kline_match(host, user))
342 adx 30 {
343     sendto_one(source_p,
344 michael 1622 ":%s NOTICE %s :K-Line for [%s@%s] is removed",
345 adx 30 me.name, source_p->name, user, host);
346 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
347 michael 1058 "%s has removed the K-Line for: [%s@%s]",
348     get_oper_name(source_p), user, host);
349 michael 1247 ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]",
350 michael 1058 source_p->name, user, host);
351 adx 30 }
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 michael 1652 if (!IsClient(source_p) || match(parv[1], me.name))
380 adx 30 return;
381    
382 michael 1632 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE,
383 adx 30 source_p->servptr->name,
384     source_p->username, source_p->host,
385     SHARED_UNKLINE))
386     {
387 michael 1622 if (remove_kline_match(khost, kuser))
388 adx 30 {
389     sendto_one(source_p,
390 michael 1622 ":%s NOTICE %s :K-Line for [%s@%s] is removed",
391 adx 30 me.name, source_p->name, kuser, khost);
392 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
393 michael 1622 "%s has removed the K-Line for: [%s@%s]",
394 adx 30 get_oper_name(source_p), kuser, khost);
395 michael 1247 ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]",
396 adx 30 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 michael 1622 remove_kline_match(const char *host, const char *user)
426 adx 30 {
427 michael 1369 struct irc_ssaddr iphost, *piphost;
428 michael 1644 struct MaskItem *conf;
429     int t = 0;
430     int aftype = 0;
431 michael 1298
432 michael 1369 if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
433 adx 30 {
434     #ifdef IPV6
435 michael 1369 if (t == HM_IPV6)
436 michael 1644 aftype = AF_INET6;
437 michael 1369 else
438 adx 30 #endif
439 michael 1644 aftype = AF_INET;
440 michael 1369 piphost = &iphost;
441 adx 30 }
442 michael 1369 else
443     piphost = NULL;
444 adx 30
445 michael 1644 if ((conf = find_conf_by_address(host, piphost, CONF_KLINE, aftype, user, NULL, 0)))
446 michael 1369 {
447 michael 1632 if (IsConfDatabase(conf))
448 michael 1369 {
449 michael 1632 delete_one_address_conf(host, conf);
450 michael 1369 return 1;
451     }
452     }
453    
454 michael 1058 return 0;
455 adx 30 }
456 michael 1230
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