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