ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.3/modules/m_dline.c
Revision: 1058
Committed: Tue Feb 2 22:15:03 2010 UTC (14 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 9203 byte(s)
Log Message:
- move DLINE into its own m_dline module

File Contents

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

Properties

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