ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_dline.c
Revision: 10042
Committed: Sun May 29 10:56:11 2022 UTC (22 months, 2 weeks ago) by michael
Content type: text/x-csrc
File size: 8042 byte(s)
Log Message:
- Implemented the owner/admin channel prefix modes. These are optional and can be enabled with the channel::enable_owner and channel::enable_admin configuration directives

File Contents

# User Rev Content
1 michael 1058 /*
2 michael 2810 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 michael 1058 *
4 michael 10024 * Copyright (c) 1997-2022 ircd-hybrid development team
5 michael 1058 *
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 4564 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 michael 1058 * USA
20     */
21    
22 michael 2810 /*! \file m_dline.c
23 michael 3348 * \brief Includes required functions for processing the DLINE command.
24 michael 2810 * \version $Id$
25     */
26    
27 michael 1058 #include "stdinc.h"
28     #include "list.h"
29     #include "client.h"
30     #include "irc_string.h"
31 michael 1632 #include "conf.h"
32 michael 7208 #include "conf_cluster.h"
33     #include "conf_shared.h"
34 michael 1058 #include "ircd.h"
35     #include "hostmask.h"
36     #include "numeric.h"
37 michael 1309 #include "log.h"
38 michael 3347 #include "misc.h"
39 michael 1058 #include "send.h"
40 michael 8165 #include "server_capab.h"
41 michael 1058 #include "parse.h"
42     #include "modules.h"
43 michael 1666 #include "memory.h"
44 michael 1058
45    
46 michael 3930 static void
47 michael 7434 dline_check(const struct AddressRec *arec)
48 michael 3930 {
49 michael 8734 dlink_list *tab[] = { &local_client_list, &unknown_list, NULL };
50 michael 3930
51 michael 8734 for (dlink_list **list = tab; *list; ++list)
52 michael 3930 {
53 michael 8736 dlink_node *node, *node_next;
54    
55 michael 8734 DLINK_FOREACH_SAFE(node, node_next, (*list)->head)
56 michael 3930 {
57 michael 9582 struct Client *client = node->data;
58 michael 3930
59 michael 9582 if (IsDead(client))
60 michael 8734 continue;
61 michael 3930
62 michael 8734 switch (arec->masktype)
63     {
64 michael 9595 case HM_IPV6:
65 michael 8734 case HM_IPV4:
66 michael 9607 if (address_compare(&client->ip, &arec->Mask.ipa.addr, false, false, arec->Mask.ipa.bits) == true)
67 michael 9595 conf_try_ban(client, CLIENT_BAN_DLINE, arec->conf->reason);
68 michael 8734 break;
69 michael 9595 default:
70     assert(0);
71 michael 8734 }
72 michael 3930 }
73     }
74     }
75    
76 michael 5830 /* dline_add()
77 michael 1058 *
78     * inputs -
79     * output - NONE
80 michael 5830 * side effects - dline as given is placed
81 michael 1058 */
82     static void
83 michael 8985 dline_handle(struct Client *source_p, const struct aline_ctx *aline)
84 michael 1058 {
85 michael 5830 char buf[IRCD_BUFSIZE];
86 michael 8669 struct irc_ssaddr addr;
87 michael 8828 int bits = 0;
88 michael 5830
89 michael 8669 switch (parse_netmask(aline->host, &addr, &bits))
90 michael 7418 {
91     case HM_IPV4:
92     if (!HasFlag(source_p, FLAGS_SERVICE) && (unsigned int)bits < ConfigGeneral.dline_min_cidr)
93     {
94     if (IsClient(source_p))
95     sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
96     ConfigGeneral.dline_min_cidr);
97     return;
98     }
99    
100     break;
101     case HM_IPV6:
102     if (!HasFlag(source_p, FLAGS_SERVICE) && (unsigned int)bits < ConfigGeneral.dline_min_cidr6)
103     {
104     if (IsClient(source_p))
105     sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.",
106     ConfigGeneral.dline_min_cidr6);
107     return;
108     }
109    
110     break;
111     default: /* HM_HOST */
112 michael 8736 if (IsClient(source_p))
113     sendto_one_notice(source_p, &me, ":Invalid D-Line");
114    
115 michael 7418 return;
116     }
117    
118 michael 8430 struct MaskItem *conf;
119 michael 8828 if ((conf = find_conf_by_address(NULL, &addr, CONF_DLINE, NULL, NULL, 1)))
120 michael 7418 {
121     if (IsClient(source_p))
122     sendto_one_notice(source_p, &me, ":[%s] already D-lined by [%s] - %s",
123 michael 8669 aline->host, conf->host, conf->reason);
124 michael 7418 return;
125     }
126    
127 michael 8669 if (aline->duration)
128 michael 6781 snprintf(buf, sizeof(buf), "Temporary D-line %ju min. - %.*s (%s)",
129 michael 8669 aline->duration / 60, REASONLEN, aline->reason, date_iso8601(0));
130 michael 5830 else
131 michael 8669 snprintf(buf, sizeof(buf), "%.*s (%s)", REASONLEN, aline->reason, date_iso8601(0));
132 michael 5830
133 michael 7418 conf = conf_make(CONF_DLINE);
134 michael 8669 conf->host = xstrdup(aline->host);
135 michael 5830 conf->reason = xstrdup(buf);
136 michael 8927 conf->setat = event_base->time.sec_real;
137 michael 5830 SetConfDatabase(conf);
138    
139 michael 8669 if (aline->duration)
140 michael 1622 {
141 michael 8927 conf->until = event_base->time.sec_real + aline->duration;
142 michael 4640
143     if (IsClient(source_p))
144 michael 6781 sendto_one_notice(source_p, &me, ":Added temporary %ju min. D-Line [%s]",
145 michael 8669 aline->duration / 60, conf->host);
146 michael 4889
147 michael 6317 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
148 michael 6781 "%s added temporary %ju min. D-Line for [%s] [%s]",
149 michael 8669 get_oper_name(source_p), aline->duration / 60,
150 michael 1632 conf->host, conf->reason);
151 michael 6781 ilog(LOG_TYPE_DLINE, "%s added temporary %ju min. D-Line for [%s] [%s]",
152 michael 8669 get_oper_name(source_p), aline->duration / 60, conf->host, conf->reason);
153 michael 1622 }
154     else
155     {
156 michael 4640 if (IsClient(source_p))
157     sendto_one_notice(source_p, &me, ":Added D-Line [%s]", conf->host);
158    
159 michael 6317 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
160 michael 1622 "%s added D-Line for [%s] [%s]",
161 michael 1632 get_oper_name(source_p), conf->host, conf->reason);
162 michael 1622 ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]",
163 michael 1632 get_oper_name(source_p), conf->host, conf->reason);
164 michael 1622 }
165    
166 michael 5831 dline_check(add_conf_by_address(CONF_DLINE, conf));
167 michael 1058 }
168    
169     /* mo_dline()
170     *
171     * inputs - pointer to server
172     * - pointer to client
173     * - parameter count
174     * - parameter list
175     * output -
176     * side effects - D line is added
177     *
178     */
179 michael 9078 static void
180 michael 3156 mo_dline(struct Client *source_p, int parc, char *parv[])
181 michael 1058 {
182 michael 8679 struct aline_ctx aline = { .add = true, .simple_mask = false };
183 michael 1058
184 michael 1301 if (!HasOFlag(source_p, OPER_FLAG_DLINE))
185 michael 1058 {
186 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "dline");
187 michael 9078 return;
188 michael 1058 }
189    
190 michael 8669 if (parse_aline("DLINE", source_p, parc, parv, &aline) == false)
191 michael 9078 return;
192 michael 1058
193 michael 8669 if (aline.server)
194 michael 1301 {
195 michael 8669 sendto_match_servs(source_p, aline.server, CAPAB_DLN, "DLINE %s %ju %s :%s",
196     aline.server, aline.duration, aline.host, aline.reason);
197 michael 1301
198 michael 6431 /* Allow ON to apply local dline as well if it matches */
199 michael 8669 if (match(aline.server, me.name))
200 michael 9078 return;
201 michael 1301 }
202     else
203 michael 7208 cluster_distribute(source_p, "DLINE", CAPAB_DLN, CLUSTER_DLINE,
204 michael 8669 "%ju %s :%s", aline.duration, aline.host, aline.reason);
205 michael 1301
206 michael 8669 dline_handle(source_p, &aline);
207 michael 1058 }
208    
209 michael 7093 /*! \brief DLINE command handler
210     *
211     * \param source_p Pointer to allocated Client struct from which the message
212     * originally comes from. This can be a local or remote client.
213     * \param parc Integer holding the number of supplied arguments.
214     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
215     * pointers.
216     * \note Valid arguments for this command are:
217     * - parv[0] = command
218     * - parv[1] = target server mask
219     * - parv[2] = duration in seconds
220     * - parv[3] = IP address
221     * - parv[4] = reason
222     */
223 michael 9078 static void
224 michael 3156 ms_dline(struct Client *source_p, int parc, char *parv[])
225 michael 1301 {
226 michael 8669 struct aline_ctx aline =
227     {
228     .add = true,
229 michael 8679 .simple_mask = false,
230 michael 8669 .host = parv[3],
231     .reason = parv[4],
232     .server = parv[1],
233     .duration = strtoumax(parv[2], NULL, 10)
234     };
235 michael 1301
236 michael 8669 sendto_match_servs(source_p, aline.server, CAPAB_DLN, "DLINE %s %ju %s :%s",
237     aline.server, aline.duration, aline.host, aline.reason);
238 michael 1301
239 michael 8669 if (match(aline.server, me.name))
240 michael 9078 return;
241 michael 1301
242 michael 2810 if (HasFlag(source_p, FLAGS_SERVICE) ||
243 michael 7208 shared_find(SHARED_DLINE, source_p->servptr->name,
244     source_p->username, source_p->host))
245 michael 8669 dline_handle(source_p, &aline);
246 michael 1301 }
247    
248 michael 2810 static struct Message dline_msgtab =
249     {
250 michael 5880 .cmd = "DLINE",
251 michael 9373 .handlers[UNREGISTERED_HANDLER] = { .handler = m_unregistered },
252     .handlers[CLIENT_HANDLER] = { .handler = m_not_oper },
253     .handlers[SERVER_HANDLER] = { .handler = ms_dline, .args_min = 5 },
254     .handlers[ENCAP_HANDLER] = { .handler = m_ignore },
255     .handlers[OPER_HANDLER] = { .handler = mo_dline, .args_min = 2 }
256 michael 1230 };
257    
258     static void
259     module_init(void)
260     {
261     mod_add_cmd(&dline_msgtab);
262 michael 10042 capab_add("DLN", CAPAB_DLN, true);
263 michael 1230 }
264    
265     static void
266     module_exit(void)
267     {
268     mod_del_cmd(&dline_msgtab);
269 michael 8165 capab_del("DLN");
270 michael 1230 }
271    
272 michael 2810 struct module module_entry =
273     {
274 michael 1230 .version = "$Revision$",
275     .modinit = module_init,
276     .modexit = module_exit,
277     };

Properties

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