ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_xline.c
Revision: 9077
Committed: Sat Oct 12 20:15:17 2019 UTC (5 years, 10 months ago) by michael
Content type: text/x-csrc
File size: 7148 byte(s)
Log Message:
- Command handlers are now of type void again

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 8752 * Copyright (c) 2003-2019 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 michael 7209 #include "conf_cluster.h"
34 michael 7304 #include "conf_gecos.h"
35 michael 7209 #include "conf_shared.h"
36 adx 30 #include "numeric.h"
37 michael 1309 #include "log.h"
38 michael 5823 #include "misc.h"
39 adx 30 #include "send.h"
40 michael 8166 #include "server_capab.h"
41 adx 30 #include "parse.h"
42     #include "modules.h"
43 michael 1666 #include "memory.h"
44 adx 30
45    
46 michael 2877 static void
47 michael 7435 xline_check(const struct GecosItem *gecos)
48 michael 2877 {
49 michael 8026 dlink_node *node, *node_next;
50 michael 2877
51 michael 4815 DLINK_FOREACH_SAFE(node, node_next, local_client_list.head)
52 michael 2877 {
53 michael 4815 struct Client *client_p = node->data;
54 michael 2877
55     if (IsDead(client_p))
56     continue;
57    
58 michael 8603 if (match(gecos->mask, client_p->info) == 0)
59 michael 7304 conf_try_ban(client_p, CLIENT_BAN_XLINE, gecos->reason);
60 michael 2877 }
61     }
62    
63 michael 7415 /* xline_handle()
64 michael 2974 *
65     * inputs - client taking credit for xline, gecos, reason, xline type
66     * outputs - none
67     * side effects - when successful, adds an xline to the conf
68     */
69     static void
70 michael 8986 xline_handle(struct Client *source_p, const struct aline_ctx *aline)
71 michael 2974 {
72 michael 5865 char buf[IRCD_BUFSIZE];
73 michael 2974
74 michael 7415 if (!HasFlag(source_p, FLAGS_SERVICE))
75     {
76 michael 8680 if (valid_wild_card_simple(aline->mask) == false)
77 michael 7415 {
78     if (IsClient(source_p))
79     sendto_one_notice(source_p, &me, ":Please include at least %u non-wildcard characters with the xline",
80     ConfigGeneral.min_nonwildcard_simple);
81     return;
82     }
83     }
84    
85 michael 8431 struct GecosItem *gecos;
86 michael 8680 if ((gecos = gecos_find(aline->mask, match)))
87 michael 7415 {
88     if (IsClient(source_p))
89     sendto_one_notice(source_p, &me, ":[%s] already X-Lined by [%s] - %s",
90 michael 8680 aline->mask, gecos->mask, gecos->reason);
91 michael 7415 return;
92     }
93    
94 michael 8670 if (aline->duration)
95 michael 6782 snprintf(buf, sizeof(buf), "Temporary X-line %ju min. - %.*s (%s)",
96 michael 8670 aline->duration / 60, REASONLEN, aline->reason, date_iso8601(0));
97 michael 5865 else
98 michael 8670 snprintf(buf, sizeof(buf), "%.*s (%s)", REASONLEN, aline->reason, date_iso8601(0));
99 michael 5865
100 michael 7415 gecos = gecos_make();
101 michael 8680 gecos->mask = xstrdup(aline->mask);
102 michael 7304 gecos->reason = xstrdup(buf);
103 michael 8926 gecos->setat = event_base->time.sec_real;
104 michael 8658 gecos->in_database = true;
105 michael 2974
106 michael 8670 if (aline->duration)
107 michael 2974 {
108 michael 8926 gecos->expire = event_base->time.sec_real + aline->duration;
109 michael 5875
110 michael 4646 if (IsClient(source_p))
111 michael 6782 sendto_one_notice(source_p, &me, ":Added temporary %ju min. X-Line [%s]",
112 michael 8670 aline->duration / 60, gecos->mask);
113 michael 4890
114 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
115 michael 6782 "%s added temporary %ju min. X-Line for [%s] [%s]",
116 michael 8670 get_oper_name(source_p), aline->duration / 60,
117 michael 7304 gecos->mask, gecos->reason);
118 michael 6782 ilog(LOG_TYPE_XLINE, "%s added temporary %ju min. X-Line for [%s] [%s]",
119 michael 8670 get_oper_name(source_p), aline->duration / 60, gecos->mask, gecos->reason);
120 michael 2974 }
121     else
122     {
123 michael 4646 if (IsClient(source_p))
124     sendto_one_notice(source_p, &me, ":Added X-Line [%s] [%s]",
125 michael 7304 gecos->mask, gecos->reason);
126 michael 4890
127 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
128 michael 2974 "%s added X-Line for [%s] [%s]",
129 michael 7304 get_oper_name(source_p), gecos->mask,
130     gecos->reason);
131 michael 2974 ilog(LOG_TYPE_XLINE, "%s added X-Line for [%s] [%s]",
132 michael 7304 get_oper_name(source_p), gecos->mask, gecos->reason);
133 michael 2974 }
134    
135 michael 7304 xline_check(gecos);
136 michael 2974 }
137    
138 adx 30 /* mo_xline()
139     *
140     * inputs - pointer to server
141     * - pointer to client
142     * - parameter count
143     * - parameter list
144     * output -
145     * side effects - x line is added
146     *
147     */
148 michael 9077 static void
149 michael 3156 mo_xline(struct Client *source_p, int parc, char *parv[])
150 adx 30 {
151 michael 8680 struct aline_ctx aline = { .add = true, .simple_mask = true };
152 adx 30
153 michael 2852 if (!HasOFlag(source_p, OPER_FLAG_XLINE))
154 adx 30 {
155 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "xline");
156 michael 9077 return;
157 adx 30 }
158    
159 michael 8670 if (parse_aline("XLINE", source_p, parc, parv, &aline) == false)
160 michael 9077 return;
161 adx 30
162 michael 8670 if (aline.server)
163 adx 30 {
164 michael 8670 sendto_match_servs(source_p, aline.server, CAPAB_CLUSTER, "XLINE %s %s %ju :%s",
165 michael 8680 aline.server, aline.mask, aline.duration, aline.reason);
166 adx 30
167     /* Allow ON to apply local xline as well if it matches */
168 michael 8670 if (match(aline.server, me.name))
169 michael 9077 return;
170 adx 30 }
171 michael 2820 else
172 michael 7209 cluster_distribute(source_p, "XLINE", CAPAB_CLUSTER, CLUSTER_XLINE, "%s %ju :%s",
173 michael 8680 aline.mask, aline.mask, aline.reason);
174 adx 30
175 michael 8670 xline_handle(source_p, &aline);
176 adx 30 }
177    
178 michael 5870 /*! \brief XLINE command handler
179 adx 30 *
180 michael 5870 * \param source_p Pointer to allocated Client struct from which the message
181     * originally comes from. This can be a local or remote client.
182     * \param parc Integer holding the number of supplied arguments.
183     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
184     * pointers.
185     * \note Valid arguments for this command are:
186     * - parv[0] = command
187 michael 7094 * - parv[1] = target server mask
188 michael 5870 * - parv[2] = gecos
189 michael 7094 * - parv[3] = duration in seconds
190 michael 5870 * - parv[4] = reason
191 adx 30 */
192 michael 9077 static void
193 michael 3156 ms_xline(struct Client *source_p, int parc, char *parv[])
194 adx 30 {
195 michael 8670 struct aline_ctx aline =
196     {
197     .add = true,
198 michael 8680 .simple_mask = true,
199     .mask = parv[2],
200 michael 8670 .reason = parv[4],
201     .server = parv[1],
202     .duration = strtoumax(parv[3], NULL, 10)
203     };
204    
205     if (parc != 5 || EmptyString(parv[parc - 1]))
206 michael 9077 return;
207 adx 30
208 michael 8670 sendto_match_servs(source_p, aline.server, CAPAB_CLUSTER, "XLINE %s %s %ju :%s",
209 michael 8680 aline.server, aline.mask, aline.duration, aline.reason);
210 michael 4646
211 michael 8670 if (match(aline.server, me.name))
212 michael 9077 return;
213 adx 30
214 michael 7413 if (HasFlag(source_p, FLAGS_SERVICE) ||
215     shared_find(SHARED_XLINE, source_p->servptr->name,
216     source_p->username, source_p->host))
217 michael 8670 xline_handle(source_p, &aline);
218 adx 30 }
219    
220 michael 2820 static struct Message xline_msgtab =
221     {
222 michael 5881 .cmd = "XLINE",
223     .args_min = 2,
224     .args_max = MAXPARA,
225     .handlers[UNREGISTERED_HANDLER] = m_unregistered,
226     .handlers[CLIENT_HANDLER] = m_not_oper,
227     .handlers[SERVER_HANDLER] = ms_xline,
228 michael 6850 .handlers[ENCAP_HANDLER] = m_ignore,
229 michael 5881 .handlers[OPER_HANDLER] = mo_xline
230 michael 1230 };
231    
232     static void
233     module_init(void)
234     {
235     mod_add_cmd(&xline_msgtab);
236     }
237    
238     static void
239     module_exit(void)
240     {
241     mod_del_cmd(&xline_msgtab);
242     }
243    
244 michael 2820 struct module module_entry =
245     {
246 michael 1230 .version = "$Revision$",
247     .modinit = module_init,
248     .modexit = module_exit,
249     };

Properties

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