/[svn]/ircd-hybrid/branches/8.2.x/modules/core/m_kill.c
ViewVC logotype

Contents of /ircd-hybrid/branches/8.2.x/modules/core/m_kill.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8436 - (show annotations)
Thu Mar 29 09:04:53 2018 UTC (4 years, 6 months ago) by michael
File MIME type: text/x-chdr
File size: 8778 byte(s)
- Stylistic changes

1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2018 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
61 if (EmptyString(parv[1]))
62 {
63 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "KILL");
64 return 0;
65 }
66
67 char *reason = parv[2]; /* Either defined or NULL (parc >= 2!!) */
68 if (!EmptyString(reason))
69 {
70 if (strlen(reason) > (size_t)REASONLEN)
71 reason[REASONLEN] = '\0';
72 }
73 else
74 reason = def_reason;
75
76 struct Client *target_p;
77 if ((target_p = hash_find_client(parv[1])) == NULL)
78 {
79 /*
80 * If the user has recently changed nick, automatically
81 * rewrite the KILL for this new nickname--this keeps
82 * servers in synch when nick change and kill collide
83 */
84 if ((target_p = whowas_get_history(parv[1], ConfigGeneral.kill_chase_time_limit)) == NULL)
85 {
86 sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, parv[1]);
87 return 0;
88 }
89
90 sendto_one_notice(source_p, &me, ":KILL changed from %s to %s",
91 parv[1], target_p->name);
92 }
93
94 if (!MyConnect(target_p) && !HasOFlag(source_p, OPER_FLAG_KILL_REMOTE))
95 {
96 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "kill:remote");
97 return 0;
98 }
99
100 if (MyConnect(target_p) && !HasOFlag(source_p, OPER_FLAG_KILL))
101 {
102 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "kill");
103 return 0;
104 }
105
106 if (IsServer(target_p) || IsMe(target_p))
107 {
108 sendto_one_numeric(source_p, &me, ERR_CANTKILLSERVER);
109 return 0;
110 }
111
112 if (MyConnect(target_p))
113 sendto_one(target_p, ":%s!%s@%s KILL %s :%s",
114 source_p->name, source_p->username, source_p->host,
115 target_p->name, reason);
116
117 /*
118 * Do not change the format of this message. There's no point in changing messages
119 * that have been around for ever, for no reason..
120 */
121 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
122 "Received KILL message for %s!%s@%s[%s]. From %s Path: %s (%s)",
123 target_p->name, target_p->username, target_p->host,
124 target_p->servptr->name,
125 source_p->name, me.name, reason);
126
127 ilog(LOG_TYPE_KILL, "KILL From %s For %s Path %s (%s)",
128 source_p->name, target_p->name, me.name, reason);
129
130 /*
131 * And pass on the message to other servers. Note, that if KILL was changed,
132 * the message has to be sent to all links, also back.
133 */
134 if (!MyConnect(target_p))
135 {
136 sendto_server(source_p, 0, 0, ":%s KILL %s :%s!%s!%s!%s (%s)",
137 source_p->id, target_p->id, me.name, source_p->host,
138 source_p->username, source_p->name, reason);
139
140 /*
141 * Set FLAGS_KILLED. This prevents exit_client() from sending
142 * the unnecessary QUIT for this. (This flag should never be
143 * set in any other place)
144 */
145 AddFlag(target_p, FLAGS_KILLED);
146 }
147
148 snprintf(buf, sizeof(buf), "Killed (%s (%s))", source_p->name, reason);
149 exit_client(target_p, buf);
150 return 0;
151 }
152
153 /*! \brief KILL command handler
154 *
155 * \param source_p Pointer to allocated Client struct from which the message
156 * originally comes from. This can be a local or remote client.
157 * \param parc Integer holding the number of supplied arguments.
158 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
159 * pointers.
160 * \note Valid arguments for this command are:
161 * - parv[0] = command
162 * - parv[1] = kill victim
163 * - parv[2] = kill path and reason
164 */
165 static int
166 ms_kill(struct Client *source_p, int parc, char *parv[])
167 {
168 char buf[IRCD_BUFSIZE] = "";
169 char def_reason[] = CONF_NOREASON;
170
171 if (parc < 3 || EmptyString(parv[2]))
172 {
173 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "KILL");
174 return 0;
175 }
176
177 struct Client *target_p;
178 if ((target_p = find_person(source_p, parv[1])) == NULL)
179 return 0;
180
181 char *reason = strchr(parv[2], ' ');
182 if (reason)
183 *reason++ = '\0';
184 else
185 reason = def_reason;
186
187 if (IsServer(target_p) || IsMe(target_p))
188 {
189 sendto_one_numeric(source_p, &me, ERR_CANTKILLSERVER);
190 return 0;
191 }
192
193 if (MyConnect(target_p))
194 {
195 if (IsServer(source_p))
196 {
197 /* Don't send clients kills from a hidden server */
198 if ((IsHidden(source_p) || ConfigServerHide.hide_servers) && !HasUMode(target_p, UMODE_OPER))
199 sendto_one(target_p, ":%s KILL %s :%s",
200 me.name, target_p->name, reason);
201 else
202 sendto_one(target_p, ":%s KILL %s :%s",
203 source_p->name, target_p->name, reason);
204 }
205 else
206 sendto_one(target_p, ":%s!%s@%s KILL %s :%s",
207 source_p->name, source_p->username, source_p->host,
208 target_p->name, reason);
209 }
210
211 /*
212 * Be warned, this message must be From %s, or it confuses clients
213 * so don't change it to From: or the case or anything! -- fl -- db
214 */
215 /*
216 * Path must contain at least 2 !'s, or bitchx falsely declares it
217 * local --fl
218 */
219 if (IsClient(source_p)) /* Send it normally */
220 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
221 "Received KILL message for %s!%s@%s[%s]. From %s Path: %s!%s!%s!%s %s",
222 target_p->name, target_p->username, target_p->host,
223 target_p->servptr->name,
224 source_p->name,
225 source_p->servptr->name, source_p->host, source_p->username,
226 source_p->name, reason);
227 else
228 sendto_realops_flags(UMODE_SKILL, L_ALL, SEND_NOTICE,
229 "Received KILL message for %s!%s@%s[%s]. From %s %s",
230 target_p->name, target_p->username, target_p->host,
231 target_p->servptr->name,
232 source_p->name, reason);
233
234 ilog(LOG_TYPE_KILL, "KILL From %s For %s Path %s %s",
235 source_p->name, target_p->name, source_p->name, reason);
236
237 sendto_server(source_p, 0, 0, ":%s KILL %s :%s %s",
238 source_p->id, target_p->id, parv[2], reason);
239 AddFlag(target_p, FLAGS_KILLED);
240
241 /* Reason comes supplied with its own ()'s */
242 if (IsServer(source_p) && (IsHidden(source_p) || ConfigServerHide.hide_servers))
243 snprintf(buf, sizeof(buf), "Killed (%s %s)", me.name, reason);
244 else
245 snprintf(buf, sizeof(buf), "Killed (%s %s)", source_p->name, reason);
246
247 exit_client(target_p, buf);
248 return 0;
249 }
250
251
252 static struct Message kill_msgtab =
253 {
254 .cmd = "KILL",
255 .args_min = 2,
256 .args_max = MAXPARA,
257 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
258 .handlers[CLIENT_HANDLER] = m_not_oper,
259 .handlers[SERVER_HANDLER] = ms_kill,
260 .handlers[ENCAP_HANDLER] = m_ignore,
261 .handlers[OPER_HANDLER] = mo_kill
262 };
263
264 static void
265 module_init(void)
266 {
267 mod_add_cmd(&kill_msgtab);
268 }
269
270 static void
271 module_exit(void)
272 {
273 mod_del_cmd(&kill_msgtab);
274 }
275
276 struct module module_entry =
277 {
278 .version = "$Revision$",
279 .modinit = module_init,
280 .modexit = module_exit,
281 .flags = MODULE_FLAG_CORE
282 };

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28