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: 1618
Committed: Tue Oct 30 21:04:38 2012 UTC (11 years, 4 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/modules/core/m_kill.c
File size: 9511 byte(s)
Log Message:
- Made m_globops() and ms_globops() use sendto_realops_flags()
- Added message-type parameter to sendto_realops_flags() which can be one of
  SEND_NOTICE, SEND_GLOBAL, SEND_LOCOPS
- Forward-port -r1617

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

Properties

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