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: 10050
Committed: Wed Jun 1 17:22:41 2022 UTC (21 months, 3 weeks ago) by michael
Content type: text/x-csrc
File size: 8545 byte(s)
Log Message:
- Style corrections

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 10024 * Copyright (c) 1997-2022 ircd-hybrid development team
5 adx 30 *
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 michael 4564 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2820 /*! \file m_kill.c
23     * \brief Includes required functions for processing the KILL command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #include "client.h"
30 michael 2820 #include "hash.h"
31 adx 30 #include "ircd.h"
32     #include "numeric.h"
33 michael 1309 #include "log.h"
34 michael 3347 #include "server.h"
35 michael 1309 #include "conf.h"
36 adx 30 #include "send.h"
37     #include "whowas.h"
38     #include "irc_string.h"
39     #include "parse.h"
40     #include "modules.h"
41    
42    
43 michael 4601 /*! \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 adx 30 */
55 michael 9078 static void
56 michael 3156 mo_kill(struct Client *source_p, int parc, char *parv[])
57 adx 30 {
58 michael 1794 char def_reason[] = CONF_NOREASON;
59 adx 30
60 michael 8058 char *reason = parv[2]; /* Either defined or NULL (parc >= 2!!) */
61 adx 30 if (!EmptyString(reason))
62     {
63 michael 9833 if (strlen(reason) > REASONLEN)
64 michael 7512 reason[REASONLEN] = '\0';
65 adx 30 }
66     else
67     reason = def_reason;
68    
69 michael 9999 struct Client *target_p = find_person(source_p, parv[1]);
70 michael 9199 if (target_p == NULL)
71 adx 30 {
72 michael 1136 /*
73     * If the user has recently changed nick, automatically
74 adx 30 * rewrite the KILL for this new nickname--this keeps
75     * servers in synch when nick change and kill collide
76     */
77 michael 9199 target_p = whowas_get_history(parv[1], ConfigGeneral.kill_chase_time_limit);
78     if (target_p == NULL)
79 adx 30 {
80 michael 3201 sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, parv[1]);
81 michael 9078 return;
82 adx 30 }
83    
84 michael 3110 sendto_one_notice(source_p, &me, ":KILL changed from %s to %s",
85 michael 3201 parv[1], target_p->name);
86 adx 30 }
87    
88 michael 2801 if (!MyConnect(target_p) && !HasOFlag(source_p, OPER_FLAG_KILL_REMOTE))
89 adx 30 {
90 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "kill:remote");
91 michael 9078 return;
92 adx 30 }
93    
94 michael 2801 if (MyConnect(target_p) && !HasOFlag(source_p, OPER_FLAG_KILL))
95     {
96 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "kill");
97 michael 9078 return;
98 michael 2801 }
99    
100 michael 2012 if (IsServer(target_p) || IsMe(target_p))
101 adx 30 {
102 michael 3109 sendto_one_numeric(source_p, &me, ERR_CANTKILLSERVER);
103 michael 9078 return;
104 adx 30 }
105    
106     if (MyConnect(target_p))
107 michael 2820 sendto_one(target_p, ":%s!%s@%s KILL %s :%s",
108 adx 30 source_p->name, source_p->username, source_p->host,
109     target_p->name, reason);
110    
111 michael 1136 /*
112     * Do not change the format of this message. There's no point in changing messages
113     * that have been around for ever, for no reason..
114     */
115 michael 6317 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
116 michael 7920 "Received KILL message for %s!%s@%s[%s]. From %s Path: %s (%s)",
117 michael 2037 target_p->name, target_p->username, target_p->host,
118     target_p->servptr->name,
119     source_p->name, me.name, reason);
120 adx 30
121 michael 1247 ilog(LOG_TYPE_KILL, "KILL From %s For %s Path %s (%s)",
122 adx 30 source_p->name, target_p->name, me.name, reason);
123    
124     /*
125 michael 8430 * And pass on the message to other servers. Note, that if KILL was changed,
126     * the message has to be sent to all links, also back.
127 michael 1136 */
128 adx 30 if (!MyConnect(target_p))
129     {
130 michael 4963 sendto_server(source_p, 0, 0, ":%s KILL %s :%s!%s!%s!%s (%s)",
131 michael 3179 source_p->id, target_p->id, me.name, source_p->host,
132     source_p->username, source_p->name, reason);
133 michael 3201
134 michael 3179 /*
135 michael 4601 * Set FLAGS_KILLED. This prevents exit_client() from sending
136 michael 3179 * the unnecessary QUIT for this. (This flag should never be
137     * set in any other place)
138     */
139 michael 1219 AddFlag(target_p, FLAGS_KILLED);
140 adx 30 }
141    
142 michael 10050 char buf[IRCD_BUFSIZE];
143 michael 1136 snprintf(buf, sizeof(buf), "Killed (%s (%s))", source_p->name, reason);
144 michael 10050
145 michael 3171 exit_client(target_p, buf);
146 adx 30 }
147    
148 michael 4601 /*! \brief KILL command handler
149     *
150     * \param source_p Pointer to allocated Client struct from which the message
151     * originally comes from. This can be a local or remote client.
152     * \param parc Integer holding the number of supplied arguments.
153     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
154     * pointers.
155     * \note Valid arguments for this command are:
156     * - parv[0] = command
157     * - parv[1] = kill victim
158     * - parv[2] = kill path and reason
159 adx 30 */
160 michael 9078 static void
161 michael 3156 ms_kill(struct Client *source_p, int parc, char *parv[])
162 adx 30 {
163 michael 1794 char def_reason[] = CONF_NOREASON;
164 adx 30
165 michael 9199 struct Client *target_p = find_person(source_p, parv[1]);
166     if (target_p == NULL)
167 michael 9078 return;
168 michael 3201
169 michael 8058 char *reason = strchr(parv[2], ' ');
170     if (reason)
171 michael 3200 *reason++ = '\0';
172     else
173 adx 30 reason = def_reason;
174    
175     if (IsServer(target_p) || IsMe(target_p))
176     {
177 michael 3109 sendto_one_numeric(source_p, &me, ERR_CANTKILLSERVER);
178 michael 9078 return;
179 adx 30 }
180    
181     if (MyConnect(target_p))
182     {
183     if (IsServer(source_p))
184     {
185 michael 4299 /* Don't send clients kills from a hidden server */
186 michael 1219 if ((IsHidden(source_p) || ConfigServerHide.hide_servers) && !HasUMode(target_p, UMODE_OPER))
187 adx 30 sendto_one(target_p, ":%s KILL %s :%s",
188 michael 1451 me.name, target_p->name, reason);
189 adx 30 else
190 michael 1451 sendto_one(target_p, ":%s KILL %s :%s",
191     source_p->name, target_p->name, reason);
192 adx 30 }
193     else
194     sendto_one(target_p, ":%s!%s@%s KILL %s :%s",
195 michael 1451 source_p->name, source_p->username, source_p->host,
196     target_p->name, reason);
197 adx 30 }
198    
199 michael 1451 /*
200     * Be warned, this message must be From %s, or it confuses clients
201 michael 4299 * so don't change it to From: or the case or anything! -- fl -- db
202 michael 1451 */
203     /*
204 michael 4299 * Path must contain at least 2 !'s, or bitchx falsely declares it
205 adx 30 * local --fl
206     */
207 michael 4702 if (IsClient(source_p)) /* Send it normally */
208 michael 6317 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
209 michael 7920 "Received KILL message for %s!%s@%s[%s]. From %s Path: %s!%s!%s!%s %s",
210 michael 2037 target_p->name, target_p->username, target_p->host,
211     target_p->servptr->name,
212 michael 7920 source_p->name,
213 michael 2037 source_p->servptr->name, source_p->host, source_p->username,
214     source_p->name, reason);
215 adx 30 else
216 michael 1618 sendto_realops_flags(UMODE_SKILL, L_ALL, SEND_NOTICE,
217 michael 7920 "Received KILL message for %s!%s@%s[%s]. From %s %s",
218 michael 2037 target_p->name, target_p->username, target_p->host,
219     target_p->servptr->name,
220     source_p->name, reason);
221 adx 30
222 michael 1247 ilog(LOG_TYPE_KILL, "KILL From %s For %s Path %s %s",
223 adx 30 source_p->name, target_p->name, source_p->name, reason);
224    
225 michael 4963 sendto_server(source_p, 0, 0, ":%s KILL %s :%s %s",
226 michael 3200 source_p->id, target_p->id, parv[2], reason);
227 michael 1219 AddFlag(target_p, FLAGS_KILLED);
228 adx 30
229 michael 4299 /* Reason comes supplied with its own ()'s */
230 michael 10050 char buf[IRCD_BUFSIZE];
231 adx 30 if (IsServer(source_p) && (IsHidden(source_p) || ConfigServerHide.hide_servers))
232 michael 1136 snprintf(buf, sizeof(buf), "Killed (%s %s)", me.name, reason);
233 adx 30 else
234 michael 1136 snprintf(buf, sizeof(buf), "Killed (%s %s)", source_p->name, reason);
235 adx 30
236 michael 3171 exit_client(target_p, buf);
237 adx 30 }
238    
239    
240 michael 2820 static struct Message kill_msgtab =
241     {
242 michael 5880 .cmd = "KILL",
243 michael 9373 .handlers[UNREGISTERED_HANDLER] = { .handler = m_unregistered },
244     .handlers[CLIENT_HANDLER] = { .handler = m_not_oper },
245     .handlers[SERVER_HANDLER] = { .handler = ms_kill, .args_min = 3 },
246     .handlers[ENCAP_HANDLER] = { .handler = m_ignore },
247     .handlers[OPER_HANDLER] = { .handler = mo_kill, .args_min = 2 }
248 michael 1230 };
249    
250     static void
251     module_init(void)
252     {
253     mod_add_cmd(&kill_msgtab);
254     }
255    
256     static void
257     module_exit(void)
258     {
259     mod_del_cmd(&kill_msgtab);
260     }
261    
262 michael 2820 struct module module_entry =
263     {
264 michael 1230 .version = "$Revision$",
265     .modinit = module_init,
266     .modexit = module_exit,
267 michael 8723 .is_core = true
268 michael 1230 };

Properties

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