ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_rkline.c
Revision: 91
Committed: Sat Oct 8 03:46:09 2005 UTC (20 years, 10 months ago) by db
Content type: text/x-csrc
File size: 15989 byte(s)
Log Message:
- Split out most of the *line *resv stuff into separate file
  parse_aline.c should go eventually into the subdir conf
- removed double -o in Makefile.in in src, this caused compile to fail for me


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

Properties

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