/[svn]/ircd-hybrid/trunk/modules/core/m_kill.c
ViewVC logotype

Contents of /ircd-hybrid/trunk/modules/core/m_kill.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4703 - (show annotations)
Sun Oct 5 16:19:05 2014 UTC (5 years, 11 months ago) by michael
File MIME type: text/x-chdr
File size: 8994 byte(s)
- m_kill.c:ms_kill(): replaced HasUMode(source_p, UMODE_OPER) with just IsClient(source_p)

1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2014 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)KILLLEN)
74 reason[KILLLEN] = '\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 if ((target_p = whowas_get_history(parv[1],
87 (time_t)ConfigGeneral.kill_chase_time_limit))
88 == NULL)
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_ALL, L_ALL, SEND_NOTICE,
126 "Received KILL message for %s!%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 target_p->servptr->id,
130 source_p->name, me.name, reason);
131
132 ilog(LOG_TYPE_KILL, "KILL From %s For %s Path %s (%s)",
133 source_p->name, target_p->name, me.name, reason);
134
135 /*
136 * And pass on the message to other servers. Note, that if KILL
137 * was changed, the message has to be sent to all links, also
138 * back.
139 * Suicide kills are NOT passed on --SRB
140 */
141 if (!MyConnect(target_p))
142 {
143 sendto_server(source_p, NOCAPS, NOCAPS, ":%s KILL %s :%s!%s!%s!%s (%s)",
144 source_p->id, target_p->id, me.name, source_p->host,
145 source_p->username, source_p->name, reason);
146
147 /*
148 * Set FLAGS_KILLED. This prevents exit_client() from sending
149 * the unnecessary QUIT for this. (This flag should never be
150 * set in any other place)
151 */
152 AddFlag(target_p, FLAGS_KILLED);
153 }
154
155 snprintf(buf, sizeof(buf), "Killed (%s (%s))", source_p->name, reason);
156 exit_client(target_p, buf);
157 return 0;
158 }
159
160 /*! \brief KILL command handler
161 *
162 * \param source_p Pointer to allocated Client struct from which the message
163 * originally comes from. This can be a local or remote client.
164 * \param parc Integer holding the number of supplied arguments.
165 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
166 * pointers.
167 * \note Valid arguments for this command are:
168 * - parv[0] = command
169 * - parv[1] = kill victim
170 * - parv[2] = kill path and reason
171 */
172 static int
173 ms_kill(struct Client *source_p, int parc, char *parv[])
174 {
175 char buf[IRCD_BUFSIZE] = "";
176 char def_reason[] = CONF_NOREASON;
177 struct Client *target_p = NULL;
178 char *reason = NULL;
179
180 if (parc < 3 || EmptyString(parv[2]))
181 {
182 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "KILL");
183 return 0;
184 }
185
186 if ((target_p = find_person(source_p, parv[1])) == NULL)
187 return 0;
188
189 if ((reason = strchr(parv[2], ' ')))
190 *reason++ = '\0';
191 else
192 reason = def_reason;
193
194 if (IsServer(target_p) || IsMe(target_p))
195 {
196 sendto_one_numeric(source_p, &me, ERR_CANTKILLSERVER);
197 return 0;
198 }
199
200 if (MyConnect(target_p))
201 {
202 if (IsServer(source_p))
203 {
204 /* Don't send clients kills from a hidden server */
205 if ((IsHidden(source_p) || ConfigServerHide.hide_servers) && !HasUMode(target_p, UMODE_OPER))
206 sendto_one(target_p, ":%s KILL %s :%s",
207 me.name, target_p->name, reason);
208 else
209 sendto_one(target_p, ":%s KILL %s :%s",
210 source_p->name, target_p->name, reason);
211 }
212 else
213 sendto_one(target_p, ":%s!%s@%s KILL %s :%s",
214 source_p->name, source_p->username, source_p->host,
215 target_p->name, reason);
216 }
217
218 /*
219 * Be warned, this message must be From %s, or it confuses clients
220 * so don't change it to From: or the case or anything! -- fl -- db
221 */
222 /*
223 * Path must contain at least 2 !'s, or bitchx falsely declares it
224 * local --fl
225 */
226 if (IsClient(source_p)) /* Send it normally */
227 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
228 "Received KILL message for %s!%s@%s[%s/%s]. From %s Path: %s!%s!%s!%s %s",
229 target_p->name, target_p->username, target_p->host,
230 target_p->servptr->name,
231 target_p->servptr->id, source_p->name,
232 source_p->servptr->name, source_p->host, source_p->username,
233 source_p->name, reason);
234 else
235 sendto_realops_flags(UMODE_SKILL, L_ALL, SEND_NOTICE,
236 "Received KILL message for %s!%s@%s[%s/%s]. From %s %s",
237 target_p->name, target_p->username, target_p->host,
238 target_p->servptr->name,
239 target_p->servptr->id,
240 source_p->name, reason);
241
242 ilog(LOG_TYPE_KILL, "KILL From %s For %s Path %s %s",
243 source_p->name, target_p->name, source_p->name, reason);
244
245 sendto_server(source_p, NOCAPS, NOCAPS, ":%s KILL %s :%s %s",
246 source_p->id, target_p->id, parv[2], reason);
247 AddFlag(target_p, FLAGS_KILLED);
248
249 /* Reason comes supplied with its own ()'s */
250 if (IsServer(source_p) && (IsHidden(source_p) || ConfigServerHide.hide_servers))
251 snprintf(buf, sizeof(buf), "Killed (%s %s)", me.name, reason);
252 else
253 snprintf(buf, sizeof(buf), "Killed (%s %s)", source_p->name, reason);
254
255 exit_client(target_p, buf);
256 return 0;
257 }
258
259
260 static struct Message kill_msgtab =
261 {
262 "KILL", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
263 { m_unregistered, m_not_oper, ms_kill, m_ignore, mo_kill, m_ignore }
264 };
265
266 static void
267 module_init(void)
268 {
269 mod_add_cmd(&kill_msgtab);
270 }
271
272 static void
273 module_exit(void)
274 {
275 mod_del_cmd(&kill_msgtab);
276 }
277
278 struct module module_entry =
279 {
280 .node = { NULL, NULL, NULL },
281 .name = NULL,
282 .version = "$Revision$",
283 .handle = NULL,
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

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