ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_xline.c
Revision: 6318
Committed: Wed Aug 5 16:04:43 2015 UTC (10 years ago) by michael
Content type: text/x-csrc
File size: 8173 byte(s)
Log Message:
- Get rid of UMODE_ALL

File Contents

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

Properties

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