ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_xline.c
Revision: 10024
Committed: Sat Jan 1 10:20:46 2022 UTC (3 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 7142 byte(s)
Log Message:
- Bump copyright years

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 2003-2022 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 "conf_cluster.h"
34 #include "conf_gecos.h"
35 #include "conf_shared.h"
36 #include "numeric.h"
37 #include "log.h"
38 #include "misc.h"
39 #include "send.h"
40 #include "server_capab.h"
41 #include "parse.h"
42 #include "modules.h"
43 #include "memory.h"
44
45
46 static void
47 xline_check(const struct GecosItem *gecos)
48 {
49 dlink_node *node, *node_next;
50
51 DLINK_FOREACH_SAFE(node, node_next, local_client_list.head)
52 {
53 struct Client *client = node->data;
54
55 if (IsDead(client))
56 continue;
57
58 if (match(gecos->mask, client->info) == 0)
59 conf_try_ban(client, CLIENT_BAN_XLINE, gecos->reason);
60 }
61 }
62
63 /* xline_handle()
64 *
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 xline_handle(struct Client *source_p, const struct aline_ctx *aline)
71 {
72 char buf[IRCD_BUFSIZE];
73
74 if (!HasFlag(source_p, FLAGS_SERVICE))
75 {
76 if (valid_wild_card_simple(aline->mask) == false)
77 {
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 struct GecosItem *gecos = gecos_find(aline->mask, match);
86 if (gecos)
87 {
88 if (IsClient(source_p))
89 sendto_one_notice(source_p, &me, ":[%s] already X-Lined by [%s] - %s",
90 aline->mask, gecos->mask, gecos->reason);
91 return;
92 }
93
94 if (aline->duration)
95 snprintf(buf, sizeof(buf), "Temporary X-line %ju min. - %.*s (%s)",
96 aline->duration / 60, REASONLEN, aline->reason, date_iso8601(0));
97 else
98 snprintf(buf, sizeof(buf), "%.*s (%s)", REASONLEN, aline->reason, date_iso8601(0));
99
100 gecos = gecos_make();
101 gecos->mask = xstrdup(aline->mask);
102 gecos->reason = xstrdup(buf);
103 gecos->setat = event_base->time.sec_real;
104 gecos->in_database = true;
105
106 if (aline->duration)
107 {
108 gecos->expire = event_base->time.sec_real + aline->duration;
109
110 if (IsClient(source_p))
111 sendto_one_notice(source_p, &me, ":Added temporary %ju min. X-Line [%s]",
112 aline->duration / 60, gecos->mask);
113
114 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
115 "%s added temporary %ju min. X-Line for [%s] [%s]",
116 get_oper_name(source_p), aline->duration / 60,
117 gecos->mask, gecos->reason);
118 ilog(LOG_TYPE_XLINE, "%s added temporary %ju min. X-Line for [%s] [%s]",
119 get_oper_name(source_p), aline->duration / 60, gecos->mask, gecos->reason);
120 }
121 else
122 {
123 if (IsClient(source_p))
124 sendto_one_notice(source_p, &me, ":Added X-Line [%s] [%s]",
125 gecos->mask, gecos->reason);
126
127 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
128 "%s added X-Line for [%s] [%s]",
129 get_oper_name(source_p), gecos->mask,
130 gecos->reason);
131 ilog(LOG_TYPE_XLINE, "%s added X-Line for [%s] [%s]",
132 get_oper_name(source_p), gecos->mask, gecos->reason);
133 }
134
135 xline_check(gecos);
136 }
137
138 /* 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 static void
149 mo_xline(struct Client *source_p, int parc, char *parv[])
150 {
151 struct aline_ctx aline = { .add = true, .simple_mask = true };
152
153 if (!HasOFlag(source_p, OPER_FLAG_XLINE))
154 {
155 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "xline");
156 return;
157 }
158
159 if (parse_aline("XLINE", source_p, parc, parv, &aline) == false)
160 return;
161
162 if (aline.server)
163 {
164 sendto_match_servs(source_p, aline.server, CAPAB_CLUSTER, "XLINE %s %s %ju :%s",
165 aline.server, aline.mask, aline.duration, aline.reason);
166
167 /* Allow ON to apply local xline as well if it matches */
168 if (match(aline.server, me.name))
169 return;
170 }
171 else
172 cluster_distribute(source_p, "XLINE", CAPAB_CLUSTER, CLUSTER_XLINE, "%s %ju :%s",
173 aline.mask, aline.mask, aline.reason);
174
175 xline_handle(source_p, &aline);
176 }
177
178 /*! \brief XLINE command handler
179 *
180 * \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 * - parv[1] = target server mask
188 * - parv[2] = gecos
189 * - parv[3] = duration in seconds
190 * - parv[4] = reason
191 */
192 static void
193 ms_xline(struct Client *source_p, int parc, char *parv[])
194 {
195 struct aline_ctx aline =
196 {
197 .add = true,
198 .simple_mask = true,
199 .mask = parv[2],
200 .reason = parv[4],
201 .server = parv[1],
202 .duration = strtoumax(parv[3], NULL, 10)
203 };
204
205 sendto_match_servs(source_p, aline.server, CAPAB_CLUSTER, "XLINE %s %s %ju :%s",
206 aline.server, aline.mask, aline.duration, aline.reason);
207
208 if (match(aline.server, me.name))
209 return;
210
211 if (HasFlag(source_p, FLAGS_SERVICE) ||
212 shared_find(SHARED_XLINE, source_p->servptr->name,
213 source_p->username, source_p->host))
214 xline_handle(source_p, &aline);
215 }
216
217 static struct Message xline_msgtab =
218 {
219 .cmd = "XLINE",
220 .handlers[UNREGISTERED_HANDLER] = { .handler = m_unregistered },
221 .handlers[CLIENT_HANDLER] = { .handler = m_not_oper },
222 .handlers[SERVER_HANDLER] = { .handler = ms_xline, .args_min = 5 },
223 .handlers[ENCAP_HANDLER] = { .handler = m_ignore },
224 .handlers[OPER_HANDLER] = { .handler = mo_xline, .args_min = 2 }
225 };
226
227 static void
228 module_init(void)
229 {
230 mod_add_cmd(&xline_msgtab);
231 }
232
233 static void
234 module_exit(void)
235 {
236 mod_del_cmd(&xline_msgtab);
237 }
238
239 struct module module_entry =
240 {
241 .version = "$Revision$",
242 .modinit = module_init,
243 .modexit = module_exit,
244 };

Properties

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