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