1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 1997-2014 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
* USA |
20 |
*/ |
21 |
|
22 |
/*! \file m_unkline.c |
23 |
* \brief Includes required functions for processing the UNKLINE 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 "hostmask.h" |
34 |
#include "numeric.h" |
35 |
#include "log.h" |
36 |
#include "misc.h" |
37 |
#include "send.h" |
38 |
#include "hash.h" |
39 |
#include "server.h" |
40 |
#include "parse.h" |
41 |
#include "modules.h" |
42 |
#include "conf_db.h" |
43 |
#include "memory.h" |
44 |
|
45 |
|
46 |
/* static int remove_tkline_match(const char *host, const char *user) |
47 |
* Input: A hostname, a username to unkline. |
48 |
* Output: returns YES on success, NO if no tkline removed. |
49 |
* Side effects: Any matching tklines are removed. |
50 |
*/ |
51 |
static int |
52 |
remove_kline_match(const char *host, const char *user) |
53 |
{ |
54 |
struct irc_ssaddr iphost, *piphost; |
55 |
struct MaskItem *conf; |
56 |
int t = 0; |
57 |
int aftype = 0; |
58 |
|
59 |
if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST) |
60 |
{ |
61 |
#ifdef IPV6 |
62 |
if (t == HM_IPV6) |
63 |
aftype = AF_INET6; |
64 |
else |
65 |
#endif |
66 |
aftype = AF_INET; |
67 |
piphost = &iphost; |
68 |
} |
69 |
else |
70 |
piphost = NULL; |
71 |
|
72 |
if ((conf = find_conf_by_address(host, piphost, CONF_KLINE, aftype, user, NULL, 0))) |
73 |
{ |
74 |
if (IsConfDatabase(conf)) |
75 |
{ |
76 |
delete_one_address_conf(host, conf); |
77 |
return 1; |
78 |
} |
79 |
} |
80 |
|
81 |
return 0; |
82 |
} |
83 |
|
84 |
/*! \brief UNKLINE command handler |
85 |
* |
86 |
* \param source_p Pointer to allocated Client struct from which the message |
87 |
* originally comes from. This can be a local or remote client. |
88 |
* \param parc Integer holding the number of supplied arguments. |
89 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
90 |
* pointers. |
91 |
* \note Valid arguments for this command are: |
92 |
* - parv[0] = command |
93 |
* - parv[1] = user\@host mask |
94 |
* - parv[2] = "ON" |
95 |
* - parv[3] = target server |
96 |
*/ |
97 |
static int |
98 |
mo_unkline(struct Client *source_p, int parc, char *parv[]) |
99 |
{ |
100 |
char *target_server = NULL; |
101 |
char *user, *host; |
102 |
|
103 |
if (!HasOFlag(source_p, OPER_FLAG_UNKLINE)) |
104 |
{ |
105 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "unkline"); |
106 |
return 0; |
107 |
} |
108 |
|
109 |
if (EmptyString(parv[1])) |
110 |
{ |
111 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "UNKLINE"); |
112 |
return 0; |
113 |
} |
114 |
|
115 |
if (parse_aline("UNKLINE", source_p, parc, parv, 0, &user, |
116 |
&host, NULL, &target_server, NULL) < 0) |
117 |
return 0; |
118 |
|
119 |
if (target_server) |
120 |
{ |
121 |
sendto_match_servs(source_p, target_server, CAP_UNKLN, |
122 |
"UNKLINE %s %s %s", |
123 |
target_server, user, host); |
124 |
|
125 |
/* Allow ON to apply local unkline as well if it matches */ |
126 |
if (match(target_server, me.name)) |
127 |
return 0; |
128 |
} |
129 |
else |
130 |
cluster_a_line(source_p, "UNKLINE", CAP_UNKLN, SHARED_UNKLINE, |
131 |
"%s %s", user, host); |
132 |
|
133 |
if (remove_kline_match(host, user)) |
134 |
{ |
135 |
sendto_one_notice(source_p, &me, ":K-Line for [%s@%s] is removed", user, host); |
136 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
137 |
"%s has removed the K-Line for: [%s@%s]", |
138 |
get_oper_name(source_p), user, host); |
139 |
ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]", |
140 |
get_oper_name(source_p), user, host); |
141 |
} |
142 |
else |
143 |
sendto_one_notice(source_p, &me, ":No K-Line for [%s@%s] found", |
144 |
user, host); |
145 |
return 0; |
146 |
} |
147 |
|
148 |
/*! \brief UNKLINE command handler |
149 |
* |
150 |
* \param source_p Pointer to allocated Client struct from which the message |
151 |
* originally comes from. This can be a local or remote client. |
152 |
* \param parc Integer holding the number of supplied arguments. |
153 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
154 |
* pointers. |
155 |
* \note Valid arguments for this command are: |
156 |
* - parv[0] = command |
157 |
* - parv[1] = target server |
158 |
* - parv[2] = user mask |
159 |
* - parv[3] = host mask |
160 |
*/ |
161 |
static int |
162 |
me_unkline(struct Client *source_p, int parc, char *parv[]) |
163 |
{ |
164 |
const char *kuser, *khost; |
165 |
|
166 |
if (parc != 4) |
167 |
return 0; |
168 |
|
169 |
kuser = parv[2]; |
170 |
khost = parv[3]; |
171 |
|
172 |
if (!IsClient(source_p) || match(parv[1], me.name)) |
173 |
return 0; |
174 |
|
175 |
if (HasFlag(source_p, FLAGS_SERVICE) || |
176 |
find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
177 |
source_p->username, source_p->host, |
178 |
SHARED_UNKLINE)) |
179 |
{ |
180 |
if (remove_kline_match(khost, kuser)) |
181 |
{ |
182 |
sendto_one_notice(source_p, &me, ":K-Line for [%s@%s] is removed", |
183 |
kuser, khost); |
184 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
185 |
"%s has removed the K-Line for: [%s@%s]", |
186 |
get_oper_name(source_p), kuser, khost); |
187 |
ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]", |
188 |
get_oper_name(source_p), kuser, khost); |
189 |
} |
190 |
else |
191 |
sendto_one_notice(source_p, &me, ":No K-Line for [%s@%s] found", |
192 |
kuser, khost); |
193 |
} |
194 |
|
195 |
return 0; |
196 |
} |
197 |
|
198 |
/*! \brief UNKLINE command handler |
199 |
* |
200 |
* \param source_p Pointer to allocated Client struct from which the message |
201 |
* originally comes from. This can be a local or remote client. |
202 |
* \param parc Integer holding the number of supplied arguments. |
203 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
204 |
* pointers. |
205 |
* \note Valid arguments for this command are: |
206 |
* - parv[0] = command |
207 |
* - parv[1] = target server |
208 |
* - parv[2] = user mask |
209 |
* - parv[3] = host mask |
210 |
*/ |
211 |
static int |
212 |
ms_unkline(struct Client *source_p, int parc, char *parv[]) |
213 |
{ |
214 |
if (parc != 4) |
215 |
return 0; |
216 |
|
217 |
sendto_match_servs(source_p, parv[1], CAP_UNKLN, |
218 |
"UNKLINE %s %s %s", |
219 |
parv[1], parv[2], parv[3]); |
220 |
|
221 |
return me_unkline(source_p, parc, parv); |
222 |
} |
223 |
|
224 |
static struct Message unkline_msgtab = |
225 |
{ |
226 |
"UNKLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
227 |
{ m_unregistered, m_not_oper, ms_unkline, me_unkline, mo_unkline, m_ignore } |
228 |
}; |
229 |
|
230 |
static void |
231 |
module_init(void) |
232 |
{ |
233 |
mod_add_cmd(&unkline_msgtab); |
234 |
add_capability("UNKLN", CAP_UNKLN, 1); |
235 |
} |
236 |
|
237 |
static void |
238 |
module_exit(void) |
239 |
{ |
240 |
mod_del_cmd(&unkline_msgtab); |
241 |
delete_capability("UNKLN"); |
242 |
} |
243 |
|
244 |
struct module module_entry = |
245 |
{ |
246 |
.node = { NULL, NULL, NULL }, |
247 |
.name = NULL, |
248 |
.version = "$Revision$", |
249 |
.handle = NULL, |
250 |
.modinit = module_init, |
251 |
.modexit = module_exit, |
252 |
.flags = 0 |
253 |
}; |