ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/core/m_kill.c
Revision: 1243
Committed: Fri Sep 30 10:47:53 2011 UTC (15 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/core/m_kill.c
File size: 9597 byte(s)
Log Message:
- move content of msg.h, ircd_handler.h and handlers.h into parse.h and
  remove headers accordingly
- killed common.h
- remove m_killhost.c and m_flags.c from contrib/
- sort out unused header includes here and there

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

Properties

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