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