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 |
|
|
#include "handlers.h" |
27 |
|
|
#include "client.h" |
28 |
|
|
#include "common.h" /* FALSE bleah */ |
29 |
|
|
#include "hash.h" |
30 |
|
|
#include "irc_string.h" |
31 |
|
|
#include "ircd.h" |
32 |
|
|
#include "numeric.h" |
33 |
|
|
#include "s_conf.h" |
34 |
|
|
#include "s_log.h" |
35 |
|
|
#include "s_serv.h" |
36 |
|
|
#include "send.h" |
37 |
|
|
#include "msg.h" |
38 |
|
|
#include "parse.h" |
39 |
|
|
#include "modules.h" |
40 |
|
|
|
41 |
|
|
|
42 |
|
|
static void ms_squit(struct Client *, struct Client *, int, char *[]); |
43 |
|
|
static void mo_squit(struct Client *, struct Client *, int, char *[]); |
44 |
|
|
|
45 |
|
|
struct Message squit_msgtab = { |
46 |
|
|
"SQUIT", 0, 0, 1, 0, MFLG_SLOW, 0, |
47 |
|
|
{m_unregistered, m_not_oper, ms_squit, m_ignore, mo_squit, m_ignore} |
48 |
|
|
}; |
49 |
|
|
|
50 |
|
|
#ifndef STATIC_MODULES |
51 |
|
|
void |
52 |
|
|
_modinit(void) |
53 |
|
|
{ |
54 |
|
|
mod_add_cmd(&squit_msgtab); |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
void |
58 |
|
|
_moddeinit(void) |
59 |
|
|
{ |
60 |
|
|
mod_del_cmd(&squit_msgtab); |
61 |
|
|
} |
62 |
|
|
|
63 |
knight |
31 |
const char *_version = "$Revision$"; |
64 |
adx |
30 |
#endif |
65 |
|
|
|
66 |
|
|
/* mo_squit - SQUIT message handler |
67 |
|
|
* parv[0] = sender prefix |
68 |
|
|
* parv[1] = server name |
69 |
|
|
* parv[2] = comment |
70 |
|
|
*/ |
71 |
|
|
static void |
72 |
|
|
mo_squit(struct Client *client_p, struct Client *source_p, |
73 |
|
|
int parc, char *parv[]) |
74 |
|
|
{ |
75 |
|
|
struct Client *target_p = NULL; |
76 |
|
|
struct Client *p; |
77 |
|
|
dlink_node *ptr; |
78 |
|
|
char *comment; |
79 |
|
|
const char *server; |
80 |
|
|
char def_reason[] = "No reason"; |
81 |
|
|
|
82 |
|
|
if (parc < 2 || EmptyString(parv[1])) |
83 |
|
|
{ |
84 |
|
|
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
85 |
|
|
me.name, source_p->name, "SQUIT"); |
86 |
|
|
return; |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
server = parv[1]; |
90 |
|
|
|
91 |
|
|
/* The following allows wild cards in SQUIT. Only |
92 |
|
|
* useful when the command is issued by an oper. |
93 |
|
|
*/ |
94 |
|
|
DLINK_FOREACH(ptr, global_serv_list.head) |
95 |
|
|
{ |
96 |
|
|
p = ptr->data; |
97 |
|
|
|
98 |
|
|
if (IsServer(p) || IsMe(p)) |
99 |
|
|
{ |
100 |
|
|
if (match(server, p->name)) |
101 |
|
|
{ |
102 |
|
|
target_p = p; |
103 |
|
|
break; |
104 |
|
|
} |
105 |
|
|
} |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
if ((target_p == NULL) || IsMe(target_p)) |
109 |
|
|
{ |
110 |
|
|
sendto_one(source_p, form_str(ERR_NOSUCHSERVER), |
111 |
|
|
me.name, source_p->name, server); |
112 |
|
|
return; |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
if (!MyConnect(target_p) && !IsOperRemote(source_p)) |
116 |
|
|
{ |
117 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
118 |
|
|
me.name, source_p->name); |
119 |
|
|
return; |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
comment = (parc > 2 && parv[2]) ? parv[2] : def_reason; |
123 |
|
|
|
124 |
|
|
if (strlen(comment) > (size_t)REASONLEN) |
125 |
|
|
comment[REASONLEN] = '\0'; |
126 |
|
|
|
127 |
|
|
if (MyConnect(target_p)) |
128 |
|
|
{ |
129 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, "Received SQUIT %s from %s (%s)", |
130 |
|
|
target_p->name, get_client_name(source_p, HIDE_IP), comment); |
131 |
|
|
ilog(L_NOTICE, "Received SQUIT %s from %s (%s)", |
132 |
|
|
target_p->name, get_client_name(source_p, HIDE_IP), comment); |
133 |
|
|
} |
134 |
|
|
|
135 |
|
|
exit_client(target_p, source_p, comment); |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
/** NOTE: I removed wildcard lookups here, because a wildcarded |
139 |
|
|
** SQUIT should/can never happen in ms_squit. -Michael |
140 |
|
|
**/ |
141 |
|
|
|
142 |
|
|
/* ms_squit - SQUIT message handler |
143 |
|
|
* parv[0] = sender prefix |
144 |
|
|
* parv[1] = server name |
145 |
|
|
* parv[2] = comment |
146 |
|
|
*/ |
147 |
|
|
static void |
148 |
|
|
ms_squit(struct Client *client_p, struct Client *source_p, |
149 |
|
|
int parc, char *parv[]) |
150 |
|
|
{ |
151 |
|
|
struct Client *target_p = NULL; |
152 |
|
|
char *comment; |
153 |
|
|
const char *server; |
154 |
|
|
char def_reason[] = "No reason"; |
155 |
|
|
|
156 |
|
|
if (parc < 2 || EmptyString(parv[1])) |
157 |
|
|
return; |
158 |
|
|
|
159 |
|
|
server = parv[1]; |
160 |
|
|
|
161 |
|
|
if ((target_p = find_server(server)) == NULL) |
162 |
|
|
return; |
163 |
|
|
|
164 |
|
|
if (!IsServer(target_p) || IsMe(target_p)) |
165 |
|
|
return; |
166 |
|
|
|
167 |
|
|
comment = (parc > 2 && parv[2]) ? parv[2] : def_reason; |
168 |
|
|
|
169 |
|
|
if (strlen(comment) > (size_t)REASONLEN) |
170 |
|
|
comment[REASONLEN] = '\0'; |
171 |
|
|
|
172 |
|
|
if (MyConnect(target_p)) |
173 |
|
|
{ |
174 |
|
|
sendto_wallops_flags(UMODE_WALLOP, &me, "Remote SQUIT %s from %s (%s)", |
175 |
|
|
target_p->name, source_p->name, comment); |
176 |
|
|
sendto_server(NULL, NULL, NULL, CAP_TS6, NOCAPS, NOFLAGS, |
177 |
|
|
":%s WALLOPS :Remote SQUIT %s from %s (%s)", |
178 |
|
|
me.id, target_p->name, source_p->name, comment); |
179 |
|
|
sendto_server(NULL, NULL, NULL, NOCAPS, CAP_TS6, NOFLAGS, |
180 |
|
|
":%s WALLOPS :Remote SQUIT %s from %s (%s)", |
181 |
|
|
me.name, target_p->name, source_p->name, comment); |
182 |
|
|
ilog(L_TRACE, "SQUIT From %s : %s (%s)", parv[0], |
183 |
|
|
target_p->name, comment); |
184 |
|
|
|
185 |
|
|
} |
186 |
|
|
|
187 |
|
|
exit_client(target_p, source_p, comment); |
188 |
|
|
} |
189 |
|
|
|