ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_kline.c
Revision: 6318
Committed: Wed Aug 5 16:04:43 2015 UTC (10 years ago) by michael
Content type: text/x-csrc
File size: 9968 byte(s)
Log Message:
- Get rid of UMODE_ALL

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2810 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 5347 * Copyright (c) 1997-2015 ircd-hybrid development team
5 adx 30 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2810 /*! \file m_kline.c
23 michael 3350 * \brief Includes required functions for processing the KLINE command.
24 michael 2810 * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #include "client.h"
30     #include "irc_string.h"
31     #include "ircd.h"
32 michael 1632 #include "conf.h"
33 adx 30 #include "hostmask.h"
34     #include "numeric.h"
35 michael 1309 #include "log.h"
36 michael 3347 #include "misc.h"
37 adx 30 #include "send.h"
38 michael 3347 #include "server.h"
39 adx 30 #include "parse.h"
40     #include "modules.h"
41 michael 1666 #include "memory.h"
42 adx 30
43 michael 1058
44 michael 2811 static void
45 michael 5832 kline_check(struct AddressRec *arec)
46 michael 2811 {
47 michael 4815 dlink_node *node = NULL, *node_next = NULL;
48 michael 2811
49 michael 4815 DLINK_FOREACH_SAFE(node, node_next, local_client_list.head)
50 michael 2811 {
51 michael 4815 struct Client *client_p = node->data;
52 michael 2811
53 michael 2812 if (IsDead(client_p))
54 michael 2811 continue;
55    
56     if (match(arec->username, client_p->username))
57     continue;
58    
59     switch (arec->masktype)
60     {
61     case HM_IPV4:
62 michael 4588 if (client_p->connection->aftype == AF_INET)
63     if (match_ipv4(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
64 michael 2813 conf_try_ban(client_p, arec->conf);
65 michael 2811 break;
66     case HM_IPV6:
67 michael 4588 if (client_p->connection->aftype == AF_INET6)
68     if (match_ipv6(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
69 michael 2813 conf_try_ban(client_p, arec->conf);
70 michael 2811 break;
71     default: /* HM_HOST */
72 michael 5387 if (!match(arec->Mask.hostname, client_p->host) || !match(arec->Mask.hostname, client_p->sockhost))
73 michael 2813 conf_try_ban(client_p, arec->conf);
74 michael 2811 break;
75     }
76     }
77     }
78    
79 michael 2810 /* apply_tkline()
80     *
81     * inputs -
82     * output - NONE
83     * side effects - tkline as given is placed
84     */
85     static void
86 michael 5828 kline_add(struct Client *source_p, const char *user, const char *host,
87     const char *reason, time_t tkline_time)
88 michael 2810 {
89 michael 5828 char buf[IRCD_BUFSIZE];
90     struct MaskItem *conf;
91    
92 michael 2810 if (tkline_time)
93 michael 5828 snprintf(buf, sizeof(buf), "Temporary K-line %d min. - %.*s (%s)",
94     (int)(tkline_time/60), REASONLEN, reason, smalldate(0));
95     else
96     snprintf(buf, sizeof(buf), "%.*s (%s)", REASONLEN, reason, smalldate(0));
97    
98     conf = conf_make(CONF_KLINE);
99     conf->host = xstrdup(host);
100     conf->user = xstrdup(user);
101     conf->setat = CurrentTime;
102     conf->reason = xstrdup(buf);
103     SetConfDatabase(conf);
104    
105     if (tkline_time)
106 michael 2810 {
107     conf->until = CurrentTime + tkline_time;
108 michael 4635
109     if (IsClient(source_p))
110     sendto_one_notice(source_p, &me, ":Added temporary %d min. K-Line [%s@%s]",
111     tkline_time/60, conf->user, conf->host);
112 michael 4890
113 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
114 michael 2810 "%s added temporary %d min. K-Line for [%s@%s] [%s]",
115     get_oper_name(source_p), tkline_time/60,
116     conf->user, conf->host,
117     conf->reason);
118     ilog(LOG_TYPE_KLINE, "%s added temporary %d min. K-Line for [%s@%s] [%s]",
119     get_oper_name(source_p), tkline_time/60,
120     conf->user, conf->host, conf->reason);
121     }
122     else
123     {
124 michael 4635 if (IsClient(source_p))
125     sendto_one_notice(source_p, &me, ":Added K-Line [%s@%s]",
126     conf->user, conf->host);
127 michael 4890
128 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
129 michael 2810 "%s added K-Line for [%s@%s] [%s]",
130     get_oper_name(source_p),
131     conf->user, conf->host, conf->reason);
132     ilog(LOG_TYPE_KLINE, "%s added K-Line for [%s@%s] [%s]",
133     get_oper_name(source_p), conf->user, conf->host, conf->reason);
134     }
135 adx 30
136 michael 5832 kline_check(add_conf_by_address(CONF_KLINE, conf));
137 michael 2810 }
138    
139     /* already_placed_kline()
140     * inputs - user to complain to, username & host to check for
141     * outputs - returns 1 on existing K-line, 0 if doesn't exist
142     * side effects - notifies source_p if the K-line already exists
143     */
144     /*
145     * Note: This currently works if the new K-line is a special case of an
146     * existing K-line, but not the other way round. To do that we would
147     * have to walk the hash and check every existing K-line. -A1kmm.
148     */
149     static int
150 michael 5875 already_placed_kline(struct Client *source_p, const char *user, const char *host)
151 michael 2810 {
152     struct irc_ssaddr iphost, *piphost;
153     struct MaskItem *conf = NULL;
154     int t = 0;
155     int aftype = 0;
156    
157 michael 5875 if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
158 michael 2810 {
159     if (t == HM_IPV6)
160     aftype = AF_INET6;
161     else
162     aftype = AF_INET;
163 michael 5875
164 michael 2810 piphost = &iphost;
165     }
166     else
167     piphost = NULL;
168    
169 michael 5875 if ((conf = find_conf_by_address(host, piphost, CONF_KLINE, aftype, user, NULL, 0)))
170 michael 2810 {
171 michael 5812 if (IsClient(source_p))
172 michael 3110 sendto_one_notice(source_p, &me, ":[%s@%s] already K-Lined by [%s@%s] - %s",
173 michael 5875 user, host, conf->user, conf->host, conf->reason);
174 michael 2810 return 1;
175     }
176    
177     return 0;
178     }
179    
180 adx 30 /* mo_kline()
181     *
182     * inputs - pointer to server
183     * - pointer to client
184     * - parameter count
185     * - parameter list
186     * output -
187     * side effects - k line is added
188     */
189 michael 2820 static int
190 michael 3156 mo_kline(struct Client *source_p, int parc, char *parv[])
191 adx 30 {
192     char *reason = NULL;
193     char *user = NULL;
194     char *host = NULL;
195     char *target_server = NULL;
196     time_t tkline_time = 0;
197 michael 5805 int bits = 0;
198 adx 30
199 michael 4019 if (!HasOFlag(source_p, OPER_FLAG_KLINE))
200 adx 30 {
201 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "kline");
202 michael 2820 return 0;
203 adx 30 }
204    
205 michael 5776 if (!parse_aline("KLINE", source_p, parc, parv, AWILD, &user, &host,
206     &tkline_time, &target_server, &reason))
207 michael 2820 return 0;
208 adx 30
209 michael 3368 if (target_server)
210 adx 30 {
211 michael 2804 sendto_match_servs(source_p, target_server, CAP_KLN, "KLINE %s %lu %s %s :%s",
212     target_server, (unsigned long)tkline_time,
213     user, host, reason);
214 adx 30
215     /* Allow ON to apply local kline as well if it matches */
216 michael 1652 if (match(target_server, me.name))
217 michael 2820 return 0;
218 adx 30 }
219     else
220     cluster_a_line(source_p, "KLINE", CAP_KLN, SHARED_KLINE,
221 michael 1058 "%d %s %s :%s", tkline_time, user, host, reason);
222 adx 30
223 michael 5812 if (already_placed_kline(source_p, user, host))
224 michael 2820 return 0;
225 adx 30
226 michael 5805 switch (parse_netmask(host, NULL, &bits))
227     {
228     case HM_IPV4:
229     if ((unsigned int)bits < ConfigGeneral.kline_min_cidr)
230     {
231     sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
232     ConfigGeneral.kline_min_cidr);
233     return 0;
234     }
235    
236     break;
237     case HM_IPV6:
238     if ((unsigned int)bits < ConfigGeneral.kline_min_cidr6)
239     {
240     sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
241     ConfigGeneral.kline_min_cidr6);
242     return 0;
243     }
244    
245     break;
246     default: /* HM_HOST */
247     break;
248     }
249    
250 michael 5828 kline_add(source_p, user, host, reason, tkline_time);
251 michael 2820 return 0;
252 adx 30 }
253    
254     /* me_kline - handle remote kline. no propagation */
255 michael 2820 static int
256 michael 4984 ms_kline(struct Client *source_p, int parc, char *parv[])
257 adx 30 {
258 michael 3928 time_t tkline_time = 0;
259 michael 5828 const char *user, *host, *reason;
260 michael 5805 int bits = 0;
261 adx 30
262 michael 352 if (parc != 6 || EmptyString(parv[5]))
263 michael 2820 return 0;
264 adx 30
265 michael 4984 /* parv[0] parv[1] parv[2] parv[3] parv[4] parv[5] */
266     /* command target_server tkline_time user host reason */
267     sendto_match_servs(source_p, parv[1], CAP_KLN, "KLINE %s %s %s %s :%s",
268     parv[1], parv[2], parv[3], parv[4], parv[5]);
269    
270 michael 1652 if (match(parv[1], me.name))
271 michael 2820 return 0;
272 adx 30
273     tkline_time = valid_tkline(parv[2], TK_SECONDS);
274 michael 5828 user = parv[3];
275     host = parv[4];
276     reason = parv[5];
277 adx 30
278 michael 2810 if (HasFlag(source_p, FLAGS_SERVICE) ||
279     find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
280 adx 30 source_p->username, source_p->host,
281     SHARED_KLINE))
282     {
283 michael 5828 if (!valid_wild_card(source_p, 2, user, host))
284 michael 5791 return 0;
285    
286 michael 5828 if (already_placed_kline(source_p, user, host))
287 michael 2820 return 0;
288 adx 30
289 michael 5828 switch (parse_netmask(host, NULL, &bits))
290 michael 5805 {
291     case HM_IPV4:
292     if ((unsigned int)bits < ConfigGeneral.kline_min_cidr)
293     {
294     if (IsClient(source_p))
295     sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
296     ConfigGeneral.kline_min_cidr);
297     return 0;
298     }
299    
300     break;
301     case HM_IPV6:
302     if ((unsigned int)bits < ConfigGeneral.kline_min_cidr6)
303     {
304     if (IsClient(source_p))
305     sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
306     ConfigGeneral.kline_min_cidr6);
307     return 0;
308     }
309    
310     break;
311     default: /* HM_HOST */
312     break;
313     }
314    
315 michael 5828 kline_add(source_p, user, host, reason, tkline_time);
316 adx 30 }
317 michael 2820
318     return 0;
319 adx 30 }
320    
321 michael 2810 static struct Message kline_msgtab =
322 adx 30 {
323 michael 5881 .cmd = "KLINE",
324     .args_min = 2,
325     .args_max = MAXPARA,
326     .handlers[UNREGISTERED_HANDLER] = m_unregistered,
327     .handlers[CLIENT_HANDLER] = m_not_oper,
328     .handlers[SERVER_HANDLER] = ms_kline,
329     .handlers[ENCAP_HANDLER] = m_ignore,
330     .handlers[OPER_HANDLER] = mo_kline
331 michael 1230 };
332    
333     static void
334     module_init(void)
335     {
336     mod_add_cmd(&kline_msgtab);
337 michael 5796 add_capability("KLN", CAP_KLN);
338 michael 1230 }
339    
340     static void
341     module_exit(void)
342     {
343     mod_del_cmd(&kline_msgtab);
344     delete_capability("KLN");
345     }
346    
347 michael 2810 struct module module_entry =
348     {
349 michael 1230 .version = "$Revision$",
350     .modinit = module_init,
351     .modexit = module_exit,
352     };

Properties

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