ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_xline.c
Revision: 3467
Committed: Sat May 3 15:39:44 2014 UTC (11 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 8073 byte(s)
Log Message:
- m_xline.c:write_xline(): removed collapse() call

File Contents

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