ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_kline.c
Revision: 2804
Committed: Sun Jan 12 16:54:01 2014 UTC (12 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 13420 byte(s)
Log Message:
- m_kline.c:mo_kline(). if a target server exists, use sendto_match_servs()
  instead of sendto_server()

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

Properties

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