1 |
adx |
30 |
/* |
2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
|
|
* m_squit.c: Makes a server quit. |
4 |
|
|
* |
5 |
|
|
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
|
|
* |
7 |
|
|
* This program is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* This program is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with this program; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
|
|
* USA |
21 |
|
|
* |
22 |
knight |
31 |
* $Id$ |
23 |
adx |
30 |
*/ |
24 |
|
|
|
25 |
|
|
#include "stdinc.h" |
26 |
michael |
1011 |
#include "list.h" |
27 |
adx |
30 |
#include "handlers.h" |
28 |
|
|
#include "client.h" |
29 |
|
|
#include "common.h" /* FALSE bleah */ |
30 |
|
|
#include "hash.h" |
31 |
|
|
#include "irc_string.h" |
32 |
|
|
#include "ircd.h" |
33 |
|
|
#include "numeric.h" |
34 |
|
|
#include "s_conf.h" |
35 |
|
|
#include "s_log.h" |
36 |
|
|
#include "s_serv.h" |
37 |
|
|
#include "send.h" |
38 |
|
|
#include "msg.h" |
39 |
|
|
#include "parse.h" |
40 |
|
|
#include "modules.h" |
41 |
|
|
|
42 |
|
|
|
43 |
|
|
/* mo_squit - SQUIT message handler |
44 |
|
|
* parv[0] = sender prefix |
45 |
|
|
* parv[1] = server name |
46 |
|
|
* parv[2] = comment |
47 |
|
|
*/ |
48 |
|
|
static void |
49 |
|
|
mo_squit(struct Client *client_p, struct Client *source_p, |
50 |
|
|
int parc, char *parv[]) |
51 |
|
|
{ |
52 |
|
|
struct Client *target_p = NULL; |
53 |
|
|
struct Client *p; |
54 |
|
|
dlink_node *ptr; |
55 |
|
|
char *comment; |
56 |
|
|
const char *server; |
57 |
|
|
char def_reason[] = "No reason"; |
58 |
|
|
|
59 |
|
|
if (parc < 2 || EmptyString(parv[1])) |
60 |
|
|
{ |
61 |
|
|
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
62 |
|
|
me.name, source_p->name, "SQUIT"); |
63 |
|
|
return; |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
server = parv[1]; |
67 |
|
|
|
68 |
|
|
/* The following allows wild cards in SQUIT. Only |
69 |
|
|
* useful when the command is issued by an oper. |
70 |
|
|
*/ |
71 |
|
|
DLINK_FOREACH(ptr, global_serv_list.head) |
72 |
|
|
{ |
73 |
|
|
p = ptr->data; |
74 |
|
|
|
75 |
|
|
if (IsServer(p) || IsMe(p)) |
76 |
|
|
{ |
77 |
|
|
if (match(server, p->name)) |
78 |
|
|
{ |
79 |
|
|
target_p = p; |
80 |
|
|
break; |
81 |
|
|
} |
82 |
|
|
} |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
if ((target_p == NULL) || IsMe(target_p)) |
86 |
|
|
{ |
87 |
|
|
sendto_one(source_p, form_str(ERR_NOSUCHSERVER), |
88 |
|
|
me.name, source_p->name, server); |
89 |
|
|
return; |
90 |
|
|
} |
91 |
|
|
|
92 |
michael |
1219 |
if (!MyConnect(target_p) && !HasOFlag(source_p, OPER_FLAG_REMOTE)) |
93 |
adx |
30 |
{ |
94 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
95 |
|
|
me.name, source_p->name); |
96 |
|
|
return; |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
comment = (parc > 2 && parv[2]) ? parv[2] : def_reason; |
100 |
|
|
|
101 |
|
|
if (strlen(comment) > (size_t)REASONLEN) |
102 |
|
|
comment[REASONLEN] = '\0'; |
103 |
|
|
|
104 |
|
|
if (MyConnect(target_p)) |
105 |
|
|
{ |
106 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, "Received SQUIT %s from %s (%s)", |
107 |
|
|
target_p->name, get_client_name(source_p, HIDE_IP), comment); |
108 |
|
|
ilog(L_NOTICE, "Received SQUIT %s from %s (%s)", |
109 |
|
|
target_p->name, get_client_name(source_p, HIDE_IP), comment); |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
exit_client(target_p, source_p, comment); |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
/** NOTE: I removed wildcard lookups here, because a wildcarded |
116 |
|
|
** SQUIT should/can never happen in ms_squit. -Michael |
117 |
|
|
**/ |
118 |
|
|
|
119 |
|
|
/* ms_squit - SQUIT message handler |
120 |
|
|
* parv[0] = sender prefix |
121 |
|
|
* parv[1] = server name |
122 |
|
|
* parv[2] = comment |
123 |
|
|
*/ |
124 |
|
|
static void |
125 |
|
|
ms_squit(struct Client *client_p, struct Client *source_p, |
126 |
|
|
int parc, char *parv[]) |
127 |
|
|
{ |
128 |
|
|
struct Client *target_p = NULL; |
129 |
|
|
char *comment; |
130 |
|
|
const char *server; |
131 |
|
|
char def_reason[] = "No reason"; |
132 |
|
|
|
133 |
|
|
if (parc < 2 || EmptyString(parv[1])) |
134 |
|
|
return; |
135 |
|
|
|
136 |
|
|
server = parv[1]; |
137 |
|
|
|
138 |
michael |
1169 |
if ((target_p = hash_find_server(server)) == NULL) |
139 |
adx |
30 |
return; |
140 |
|
|
|
141 |
|
|
if (!IsServer(target_p) || IsMe(target_p)) |
142 |
|
|
return; |
143 |
|
|
|
144 |
|
|
comment = (parc > 2 && parv[2]) ? parv[2] : def_reason; |
145 |
|
|
|
146 |
|
|
if (strlen(comment) > (size_t)REASONLEN) |
147 |
|
|
comment[REASONLEN] = '\0'; |
148 |
|
|
|
149 |
|
|
if (MyConnect(target_p)) |
150 |
|
|
{ |
151 |
|
|
sendto_wallops_flags(UMODE_WALLOP, &me, "Remote SQUIT %s from %s (%s)", |
152 |
|
|
target_p->name, source_p->name, comment); |
153 |
michael |
885 |
sendto_server(NULL, NULL, CAP_TS6, NOCAPS, |
154 |
adx |
30 |
":%s WALLOPS :Remote SQUIT %s from %s (%s)", |
155 |
|
|
me.id, target_p->name, source_p->name, comment); |
156 |
michael |
885 |
sendto_server(NULL, NULL, NOCAPS, CAP_TS6, |
157 |
adx |
30 |
":%s WALLOPS :Remote SQUIT %s from %s (%s)", |
158 |
|
|
me.name, target_p->name, source_p->name, comment); |
159 |
michael |
1230 |
ilog(L_TRACE, "SQUIT From %s : %s (%s)", source_p->name, |
160 |
adx |
30 |
target_p->name, comment); |
161 |
|
|
|
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
exit_client(target_p, source_p, comment); |
165 |
|
|
} |
166 |
michael |
1230 |
|
167 |
|
|
static struct Message squit_msgtab = { |
168 |
|
|
"SQUIT", 0, 0, 1, MAXPARA, MFLG_SLOW, 0, |
169 |
|
|
{m_unregistered, m_not_oper, ms_squit, m_ignore, mo_squit, m_ignore} |
170 |
|
|
}; |
171 |
|
|
|
172 |
|
|
static void |
173 |
|
|
module_init(void) |
174 |
|
|
{ |
175 |
|
|
mod_add_cmd(&squit_msgtab); |
176 |
|
|
} |
177 |
|
|
|
178 |
|
|
static void |
179 |
|
|
module_exit(void) |
180 |
|
|
{ |
181 |
|
|
mod_del_cmd(&squit_msgtab); |
182 |
|
|
} |
183 |
|
|
|
184 |
|
|
struct module module_entry = { |
185 |
|
|
.node = { NULL, NULL, NULL }, |
186 |
|
|
.name = NULL, |
187 |
|
|
.version = "$Revision$", |
188 |
|
|
.handle = NULL, |
189 |
|
|
.modinit = module_init, |
190 |
|
|
.modexit = module_exit, |
191 |
|
|
.flags = MODULE_FLAG_CORE |
192 |
|
|
}; |