ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/branches/newio/modules/m_dline.c
Revision: 1247
Committed: Sat Oct 1 07:54:24 2011 UTC (12 years, 5 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_dline.c
File size: 9124 byte(s)
Log Message:
- Rewrite and cleanup half-broken logging subsystem.
  Logfile rotating is not working yet

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

Properties

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