ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_kline.c
Revision: 4889
Committed: Wed Nov 19 17:10:25 2014 UTC (9 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 9012 byte(s)
Log Message:
- Style corrections

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 2818 * Copyright (c) 1997-2014 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 4564 * 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     #include "hash.h"
39 michael 3347 #include "server.h"
40 adx 30 #include "parse.h"
41     #include "modules.h"
42 michael 1622 #include "conf_db.h"
43 michael 1666 #include "memory.h"
44 adx 30
45 michael 1058
46 michael 2811 static void
47     check_kline(struct AddressRec *arec)
48     {
49 michael 4816 dlink_node *node = NULL, *node_next = NULL;
50 michael 2811
51 michael 4816 DLINK_FOREACH_SAFE(node, node_next, local_client_list.head)
52 michael 2811 {
53 michael 4816 struct Client *client_p = node->data;
54 michael 2811
55 michael 2812 if (IsDead(client_p))
56 michael 2811 continue;
57    
58     if (match(arec->username, client_p->username))
59     continue;
60    
61     switch (arec->masktype)
62     {
63     case HM_IPV4:
64 michael 4589 if (client_p->connection->aftype == AF_INET)
65     if (match_ipv4(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
66 michael 2813 conf_try_ban(client_p, arec->conf);
67 michael 2811 break;
68     case HM_IPV6:
69 michael 4589 if (client_p->connection->aftype == AF_INET6)
70     if (match_ipv6(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
71 michael 2813 conf_try_ban(client_p, arec->conf);
72 michael 2811 break;
73     default: /* HM_HOST */
74     if (!match(arec->Mask.hostname, client_p->host))
75 michael 2813 conf_try_ban(client_p, arec->conf);
76 michael 2811 break;
77     }
78     }
79     }
80    
81 michael 2810 /* apply_tkline()
82     *
83     * inputs -
84     * output - NONE
85     * side effects - tkline as given is placed
86     */
87     static void
88     m_kline_add_kline(struct Client *source_p, struct MaskItem *conf,
89     time_t tkline_time)
90     {
91     if (tkline_time)
92     {
93     conf->until = CurrentTime + tkline_time;
94 michael 4636
95     if (IsClient(source_p))
96     sendto_one_notice(source_p, &me, ":Added temporary %d min. K-Line [%s@%s]",
97     tkline_time/60, conf->user, conf->host);
98 michael 4889
99 michael 2810 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
100     "%s added temporary %d min. K-Line for [%s@%s] [%s]",
101     get_oper_name(source_p), tkline_time/60,
102     conf->user, conf->host,
103     conf->reason);
104     ilog(LOG_TYPE_KLINE, "%s added temporary %d min. K-Line for [%s@%s] [%s]",
105     get_oper_name(source_p), tkline_time/60,
106     conf->user, conf->host, conf->reason);
107     }
108     else
109     {
110 michael 4636 if (IsClient(source_p))
111     sendto_one_notice(source_p, &me, ":Added K-Line [%s@%s]",
112     conf->user, conf->host);
113 michael 4889
114 michael 2810 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
115     "%s added K-Line for [%s@%s] [%s]",
116     get_oper_name(source_p),
117     conf->user, conf->host, conf->reason);
118     ilog(LOG_TYPE_KLINE, "%s added K-Line for [%s@%s] [%s]",
119     get_oper_name(source_p), conf->user, conf->host, conf->reason);
120     }
121 adx 30
122 michael 2810 conf->setat = CurrentTime;
123     SetConfDatabase(conf);
124 adx 30
125 michael 2811 check_kline(add_conf_by_address(CONF_KLINE, conf));
126 michael 2810 }
127    
128     /* already_placed_kline()
129     * inputs - user to complain to, username & host to check for
130     * outputs - returns 1 on existing K-line, 0 if doesn't exist
131     * side effects - notifies source_p if the K-line already exists
132     */
133     /*
134     * Note: This currently works if the new K-line is a special case of an
135     * existing K-line, but not the other way round. To do that we would
136     * have to walk the hash and check every existing K-line. -A1kmm.
137     */
138     static int
139     already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int warn)
140     {
141     struct irc_ssaddr iphost, *piphost;
142     struct MaskItem *conf = NULL;
143     int t = 0;
144     int aftype = 0;
145    
146     if ((t = parse_netmask(lhost, &iphost, NULL)) != HM_HOST)
147     {
148     if (t == HM_IPV6)
149     aftype = AF_INET6;
150     else
151     aftype = AF_INET;
152     piphost = &iphost;
153     }
154     else
155     piphost = NULL;
156    
157     if ((conf = find_conf_by_address(lhost, piphost, CONF_KLINE, aftype, luser, NULL, 0)))
158     {
159 michael 4636 if (IsClient(source_p) && warn)
160 michael 3110 sendto_one_notice(source_p, &me, ":[%s@%s] already K-Lined by [%s@%s] - %s",
161 michael 4664 luser, lhost, conf->user, conf->host, conf->reason);
162 michael 2810 return 1;
163     }
164    
165     return 0;
166     }
167    
168 adx 30 /* mo_kline()
169     *
170     * inputs - pointer to server
171     * - pointer to client
172     * - parameter count
173     * - parameter list
174     * output -
175     * side effects - k line is added
176     */
177 michael 2820 static int
178 michael 3156 mo_kline(struct Client *source_p, int parc, char *parv[])
179 adx 30 {
180 michael 2810 char buffer[IRCD_BUFSIZE];
181 adx 30 char *reason = NULL;
182     char *user = NULL;
183     char *host = NULL;
184     char *target_server = NULL;
185 michael 1632 struct MaskItem *conf;
186 adx 30 time_t tkline_time = 0;
187    
188 michael 4018 if (!HasOFlag(source_p, OPER_FLAG_KLINE))
189 adx 30 {
190 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "kline");
191 michael 2820 return 0;
192 adx 30 }
193    
194 michael 2810 if (parse_aline("KLINE", source_p, parc, parv, AWILD, &user, &host,
195     &tkline_time, &target_server, &reason) < 0)
196 michael 2820 return 0;
197 adx 30
198 michael 3368 if (target_server)
199 adx 30 {
200 michael 2804 sendto_match_servs(source_p, target_server, CAP_KLN, "KLINE %s %lu %s %s :%s",
201     target_server, (unsigned long)tkline_time,
202     user, host, reason);
203 adx 30
204     /* Allow ON to apply local kline as well if it matches */
205 michael 1652 if (match(target_server, me.name))
206 michael 2820 return 0;
207 adx 30 }
208     else
209     cluster_a_line(source_p, "KLINE", CAP_KLN, SHARED_KLINE,
210 michael 1058 "%d %s %s :%s", tkline_time, user, host, reason);
211 adx 30
212 michael 1243 if (already_placed_kline(source_p, user, host, 1))
213 michael 2820 return 0;
214 adx 30
215 michael 1632 conf = conf_make(CONF_KLINE);
216 michael 1646 conf->host = xstrdup(host);
217     conf->user = xstrdup(user);
218 adx 30
219 michael 3368 if (tkline_time)
220 michael 4672 snprintf(buffer, sizeof(buffer), "Temporary K-line %d min. - %.*s (%s)",
221 michael 4889 (int)(tkline_time/60), REASONLEN, reason, smalldate(0));
222 adx 30 else
223 michael 4889 snprintf(buffer, sizeof(buffer), "%.*s (%s)", REASONLEN, reason, smalldate(0));
224 adx 30
225 michael 1646 conf->reason = xstrdup(buffer);
226 michael 1632 m_kline_add_kline(source_p, conf, tkline_time);
227 michael 2820 return 0;
228 adx 30 }
229    
230     /* me_kline - handle remote kline. no propagation */
231 michael 2820 static int
232 michael 3156 me_kline(struct Client *source_p, int parc, char *parv[])
233 adx 30 {
234 michael 2810 char buffer[IRCD_BUFSIZE];
235 michael 1632 struct MaskItem *conf = NULL;
236 michael 3927 time_t tkline_time = 0;
237 michael 1622 char *kuser, *khost, *kreason;
238 adx 30
239 michael 352 if (parc != 6 || EmptyString(parv[5]))
240 michael 2820 return 0;
241 adx 30
242 michael 1652 if (match(parv[1], me.name))
243 michael 2820 return 0;
244 adx 30
245     tkline_time = valid_tkline(parv[2], TK_SECONDS);
246     kuser = parv[3];
247     khost = parv[4];
248     kreason = parv[5];
249    
250 michael 2810 if (HasFlag(source_p, FLAGS_SERVICE) ||
251     find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
252 adx 30 source_p->username, source_p->host,
253     SHARED_KLINE))
254     {
255 michael 4636 if (already_placed_kline(source_p, kuser, khost, 1))
256 michael 2820 return 0;
257 adx 30
258 michael 1632 conf = conf_make(CONF_KLINE);
259 michael 1646 conf->host = xstrdup(khost);
260     conf->user = xstrdup(kuser);
261 adx 30
262 michael 3368 if (tkline_time)
263 michael 4672 snprintf(buffer, sizeof(buffer), "Temporary K-line %u min. - %.*s (%s)",
264 michael 4889 (unsigned int)(tkline_time/60), REASONLEN, kreason, smalldate(0));
265 adx 30 else
266 michael 4889 snprintf(buffer, sizeof(buffer), "%.*s (%s)", REASONLEN, kreason, smalldate(0));
267 adx 30
268 michael 1646 conf->reason = xstrdup(buffer);
269 michael 1632 m_kline_add_kline(source_p, conf, tkline_time);
270 adx 30 }
271 michael 2820
272     return 0;
273 adx 30 }
274    
275 michael 2820 static int
276 michael 3156 ms_kline(struct Client *source_p, int parc, char *parv[])
277 adx 30 {
278 michael 352 if (parc != 6 || EmptyString(parv[5]))
279 michael 2820 return 0;
280 adx 30
281     /* parv[0] parv[1] parv[2] parv[3] parv[4] parv[5] */
282 michael 4633 /* command target_server tkline_time user host reason */
283 michael 2820 sendto_match_servs(source_p, parv[1], CAP_KLN, "KLINE %s %s %s %s :%s",
284 adx 30 parv[1], parv[2], parv[3], parv[4], parv[5]);
285    
286 michael 3156 return me_kline(source_p, parc, parv);
287 adx 30 }
288    
289 michael 2810 static struct Message kline_msgtab =
290 adx 30 {
291 michael 4546 "KLINE", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
292 michael 2810 { m_unregistered, m_not_oper, ms_kline, me_kline, mo_kline, m_ignore }
293 michael 1230 };
294    
295     static void
296     module_init(void)
297     {
298     mod_add_cmd(&kline_msgtab);
299     add_capability("KLN", CAP_KLN, 1);
300     }
301    
302     static void
303     module_exit(void)
304     {
305     mod_del_cmd(&kline_msgtab);
306     delete_capability("KLN");
307     }
308    
309 michael 2810 struct module module_entry =
310     {
311 michael 1230 .node = { NULL, NULL, NULL },
312     .name = NULL,
313     .version = "$Revision$",
314     .handle = NULL,
315     .modinit = module_init,
316     .modexit = module_exit,
317     .flags = 0
318     };

Properties

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