ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_xline.c
Revision: 4340
Committed: Sat Aug 2 16:53:22 2014 UTC (11 years ago) by michael
Content type: text/x-csrc
File size: 8012 byte(s)
Log Message:
- Renamed structures to meet code conventions

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 2820 * Copyright (c) 2003-2014 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     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19     * 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 adx 30 #include "send.h"
36 michael 3347 #include "server.h"
37 adx 30 #include "parse.h"
38     #include "modules.h"
39 michael 1622 #include "conf_db.h"
40 michael 1666 #include "memory.h"
41 adx 30
42    
43 michael 2877 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 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 4274 valid_xline(struct Client *source_p, const char *gecos, const char *reason)
68 michael 2974 {
69     if (EmptyString(reason))
70     {
71 michael 4274 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "XLINE");
72 michael 2974 return 0;
73     }
74    
75     if (!valid_wild_card_simple(gecos))
76     {
77 michael 4274 sendto_one_notice(source_p, &me, ":Please include at least %u non-wildcard characters with the xline",
78 michael 4340 ConfigGeneral.min_nonwildcard_simple);
79 michael 2974 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 michael 3368 if (tkline_time)
104 michael 2974 {
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 michael 3110 sendto_one_notice(source_p, &me, ":Added temporary %d min. X-Line [%s]",
110     (int)tkline_time/60, conf->name);
111 michael 2974 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 michael 3110 sendto_one_notice(source_p, &me, ":Added X-Line [%s] [%s]",
122     conf->name, conf->reason);
123 michael 2974 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 michael 3110 sendto_one_notice(source_p, &me, ":[%s] already X-Lined by [%s] - %s",
152     parv[2], conf->name, conf->reason);
153 michael 2974 return;
154     }
155    
156     write_xline(source_p, parv[2], parv[4], t_sec);
157     }
158     }
159    
160 adx 30 /* 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 michael 2820 static int
171 michael 3156 mo_xline(struct Client *source_p, int parc, char *parv[])
172 adx 30 {
173     char *reason = NULL;
174     char *gecos = NULL;
175 michael 1632 struct MaskItem *conf = NULL;
176 adx 30 char *target_server = NULL;
177     time_t tkline_time = 0;
178    
179 michael 2852 if (!HasOFlag(source_p, OPER_FLAG_XLINE))
180 adx 30 {
181 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "xline");
182 michael 2820 return 0;
183 adx 30 }
184    
185     /*
186     * XLINE <gecos> <time> ON <mask> :<reason>
187     * XLINE <gecos> ON <mask> :<reason>
188     */
189 michael 4274 if (parse_aline("XLINE", source_p, parc, parv, 0, &gecos, NULL,
190 adx 30 &tkline_time, &target_server, &reason) < 0)
191 michael 2820 return 0;
192 adx 30
193 michael 3368 if (target_server)
194 adx 30 {
195     /* if a given expire time is given, ENCAP it */
196 michael 3368 if (tkline_time)
197 adx 30 sendto_match_servs(source_p, target_server, CAP_ENCAP,
198 michael 2820 "ENCAP %s XLINE %d %s 0 :%s",
199     target_server, (int)tkline_time, gecos, reason);
200 adx 30 else
201     sendto_match_servs(source_p, target_server, CAP_CLUSTER,
202 michael 2820 "XLINE %s %s %d :%s",
203     target_server, gecos, (int)tkline_time, reason);
204 adx 30
205     /* Allow ON to apply local xline as well if it matches */
206 michael 1652 if (match(target_server, me.name))
207 michael 2820 return 0;
208 adx 30 }
209 michael 2820 else
210 adx 30 {
211 michael 3368 if (tkline_time)
212 adx 30 cluster_a_line(source_p, "ENCAP", CAP_ENCAP, SHARED_XLINE,
213 michael 2820 "XLINE %d %s 0 :%s", (int)tkline_time, gecos, reason);
214 adx 30 else
215     cluster_a_line(source_p, "XLINE", CAP_KLN, SHARED_XLINE,
216 michael 2820 "%s 0 :%s", gecos, reason);
217 adx 30 }
218    
219 michael 4274 if (!valid_xline(source_p, gecos, reason))
220 michael 2820 return 0;
221 adx 30
222 michael 2820 if ((conf = find_matching_name_conf(CONF_XLINE, gecos, NULL, NULL, 0)))
223 adx 30 {
224 michael 3110 sendto_one_notice(source_p, &me, ":[%s] already X-Lined by [%s] - %s",
225     gecos, conf->name, conf->reason);
226 michael 2820 return 0;
227 adx 30 }
228    
229     write_xline(source_p, gecos, reason, tkline_time);
230 michael 2820 return 0;
231 adx 30 }
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 michael 2820 static int
241 michael 3156 ms_xline(struct Client *source_p, int parc, char *parv[])
242 adx 30 {
243     if (parc != 5 || EmptyString(parv[4]))
244 michael 2820 return 0;
245 adx 30
246     if (!IsClient(source_p))
247 michael 2820 return 0;
248 adx 30
249 michael 4274 if (!valid_xline(source_p, parv[2], parv[4]))
250 michael 2820 return 0;
251 adx 30
252     relay_xline(source_p, parv);
253 michael 2820 return 0;
254 adx 30 }
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 michael 2828 * parv[1] = target server
264     * parv[2] = xline
265     * parv[3] = time
266     * parv[4] = reason
267 adx 30 *
268     * outputs - none
269 michael 2820 * side effects -
270 adx 30 */
271 michael 2820 static int
272 michael 3156 me_xline(struct Client *source_p, int parc, char *parv[])
273 adx 30 {
274     if (!IsClient(source_p) || parc != 5)
275 michael 2820 return 0;
276 adx 30
277     relay_xline(source_p, parv);
278 michael 2820 return 0;
279 adx 30 }
280    
281 michael 2820 static struct Message xline_msgtab =
282     {
283 michael 1230 "XLINE", 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 michael 2820 struct module module_entry =
300     {
301 michael 1230 .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