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: 7925
Committed: Sat Dec 31 13:57:24 2016 UTC (7 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 8830 byte(s)
Log Message:
- Update copyright years

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2017 ircd-hybrid development team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file m_kill.c
23 * \brief Includes required functions for processing the KILL command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "client.h"
30 #include "hash.h"
31 #include "ircd.h"
32 #include "numeric.h"
33 #include "log.h"
34 #include "server.h"
35 #include "conf.h"
36 #include "send.h"
37 #include "whowas.h"
38 #include "irc_string.h"
39 #include "parse.h"
40 #include "modules.h"
41
42
43 /*! \brief KILL command handler
44 *
45 * \param source_p Pointer to allocated Client struct from which the message
46 * originally comes from. This can be a local or remote client.
47 * \param parc Integer holding the number of supplied arguments.
48 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
49 * pointers.
50 * \note Valid arguments for this command are:
51 * - parv[0] = command
52 * - parv[1] = kill victim
53 * - parv[2] = reason
54 */
55 static int
56 mo_kill(struct Client *source_p, int parc, char *parv[])
57 {
58 char buf[IRCD_BUFSIZE] = "";
59 char def_reason[] = CONF_NOREASON;
60 struct Client *target_p = NULL;
61 char *reason = NULL;
62
63 if (EmptyString(parv[1]))
64 {
65 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "KILL");
66 return 0;
67 }
68
69 reason = parv[2]; /* Either defined or NULL (parc >= 2!!) */
70
71 if (!EmptyString(reason))
72 {
73 if (strlen(reason) > (size_t)REASONLEN)
74 reason[REASONLEN] = '\0';
75 }
76 else
77 reason = def_reason;
78
79 if ((target_p = hash_find_client(parv[1])) == NULL)
80 {
81 /*
82 * If the user has recently changed nick, automatically
83 * rewrite the KILL for this new nickname--this keeps
84 * servers in synch when nick change and kill collide
85 */
86 target_p = whowas_get_history(parv[1], ConfigGeneral.kill_chase_time_limit);
87
88 if (!target_p)
89 {
90 sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, parv[1]);
91 return 0;
92 }
93
94 sendto_one_notice(source_p, &me, ":KILL changed from %s to %s",
95 parv[1], target_p->name);
96 }
97
98 if (!MyConnect(target_p) && !HasOFlag(source_p, OPER_FLAG_KILL_REMOTE))
99 {
100 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "kill:remote");
101 return 0;
102 }
103
104 if (MyConnect(target_p) && !HasOFlag(source_p, OPER_FLAG_KILL))
105 {
106 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "kill");
107 return 0;
108 }
109
110 if (IsServer(target_p) || IsMe(target_p))
111 {
112 sendto_one_numeric(source_p, &me, ERR_CANTKILLSERVER);
113 return 0;
114 }
115
116 if (MyConnect(target_p))
117 sendto_one(target_p, ":%s!%s@%s KILL %s :%s",
118 source_p->name, source_p->username, source_p->host,
119 target_p->name, reason);
120
121 /*
122 * Do not change the format of this message. There's no point in changing messages
123 * that have been around for ever, for no reason..
124 */
125 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
126 "Received KILL message for %s!%s@%s[%s]. From %s Path: %s (%s)",
127 target_p->name, target_p->username, target_p->host,
128 target_p->servptr->name,
129 source_p->name, me.name, reason);
130
131 ilog(LOG_TYPE_KILL, "KILL From %s For %s Path %s (%s)",
132 source_p->name, target_p->name, me.name, reason);
133
134 /*
135 * And pass on the message to other servers. Note, that if KILL
136 * was changed, the message has to be sent to all links, also
137 * back.
138 */
139 if (!MyConnect(target_p))
140 {
141 sendto_server(source_p, 0, 0, ":%s KILL %s :%s!%s!%s!%s (%s)",
142 source_p->id, target_p->id, me.name, source_p->host,
143 source_p->username, source_p->name, reason);
144
145 /*
146 * Set FLAGS_KILLED. This prevents exit_client() from sending
147 * the unnecessary QUIT for this. (This flag should never be
148 * set in any other place)
149 */
150 AddFlag(target_p, FLAGS_KILLED);
151 }
152
153 snprintf(buf, sizeof(buf), "Killed (%s (%s))", source_p->name, reason);
154 exit_client(target_p, buf);
155 return 0;
156 }
157
158 /*! \brief KILL command handler
159 *
160 * \param source_p Pointer to allocated Client struct from which the message
161 * originally comes from. This can be a local or remote client.
162 * \param parc Integer holding the number of supplied arguments.
163 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
164 * pointers.
165 * \note Valid arguments for this command are:
166 * - parv[0] = command
167 * - parv[1] = kill victim
168 * - parv[2] = kill path and reason
169 */
170 static int
171 ms_kill(struct Client *source_p, int parc, char *parv[])
172 {
173 char buf[IRCD_BUFSIZE] = "";
174 char def_reason[] = CONF_NOREASON;
175 struct Client *target_p = NULL;
176 char *reason = NULL;
177
178 if (parc < 3 || EmptyString(parv[2]))
179 {
180 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "KILL");
181 return 0;
182 }
183
184 if ((target_p = find_person(source_p, parv[1])) == NULL)
185 return 0;
186
187 if ((reason = strchr(parv[2], ' ')))
188 *reason++ = '\0';
189 else
190 reason = def_reason;
191
192 if (IsServer(target_p) || IsMe(target_p))
193 {
194 sendto_one_numeric(source_p, &me, ERR_CANTKILLSERVER);
195 return 0;
196 }
197
198 if (MyConnect(target_p))
199 {
200 if (IsServer(source_p))
201 {
202 /* Don't send clients kills from a hidden server */
203 if ((IsHidden(source_p) || ConfigServerHide.hide_servers) && !HasUMode(target_p, UMODE_OPER))
204 sendto_one(target_p, ":%s KILL %s :%s",
205 me.name, target_p->name, reason);
206 else
207 sendto_one(target_p, ":%s KILL %s :%s",
208 source_p->name, target_p->name, reason);
209 }
210 else
211 sendto_one(target_p, ":%s!%s@%s KILL %s :%s",
212 source_p->name, source_p->username, source_p->host,
213 target_p->name, reason);
214 }
215
216 /*
217 * Be warned, this message must be From %s, or it confuses clients
218 * so don't change it to From: or the case or anything! -- fl -- db
219 */
220 /*
221 * Path must contain at least 2 !'s, or bitchx falsely declares it
222 * local --fl
223 */
224 if (IsClient(source_p)) /* Send it normally */
225 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
226 "Received KILL message for %s!%s@%s[%s]. From %s Path: %s!%s!%s!%s %s",
227 target_p->name, target_p->username, target_p->host,
228 target_p->servptr->name,
229 source_p->name,
230 source_p->servptr->name, source_p->host, source_p->username,
231 source_p->name, reason);
232 else
233 sendto_realops_flags(UMODE_SKILL, L_ALL, SEND_NOTICE,
234 "Received KILL message for %s!%s@%s[%s]. From %s %s",
235 target_p->name, target_p->username, target_p->host,
236 target_p->servptr->name,
237 source_p->name, reason);
238
239 ilog(LOG_TYPE_KILL, "KILL From %s For %s Path %s %s",
240 source_p->name, target_p->name, source_p->name, reason);
241
242 sendto_server(source_p, 0, 0, ":%s KILL %s :%s %s",
243 source_p->id, target_p->id, parv[2], reason);
244 AddFlag(target_p, FLAGS_KILLED);
245
246 /* Reason comes supplied with its own ()'s */
247 if (IsServer(source_p) && (IsHidden(source_p) || ConfigServerHide.hide_servers))
248 snprintf(buf, sizeof(buf), "Killed (%s %s)", me.name, reason);
249 else
250 snprintf(buf, sizeof(buf), "Killed (%s %s)", source_p->name, reason);
251
252 exit_client(target_p, buf);
253 return 0;
254 }
255
256
257 static struct Message kill_msgtab =
258 {
259 .cmd = "KILL",
260 .args_min = 2,
261 .args_max = MAXPARA,
262 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
263 .handlers[CLIENT_HANDLER] = m_not_oper,
264 .handlers[SERVER_HANDLER] = ms_kill,
265 .handlers[ENCAP_HANDLER] = m_ignore,
266 .handlers[OPER_HANDLER] = mo_kill
267 };
268
269 static void
270 module_init(void)
271 {
272 mod_add_cmd(&kill_msgtab);
273 }
274
275 static void
276 module_exit(void)
277 {
278 mod_del_cmd(&kill_msgtab);
279 }
280
281 struct module module_entry =
282 {
283 .version = "$Revision$",
284 .modinit = module_init,
285 .modexit = module_exit,
286 .flags = MODULE_FLAG_CORE
287 };

Properties

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