1 |
adx |
30 |
/* |
2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
|
|
* m_killhost.c: Kills a users with agree host. |
4 |
|
|
* |
5 |
|
|
* Copyright (C) 2002 by Ilya Shtift. |
6 |
|
|
* |
7 |
|
|
* This program is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* This program is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with this program; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
|
|
* USA |
21 |
|
|
* |
22 |
knight |
31 |
* $Id$ |
23 |
adx |
30 |
* |
24 |
|
|
*/ |
25 |
|
|
|
26 |
|
|
#include "stdinc.h" |
27 |
|
|
#include "handlers.h" |
28 |
|
|
#include "client.h" |
29 |
|
|
#include "common.h" |
30 |
|
|
#include "hash.h" |
31 |
|
|
#include "ircd.h" |
32 |
|
|
#include "numeric.h" |
33 |
|
|
#include "s_log.h" |
34 |
|
|
#include "s_serv.h" |
35 |
|
|
#include "s_conf.h" |
36 |
|
|
#include "send.h" |
37 |
|
|
#include "whowas.h" |
38 |
|
|
#include "irc_string.h" |
39 |
|
|
#include "sprintf_irc.h" |
40 |
|
|
#include "msg.h" |
41 |
|
|
#include "parse.h" |
42 |
|
|
#include "channel_mode.h" /* needed only for split_nuh() */ |
43 |
|
|
#include "modules.h" |
44 |
|
|
|
45 |
|
|
static void mo_killhost(struct Client *, struct Client *, int, char *[]); |
46 |
|
|
static void kh_relay_kill(struct Client *, struct Client *, struct Client *, |
47 |
|
|
const char *, const char *); |
48 |
|
|
|
49 |
|
|
struct Message killhost_msgtab = { |
50 |
|
|
"KILLHOST", 0, 0, 2, 0, MFLG_SLOW, 0, |
51 |
|
|
{ m_unregistered, m_ignore, m_ignore, m_ignore, mo_killhost, m_ignore } |
52 |
|
|
}; |
53 |
|
|
|
54 |
|
|
#ifndef STATIC_MODULES |
55 |
|
|
void |
56 |
|
|
_modinit(void) |
57 |
|
|
{ |
58 |
|
|
mod_add_cmd(&killhost_msgtab); |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
void |
62 |
|
|
_moddeinit(void) |
63 |
|
|
{ |
64 |
|
|
mod_del_cmd(&killhost_msgtab); |
65 |
|
|
} |
66 |
|
|
|
67 |
knight |
31 |
const char *_version = "$Revision$"; |
68 |
adx |
30 |
#endif |
69 |
|
|
|
70 |
|
|
/* mo_killhost() |
71 |
|
|
* Created May 5, 2003 |
72 |
|
|
* common (Ilya Shtift) ishtift@tagil.svrw.ru |
73 |
|
|
* |
74 |
|
|
* parv[0] = sender prefix |
75 |
|
|
* parv[1] = host |
76 |
|
|
* parv[2] = reason |
77 |
|
|
*/ |
78 |
|
|
static void |
79 |
|
|
mo_killhost(struct Client *client_p, struct Client *source_p, |
80 |
|
|
int parc, char *parv[]) |
81 |
|
|
{ |
82 |
|
|
dlink_node *ptr = NULL, *ptr_next = NULL; |
83 |
|
|
struct Client *target_p = NULL; |
84 |
|
|
const char *inpath = client_p->name; |
85 |
|
|
char *reason = NULL; |
86 |
|
|
char bufhost[IRCD_BUFSIZE]; |
87 |
michael |
620 |
char nick[NICKLEN + 1]; |
88 |
|
|
char user[USERLEN + 1]; |
89 |
|
|
char host[HOSTLEN + 1]; |
90 |
michael |
593 |
char def_reason[] = "No reason"; |
91 |
adx |
30 |
unsigned int count = 0; |
92 |
michael |
593 |
struct split_nuh_item nuh; |
93 |
adx |
30 |
|
94 |
|
|
if (!(IsOperK(source_p) || IsOperGlobalKill(source_p))) |
95 |
|
|
{ |
96 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
97 |
|
|
me.name, source_p->name); |
98 |
|
|
return; |
99 |
|
|
} |
100 |
|
|
|
101 |
michael |
593 |
nuh.nuhmask = parv[1]; |
102 |
michael |
620 |
nuh.nickptr = nick; |
103 |
|
|
nuh.userptr = user; |
104 |
|
|
nuh.hostptr = host; |
105 |
adx |
30 |
|
106 |
michael |
620 |
nuh.nicksize = sizeof(nick); |
107 |
|
|
nuh.usersize = sizeof(user); |
108 |
|
|
nuh.hostsize = sizeof(host); |
109 |
michael |
593 |
|
110 |
|
|
split_nuh(&nuh); |
111 |
|
|
|
112 |
adx |
30 |
if (!valid_wild_card(source_p, YES, 3, nick, user, host)) |
113 |
michael |
593 |
return; |
114 |
adx |
30 |
|
115 |
|
|
if (!EmptyString(parv[2])) |
116 |
|
|
{ |
117 |
|
|
reason = parv[2]; |
118 |
|
|
if (strlen(reason) > (size_t)KILLLEN) |
119 |
|
|
reason[KILLLEN] = '\0'; |
120 |
|
|
} |
121 |
|
|
else |
122 |
|
|
reason = def_reason; |
123 |
|
|
|
124 |
|
|
DLINK_FOREACH_SAFE(ptr, ptr_next, global_client_list.head) |
125 |
|
|
{ |
126 |
|
|
target_p = ptr->data; |
127 |
|
|
|
128 |
|
|
if (!IsClient(target_p) || (source_p == target_p)) |
129 |
|
|
continue; |
130 |
|
|
|
131 |
|
|
if (!MyConnect(target_p) && !IsOperGlobalKill(source_p)) |
132 |
|
|
continue; |
133 |
michael |
620 |
|
134 |
adx |
30 |
if (match(nick, target_p->name) && |
135 |
|
|
match(user, target_p->username) && |
136 |
|
|
match(host, target_p->host)) |
137 |
|
|
{ |
138 |
|
|
if (MyConnect(target_p)) |
139 |
|
|
sendto_one(target_p, ":%s!%s@%s KILL %s :%s", |
140 |
|
|
source_p->name, source_p->username, source_p->host, |
141 |
|
|
target_p->name, reason); |
142 |
|
|
|
143 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
144 |
|
|
"Received KILL message for %s. From %s Path: %s (%s)", |
145 |
|
|
target_p->name, source_p->name, me.name, reason); |
146 |
|
|
|
147 |
|
|
ilog(L_INFO,"KILL From %s For %s Path %s (%s)", |
148 |
|
|
source_p->name, target_p->name, me.name, reason); |
149 |
|
|
|
150 |
|
|
if (!MyConnect(target_p)) |
151 |
|
|
{ |
152 |
|
|
kh_relay_kill(client_p, source_p, target_p, inpath, reason); |
153 |
|
|
SetKilled(target_p); |
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
if (!count++) |
157 |
|
|
ircsprintf(bufhost, "Killed (%s (%s))", source_p->name, reason); |
158 |
|
|
|
159 |
|
|
exit_client(target_p, source_p, bufhost); |
160 |
|
|
} |
161 |
|
|
} |
162 |
|
|
|
163 |
|
|
if (count > 0) |
164 |
|
|
sendto_wallops_flags(UMODE_OPERWALL, source_p, "OPERWALL - KILLHOST %s %s", |
165 |
|
|
host, reason); |
166 |
|
|
|
167 |
|
|
sendto_one(source_p,":%s NOTICE %s :%u clients killed", |
168 |
|
|
me.name, source_p->name, count); |
169 |
|
|
} |
170 |
|
|
|
171 |
|
|
static void |
172 |
|
|
kh_relay_kill(struct Client *one, struct Client *source_p, struct Client *target_p, |
173 |
|
|
const char *inpath, const char *reason) |
174 |
|
|
{ |
175 |
|
|
dlink_node *ptr; |
176 |
|
|
struct Client *client_p; |
177 |
|
|
int introduce_killed_client; |
178 |
|
|
char *user; |
179 |
|
|
|
180 |
|
|
/* LazyLinks: |
181 |
|
|
* Check if each lazylink knows about target_p. |
182 |
|
|
* If it does, send the kill, introducing source_p if required. |
183 |
|
|
* If it doesn't either: |
184 |
|
|
* a) don't send the kill (risk ghosts) |
185 |
|
|
* b) introduce the client (and source_p, if required) |
186 |
|
|
* [rather redundant] |
187 |
|
|
* |
188 |
|
|
* Use a) if IsServer(source_p), but if an oper kills someone, |
189 |
|
|
* ensure we blow away any ghosts. |
190 |
|
|
* |
191 |
|
|
* -davidt |
192 |
|
|
*/ |
193 |
|
|
|
194 |
|
|
if(IsServer(source_p)) |
195 |
|
|
introduce_killed_client = 0; |
196 |
|
|
else |
197 |
|
|
introduce_killed_client = 1; |
198 |
|
|
|
199 |
|
|
DLINK_FOREACH(ptr, serv_list.head) |
200 |
|
|
{ |
201 |
|
|
client_p = ptr->data; |
202 |
|
|
|
203 |
|
|
if (client_p == one) |
204 |
|
|
continue; |
205 |
|
|
|
206 |
|
|
if (!introduce_killed_client) |
207 |
|
|
{ |
208 |
|
|
if (ServerInfo.hub && IsCapable(client_p, CAP_LL) ) |
209 |
|
|
{ |
210 |
|
|
if (((client_p->localClient->serverMask & |
211 |
|
|
target_p->lazyLinkClientExists) == 0)) |
212 |
|
|
{ |
213 |
|
|
/* target isn't known to lazy leaf, skip it */ |
214 |
|
|
continue; |
215 |
|
|
} |
216 |
|
|
} |
217 |
|
|
} |
218 |
|
|
/* force introduction of killed client but check that |
219 |
|
|
* its not on the server we're bursting too.. */ |
220 |
|
|
else if (strcmp(target_p->servptr->name,client_p->name)) |
221 |
|
|
client_burst_if_needed(client_p, target_p); |
222 |
|
|
|
223 |
|
|
/* introduce source of kill */ |
224 |
|
|
client_burst_if_needed(client_p, source_p); |
225 |
|
|
|
226 |
|
|
/* check the server supports TS6 */ |
227 |
|
|
if (IsCapable(client_p, CAP_TS6)) |
228 |
|
|
user = ID(target_p); |
229 |
|
|
else |
230 |
|
|
user = target_p->name; |
231 |
|
|
|
232 |
|
|
if (MyClient(source_p)) |
233 |
|
|
{ |
234 |
|
|
sendto_one(client_p, ":%s KILL %s :%s!%s!%s!%s (%s)", |
235 |
|
|
source_p->name, user, |
236 |
|
|
me.name, source_p->host, source_p->username, |
237 |
|
|
source_p->name, reason); |
238 |
|
|
} |
239 |
|
|
else |
240 |
|
|
{ |
241 |
|
|
sendto_one(client_p, ":%s KILL %s :%s %s", |
242 |
|
|
source_p->name, user, |
243 |
|
|
inpath, reason); |
244 |
|
|
} |
245 |
|
|
} |
246 |
|
|
} |