/[svn]/ircd-hybrid/branches/8.2.x/modules/m_kline.c
ViewVC logotype

Contents of /ircd-hybrid/branches/8.2.x/modules/m_kline.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4985 - (show annotations)
Mon Dec 8 14:46:29 2014 UTC (5 years, 6 months ago) by michael
File MIME type: text/x-chdr
File size: 8841 byte(s)
- m_kline.c: merged ms_kline() and me_kline(); removed unused encap handler

1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2014 ircd-hybrid development team
5 *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file m_kline.c
23 * \brief Includes required functions for processing the KLINE command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "client.h"
30 #include "irc_string.h"
31 #include "ircd.h"
32 #include "conf.h"
33 #include "hostmask.h"
34 #include "numeric.h"
35 #include "log.h"
36 #include "misc.h"
37 #include "send.h"
38 #include "hash.h"
39 #include "server.h"
40 #include "parse.h"
41 #include "modules.h"
42 #include "conf_db.h"
43 #include "memory.h"
44
45
46 static void
47 check_kline(struct AddressRec *arec)
48 {
49 dlink_node *node = NULL, *node_next = NULL;
50
51 DLINK_FOREACH_SAFE(node, node_next, local_client_list.head)
52 {
53 struct Client *client_p = node->data;
54
55 if (IsDead(client_p))
56 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->connection->aftype == AF_INET)
65 if (match_ipv4(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
66 conf_try_ban(client_p, arec->conf);
67 break;
68 case HM_IPV6:
69 if (client_p->connection->aftype == AF_INET6)
70 if (match_ipv6(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
71 conf_try_ban(client_p, arec->conf);
72 break;
73 default: /* HM_HOST */
74 if (!match(arec->Mask.hostname, client_p->host))
75 conf_try_ban(client_p, arec->conf);
76 break;
77 }
78 }
79 }
80
81 /* 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
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
99 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 if (IsClient(source_p))
111 sendto_one_notice(source_p, &me, ":Added K-Line [%s@%s]",
112 conf->user, conf->host);
113
114 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
122 conf->setat = CurrentTime;
123 SetConfDatabase(conf);
124
125 check_kline(add_conf_by_address(CONF_KLINE, conf));
126 }
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 if (IsClient(source_p) && warn)
160 sendto_one_notice(source_p, &me, ":[%s@%s] already K-Lined by [%s@%s] - %s",
161 luser, lhost, conf->user, conf->host, conf->reason);
162 return 1;
163 }
164
165 return 0;
166 }
167
168 /* 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 static int
178 mo_kline(struct Client *source_p, int parc, char *parv[])
179 {
180 char buffer[IRCD_BUFSIZE];
181 char *reason = NULL;
182 char *user = NULL;
183 char *host = NULL;
184 char *target_server = NULL;
185 struct MaskItem *conf;
186 time_t tkline_time = 0;
187
188 if (!HasOFlag(source_p, OPER_FLAG_KLINE))
189 {
190 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "kline");
191 return 0;
192 }
193
194 if (parse_aline("KLINE", source_p, parc, parv, AWILD, &user, &host,
195 &tkline_time, &target_server, &reason) < 0)
196 return 0;
197
198 if (target_server)
199 {
200 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
204 /* Allow ON to apply local kline as well if it matches */
205 if (match(target_server, me.name))
206 return 0;
207 }
208 else
209 cluster_a_line(source_p, "KLINE", CAP_KLN, SHARED_KLINE,
210 "%d %s %s :%s", tkline_time, user, host, reason);
211
212 if (already_placed_kline(source_p, user, host, 1))
213 return 0;
214
215 conf = conf_make(CONF_KLINE);
216 conf->host = xstrdup(host);
217 conf->user = xstrdup(user);
218
219 if (tkline_time)
220 snprintf(buffer, sizeof(buffer), "Temporary K-line %d min. - %.*s (%s)",
221 (int)(tkline_time/60), REASONLEN, reason, smalldate(0));
222 else
223 snprintf(buffer, sizeof(buffer), "%.*s (%s)", REASONLEN, reason, smalldate(0));
224
225 conf->reason = xstrdup(buffer);
226 m_kline_add_kline(source_p, conf, tkline_time);
227 return 0;
228 }
229
230 /* me_kline - handle remote kline. no propagation */
231 static int
232 ms_kline(struct Client *source_p, int parc, char *parv[])
233 {
234 char buffer[IRCD_BUFSIZE];
235 struct MaskItem *conf = NULL;
236 time_t tkline_time = 0;
237 char *kuser, *khost, *kreason;
238
239 if (parc != 6 || EmptyString(parv[5]))
240 return 0;
241
242 /* parv[0] parv[1] parv[2] parv[3] parv[4] parv[5] */
243 /* command target_server tkline_time user host reason */
244 sendto_match_servs(source_p, parv[1], CAP_KLN, "KLINE %s %s %s %s :%s",
245 parv[1], parv[2], parv[3], parv[4], parv[5]);
246
247 if (match(parv[1], me.name))
248 return 0;
249
250 tkline_time = valid_tkline(parv[2], TK_SECONDS);
251 kuser = parv[3];
252 khost = parv[4];
253 kreason = parv[5];
254
255 if (HasFlag(source_p, FLAGS_SERVICE) ||
256 find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
257 source_p->username, source_p->host,
258 SHARED_KLINE))
259 {
260 if (already_placed_kline(source_p, kuser, khost, 1))
261 return 0;
262
263 conf = conf_make(CONF_KLINE);
264 conf->host = xstrdup(khost);
265 conf->user = xstrdup(kuser);
266
267 if (tkline_time)
268 snprintf(buffer, sizeof(buffer), "Temporary K-line %u min. - %.*s (%s)",
269 (unsigned int)(tkline_time/60), REASONLEN, kreason, smalldate(0));
270 else
271 snprintf(buffer, sizeof(buffer), "%.*s (%s)", REASONLEN, kreason, smalldate(0));
272
273 conf->reason = xstrdup(buffer);
274 m_kline_add_kline(source_p, conf, tkline_time);
275 }
276
277 return 0;
278 }
279
280 static struct Message kline_msgtab =
281 {
282 "KLINE", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
283 { m_unregistered, m_not_oper, ms_kline, m_ignore, mo_kline, m_ignore }
284 };
285
286 static void
287 module_init(void)
288 {
289 mod_add_cmd(&kline_msgtab);
290 add_capability("KLN", CAP_KLN, 1);
291 }
292
293 static void
294 module_exit(void)
295 {
296 mod_del_cmd(&kline_msgtab);
297 delete_capability("KLN");
298 }
299
300 struct module module_entry =
301 {
302 .node = { NULL, NULL, NULL },
303 .name = NULL,
304 .version = "$Revision$",
305 .handle = NULL,
306 .modinit = module_init,
307 .modexit = module_exit,
308 .flags = 0
309 };

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28