ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_dline.c
Revision: 1243
Committed: Fri Sep 30 10:47:53 2011 UTC (14 years, 9 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_dline.c
File size: 9217 byte(s)
Log Message:
- move content of msg.h, ircd_handler.h and handlers.h into parse.h and
  remove headers accordingly
- killed common.h
- remove m_killhost.c and m_flags.c from contrib/
- sort out unused header includes here and there

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

Properties

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