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: m_unkline.c 3347 2014-04-20 14:03:06Z michael $ |
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 |
/* |
85 |
** mo_unkline |
86 |
** Added Aug 31, 1997 |
87 |
** common (Keith Fralick) fralick@gate.net |
88 |
** |
89 |
** parv[0] = command |
90 |
** parv[1] = address to remove |
91 |
* |
92 |
* |
93 |
*/ |
94 |
static int |
95 |
mo_unkline(struct Client *source_p, int parc, char *parv[]) |
96 |
{ |
97 |
char *target_server = NULL; |
98 |
char *user, *host; |
99 |
|
100 |
if (!HasOFlag(source_p, OPER_FLAG_UNKLINE)) |
101 |
{ |
102 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "unkline"); |
103 |
return 0; |
104 |
} |
105 |
|
106 |
if (EmptyString(parv[1])) |
107 |
{ |
108 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "UNKLINE"); |
109 |
return 0; |
110 |
} |
111 |
|
112 |
if (parse_aline("UNKLINE", source_p, parc, parv, 0, &user, |
113 |
&host, NULL, &target_server, NULL) < 0) |
114 |
return 0; |
115 |
|
116 |
if (target_server != NULL) |
117 |
{ |
118 |
sendto_match_servs(source_p, target_server, CAP_UNKLN, |
119 |
"UNKLINE %s %s %s", |
120 |
target_server, user, host); |
121 |
|
122 |
/* Allow ON to apply local unkline as well if it matches */ |
123 |
if (match(target_server, me.name)) |
124 |
return 0; |
125 |
} |
126 |
else |
127 |
cluster_a_line(source_p, "UNKLINE", CAP_UNKLN, SHARED_UNKLINE, |
128 |
"%s %s", user, host); |
129 |
|
130 |
if (remove_kline_match(host, user)) |
131 |
{ |
132 |
sendto_one_notice(source_p, &me, ":K-Line for [%s@%s] is removed", |
133 |
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", |
142 |
user, host); |
143 |
return 0; |
144 |
} |
145 |
|
146 |
/* me_unkline() |
147 |
* |
148 |
* inputs - server |
149 |
* - client |
150 |
* - parc |
151 |
* - parv |
152 |
* outputs - none |
153 |
* side effects - if server is authorized, kline is removed |
154 |
* does not propagate message |
155 |
*/ |
156 |
static int |
157 |
me_unkline(struct Client *source_p, int parc, char *parv[]) |
158 |
{ |
159 |
const char *kuser, *khost; |
160 |
|
161 |
if (parc != 4) |
162 |
return 0; |
163 |
|
164 |
kuser = parv[2]; |
165 |
khost = parv[3]; |
166 |
|
167 |
if (!IsClient(source_p) || match(parv[1], me.name)) |
168 |
return 0; |
169 |
|
170 |
if (HasFlag(source_p, FLAGS_SERVICE) || |
171 |
find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
172 |
source_p->username, source_p->host, |
173 |
SHARED_UNKLINE)) |
174 |
{ |
175 |
if (remove_kline_match(khost, kuser)) |
176 |
{ |
177 |
sendto_one_notice(source_p, &me, ":K-Line for [%s@%s] is removed", |
178 |
kuser, khost); |
179 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
180 |
"%s has removed the K-Line for: [%s@%s]", |
181 |
get_oper_name(source_p), kuser, khost); |
182 |
ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]", |
183 |
get_oper_name(source_p), kuser, khost); |
184 |
} |
185 |
else |
186 |
sendto_one_notice(source_p, &me, ":No K-Line for [%s@%s] found", |
187 |
kuser, khost); |
188 |
} |
189 |
|
190 |
return 0; |
191 |
} |
192 |
|
193 |
/* ms_unkline - propagates and handles a remote unkline message */ |
194 |
static int |
195 |
ms_unkline(struct Client *source_p, int parc, char *parv[]) |
196 |
{ |
197 |
if (parc != 4) |
198 |
return 0; |
199 |
|
200 |
sendto_match_servs(source_p, parv[1], CAP_UNKLN, |
201 |
"UNKLINE %s %s %s", |
202 |
parv[1], parv[2], parv[3]); |
203 |
|
204 |
return me_unkline(source_p, parc, parv); |
205 |
} |
206 |
|
207 |
static struct Message unkline_msgtab = |
208 |
{ |
209 |
"UNKLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
210 |
{ m_unregistered, m_not_oper, ms_unkline, me_unkline, mo_unkline, m_ignore } |
211 |
}; |
212 |
|
213 |
static void |
214 |
module_init(void) |
215 |
{ |
216 |
mod_add_cmd(&unkline_msgtab); |
217 |
add_capability("UNKLN", CAP_UNKLN, 1); |
218 |
} |
219 |
|
220 |
static void |
221 |
module_exit(void) |
222 |
{ |
223 |
mod_del_cmd(&unkline_msgtab); |
224 |
delete_capability("UNKLN"); |
225 |
} |
226 |
|
227 |
struct module module_entry = |
228 |
{ |
229 |
.node = { NULL, NULL, NULL }, |
230 |
.name = NULL, |
231 |
.version = "$Revision: 3347 $", |
232 |
.handle = NULL, |
233 |
.modinit = module_init, |
234 |
.modexit = module_exit, |
235 |
.flags = 0 |
236 |
}; |