ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/core/m_kill.c
Revision: 1309
Committed: Sun Mar 25 11:24:18 2012 UTC (12 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/core/m_kill.c
File size: 9532 byte(s)
Log Message:
- renaming files:

  ircd_parser.y -> conf_parser.y
  ircd_lexer.l  -> conf_lexer.l
  s_conf.c      -> conf.c
  s_conf.h      -> conf.h
  s_log.c       -> log.c
  s_log.h       -> log.h

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

Properties

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