/[svn]/ircd-hybrid/trunk/modules/m_xline.c
ViewVC logotype

Contents of /ircd-hybrid/trunk/modules/m_xline.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4565 - (show annotations)
Sun Aug 24 10:27:40 2014 UTC (7 years, 11 months ago) by michael
File MIME type: text/x-chdr
File size: 8022 byte(s)
- Update GPL 2 license headers

1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 2003-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_xline.c
23 * \brief Includes required functions for processing the XLINE 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 "numeric.h"
34 #include "log.h"
35 #include "send.h"
36 #include "server.h"
37 #include "parse.h"
38 #include "modules.h"
39 #include "conf_db.h"
40 #include "memory.h"
41
42
43 static void
44 check_xline(struct MaskItem *conf)
45 {
46 dlink_node *ptr = NULL, *ptr_next = NULL;
47
48 DLINK_FOREACH_SAFE(ptr, ptr_next, local_client_list.head)
49 {
50 struct Client *client_p = ptr->data;
51
52 if (IsDead(client_p))
53 continue;
54
55 if (!match(conf->name, client_p->info))
56 conf_try_ban(client_p, conf);
57 }
58 }
59
60 /* valid_xline()
61 *
62 * inputs - client to complain to, gecos, reason, whether to complain
63 * outputs - 1 for valid, else 0
64 * side effects - complains to client, when warn != 0
65 */
66 static int
67 valid_xline(struct Client *source_p, const char *gecos, const char *reason)
68 {
69 if (EmptyString(reason))
70 {
71 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "XLINE");
72 return 0;
73 }
74
75 if (!valid_wild_card_simple(gecos))
76 {
77 sendto_one_notice(source_p, &me, ":Please include at least %u non-wildcard characters with the xline",
78 ConfigGeneral.min_nonwildcard_simple);
79 return 0;
80 }
81
82 return 1;
83 }
84
85 /* write_xline()
86 *
87 * inputs - client taking credit for xline, gecos, reason, xline type
88 * outputs - none
89 * side effects - when successful, adds an xline to the conf
90 */
91 static void
92 write_xline(struct Client *source_p, char *gecos, char *reason,
93 time_t tkline_time)
94 {
95 struct MaskItem *conf = conf_make(CONF_XLINE);
96
97 conf->name = xstrdup(gecos);
98 conf->reason = xstrdup(reason);
99 conf->setat = CurrentTime;
100
101 SetConfDatabase(conf);
102
103 if (tkline_time)
104 {
105 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
106 "%s added temporary %d min. X-Line for [%s] [%s]",
107 get_oper_name(source_p), (int)tkline_time/60,
108 conf->name, conf->reason);
109 sendto_one_notice(source_p, &me, ":Added temporary %d min. X-Line [%s]",
110 (int)tkline_time/60, conf->name);
111 ilog(LOG_TYPE_XLINE, "%s added temporary %d min. X-Line for [%s] [%s]",
112 source_p->name, (int)tkline_time/60, conf->name, conf->reason);
113 conf->until = CurrentTime + tkline_time;
114 }
115 else
116 {
117 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
118 "%s added X-Line for [%s] [%s]",
119 get_oper_name(source_p), conf->name,
120 conf->reason);
121 sendto_one_notice(source_p, &me, ":Added X-Line [%s] [%s]",
122 conf->name, conf->reason);
123 ilog(LOG_TYPE_XLINE, "%s added X-Line for [%s] [%s]",
124 get_oper_name(source_p), conf->name, conf->reason);
125 }
126
127 check_xline(conf);
128 }
129
130 static void
131 relay_xline(struct Client *source_p, char *parv[])
132 {
133 struct MaskItem *conf = NULL;
134 int t_sec;
135
136 t_sec = atoi(parv[3]);
137
138 sendto_match_servs(source_p, parv[1], CAP_CLUSTER,
139 "XLINE %s %s %s :%s",
140 parv[1], parv[2], parv[3], parv[4]);
141
142 if (match(parv[1], me.name))
143 return;
144
145 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
146 source_p->username, source_p->host,
147 SHARED_XLINE))
148 {
149 if ((conf = find_matching_name_conf(CONF_XLINE, parv[2], NULL, NULL, 0)))
150 {
151 sendto_one_notice(source_p, &me, ":[%s] already X-Lined by [%s] - %s",
152 parv[2], conf->name, conf->reason);
153 return;
154 }
155
156 write_xline(source_p, parv[2], parv[4], t_sec);
157 }
158 }
159
160 /* mo_xline()
161 *
162 * inputs - pointer to server
163 * - pointer to client
164 * - parameter count
165 * - parameter list
166 * output -
167 * side effects - x line is added
168 *
169 */
170 static int
171 mo_xline(struct Client *source_p, int parc, char *parv[])
172 {
173 char *reason = NULL;
174 char *gecos = NULL;
175 struct MaskItem *conf = NULL;
176 char *target_server = NULL;
177 time_t tkline_time = 0;
178
179 if (!HasOFlag(source_p, OPER_FLAG_XLINE))
180 {
181 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "xline");
182 return 0;
183 }
184
185 /*
186 * XLINE <gecos> <time> ON <mask> :<reason>
187 * XLINE <gecos> ON <mask> :<reason>
188 */
189 if (parse_aline("XLINE", source_p, parc, parv, 0, &gecos, NULL,
190 &tkline_time, &target_server, &reason) < 0)
191 return 0;
192
193 if (target_server)
194 {
195 /* if a given expire time is given, ENCAP it */
196 if (tkline_time)
197 sendto_match_servs(source_p, target_server, CAP_ENCAP,
198 "ENCAP %s XLINE %d %s 0 :%s",
199 target_server, (int)tkline_time, gecos, reason);
200 else
201 sendto_match_servs(source_p, target_server, CAP_CLUSTER,
202 "XLINE %s %s %d :%s",
203 target_server, gecos, (int)tkline_time, reason);
204
205 /* Allow ON to apply local xline as well if it matches */
206 if (match(target_server, me.name))
207 return 0;
208 }
209 else
210 {
211 if (tkline_time)
212 cluster_a_line(source_p, "ENCAP", CAP_ENCAP, SHARED_XLINE,
213 "XLINE %d %s 0 :%s", (int)tkline_time, gecos, reason);
214 else
215 cluster_a_line(source_p, "XLINE", CAP_KLN, SHARED_XLINE,
216 "%s 0 :%s", gecos, reason);
217 }
218
219 if (!valid_xline(source_p, gecos, reason))
220 return 0;
221
222 if ((conf = find_matching_name_conf(CONF_XLINE, gecos, NULL, NULL, 0)))
223 {
224 sendto_one_notice(source_p, &me, ":[%s] already X-Lined by [%s] - %s",
225 gecos, conf->name, conf->reason);
226 return 0;
227 }
228
229 write_xline(source_p, gecos, reason, tkline_time);
230 return 0;
231 }
232
233 /* ms_xline()
234 *
235 * inputs - oper, target server, xline, {type}, reason
236 *
237 * outputs - none
238 * side effects - propagates xline, applies it if we are a target
239 */
240 static int
241 ms_xline(struct Client *source_p, int parc, char *parv[])
242 {
243 if (parc != 5 || EmptyString(parv[4]))
244 return 0;
245
246 if (!IsClient(source_p))
247 return 0;
248
249 if (!valid_xline(source_p, parv[2], parv[4]))
250 return 0;
251
252 relay_xline(source_p, parv);
253 return 0;
254 }
255
256 /* me_xline()
257 *
258 * inputs - server
259 * - client (oper)
260 * - parc number of arguments
261 * - parv list of arguments
262 * via parv[]
263 * parv[1] = target server
264 * parv[2] = xline
265 * parv[3] = time
266 * parv[4] = reason
267 *
268 * outputs - none
269 * side effects -
270 */
271 static int
272 me_xline(struct Client *source_p, int parc, char *parv[])
273 {
274 if (!IsClient(source_p) || parc != 5)
275 return 0;
276
277 relay_xline(source_p, parv);
278 return 0;
279 }
280
281 static struct Message xline_msgtab =
282 {
283 "XLINE", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
284 { m_unregistered, m_not_oper, ms_xline, me_xline, mo_xline, m_ignore }
285 };
286
287 static void
288 module_init(void)
289 {
290 mod_add_cmd(&xline_msgtab);
291 }
292
293 static void
294 module_exit(void)
295 {
296 mod_del_cmd(&xline_msgtab);
297 }
298
299 struct module module_entry =
300 {
301 .node = { NULL, NULL, NULL },
302 .name = NULL,
303 .version = "$Revision$",
304 .handle = NULL,
305 .modinit = module_init,
306 .modexit = module_exit,
307 .flags = 0
308 };

Properties

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

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