]> jfr.im git - solanum.git/blob - modules/core/m_kill.c
Migrate remaining modules to AV2
[solanum.git] / modules / core / m_kill.c
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_kill.c: Kills a user.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 */
24
25 #include "stdinc.h"
26 #include "client.h"
27 #include "hash.h" /* for find_client() */
28 #include "ircd.h"
29 #include "numeric.h"
30 #include "logger.h"
31 #include "s_serv.h"
32 #include "s_conf.h"
33 #include "send.h"
34 #include "whowas.h"
35 #include "match.h"
36 #include "msg.h"
37 #include "parse.h"
38 #include "modules.h"
39 #include "s_newconf.h"
40
41 static int h_can_kill;
42 static char buf[BUFSIZE];
43
44 static int ms_kill(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
45 static int mo_kill(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
46 static void relay_kill(struct Client *, struct Client *, struct Client *,
47 const char *, const char *);
48
49 struct Message kill_msgtab = {
50 "KILL", 0, 0, 0, 0,
51 {mg_unreg, mg_not_oper, {ms_kill, 2}, {ms_kill, 2}, mg_ignore, {mo_kill, 2}}
52 };
53
54 mapi_clist_av1 kill_clist[] = { &kill_msgtab, NULL };
55
56 mapi_hlist_av1 kill_hlist[] = {
57 { "can_kill", &h_can_kill },
58 { NULL, NULL},
59 };
60
61 DECLARE_MODULE_AV2(kill, NULL, NULL, kill_clist, kill_hlist, NULL, NULL, NULL, NULL);
62
63 /*
64 ** mo_kill
65 ** parv[1] = kill victim
66 ** parv[2] = kill path
67 */
68 static int
69 mo_kill(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
70 {
71 struct Client *target_p;
72 const char *inpath = client_p->name;
73 const char *user;
74 const char *reason;
75 hook_data_client_approval moduledata;
76
77 user = parv[1];
78
79 if(!IsOperLocalKill(source_p))
80 {
81 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "local_kill");
82 return 0;
83 }
84
85 if(!EmptyString(parv[2]))
86 {
87 char *s;
88 s = LOCAL_COPY(parv[2]);
89 if(strlen(s) > (size_t) KILLLEN)
90 s[KILLLEN] = '\0';
91 reason = s;
92 }
93 else
94 reason = "<No reason given>";
95
96 if((target_p = find_named_person(user)) == NULL)
97 {
98 /*
99 ** If the user has recently changed nick, automatically
100 ** rewrite the KILL for this new nickname--this keeps
101 ** servers in synch when nick change and kill collide
102 */
103 if((target_p = whowas_get_history(user, (long) KILLCHASETIMELIMIT)) == NULL)
104 {
105 if (strchr(user, '.'))
106 sendto_one_numeric(source_p, ERR_CANTKILLSERVER, form_str(ERR_CANTKILLSERVER));
107 else
108 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
109 form_str(ERR_NOSUCHNICK), user);
110 return 0;
111 }
112 sendto_one_notice(source_p, ":KILL changed from %s to %s", user, target_p->name);
113 }
114
115 if(!MyConnect(target_p) && (!IsOperGlobalKill(source_p)))
116 {
117 sendto_one_notice(source_p, ":Nick %s is not on your server "
118 "and you do not have the global_kill flag",
119 target_p->name);
120 return 0;
121 }
122
123 /* Last chance to stop the kill */
124 moduledata.client = source_p;
125 moduledata.target = target_p;
126 moduledata.approved = 1;
127 call_hook(h_can_kill, &moduledata);
128
129 if (moduledata.approved == 0)
130 /* The callee should have sent a message. */
131 return 0;
132
133 if(MyConnect(target_p))
134 sendto_one(target_p, ":%s!%s@%s KILL %s :%s",
135 source_p->name, source_p->username, source_p->host,
136 target_p->name, reason);
137
138 /* Do not change the format of this message. There's no point in changing messages
139 * that have been around for ever, for no reason.. */
140 sendto_realops_snomask(SNO_GENERAL, L_ALL,
141 "Received KILL message for %s!%s@%s. From %s Path: %s (%s)",
142 target_p->name, target_p->username, target_p->orighost,
143 source_p->name, me.name, reason);
144
145 ilog(L_KILL, "%c %s %s!%s@%s %s %s",
146 MyConnect(target_p) ? 'L' : 'G', get_oper_name(source_p),
147 target_p->name, target_p->username, target_p->host, target_p->servptr->name, reason);
148
149 /*
150 ** And pass on the message to other servers. Note, that if KILL
151 ** was changed, the message has to be sent to all links, also
152 ** back.
153 ** Suicide kills are NOT passed on --SRB
154 */
155 if(!MyConnect(target_p))
156 {
157 relay_kill(client_p, source_p, target_p, inpath, reason);
158 /*
159 ** Set FLAGS_KILLED. This prevents exit_one_client from sending
160 ** the unnecessary QUIT for this. (This flag should never be
161 ** set in any other place)
162 */
163 target_p->flags |= FLAGS_KILLED;
164 }
165
166 sprintf(buf, "Killed (%s (%s))", source_p->name, reason);
167
168 exit_client(client_p, target_p, source_p, buf);
169
170 return 0;
171 }
172
173 /*
174 * ms_kill
175 * parv[1] = kill victim
176 * parv[2] = kill path and reason
177 */
178 static int
179 ms_kill(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
180 {
181 struct Client *target_p;
182 const char *user;
183 const char *reason;
184 char default_reason[] = "<No reason given>";
185 const char *path;
186
187 *buf = '\0';
188
189 user = parv[1];
190
191 if(EmptyString(parv[2]))
192 {
193 reason = default_reason;
194
195 /* hyb6 takes the nick of the killer from the path *sigh* --fl_ */
196 path = source_p->name;
197 }
198 else
199 {
200 char *s = LOCAL_COPY(parv[2]), *t;
201 t = strchr(s, ' ');
202
203 if(t)
204 {
205 *t = '\0';
206 t++;
207 reason = t;
208 }
209 else
210 reason = default_reason;
211
212 path = s;
213 }
214
215 if((target_p = find_person(user)) == NULL)
216 {
217 /*
218 * If the user has recently changed nick, but only if its
219 * not an uid, automatically rewrite the KILL for this new nickname.
220 * --this keeps servers in synch when nick change and kill collide
221 */
222 if(IsDigit(*user) || (!(target_p = whowas_get_history(user, (long) KILLCHASETIMELIMIT))))
223 {
224 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
225 form_str(ERR_NOSUCHNICK), IsDigit(*user) ? "*" : user);
226 return 0;
227 }
228 sendto_one_notice(source_p, ":KILL changed from %s to %s", user, target_p->name);
229 }
230
231 if(IsServer(target_p) || IsMe(target_p))
232 {
233 sendto_one_numeric(source_p, ERR_CANTKILLSERVER, form_str(ERR_CANTKILLSERVER));
234 return 0;
235 }
236
237 if(MyConnect(target_p))
238 {
239 if(IsServer(source_p))
240 {
241 sendto_one(target_p, ":%s KILL %s :%s",
242 source_p->name, target_p->name, reason);
243 }
244 else
245 sendto_one(target_p, ":%s!%s@%s KILL %s :%s",
246 source_p->name, source_p->username, source_p->host,
247 target_p->name, reason);
248 }
249
250 /* Be warned, this message must be From %s, or it confuses clients
251 * so dont change it to From: or the case or anything! -- fl -- db */
252 /* path must contain at least 2 !'s, or bitchx falsely declares it
253 * local --fl
254 */
255 if(IsOper(source_p)) /* send it normally */
256 {
257 sendto_realops_snomask(IsService(source_p) ? SNO_SKILL : SNO_GENERAL, L_ALL,
258 "Received KILL message for %s!%s@%s. From %s Path: %s!%s!%s!%s %s",
259 target_p->name, target_p->username, target_p->orighost, source_p->name,
260 source_p->servptr->name, source_p->host, source_p->username,
261 source_p->name, reason);
262
263 ilog(L_KILL, "%c %s %s!%s@%s %s %s",
264 MyConnect(target_p) ? 'O' : 'R', get_oper_name(source_p),
265 target_p->name, target_p->username, target_p->host,
266 target_p->servptr->name, reason);
267 }
268 else
269 {
270 sendto_realops_snomask(SNO_SKILL, L_ALL,
271 "Received KILL message for %s!%s@%s. From %s %s",
272 target_p->name, target_p->username, target_p->orighost,
273 source_p->name, reason);
274
275 ilog(L_KILL, "S %s %s!%s@%s %s %s",
276 source_p->name, target_p->name, target_p->username,
277 target_p->host, target_p->servptr->name, reason);
278 }
279
280 relay_kill(client_p, source_p, target_p, path, reason);
281
282 /* FLAGS_KILLED prevents a quit being sent out */
283 target_p->flags |= FLAGS_KILLED;
284
285 sprintf(buf, "Killed (%s %s)", source_p->name, reason);
286
287 exit_client(client_p, target_p, source_p, buf);
288
289 return 0;
290 }
291
292 static void
293 relay_kill(struct Client *one, struct Client *source_p,
294 struct Client *target_p, const char *inpath, const char *reason)
295 {
296 struct Client *client_p;
297 rb_dlink_node *ptr;
298 char buffer[BUFSIZE];
299
300 if(MyClient(source_p))
301 snprintf(buffer, sizeof(buffer),
302 "%s!%s!%s!%s (%s)",
303 me.name, source_p->host, source_p->username, source_p->name, reason);
304 else
305 snprintf(buffer, sizeof(buffer), "%s %s", inpath, reason);
306
307 RB_DLINK_FOREACH(ptr, serv_list.head)
308 {
309 client_p = ptr->data;
310
311 if(!client_p || client_p == one)
312 continue;
313
314 sendto_one(client_p, ":%s KILL %s :%s",
315 get_id(source_p, client_p), get_id(target_p, client_p), buffer);
316 }
317 }