ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/core/m_kill.c
Revision: 1169
Committed: Fri Aug 12 18:45:03 2011 UTC (12 years, 7 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/core/m_kill.c
File size: 9495 byte(s)
Log Message:
- rename find_server to hash_find_server to satisfy naming convention
- pull m_services.c and m_jupe.c from contrib/
- style fixes in some places

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_kill.c: Kills a user.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
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 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "list.h"
27 #include "handlers.h"
28 #include "client.h"
29 #include "hash.h" /* for find_client() */
30 #include "ircd.h"
31 #include "numeric.h"
32 #include "s_log.h"
33 #include "s_serv.h"
34 #include "s_conf.h"
35 #include "send.h"
36 #include "whowas.h"
37 #include "irc_string.h"
38 #include "sprintf_irc.h"
39 #include "msg.h"
40 #include "parse.h"
41 #include "modules.h"
42
43
44 static char buf[IRCD_BUFSIZE];
45
46 static void ms_kill(struct Client *, struct Client *, int, char *[]);
47 static void mo_kill(struct Client *, struct Client *, int, char *[]);
48 static void relay_kill(struct Client *, struct Client *, struct Client *,
49 const char *, const char *);
50
51 struct Message kill_msgtab = {
52 "KILL", 0, 0, 2, 0, MFLG_SLOW, 0,
53 {m_unregistered, m_not_oper, ms_kill, m_ignore, mo_kill, m_ignore}
54 };
55
56 void
57 _modinit(void)
58 {
59 mod_add_cmd(&kill_msgtab);
60 }
61
62 void
63 _moddeinit(void)
64 {
65 mod_del_cmd(&kill_msgtab);
66 }
67
68 const char *_version = "$Revision$";
69
70 /* mo_kill()
71 * parv[0] = sender prefix
72 * parv[1] = kill victim
73 * parv[2] = kill path
74 */
75 static void
76 mo_kill(struct Client *client_p, struct Client *source_p,
77 int parc, char *parv[])
78 {
79 struct Client *target_p;
80 const char *inpath = client_p->name;
81 char *user;
82 char *reason;
83 char def_reason[] = "No reason";
84
85 user = parv[1];
86 reason = parv[2]; /* Either defined or NULL (parc >= 2!!) */
87
88 if (*user == '\0')
89 {
90 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
91 me.name, source_p->name, "KILL");
92 return;
93 }
94
95 if (IsDigit(*user)) /* opers shouldn't be trying uids anyway ;-) */
96 return;
97
98 if (!IsOperK(source_p) && !IsOperGlobalKill(source_p))
99 {
100 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
101 me.name, source_p->name);
102 return;
103 }
104
105 if (!EmptyString(reason))
106 {
107 if (strlen(reason) > (size_t)KILLLEN)
108 reason[KILLLEN] = '\0';
109 }
110 else
111 reason = def_reason;
112
113 if ((target_p = hash_find_client(user)) == NULL)
114 {
115 /*
116 * If the user has recently changed nick, automatically
117 * rewrite the KILL for this new nickname--this keeps
118 * servers in synch when nick change and kill collide
119 */
120 if ((target_p = get_history(user,
121 (time_t)ConfigFileEntry.kill_chase_time_limit))
122 == NULL)
123 {
124 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
125 me.name, source_p->name, user);
126 return;
127 }
128
129 sendto_one(source_p, ":%s NOTICE %s :KILL changed from %s to %s",
130 me.name, source_p->name, user, target_p->name);
131 }
132
133 if (IsServer(target_p) || IsMe(target_p))
134 {
135 sendto_one(source_p, form_str(ERR_CANTKILLSERVER),
136 me.name, source_p->name);
137 return;
138 }
139
140 if (!MyConnect(target_p) && !IsOperGlobalKill(source_p))
141 {
142 sendto_one(source_p, ":%s NOTICE %s :Nick %s isnt on your server",
143 me.name, source_p->name, target_p->name);
144 return;
145 }
146
147 if (MyConnect(target_p))
148 sendto_one(target_p, ":%s!%s@%s KILL %s :%s",
149 source_p->name, source_p->username, source_p->host,
150 target_p->name, reason);
151
152 /*
153 * Do not change the format of this message. There's no point in changing messages
154 * that have been around for ever, for no reason..
155 */
156 sendto_realops_flags(UMODE_ALL, L_ALL,
157 "Received KILL message for %s. From %s Path: %s (%s)",
158 target_p->name, source_p->name, me.name, reason);
159
160 ilog(L_INFO, "KILL From %s For %s Path %s (%s)",
161 source_p->name, target_p->name, me.name, reason);
162 log_oper_action(LOG_KILL_TYPE, source_p, "%s %s\n",
163 me.name, reason);
164
165 /*
166 * And pass on the message to other servers. Note, that if KILL
167 * was changed, the message has to be sent to all links, also
168 * back.
169 * Suicide kills are NOT passed on --SRB
170 */
171 if (!MyConnect(target_p))
172 {
173 relay_kill(client_p, source_p, target_p, inpath, reason);
174 /*
175 * Set FLAGS_KILLED. This prevents exit_one_client from sending
176 * the unnecessary QUIT for this. (This flag should never be
177 * set in any other place)
178 */
179 SetKilled(target_p);
180 }
181
182 snprintf(buf, sizeof(buf), "Killed (%s (%s))", source_p->name, reason);
183 exit_client(target_p, source_p, buf);
184 }
185
186 /* ms_kill()
187 * parv[0] = sender prefix
188 * parv[1] = kill victim
189 * parv[2] = kill path and reason
190 */
191 static void
192 ms_kill(struct Client *client_p, struct Client *source_p,
193 int parc, char *parv[])
194 {
195 struct Client *target_p;
196 char *user;
197 char *reason;
198 const char *path;
199 char def_reason[] = "No reason";
200
201 if (EmptyString(parv[1]))
202 {
203 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
204 me.name, source_p->name, "KILL");
205 return;
206 }
207
208 user = parv[1];
209
210 if (EmptyString(parv[2]))
211 {
212 reason = def_reason;
213
214 /* hyb6 takes the nick of the killer from the path *sigh* --fl_ */
215 path = source_p->name;
216 }
217 else
218 {
219 reason = strchr(parv[2], ' ');
220
221 if (reason != NULL)
222 *reason++ = '\0';
223 else
224 reason = def_reason;
225
226 path = parv[2];
227 }
228
229 if ((target_p = find_person(client_p, user)) == NULL)
230 {
231 /* If the user has recently changed nick, but only if its
232 * not an uid, automatically rewrite the KILL for this new nickname.
233 * --this keeps servers in synch when nick change and kill collide
234 */
235 if (IsDigit(*user)) /* Somehow an uid was not found in the hash ! */
236 return;
237 if ((target_p = get_history(user,
238 (time_t)ConfigFileEntry.kill_chase_time_limit))
239 == NULL)
240 {
241 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
242 me.name, source_p->name, user);
243 return;
244 }
245
246 sendto_one(source_p,":%s NOTICE %s :KILL changed from %s to %s",
247 me.name, source_p->name, user, target_p->name);
248 }
249
250 if (IsServer(target_p) || IsMe(target_p))
251 {
252 sendto_one(source_p, form_str(ERR_CANTKILLSERVER),
253 me.name, source_p->name);
254 return;
255 }
256
257 if (MyConnect(target_p))
258 {
259 if (IsServer(source_p))
260 {
261 /* dont send clients kills from a hidden server */
262 if ((IsHidden(source_p) || ConfigServerHide.hide_servers) && !IsOper(target_p))
263 sendto_one(target_p, ":%s KILL %s :%s",
264 me.name, target_p->name, reason);
265 else
266 sendto_one(target_p, ":%s KILL %s :%s",
267 source_p->name, target_p->name, reason);
268 }
269 else
270 sendto_one(target_p, ":%s!%s@%s KILL %s :%s",
271 source_p->name, source_p->username, source_p->host,
272 target_p->name, reason);
273 }
274
275 /* Be warned, this message must be From %s, or it confuses clients
276 * so dont change it to From: or the case or anything! -- fl -- db */
277 /* path must contain at least 2 !'s, or bitchx falsely declares it
278 * local --fl
279 */
280 if (IsOper(source_p)) /* send it normally */
281 sendto_realops_flags(UMODE_ALL, L_ALL,
282 "Received KILL message for %s. From %s Path: %s!%s!%s!%s %s",
283 target_p->name, source_p->name, source_p->servptr->name,
284 source_p->host, source_p->username, source_p->name, reason);
285 else
286 sendto_realops_flags(UMODE_SKILL, L_ALL,
287 "Received KILL message for %s. From %s %s",
288 target_p->name, source_p->name, reason);
289
290 ilog(L_INFO,"KILL From %s For %s Path %s %s",
291 source_p->name, target_p->name, source_p->name, reason);
292
293 relay_kill(client_p, source_p, target_p, path, reason);
294 SetKilled(target_p);
295
296 /* reason comes supplied with its own ()'s */
297 if (IsServer(source_p) && (IsHidden(source_p) || ConfigServerHide.hide_servers))
298 snprintf(buf, sizeof(buf), "Killed (%s %s)", me.name, reason);
299 else
300 snprintf(buf, sizeof(buf), "Killed (%s %s)", source_p->name, reason);
301
302 exit_client(target_p, source_p, buf);
303 }
304
305 static void
306 relay_kill(struct Client *one, struct Client *source_p,
307 struct Client *target_p, const char *inpath, const char *reason)
308 {
309 dlink_node *ptr;
310 struct Client *client_p;
311 const char *from, *to;
312
313 DLINK_FOREACH(ptr, serv_list.head)
314 {
315 client_p = ptr->data;
316
317 if (client_p == NULL || client_p == one)
318 continue;
319
320 /* use UID if possible */
321 from = ID_or_name(source_p, client_p);
322 to = ID_or_name(target_p, client_p);
323
324 if (MyClient(source_p))
325 {
326 sendto_one(client_p, ":%s KILL %s :%s!%s!%s!%s (%s)",
327 from, to,
328 me.name, source_p->host, source_p->username,
329 source_p->name, reason);
330 }
331 else
332 {
333 sendto_one(client_p, ":%s KILL %s :%s %s",
334 from, to, inpath, reason);
335 }
336 }
337 }
338

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision