1 |
adx |
30 |
/* |
2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
2820 |
* Copyright (c) 1997-2014 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 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
|
|
* USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
michael |
2820 |
/*! \file m_squit.c |
23 |
|
|
* \brief Includes required functions for processing the SQUIT 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 |
|
|
#include "hash.h" |
31 |
|
|
#include "irc_string.h" |
32 |
|
|
#include "ircd.h" |
33 |
|
|
#include "numeric.h" |
34 |
michael |
1309 |
#include "conf.h" |
35 |
|
|
#include "log.h" |
36 |
adx |
30 |
#include "s_serv.h" |
37 |
|
|
#include "send.h" |
38 |
|
|
#include "parse.h" |
39 |
|
|
#include "modules.h" |
40 |
|
|
|
41 |
|
|
|
42 |
|
|
/* mo_squit - SQUIT message handler |
43 |
michael |
3096 |
* parv[0] = command |
44 |
adx |
30 |
* parv[1] = server name |
45 |
|
|
* parv[2] = comment |
46 |
|
|
*/ |
47 |
michael |
2820 |
static int |
48 |
michael |
3156 |
mo_squit(struct Client *source_p, int parc, char *parv[]) |
49 |
adx |
30 |
{ |
50 |
|
|
struct Client *target_p = NULL; |
51 |
|
|
struct Client *p; |
52 |
|
|
dlink_node *ptr; |
53 |
|
|
char *comment; |
54 |
|
|
const char *server; |
55 |
michael |
1794 |
char def_reason[] = CONF_NOREASON; |
56 |
adx |
30 |
|
57 |
|
|
if (parc < 2 || EmptyString(parv[1])) |
58 |
|
|
{ |
59 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "SQUIT"); |
60 |
michael |
2820 |
return 0; |
61 |
adx |
30 |
} |
62 |
|
|
|
63 |
|
|
server = parv[1]; |
64 |
|
|
|
65 |
|
|
/* The following allows wild cards in SQUIT. Only |
66 |
|
|
* useful when the command is issued by an oper. |
67 |
|
|
*/ |
68 |
|
|
DLINK_FOREACH(ptr, global_serv_list.head) |
69 |
|
|
{ |
70 |
|
|
p = ptr->data; |
71 |
|
|
|
72 |
|
|
if (IsServer(p) || IsMe(p)) |
73 |
|
|
{ |
74 |
michael |
1652 |
if (!match(server, p->name)) |
75 |
adx |
30 |
{ |
76 |
|
|
target_p = p; |
77 |
|
|
break; |
78 |
|
|
} |
79 |
|
|
} |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
if ((target_p == NULL) || IsMe(target_p)) |
83 |
|
|
{ |
84 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, server); |
85 |
michael |
2820 |
return 0; |
86 |
adx |
30 |
} |
87 |
|
|
|
88 |
michael |
2801 |
if (!MyConnect(target_p) && !HasOFlag(source_p, OPER_FLAG_SQUIT_REMOTE)) |
89 |
adx |
30 |
{ |
90 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "squit:remote"); |
91 |
michael |
2820 |
return 0; |
92 |
adx |
30 |
} |
93 |
|
|
|
94 |
michael |
2801 |
if (MyConnect(target_p) && !HasOFlag(source_p, OPER_FLAG_SQUIT)) |
95 |
|
|
{ |
96 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "squit"); |
97 |
michael |
2820 |
return 0; |
98 |
michael |
2801 |
} |
99 |
|
|
|
100 |
adx |
30 |
comment = (parc > 2 && parv[2]) ? parv[2] : def_reason; |
101 |
|
|
|
102 |
|
|
if (strlen(comment) > (size_t)REASONLEN) |
103 |
|
|
comment[REASONLEN] = '\0'; |
104 |
|
|
|
105 |
|
|
if (MyConnect(target_p)) |
106 |
|
|
{ |
107 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
108 |
|
|
"Received SQUIT %s from %s (%s)", |
109 |
adx |
30 |
target_p->name, get_client_name(source_p, HIDE_IP), comment); |
110 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "Received SQUIT %s from %s (%s)", |
111 |
adx |
30 |
target_p->name, get_client_name(source_p, HIDE_IP), comment); |
112 |
michael |
3171 |
|
113 |
|
|
/* To them, we are exiting */ |
114 |
|
|
sendto_one(target_p, ":%s SQUIT %s :%s", ID(source_p), ID(&me), comment); |
115 |
|
|
/* Send to everything but target */ |
116 |
|
|
sendto_server(target_p, NOCAPS, NOCAPS, ":%s SQUIT %s :%s", |
117 |
|
|
ID(source_p), ID(target_p), comment); |
118 |
adx |
30 |
} |
119 |
michael |
3171 |
else |
120 |
|
|
/* Send to everything */ |
121 |
|
|
sendto_server(NULL, NOCAPS, NOCAPS, ":%s SQUIT %s :%s", |
122 |
|
|
ID(source_p), ID(target_p), comment); |
123 |
adx |
30 |
|
124 |
michael |
3171 |
AddFlag(target_p, FLAGS_SQUIT); |
125 |
|
|
|
126 |
|
|
exit_client(target_p, comment); |
127 |
michael |
2820 |
return 0; |
128 |
adx |
30 |
} |
129 |
|
|
|
130 |
|
|
/** NOTE: I removed wildcard lookups here, because a wildcarded |
131 |
|
|
** SQUIT should/can never happen in ms_squit. -Michael |
132 |
|
|
**/ |
133 |
|
|
|
134 |
|
|
/* ms_squit - SQUIT message handler |
135 |
michael |
3096 |
* parv[0] = command |
136 |
adx |
30 |
* parv[1] = server name |
137 |
|
|
* parv[2] = comment |
138 |
|
|
*/ |
139 |
michael |
2820 |
static int |
140 |
michael |
3156 |
ms_squit(struct Client *source_p, int parc, char *parv[]) |
141 |
adx |
30 |
{ |
142 |
|
|
struct Client *target_p = NULL; |
143 |
michael |
1572 |
const char *comment = NULL; |
144 |
michael |
3171 |
dlink_node *ptr; |
145 |
adx |
30 |
|
146 |
michael |
1572 |
if (parc < 2 || EmptyString(parv[parc - 1])) |
147 |
michael |
2820 |
return 0; |
148 |
adx |
30 |
|
149 |
michael |
1572 |
if ((target_p = hash_find_server(parv[1])) == NULL) |
150 |
michael |
2820 |
return 0; |
151 |
adx |
30 |
|
152 |
michael |
1572 |
if (!IsServer(target_p) && !IsMe(target_p)) |
153 |
michael |
2820 |
return 0; |
154 |
adx |
30 |
|
155 |
michael |
1572 |
if (IsMe(target_p)) |
156 |
michael |
3156 |
target_p = source_p->from; |
157 |
adx |
30 |
|
158 |
michael |
3156 |
comment = (parc > 2 && parv[parc - 1]) ? parv[parc - 1] : source_p->name; |
159 |
adx |
30 |
|
160 |
|
|
if (MyConnect(target_p)) |
161 |
|
|
{ |
162 |
|
|
sendto_wallops_flags(UMODE_WALLOP, &me, "Remote SQUIT %s from %s (%s)", |
163 |
|
|
target_p->name, source_p->name, comment); |
164 |
michael |
3156 |
sendto_server(source_p, NOCAPS, NOCAPS, |
165 |
adx |
30 |
":%s WALLOPS :Remote SQUIT %s from %s (%s)", |
166 |
|
|
me.id, target_p->name, source_p->name, comment); |
167 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "SQUIT From %s : %s (%s)", source_p->name, |
168 |
adx |
30 |
target_p->name, comment); |
169 |
michael |
3171 |
|
170 |
|
|
/* To them, we are exiting */ |
171 |
|
|
sendto_one(target_p, ":%s SQUIT %s :%s", ID(source_p), ID(&me), comment); |
172 |
|
|
|
173 |
|
|
/* Send to everything but target and source */ |
174 |
|
|
DLINK_FOREACH(ptr, serv_list.head) |
175 |
|
|
{ |
176 |
|
|
struct Client *client_p = ptr->data; |
177 |
|
|
|
178 |
|
|
if (client_p == target_p || client_p == source_p->from) |
179 |
|
|
continue; |
180 |
|
|
|
181 |
|
|
sendto_one(client_p, ":%s SQUIT %s :%s", |
182 |
|
|
ID(source_p), ID(target_p), comment); |
183 |
|
|
} |
184 |
michael |
2820 |
} |
185 |
michael |
3171 |
else |
186 |
|
|
/* Send to everything but source */ |
187 |
|
|
sendto_server(source_p, NOCAPS, NOCAPS, ":%s SQUIT %s :%s", |
188 |
|
|
ID(source_p), ID(target_p), comment); |
189 |
adx |
30 |
|
190 |
michael |
3171 |
AddFlag(target_p, FLAGS_SQUIT); |
191 |
|
|
|
192 |
|
|
exit_client(target_p, comment); |
193 |
michael |
2820 |
return 0; |
194 |
adx |
30 |
} |
195 |
michael |
1230 |
|
196 |
michael |
2820 |
static struct Message squit_msgtab = |
197 |
|
|
{ |
198 |
michael |
1230 |
"SQUIT", 0, 0, 1, MAXPARA, MFLG_SLOW, 0, |
199 |
michael |
2820 |
{ m_unregistered, m_not_oper, ms_squit, m_ignore, mo_squit, m_ignore } |
200 |
michael |
1230 |
}; |
201 |
|
|
|
202 |
|
|
static void |
203 |
|
|
module_init(void) |
204 |
|
|
{ |
205 |
|
|
mod_add_cmd(&squit_msgtab); |
206 |
|
|
} |
207 |
|
|
|
208 |
|
|
static void |
209 |
|
|
module_exit(void) |
210 |
|
|
{ |
211 |
|
|
mod_del_cmd(&squit_msgtab); |
212 |
|
|
} |
213 |
|
|
|
214 |
michael |
2820 |
struct module module_entry = |
215 |
|
|
{ |
216 |
michael |
1230 |
.node = { NULL, NULL, NULL }, |
217 |
|
|
.name = NULL, |
218 |
|
|
.version = "$Revision$", |
219 |
|
|
.handle = NULL, |
220 |
|
|
.modinit = module_init, |
221 |
|
|
.modexit = module_exit, |
222 |
|
|
.flags = MODULE_FLAG_CORE |
223 |
|
|
}; |