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_squit.c |
23 |
* \brief Includes required functions for processing the SQUIT command. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "list.h" |
29 |
#include "client.h" |
30 |
#include "hash.h" |
31 |
#include "irc_string.h" |
32 |
#include "ircd.h" |
33 |
#include "numeric.h" |
34 |
#include "conf.h" |
35 |
#include "log.h" |
36 |
#include "server.h" |
37 |
#include "send.h" |
38 |
#include "parse.h" |
39 |
#include "modules.h" |
40 |
|
41 |
|
42 |
/*! \brief SQUIT command handler |
43 |
* |
44 |
* \param source_p Pointer to allocated Client struct from which the message |
45 |
* originally comes from. This can be a local or remote client. |
46 |
* \param parc Integer holding the number of supplied arguments. |
47 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
48 |
* pointers. |
49 |
* \note Valid arguments for this command are: |
50 |
* - parv[0] = command |
51 |
* - parv[1] = server name |
52 |
* - parv[2] = comment |
53 |
*/ |
54 |
static int |
55 |
mo_squit(struct Client *source_p, int parc, char *parv[]) |
56 |
{ |
57 |
char comment[REASONLEN + 1] = ""; |
58 |
struct Client *target_p = NULL; |
59 |
dlink_node *node = NULL; |
60 |
const char *server = parv[1]; |
61 |
|
62 |
if (parc < 2 || EmptyString(parv[1])) |
63 |
{ |
64 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "SQUIT"); |
65 |
return 0; |
66 |
} |
67 |
|
68 |
/* The following allows wild cards in SQUIT. */ |
69 |
DLINK_FOREACH(node, global_server_list.head) |
70 |
{ |
71 |
struct Client *p = node->data; |
72 |
|
73 |
if (IsServer(p) || IsMe(p)) |
74 |
{ |
75 |
if (!match(server, p->name)) |
76 |
{ |
77 |
target_p = p; |
78 |
break; |
79 |
} |
80 |
} |
81 |
} |
82 |
|
83 |
if (!target_p || IsMe(target_p)) |
84 |
{ |
85 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, server); |
86 |
return 0; |
87 |
} |
88 |
|
89 |
if (!MyConnect(target_p) && !HasOFlag(source_p, OPER_FLAG_SQUIT_REMOTE)) |
90 |
{ |
91 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "squit:remote"); |
92 |
return 0; |
93 |
} |
94 |
|
95 |
if (MyConnect(target_p) && !HasOFlag(source_p, OPER_FLAG_SQUIT)) |
96 |
{ |
97 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "squit"); |
98 |
return 0; |
99 |
} |
100 |
|
101 |
if (!EmptyString(parv[2])) |
102 |
strlcpy(comment, parv[2], sizeof(comment)); |
103 |
else |
104 |
strlcpy(comment, CONF_NOREASON, sizeof(comment)); |
105 |
|
106 |
if (MyConnect(target_p)) |
107 |
{ |
108 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
109 |
"Received SQUIT %s from %s (%s)", |
110 |
target_p->name, get_oper_name(source_p), comment); |
111 |
ilog(LOG_TYPE_IRCD, "SQUIT %s from %s (%s)", |
112 |
target_p->name, get_oper_name(source_p), comment); |
113 |
|
114 |
/* To them, we are exiting */ |
115 |
sendto_one(target_p, ":%s SQUIT %s :%s", source_p->id, me.id, comment); |
116 |
|
117 |
/* Send to everything but target */ |
118 |
sendto_server(target_p, 0, 0, ":%s SQUIT %s :%s", |
119 |
source_p->id, target_p->id, comment); |
120 |
} |
121 |
else |
122 |
/* Send to everything */ |
123 |
sendto_server(NULL, 0, 0, ":%s SQUIT %s :%s", |
124 |
source_p->id, target_p->id, comment); |
125 |
|
126 |
AddFlag(target_p, FLAGS_SQUIT); |
127 |
|
128 |
exit_client(target_p, comment); |
129 |
return 0; |
130 |
} |
131 |
|
132 |
/*! \brief SQUIT command handler |
133 |
* |
134 |
* \param source_p Pointer to allocated Client struct from which the message |
135 |
* originally comes from. This can be a local or remote client. |
136 |
* \param parc Integer holding the number of supplied arguments. |
137 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
138 |
* pointers. |
139 |
* \note Valid arguments for this command are: |
140 |
* - parv[0] = command |
141 |
* - parv[1] = server name |
142 |
* - parv[2] = comment |
143 |
*/ |
144 |
static int |
145 |
ms_squit(struct Client *source_p, int parc, char *parv[]) |
146 |
{ |
147 |
struct Client *target_p = NULL; |
148 |
const char *comment = NULL; |
149 |
dlink_node *node = NULL; |
150 |
|
151 |
if (parc < 2 || EmptyString(parv[1])) |
152 |
return 0; |
153 |
|
154 |
if ((target_p = hash_find_server(parv[1])) == NULL) |
155 |
return 0; |
156 |
|
157 |
if (!IsServer(target_p) && !IsMe(target_p)) |
158 |
return 0; |
159 |
|
160 |
if (IsMe(target_p)) |
161 |
target_p = source_p->from; |
162 |
|
163 |
comment = (parc > 2 && parv[parc - 1]) ? parv[parc - 1] : source_p->name; |
164 |
|
165 |
if (MyConnect(target_p)) |
166 |
{ |
167 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_GLOBAL, "from %s: Remote SQUIT %s from %s (%s)", |
168 |
me.name, target_p->name, get_oper_name(source_p), comment); |
169 |
sendto_server(source_p, 0, 0, ":%s GLOBOPS :Remote SQUIT %s from %s (%s)", |
170 |
me.id, target_p->name, get_oper_name(source_p), comment); |
171 |
ilog(LOG_TYPE_IRCD, "Remote SQUIT %s from %s (%s)", |
172 |
target_p->name, get_oper_name(source_p), comment); |
173 |
|
174 |
/* To them, we are exiting */ |
175 |
sendto_one(target_p, ":%s SQUIT %s :%s", source_p->id, me.id, comment); |
176 |
|
177 |
/* Send to everything but target and source */ |
178 |
DLINK_FOREACH(node, local_server_list.head) |
179 |
{ |
180 |
struct Client *client_p = node->data; |
181 |
|
182 |
if (client_p == target_p || client_p == source_p->from) |
183 |
continue; |
184 |
|
185 |
sendto_one(client_p, ":%s SQUIT %s :%s", |
186 |
source_p->id, target_p->id, comment); |
187 |
} |
188 |
} |
189 |
else |
190 |
/* Send to everything but source */ |
191 |
sendto_server(source_p, 0, 0, ":%s SQUIT %s :%s", |
192 |
source_p->id, target_p->id, comment); |
193 |
|
194 |
AddFlag(target_p, FLAGS_SQUIT); |
195 |
|
196 |
exit_client(target_p, comment); |
197 |
return 0; |
198 |
} |
199 |
|
200 |
static struct Message squit_msgtab = |
201 |
{ |
202 |
.cmd = "SQUIT", |
203 |
.args_max = MAXPARA, |
204 |
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
205 |
.handlers[CLIENT_HANDLER] = m_not_oper, |
206 |
.handlers[SERVER_HANDLER] = ms_squit, |
207 |
.handlers[ENCAP_HANDLER] = m_ignore, |
208 |
.handlers[OPER_HANDLER] = mo_squit |
209 |
}; |
210 |
|
211 |
static void |
212 |
module_init(void) |
213 |
{ |
214 |
mod_add_cmd(&squit_msgtab); |
215 |
} |
216 |
|
217 |
static void |
218 |
module_exit(void) |
219 |
{ |
220 |
mod_del_cmd(&squit_msgtab); |
221 |
} |
222 |
|
223 |
struct module module_entry = |
224 |
{ |
225 |
.version = "$Revision$", |
226 |
.modinit = module_init, |
227 |
.modexit = module_exit, |
228 |
.flags = MODULE_FLAG_CORE |
229 |
}; |