ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_kline.c
Revision: 5796
Committed: Fri Apr 17 16:12:30 2015 UTC (10 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 8939 byte(s)
Log Message:
- Minor cleanups to CAPAB related code

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

Properties

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