ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_kline.c
Revision: 4545
Committed: Fri Aug 22 08:46:13 2014 UTC (11 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 9106 byte(s)
Log Message:
- Implemented pseudo {} blocks (service aliases)
- Fixed compile warnings with -Wmissing-field-initializers

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     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19     * 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     dlink_node *ptr = NULL, *ptr_next = NULL;
50    
51     DLINK_FOREACH_SAFE(ptr, ptr_next, local_client_list.head)
52     {
53     struct Client *client_p = ptr->data;
54    
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     if (client_p->localClient->aftype == AF_INET)
65     if (match_ipv4(&client_p->localClient->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     if (client_p->localClient->aftype == AF_INET6)
70     if (match_ipv6(&client_p->localClient->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     sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
95     "%s added temporary %d min. K-Line for [%s@%s] [%s]",
96     get_oper_name(source_p), tkline_time/60,
97     conf->user, conf->host,
98     conf->reason);
99 michael 3110 sendto_one_notice(source_p, &me, ":Added temporary %d min. K-Line [%s@%s]",
100     tkline_time/60, conf->user, conf->host);
101 michael 2810 ilog(LOG_TYPE_KLINE, "%s added temporary %d min. K-Line for [%s@%s] [%s]",
102     get_oper_name(source_p), tkline_time/60,
103     conf->user, conf->host, conf->reason);
104     }
105     else
106     {
107     sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
108     "%s added K-Line for [%s@%s] [%s]",
109     get_oper_name(source_p),
110     conf->user, conf->host, conf->reason);
111 michael 3110 sendto_one_notice(source_p, &me, ":Added K-Line [%s@%s]",
112     conf->user, conf->host);
113 michael 2810 ilog(LOG_TYPE_KLINE, "%s added K-Line for [%s@%s] [%s]",
114     get_oper_name(source_p), conf->user, conf->host, conf->reason);
115     }
116 adx 30
117 michael 2810 conf->setat = CurrentTime;
118     SetConfDatabase(conf);
119 adx 30
120 michael 2811 check_kline(add_conf_by_address(CONF_KLINE, conf));
121 michael 2810 }
122    
123     /* already_placed_kline()
124     * inputs - user to complain to, username & host to check for
125     * outputs - returns 1 on existing K-line, 0 if doesn't exist
126     * side effects - notifies source_p if the K-line already exists
127     */
128     /*
129     * Note: This currently works if the new K-line is a special case of an
130     * existing K-line, but not the other way round. To do that we would
131     * have to walk the hash and check every existing K-line. -A1kmm.
132     */
133     static int
134     already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int warn)
135     {
136     const char *reason;
137     struct irc_ssaddr iphost, *piphost;
138     struct MaskItem *conf = NULL;
139     int t = 0;
140     int aftype = 0;
141    
142     if ((t = parse_netmask(lhost, &iphost, NULL)) != HM_HOST)
143     {
144     if (t == HM_IPV6)
145     aftype = AF_INET6;
146     else
147     aftype = AF_INET;
148     piphost = &iphost;
149     }
150     else
151     piphost = NULL;
152    
153     if ((conf = find_conf_by_address(lhost, piphost, CONF_KLINE, aftype, luser, NULL, 0)))
154     {
155     if (warn)
156     {
157     reason = conf->reason ? conf->reason : CONF_NOREASON;
158 michael 3110 sendto_one_notice(source_p, &me, ":[%s@%s] already K-Lined by [%s@%s] - %s",
159     luser, lhost, conf->user, conf->host, reason);
160 michael 2810 }
161    
162     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     const char *current_date;
185     char *target_server = NULL;
186 michael 1632 struct MaskItem *conf;
187 adx 30 time_t tkline_time = 0;
188    
189 michael 4019 if (!HasOFlag(source_p, OPER_FLAG_KLINE))
190 adx 30 {
191 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "kline");
192 michael 2820 return 0;
193 adx 30 }
194    
195 michael 2810 if (parse_aline("KLINE", source_p, parc, parv, AWILD, &user, &host,
196     &tkline_time, &target_server, &reason) < 0)
197 michael 2820 return 0;
198 adx 30
199 michael 3368 if (target_server)
200 adx 30 {
201 michael 2804 sendto_match_servs(source_p, target_server, CAP_KLN, "KLINE %s %lu %s %s :%s",
202     target_server, (unsigned long)tkline_time,
203     user, host, reason);
204 adx 30
205     /* Allow ON to apply local kline as well if it matches */
206 michael 1652 if (match(target_server, me.name))
207 michael 2820 return 0;
208 adx 30 }
209     else
210     cluster_a_line(source_p, "KLINE", CAP_KLN, SHARED_KLINE,
211 michael 1058 "%d %s %s :%s", tkline_time, user, host, reason);
212 adx 30
213 michael 1243 if (already_placed_kline(source_p, user, host, 1))
214 michael 2820 return 0;
215 adx 30
216 michael 3208 current_date = smalldate(0);
217 michael 1632 conf = conf_make(CONF_KLINE);
218 adx 30
219 michael 1646 conf->host = xstrdup(host);
220     conf->user = xstrdup(user);
221 adx 30
222 michael 3368 if (tkline_time)
223 michael 1233 snprintf(buffer, sizeof(buffer), "Temporary K-line %d min. - %s (%s)",
224     (int)(tkline_time/60), reason, current_date);
225 adx 30 else
226 michael 1233 snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
227 adx 30
228 michael 1646 conf->reason = xstrdup(buffer);
229 michael 1632 m_kline_add_kline(source_p, conf, tkline_time);
230 michael 2820 return 0;
231 adx 30 }
232    
233     /* me_kline - handle remote kline. no propagation */
234 michael 2820 static int
235 michael 3156 me_kline(struct Client *source_p, int parc, char *parv[])
236 adx 30 {
237 michael 2810 char buffer[IRCD_BUFSIZE];
238 michael 1632 struct MaskItem *conf = NULL;
239 michael 3928 time_t tkline_time = 0;
240 michael 2810 const char *current_date;
241 michael 1622 char *kuser, *khost, *kreason;
242 adx 30
243 michael 352 if (parc != 6 || EmptyString(parv[5]))
244 michael 2820 return 0;
245 adx 30
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 3208 current_date = smalldate(0);
255 adx 30
256 michael 2810 if (HasFlag(source_p, FLAGS_SERVICE) ||
257     find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
258 adx 30 source_p->username, source_p->host,
259     SHARED_KLINE))
260     {
261     if (!IsClient(source_p) ||
262 michael 1243 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 3928 snprintf(buffer, sizeof(buffer), "Temporary K-line %u min. - %s (%s)",
271     (unsigned int)(tkline_time/60), kreason, current_date);
272 adx 30 else
273 michael 1233 snprintf(buffer, sizeof(buffer), "%s (%s)", kreason, current_date);
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 2820 static int
283 michael 3156 ms_kline(struct Client *source_p, int parc, char *parv[])
284 adx 30 {
285 michael 352 if (parc != 6 || EmptyString(parv[5]))
286 michael 2820 return 0;
287 adx 30
288     /* parv[0] parv[1] parv[2] parv[3] parv[4] parv[5] */
289     /* oper target_server tkline_time user host reason */
290 michael 2820 sendto_match_servs(source_p, parv[1], CAP_KLN, "KLINE %s %s %s %s :%s",
291 adx 30 parv[1], parv[2], parv[3], parv[4], parv[5]);
292    
293 michael 3156 return me_kline(source_p, parc, parv);
294 adx 30 }
295    
296 michael 2810 static struct Message kline_msgtab =
297 adx 30 {
298 michael 4545 "KLINE", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
299 michael 2810 { m_unregistered, m_not_oper, ms_kline, me_kline, mo_kline, m_ignore }
300 michael 1230 };
301    
302     static void
303     module_init(void)
304     {
305     mod_add_cmd(&kline_msgtab);
306     add_capability("KLN", CAP_KLN, 1);
307     }
308    
309     static void
310     module_exit(void)
311     {
312     mod_del_cmd(&kline_msgtab);
313     delete_capability("KLN");
314     }
315    
316 michael 2810 struct module module_entry =
317     {
318 michael 1230 .node = { NULL, NULL, NULL },
319     .name = NULL,
320     .version = "$Revision$",
321     .handle = NULL,
322     .modinit = module_init,
323     .modexit = module_exit,
324     .flags = 0
325     };

Properties

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