ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/core/m_kill.c
Revision: 1410
Committed: Fri May 11 10:59:03 2012 UTC (14 years, 5 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/core/m_kill.c
File size: 9449 byte(s)
Log Message:
- mo_kill(): remove useless IsDigit() test. hash_find_client() doesn't do
  UID lookups, so we'll end up with ERR_NOSUCHNICK.

File Contents

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

Properties

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