ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_rkline.c
Revision: 69
Committed: Tue Oct 4 16:09:51 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 15964 byte(s)
Log Message:
- splitted ircd/libio, all headers connected with libio sources have been
  moved for internal use only. To use libio interface, include "libio.h"
  (which is already done in "stdinc.h")


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) 2005 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     #include "channel.h"
27     #include "client.h"
28     #include "common.h"
29     #include "ircd.h"
30     #include "hostmask.h"
31     #include "numeric.h"
32     #include "s_conf.h"
33     #include "send.h"
34     #include "hash.h"
35     #include "handlers.h"
36     #include "s_serv.h"
37     #include "msg.h"
38     #include "s_gline.h"
39     #include "parse.h"
40     #include "modules.h"
41    
42     static void me_rkline(struct Client *, struct Client *, int, char *[]);
43     static void mo_rkline(struct Client *, struct Client *, int, char *[]);
44     static void ms_rkline(struct Client *, struct Client *, int, char *[]);
45    
46     static void me_unrkline(struct Client *, struct Client *, int, char *[]);
47     static void mo_unrkline(struct Client *, struct Client *, int, char *[]);
48     static void ms_unrkline(struct Client *, struct Client *, int, char *[]);
49     /* Local function prototypes */
50     static int already_placed_rkline(struct Client *, const char *, const char *);
51     static void apply_rkline(struct Client *, struct ConfItem *, const char *, time_t);
52     static void apply_trkline(struct Client *, struct ConfItem *, int);
53    
54     static char buffer[IRCD_BUFSIZE];
55     static int remove_trkline_match(const char *, const char *);
56    
57     struct Message rkline_msgtab = {
58     "RKLINE", 0, 0, 2, 0, MFLG_SLOW, 0,
59     {m_unregistered, m_not_oper, ms_rkline, me_rkline, mo_rkline, m_ignore}
60     };
61    
62     struct Message unrkline_msgtab = {
63     "UNRKLINE", 0, 0, 2, 0, MFLG_SLOW, 0,
64     {m_unregistered, m_not_oper, ms_unrkline, me_unrkline, mo_unrkline, m_ignore}
65     };
66    
67     #ifndef STATIC_MODULES
68     void
69     _modinit(void)
70     {
71     mod_add_cmd(&rkline_msgtab);
72     mod_add_cmd(&unrkline_msgtab);
73     }
74    
75     void
76     _moddeinit(void)
77     {
78     mod_del_cmd(&rkline_msgtab);
79     mod_del_cmd(&unrkline_msgtab);
80     }
81    
82 knight 31 const char *_version = "$Revision$";
83 adx 30 #endif
84    
85     /* mo_rkline()
86     *
87     * inputs - pointer to server
88     * - pointer to client
89     * - parameter count
90     * - parameter list
91     * output -
92     * side effects - rk line is added
93     */
94     static void
95     mo_rkline(struct Client *client_p, struct Client *source_p,
96     int parc, char *parv[])
97     {
98     pcre *exp_user = NULL, *exp_host = NULL;
99     const char *errptr = NULL;
100     char *reason = NULL;
101     char *oper_reason = NULL;
102     char *user = NULL;
103     char *host = NULL;
104     const char *current_date = NULL;
105     char *target_server = NULL;
106     struct ConfItem *conf = NULL;
107     struct AccessItem *aconf = NULL;
108     time_t tkline_time = 0;
109     time_t cur_time = 0;
110    
111     if (!IsAdmin(source_p) || !IsOperK(source_p))
112     {
113     sendto_one(source_p, form_str(ERR_NOPRIVS),
114     me.name, source_p->name, "rkline");
115     return;
116     }
117    
118     if (parse_aline("RKLINE", source_p, parc, parv, NOUSERLOOKUP, &user,
119     &host, &tkline_time, &target_server, &reason) < 0)
120     return;
121    
122     if (target_server != NULL)
123     {
124     if (HasID(source_p))
125     {
126     sendto_server(NULL, source_p, NULL, CAP_KLN|CAP_TS6, NOCAPS, LL_ICLIENT,
127     ":%s RKLINE %s %lu %s %s :%s",
128     source_p->id, target_server, (unsigned long)tkline_time,
129     user, host, reason);
130     sendto_server(NULL, source_p, NULL, CAP_KLN, CAP_TS6, LL_ICLIENT,
131     ":%s RKLINE %s %lu %s %s :%s",
132     source_p->name, target_server, (unsigned long)tkline_time,
133     user, host, reason);
134     }
135     else
136     sendto_server(NULL, source_p, NULL, CAP_KLN, NOCAPS, LL_ICLIENT,
137     ":%s RKLINE %s %lu %s %s :%s",
138     source_p->name, target_server, (unsigned long)tkline_time,
139     user, host, reason);
140    
141     /* Allow ON to apply local kline as well if it matches */
142     if (!match(target_server, me.name))
143     return;
144     }
145     #if 0
146     else
147     cluster_a_line(source_p, "RKLINE", CAP_KLN, SHARED_KLINE,
148     "%d %s %s :%s", tkline_time, user, host, reason);
149     #endif
150    
151     if (already_placed_rkline(source_p, user, host))
152     return;
153    
154     /* Look for an oper reason */
155     if ((oper_reason = strchr(reason, '|')) != NULL)
156     *oper_reason++ = '\0';
157    
158     if (!(exp_user = ircd_pcre_compile(user, &errptr)) ||
159     !(exp_host = ircd_pcre_compile(host, &errptr)))
160     {
161     sendto_realops_flags(UMODE_ALL, L_ALL,
162     "Failed to add regular expression based K-Line: %s", errptr);
163     return;
164     }
165    
166     cur_time = CurrentTime;
167     current_date = smalldate(cur_time);
168     conf = make_conf_item(RKLINE_TYPE);
169     aconf = map_to_conf(conf);
170    
171     DupString(aconf->host, host);
172     DupString(aconf->user, user);
173    
174     aconf->regexuser = exp_user;
175     aconf->regexhost = exp_host;
176    
177     if (tkline_time != 0)
178     {
179     ircsprintf(buffer, "Temporary RK-line %d min. - %s (%s)",
180     (int)(tkline_time/60), reason, current_date);
181     DupString(aconf->reason, buffer);
182    
183     if (oper_reason != NULL)
184     DupString(aconf->oper_reason, oper_reason);
185     apply_trkline(source_p, conf, tkline_time);
186     }
187     else
188     {
189     ircsprintf(buffer, "%s (%s)", reason, current_date);
190     DupString(aconf->reason, buffer);
191    
192     if (oper_reason != NULL)
193     DupString(aconf->oper_reason, oper_reason);
194     apply_rkline(source_p, conf, current_date, cur_time);
195     }
196     }
197    
198     /* me_rkline - handle remote rkline. no propagation */
199     static void
200     me_rkline(struct Client *client_p, struct Client *source_p,
201     int parc, char *parv[])
202     {
203     struct ConfItem *conf = NULL;
204     struct AccessItem *aconf = NULL;
205     int tkline_time;
206     const char *current_date = NULL;
207     time_t cur_time;
208     char *kuser, *khost, *kreason, *oper_reason;
209    
210     if (parc != 6 || EmptyString(parv[5]))
211     return;
212    
213     if (!match(parv[1], me.name))
214     return;
215    
216     tkline_time = valid_tkline(parv[2], TK_SECONDS);
217     kuser = parv[3];
218     khost = parv[4];
219     kreason = parv[5];
220    
221     if ((oper_reason = strchr(kreason, '|')) != NULL)
222     *oper_reason++ = '\0';
223    
224     cur_time = CurrentTime;
225     current_date = smalldate(cur_time);
226    
227     if (find_matching_name_conf(ULINE_TYPE, source_p->servptr->name,
228     source_p->username, source_p->host,
229     SHARED_KLINE))
230     {
231     pcre *exp_user = NULL, *exp_host = NULL;
232     const char *errptr = NULL;
233    
234     if (!IsClient(source_p) ||
235     already_placed_rkline(source_p, kuser, khost))
236     return;
237    
238     if (!(exp_user = ircd_pcre_compile(kuser, &errptr)) ||
239     !(exp_host = ircd_pcre_compile(khost, &errptr)))
240     {
241     sendto_realops_flags(UMODE_ALL, L_ALL,
242     "Failed to add regular expression based K-Line: %s", errptr);
243     return;
244     }
245    
246     conf = make_conf_item(RKLINE_TYPE);
247     aconf = map_to_conf(conf);
248     DupString(aconf->host, khost);
249     DupString(aconf->user, kuser);
250    
251     aconf->regexuser = exp_user;
252     aconf->regexhost = exp_host;
253    
254     if (tkline_time)
255     {
256     ircsprintf(buffer, "Temporary RK-line %d min. - %s (%s)",
257     (int)(tkline_time/60), kreason, current_date);
258     DupString(aconf->reason, buffer);
259    
260     if (oper_reason != NULL)
261     DupString(aconf->oper_reason, oper_reason);
262     apply_trkline(source_p, conf, tkline_time);
263     }
264     else
265     {
266     ircsprintf(buffer, "%s (%s)", kreason, current_date);
267     DupString(aconf->reason, buffer);
268    
269     if (oper_reason != NULL)
270     DupString(aconf->oper_reason, oper_reason);
271     apply_rkline(source_p, conf, current_date, cur_time);
272     }
273     }
274     }
275    
276     static void
277     ms_rkline(struct Client *client_p, struct Client *source_p,
278     int parc, char *parv[])
279     {
280     if (parc != 6 || EmptyString(parv[5]))
281     return;
282    
283     /* parv[0] parv[1] parv[2] parv[3] parv[4] parv[5] */
284     /* oper target_server tkline_time user host reason */
285     sendto_match_servs(source_p, parv[1], CAP_KLN,
286     "RKLINE %s %s %s %s :%s",
287     parv[1], parv[2], parv[3], parv[4], parv[5]);
288    
289     me_rkline(client_p, source_p, parc, parv);
290     }
291    
292     /* apply_rkline()
293     *
294     * inputs -
295     * output - NONE
296     * side effects - kline as given, is added to the hashtable
297     * and conf file
298     */
299     static void
300     apply_rkline(struct Client *source_p, struct ConfItem *conf,
301     const char *current_date, time_t cur_time)
302     {
303     write_conf_line(source_p, conf, current_date, cur_time);
304     /* Now, activate kline against current online clients */
305     rehashed_klines = 1;
306     }
307    
308     /* apply_trkline()
309     *
310     * inputs -
311     * output - NONE
312     * side effects - tkline as given is placed
313     */
314     static void
315     apply_trkline(struct Client *source_p, struct ConfItem *conf,
316     int tkline_time)
317     {
318     struct AccessItem *aconf = map_to_conf(conf);
319    
320     aconf->hold = CurrentTime + tkline_time;
321     add_temp_line(conf);
322     sendto_realops_flags(UMODE_ALL, L_ALL,
323     "%s added temporary %d min. RK-Line for [%s@%s] [%s]",
324     get_oper_name(source_p), tkline_time/60,
325     aconf->user, aconf->host,
326     aconf->reason);
327     sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. RK-Line [%s@%s]",
328     MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
329     source_p->name, tkline_time/60, aconf->user, aconf->host);
330     ilog(L_TRACE, "%s added temporary %d min. RK-Line for [%s@%s] [%s]",
331     source_p->name, tkline_time/60,
332     aconf->user, aconf->host, aconf->reason);
333     rehashed_klines = 1;
334     }
335    
336     /* already_placed_rkline()
337     * inputs - user to complain to, username & host to check for
338     * outputs - returns 1 on existing K-line, 0 if doesn't exist
339     * side effects - notifies source_p if the K-line already exists
340     */
341     static int
342     already_placed_rkline(struct Client *source_p, const char *user, const char *host)
343     {
344     const dlink_node *ptr = NULL;
345    
346     DLINK_FOREACH(ptr, rkconf_items.head)
347     {
348     struct AccessItem *aptr = map_to_conf(ptr->data);
349    
350     if (!strcmp(user, aptr->user) &&
351     !strcmp(aptr->host, host))
352     {
353     sendto_one(source_p,
354     ":%s NOTICE %s :[%s@%s] already RK-Lined by [%s@%s] - %s",
355     me.name, source_p->name, user, host, aptr->user,
356     aptr->host, aptr->reason ? aptr->reason : "No reason");
357     return 1;
358     }
359     }
360    
361     return 0;
362     }
363    
364     /*
365     * mo_unrkline
366     * parv[0] = sender
367     * parv[1] = address to remove
368     */
369     static void
370     mo_unrkline(struct Client *client_p,struct Client *source_p,
371     int parc, char *parv[])
372     {
373     char *target_server = NULL;
374     char *user, *host;
375    
376     if (!IsAdmin(source_p) || !IsOperUnkline(source_p))
377     {
378     sendto_one(source_p, form_str(ERR_NOPRIVS),
379     me.name, source_p->name, "unrkline");
380     return;
381     }
382    
383     if (parc < 2 || *parv[1] == '\0')
384     {
385     sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
386     me.name, source_p->name, "UNRKLINE");
387     return;
388     }
389    
390     if (parse_aline("UNRKLINE", source_p, parc, parv, NOUSERLOOKUP, &user,
391     &host, NULL, &target_server, NULL) < 0)
392     return;
393    
394     if (target_server != NULL)
395     {
396     sendto_match_servs(source_p, target_server, CAP_UNKLN,
397     "UNRKLINE %s %s %s",
398     target_server, user, host);
399    
400     /* Allow ON to apply local unkline as well if it matches */
401     if (!match(target_server, me.name))
402     return;
403     }
404     #if 0
405     else
406     cluster_a_line(source_p, "UNRKLINE", CAP_UNKLN, SHARED_UNKLINE,
407     "%s %s", user, host);
408     #endif
409    
410     if (remove_trkline_match(host, user))
411     {
412     sendto_one(source_p,
413     ":%s NOTICE %s :Un-klined [%s@%s] from temporary RK-Lines",
414     me.name, source_p->name, user, host);
415     sendto_realops_flags(UMODE_ALL, L_ALL,
416     "%s has removed the temporary RK-Line for: [%s@%s]",
417     get_oper_name(source_p), user, host);
418     ilog(L_NOTICE, "%s removed temporary RK-Line for [%s@%s]",
419     source_p->name, user, host);
420     return;
421     }
422    
423     if (remove_conf_line(RKLINE_TYPE, source_p, user, host) > 0)
424     {
425     sendto_one(source_p, ":%s NOTICE %s :RK-Line for [%s@%s] is removed",
426     me.name, source_p->name, user,host);
427     sendto_realops_flags(UMODE_ALL, L_ALL,
428     "%s has removed the RK-Line for: [%s@%s]",
429     get_oper_name(source_p), user, host);
430     ilog(L_NOTICE, "%s removed RK-Line for [%s@%s]",
431     source_p->name, user, host);
432     }
433     else
434     sendto_one(source_p, ":%s NOTICE %s :No RK-Line for [%s@%s] found",
435     me.name, source_p->name, user, host);
436     }
437    
438     /* me_unrkline()
439     *
440     * inputs - server
441     * - client
442     * - parc
443     * - parv
444     * outputs - none
445     * side effects - if server is authorized, rkline is removed
446     * does not propagate message
447     */
448     static void
449     me_unrkline(struct Client *client_p, struct Client *source_p,
450     int parc, char *parv[])
451     {
452     const char *user = NULL, *host = NULL;
453    
454     if (parc != 4 || EmptyString(parv[3]))
455     return;
456    
457     user = parv[2];
458     host = parv[3];
459    
460     if (!IsClient(source_p) || !match(parv[1], me.name))
461     return;
462    
463     if (find_matching_name_conf(ULINE_TYPE, source_p->servptr->name,
464     source_p->username, source_p->host,
465     SHARED_UNKLINE))
466     {
467     if (remove_trkline_match(host, user))
468     {
469     sendto_one(source_p,
470     ":%s NOTICE %s :Un-klined [%s@%s] from temporary RK-Lines",
471     me.name, source_p->name, user, host);
472     sendto_realops_flags(UMODE_ALL, L_ALL,
473     "%s has removed the temporary RK-Line for: [%s@%s]",
474     get_oper_name(source_p), user, host);
475     ilog(L_NOTICE, "%s removed temporary RK-Line for [%s@%s]",
476     source_p->name, user, host);
477     return;
478     }
479    
480     if (remove_conf_line(RKLINE_TYPE, source_p, user, host) > 0)
481     {
482     sendto_one(source_p, ":%s NOTICE %s :RK-Line for [%s@%s] is removed",
483     me.name, source_p->name, user, host);
484     sendto_realops_flags(UMODE_ALL, L_ALL,
485     "%s has removed the RK-Line for: [%s@%s]",
486     get_oper_name(source_p), user, host);
487    
488     ilog(L_NOTICE, "%s removed RK-Line for [%s@%s]",
489     source_p->name, user, host);
490     }
491     else
492     sendto_one(source_p, ":%s NOTICE %s :No RK-Line for [%s@%s] found",
493     me.name, source_p->name, user, host);
494     }
495     }
496    
497     /* ms_unrkline - propagates and handles a remote unrkline message */
498     static void
499     ms_unrkline(struct Client *client_p, struct Client *source_p,
500     int parc, char *parv[])
501     {
502     if (parc != 4 || EmptyString(parv[3]))
503     return;
504    
505     sendto_match_servs(source_p, parv[1], CAP_UNKLN,
506     "UNRKLINE %s %s %s",
507     parv[1], parv[2], parv[3]);
508    
509     me_unrkline(client_p, source_p, parc, parv);
510     }
511    
512     /* static int remove_rtkline_match(const char *host, const char *user)
513     * Input: A hostname, a username to unrkline.
514     * Output: returns YES on success, NO if no trkline removed.
515     * Side effects: Any matching trklines are removed.
516     */
517     static int
518     remove_trkline_match(const char *const host,
519     const char *const user)
520     {
521     dlink_node *ptr = NULL;
522    
523     DLINK_FOREACH(ptr, temporary_rklines.head)
524     {
525     struct ConfItem *conf = ptr->data;
526     struct AccessItem *aptr = map_to_conf(ptr->data);
527    
528     if (!strcmp(user, aptr->user) &&
529     !strcmp(aptr->host, host))
530     {
531     dlinkDelete(ptr, &temporary_rklines);
532     free_dlink_node(ptr);
533     delete_conf_item(conf);
534     return 1;
535     }
536     }
537    
538     return 0;
539     }

Properties

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