ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_kline.c
Revision: 1632
Committed: Sun Nov 4 15:37:10 2012 UTC (13 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 13865 byte(s)
Log Message:
- Initial rewrite of the configuration subsystem

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

Properties

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