ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_dline.c
Revision: 1156
Committed: Tue Aug 9 20:29:20 2011 UTC (14 years, 11 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_dline.c
File size: 9161 byte(s)
Log Message:
- create ircd-hybrid-8 "branch"

File Contents

# User Rev Content
1 michael 1058 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_dline.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     * $Id$
23     */
24    
25     #include "stdinc.h"
26     #include "list.h"
27     #include "channel.h"
28     #include "client.h"
29     #include "common.h"
30     #include "irc_string.h"
31     #include "sprintf_irc.h"
32     #include "ircd.h"
33     #include "hostmask.h"
34     #include "numeric.h"
35     #include "fdlist.h"
36     #include "s_bsd.h"
37     #include "s_conf.h"
38     #include "s_log.h"
39     #include "s_misc.h"
40     #include "send.h"
41     #include "hash.h"
42     #include "handlers.h"
43     #include "s_serv.h"
44     #include "msg.h"
45     #include "s_gline.h"
46     #include "parse.h"
47     #include "modules.h"
48    
49    
50     static void mo_dline(struct Client *, struct Client *, int, char *[]);
51     static void mo_undline(struct Client *, struct Client *, int, char *[]);
52    
53     static int remove_tdline_match(const char *);
54    
55     struct Message dline_msgtab = {
56     "DLINE", 0, 0, 2, 0, MFLG_SLOW, 0,
57     {m_unregistered, m_not_oper, rfc1459_command_send_error, m_ignore, mo_dline, m_ignore}
58     };
59    
60     struct Message undline_msgtab = {
61     "UNDLINE", 0, 0, 2, 0, MFLG_SLOW, 0,
62     {m_unregistered, m_not_oper, rfc1459_command_send_error, m_ignore, mo_undline, m_ignore}
63     };
64    
65     void
66     _modinit(void)
67     {
68     mod_add_cmd(&dline_msgtab);
69     mod_add_cmd(&undline_msgtab);
70     }
71    
72     void
73     _moddeinit(void)
74     {
75     mod_del_cmd(&dline_msgtab);
76     mod_del_cmd(&undline_msgtab);
77     }
78    
79     const char *_version = "$Revision$";
80    
81     static char buffer[IRCD_BUFSIZE];
82    
83    
84     /* apply_tdline()
85     *
86     * inputs -
87     * output - NONE
88     * side effects - tkline as given is placed
89     */
90     static void
91     apply_tdline(struct Client *source_p, struct ConfItem *conf,
92     const char *current_date, int tkline_time)
93     {
94     struct AccessItem *aconf;
95    
96     aconf = map_to_conf(conf);
97     aconf->hold = CurrentTime + tkline_time;
98    
99     add_temp_line(conf);
100     sendto_realops_flags(UMODE_ALL, L_ALL,
101     "%s added temporary %d min. D-Line for [%s] [%s]",
102     get_oper_name(source_p), tkline_time/60,
103     aconf->host, aconf->reason);
104    
105     sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line [%s]",
106     MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
107     source_p->name, tkline_time/60, aconf->host);
108     ilog(L_TRACE, "%s added temporary %d min. D-Line for [%s] [%s]",
109     source_p->name, tkline_time/60, aconf->host, aconf->reason);
110     log_oper_action(LOG_TEMP_DLINE_TYPE, source_p, "[%s@%s] [%s]\n",
111     aconf->user, aconf->host, aconf->reason);
112     rehashed_klines = 1;
113     }
114    
115     /* mo_dline()
116     *
117     * inputs - pointer to server
118     * - pointer to client
119     * - parameter count
120     * - parameter list
121     * output -
122     * side effects - D line is added
123     *
124     */
125     static void
126     mo_dline(struct Client *client_p, struct Client *source_p,
127     int parc, char *parv[])
128     {
129     char def_reason[] = "No reason";
130     char *dlhost, *oper_reason, *reason;
131     const char *creason;
132     const struct Client *target_p = NULL;
133     struct irc_ssaddr daddr;
134     struct ConfItem *conf=NULL;
135     struct AccessItem *aconf=NULL;
136     time_t tkline_time=0;
137     int bits, t;
138     const char *current_date = NULL;
139     time_t cur_time;
140     char hostip[HOSTIPLEN];
141    
142     if (!IsOperK(source_p))
143     {
144     sendto_one(source_p, form_str(ERR_NOPRIVS),
145     me.name, source_p->name, "kline");
146     return;
147     }
148    
149     if (parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost,
150     NULL, &tkline_time, NULL, &reason) < 0)
151     return;
152    
153     if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
154     {
155     if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL)
156     return;
157    
158     if (!MyConnect(target_p))
159     {
160     sendto_one(source_p,
161     ":%s NOTICE %s :Can't DLINE nick on another server",
162     me.name, source_p->name);
163     return;
164     }
165    
166     if (IsExemptKline(target_p))
167     {
168     sendto_one(source_p,
169     ":%s NOTICE %s :%s is E-lined", me.name,
170     source_p->name, target_p->name);
171     return;
172     }
173    
174 michael 1123 getnameinfo((struct sockaddr *)&target_p->localClient->ip,
175     target_p->localClient->ip.ss_len, hostip,
176     sizeof(hostip), NULL, 0, NI_NUMERICHOST);
177 michael 1058 dlhost = hostip;
178     t = parse_netmask(dlhost, NULL, &bits);
179     assert(t == HM_IPV4 || t == HM_IPV6);
180     }
181    
182     if (bits < 8)
183     {
184     sendto_one(source_p,
185     ":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.",
186     me.name, source_p->name);
187     return;
188     }
189    
190     #ifdef IPV6
191     if (t == HM_IPV6)
192     t = AF_INET6;
193     else
194     #endif
195     t = AF_INET;
196    
197     parse_netmask(dlhost, &daddr, NULL);
198    
199     if ((aconf = find_dline_conf(&daddr, t)) != NULL)
200     {
201     creason = aconf->reason ? aconf->reason : def_reason;
202     if (IsConfExemptKline(aconf))
203     sendto_one(source_p,
204     ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
205     me.name, source_p->name, dlhost, aconf->host, creason);
206     else
207     sendto_one(source_p,
208     ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
209     me.name, source_p->name, dlhost, aconf->host, creason);
210     return;
211     }
212    
213     cur_time = CurrentTime;
214     current_date = smalldate(cur_time);
215    
216     /* Look for an oper reason */
217     if ((oper_reason = strchr(reason, '|')) != NULL)
218     *oper_reason++ = '\0';
219    
220     if (!valid_comment(source_p, reason, YES))
221     return;
222    
223     conf = make_conf_item(DLINE_TYPE);
224     aconf = map_to_conf(conf);
225     DupString(aconf->host, dlhost);
226    
227     if (tkline_time != 0)
228     {
229     ircsprintf(buffer, "Temporary D-line %d min. - %s (%s)",
230     (int)(tkline_time/60), reason, current_date);
231     DupString(aconf->reason, buffer);
232     if (oper_reason != NULL)
233     DupString(aconf->oper_reason, oper_reason);
234     apply_tdline(source_p, conf, current_date, tkline_time);
235     }
236     else
237     {
238     ircsprintf(buffer, "%s (%s)", reason, current_date);
239     DupString(aconf->reason, buffer);
240     if (oper_reason != NULL)
241     DupString(aconf->oper_reason, oper_reason);
242     add_conf_by_address(CONF_DLINE, aconf);
243     write_conf_line(source_p, conf, current_date, cur_time);
244     }
245    
246     rehashed_klines = 1;
247     }
248    
249     /* static int remove_tdline_match(const char *host, const char *user)
250     * Input: An ip to undline.
251     * Output: returns YES on success, NO if no tdline removed.
252     * Side effects: Any matching tdlines are removed.
253     */
254     static int
255     remove_tdline_match(const char *cidr)
256     {
257     struct AccessItem *td_conf;
258     dlink_node *td_node;
259     struct irc_ssaddr addr, caddr;
260     int nm_t, cnm_t, bits, cbits;
261     nm_t = parse_netmask(cidr, &addr, &bits);
262    
263     DLINK_FOREACH(td_node, temporary_dlines.head)
264     {
265     td_conf = map_to_conf(td_node->data);
266     cnm_t = parse_netmask(td_conf->host, &caddr, &cbits);
267    
268     if (cnm_t != nm_t)
269     continue;
270    
271     if((nm_t==HM_HOST && !irccmp(td_conf->host, cidr)) ||
272     (nm_t==HM_IPV4 && bits==cbits && match_ipv4(&addr, &caddr, bits))
273     #ifdef IPV6
274     || (nm_t==HM_IPV6 && bits==cbits && match_ipv6(&addr, &caddr, bits))
275     #endif
276     )
277     {
278     dlinkDelete(td_node, &temporary_dlines);
279     delete_one_address_conf(td_conf->host, td_conf);
280     return 1;
281     }
282     }
283    
284     return 0;
285     }
286    
287     /*
288     ** m_undline
289     ** added May 28th 2000 by Toby Verrall <toot@melnet.co.uk>
290     ** based totally on m_unkline
291     ** added to hybrid-7 7/11/2000 --is
292     **
293     ** parv[0] = sender nick
294     ** parv[1] = dline to remove
295     */
296     static void
297     mo_undline(struct Client *client_p, struct Client *source_p,
298     int parc, char *parv[])
299     {
300     const char *cidr = NULL;
301    
302     if (!IsOperUnkline(source_p))
303     {
304     sendto_one(source_p, form_str(ERR_NOPRIVS),
305     me.name, source_p->name, "undline");
306     return;
307     }
308    
309     cidr = parv[1];
310    
311     if (remove_tdline_match(cidr))
312     {
313     sendto_one(source_p,
314     ":%s NOTICE %s :Un-Dlined [%s] from temporary D-Lines",
315     me.name, source_p->name, cidr);
316     sendto_realops_flags(UMODE_ALL, L_ALL,
317     "%s has removed the temporary D-Line for: [%s]",
318     get_oper_name(source_p), cidr);
319     ilog(L_NOTICE, "%s removed temporary D-Line for [%s]", source_p->name, cidr);
320     return;
321     }
322    
323     if (remove_conf_line(DLINE_TYPE, source_p, cidr, NULL) > 0)
324     {
325     sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed",
326     me.name, source_p->name, cidr);
327     sendto_realops_flags(UMODE_ALL, L_ALL,
328     "%s has removed the D-Line for: [%s]",
329     get_oper_name(source_p), cidr);
330     ilog(L_NOTICE, "%s removed D-Line for [%s]",
331     get_oper_name(source_p), cidr);
332     }
333     else
334     sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
335     me.name, source_p->name, cidr);
336     }

Properties

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