/[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 4625 - (show annotations)
Sun Sep 21 09:34:46 2014 UTC (7 years, 10 months ago) by michael
File MIME type: text/x-chdr
File size: 7991 byte(s)
- m_xline.c:relay_xline(): only call atoi() if really needed

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
135 sendto_match_servs(source_p, parv[1], CAP_CLUSTER,
136 "XLINE %s %s %s :%s",
137 parv[1], parv[2], parv[3], parv[4]);
138
139 if (match(parv[1], me.name))
140 return;
141
142 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
143 source_p->username, source_p->host,
144 SHARED_XLINE))
145 {
146 if ((conf = find_matching_name_conf(CONF_XLINE, parv[2], NULL, NULL, 0)))
147 {
148 sendto_one_notice(source_p, &me, ":[%s] already X-Lined by [%s] - %s",
149 parv[2], conf->name, conf->reason);
150 return;
151 }
152
153 write_xline(source_p, parv[2], parv[4], atoi(parv[3]));
154 }
155 }
156
157 /* mo_xline()
158 *
159 * inputs - pointer to server
160 * - pointer to client
161 * - parameter count
162 * - parameter list
163 * output -
164 * side effects - x line is added
165 *
166 */
167 static int
168 mo_xline(struct Client *source_p, int parc, char *parv[])
169 {
170 char *reason = NULL;
171 char *gecos = NULL;
172 struct MaskItem *conf = NULL;
173 char *target_server = NULL;
174 time_t tkline_time = 0;
175
176 if (!HasOFlag(source_p, OPER_FLAG_XLINE))
177 {
178 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "xline");
179 return 0;
180 }
181
182 /*
183 * XLINE <gecos> <time> ON <mask> :<reason>
184 * XLINE <gecos> ON <mask> :<reason>
185 */
186 if (parse_aline("XLINE", source_p, parc, parv, 0, &gecos, NULL,
187 &tkline_time, &target_server, &reason) < 0)
188 return 0;
189
190 if (target_server)
191 {
192 /* if a given expire time is given, ENCAP it */
193 if (tkline_time)
194 sendto_match_servs(source_p, target_server, CAP_ENCAP,
195 "ENCAP %s XLINE %d %s 0 :%s",
196 target_server, (int)tkline_time, gecos, reason);
197 else
198 sendto_match_servs(source_p, target_server, CAP_CLUSTER,
199 "XLINE %s %s %d :%s",
200 target_server, gecos, (int)tkline_time, reason);
201
202 /* Allow ON to apply local xline as well if it matches */
203 if (match(target_server, me.name))
204 return 0;
205 }
206 else
207 {
208 if (tkline_time)
209 cluster_a_line(source_p, "ENCAP", CAP_ENCAP, SHARED_XLINE,
210 "XLINE %d %s 0 :%s", (int)tkline_time, gecos, reason);
211 else
212 cluster_a_line(source_p, "XLINE", CAP_KLN, SHARED_XLINE,
213 "%s 0 :%s", gecos, reason);
214 }
215
216 if (!valid_xline(source_p, gecos, reason))
217 return 0;
218
219 if ((conf = find_matching_name_conf(CONF_XLINE, gecos, NULL, NULL, 0)))
220 {
221 sendto_one_notice(source_p, &me, ":[%s] already X-Lined by [%s] - %s",
222 gecos, conf->name, conf->reason);
223 return 0;
224 }
225
226 write_xline(source_p, gecos, reason, tkline_time);
227 return 0;
228 }
229
230 /* ms_xline()
231 *
232 * inputs - oper, target server, xline, {type}, reason
233 *
234 * outputs - none
235 * side effects - propagates xline, applies it if we are a target
236 */
237 static int
238 ms_xline(struct Client *source_p, int parc, char *parv[])
239 {
240 if (parc != 5 || EmptyString(parv[4]))
241 return 0;
242
243 if (!IsClient(source_p))
244 return 0;
245
246 if (!valid_xline(source_p, parv[2], parv[4]))
247 return 0;
248
249 relay_xline(source_p, parv);
250 return 0;
251 }
252
253 /* me_xline()
254 *
255 * inputs - server
256 * - client (oper)
257 * - parc number of arguments
258 * - parv list of arguments
259 * via parv[]
260 * parv[1] = target server
261 * parv[2] = xline
262 * parv[3] = time
263 * parv[4] = reason
264 *
265 * outputs - none
266 * side effects -
267 */
268 static int
269 me_xline(struct Client *source_p, int parc, char *parv[])
270 {
271 if (!IsClient(source_p) || parc != 5)
272 return 0;
273
274 relay_xline(source_p, parv);
275 return 0;
276 }
277
278 static struct Message xline_msgtab =
279 {
280 "XLINE", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
281 { m_unregistered, m_not_oper, ms_xline, me_xline, mo_xline, m_ignore }
282 };
283
284 static void
285 module_init(void)
286 {
287 mod_add_cmd(&xline_msgtab);
288 }
289
290 static void
291 module_exit(void)
292 {
293 mod_del_cmd(&xline_msgtab);
294 }
295
296 struct module module_entry =
297 {
298 .node = { NULL, NULL, NULL },
299 .name = NULL,
300 .version = "$Revision$",
301 .handle = NULL,
302 .modinit = module_init,
303 .modexit = module_exit,
304 .flags = 0
305 };

Properties

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

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