ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_xline.c
Revision: 5881
Committed: Sun May 3 16:04:15 2015 UTC (10 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 8180 byte(s)
Log Message:
- Use C99-style initializers in all struct Message items
- Removed MFLG_SLOW
- Removed DUMMY_HANDLER

File Contents

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

Properties

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