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_undline.c |
23 |
* \brief Includes required functions for processing the UNDLINE 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 "conf.h" |
32 |
#include "ircd.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_tdline_match(const char *host, const char *user) |
47 |
* Input: An ip to undline. |
48 |
* Output: returns YES on success, NO if no tdline removed. |
49 |
* Side effects: Any matching tdlines are removed. |
50 |
*/ |
51 |
static int |
52 |
remove_dline_match(const char *host) |
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_DLINE, aftype, NULL, 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 UNDLINE 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] = IP address |
94 |
* - parv[2] = "ON" |
95 |
* - parv[3] = target server |
96 |
*/ |
97 |
static int |
98 |
mo_undline(struct Client *source_p, int parc, char *parv[]) |
99 |
{ |
100 |
char *addr = NULL, *user = NULL; |
101 |
char *target_server = NULL; |
102 |
|
103 |
if (!HasOFlag(source_p, OPER_FLAG_UNDLINE)) |
104 |
{ |
105 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "undline"); |
106 |
return 0; |
107 |
} |
108 |
|
109 |
if (parc < 2 || EmptyString(parv[1])) |
110 |
{ |
111 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "UNDLINE"); |
112 |
return 0; |
113 |
} |
114 |
|
115 |
if (parse_aline("UNDLINE", source_p, parc, parv, 0, &user, |
116 |
&addr, NULL, &target_server, NULL) < 0) |
117 |
return 0; |
118 |
|
119 |
if (target_server) |
120 |
{ |
121 |
sendto_match_servs(source_p, target_server, CAP_UNDLN, |
122 |
"UNDLINE %s %s", target_server, addr); |
123 |
|
124 |
/* Allow ON to apply local undline as well if it matches */ |
125 |
if (match(target_server, me.name)) |
126 |
return 0; |
127 |
} |
128 |
else |
129 |
cluster_a_line(source_p, "UNDLINE", CAP_UNDLN, SHARED_UNDLINE, "%s", addr); |
130 |
|
131 |
if (remove_dline_match(addr)) |
132 |
{ |
133 |
sendto_one_notice(source_p, &me, ":D-Line for [%s] is removed", addr); |
134 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
135 |
"%s has removed the D-Line for: [%s]", |
136 |
get_oper_name(source_p), addr); |
137 |
ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]", |
138 |
get_oper_name(source_p), addr); |
139 |
} |
140 |
else |
141 |
sendto_one_notice(source_p, &me, ":No D-Line for [%s] found", addr); |
142 |
|
143 |
return 0; |
144 |
} |
145 |
|
146 |
/*! \brief UNDLINE command handler |
147 |
* |
148 |
* \param source_p Pointer to allocated Client struct from which the message |
149 |
* originally comes from. This can be a local or remote client. |
150 |
* \param parc Integer holding the number of supplied arguments. |
151 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
152 |
* pointers. |
153 |
* \note Valid arguments for this command are: |
154 |
* - parv[0] = command |
155 |
* - parv[1] = target server |
156 |
* - parv[2] = IP address |
157 |
*/ |
158 |
static int |
159 |
ms_undline(struct Client *source_p, int parc, char *parv[]) |
160 |
{ |
161 |
const char *addr = parv[1]; |
162 |
|
163 |
if (parc != 3 || EmptyString(parv[2])) |
164 |
return 0; |
165 |
|
166 |
sendto_match_servs(source_p, parv[1], CAP_UNDLN, "UNDLINE %s %s", |
167 |
parv[1], parv[2]); |
168 |
|
169 |
if (!IsClient(source_p) || match(parv[1], me.name)) |
170 |
return 0; |
171 |
|
172 |
if (HasFlag(source_p, FLAGS_SERVICE) || |
173 |
find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
174 |
source_p->username, source_p->host, |
175 |
SHARED_UNDLINE)) |
176 |
{ |
177 |
if (remove_dline_match(addr)) |
178 |
{ |
179 |
sendto_one_notice(source_p, &me, ":D-Line for [%s] is removed", addr); |
180 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
181 |
"%s has removed the D-Line for: [%s]", |
182 |
get_oper_name(source_p), addr); |
183 |
ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]", |
184 |
get_oper_name(source_p), addr); |
185 |
} |
186 |
else |
187 |
sendto_one_notice(source_p, &me, ":No D-Line for [%s] found", addr); |
188 |
} |
189 |
|
190 |
return 0; |
191 |
} |
192 |
|
193 |
static struct Message undline_msgtab = |
194 |
{ |
195 |
"UNDLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
196 |
{ m_unregistered, m_not_oper, ms_undline, m_ignore, mo_undline, m_ignore } |
197 |
}; |
198 |
|
199 |
static void |
200 |
module_init(void) |
201 |
{ |
202 |
mod_add_cmd(&undline_msgtab); |
203 |
add_capability("UNDLN", CAP_UNDLN, 1); |
204 |
} |
205 |
|
206 |
static void |
207 |
module_exit(void) |
208 |
{ |
209 |
mod_del_cmd(&undline_msgtab); |
210 |
delete_capability("UNDLN"); |
211 |
} |
212 |
|
213 |
struct module module_entry = |
214 |
{ |
215 |
.node = { NULL, NULL, NULL }, |
216 |
.name = NULL, |
217 |
.version = "$Revision$", |
218 |
.handle = NULL, |
219 |
.modinit = module_init, |
220 |
.modexit = module_exit, |
221 |
.flags = 0 |
222 |
}; |