]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/core/m_squit.c
Do not install ban .conf files (like kline.conf, rsv.conf, etc) as they aren't used...
[irc/rqf/shadowircd.git] / modules / core / m_squit.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_squit.c: Makes a server quit.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 *
212380e3 24 */
25
26#include "stdinc.h"
27#include "client.h"
28#include "common.h" /* FALSE bleah */
13ae2f4b 29#include "match.h"
212380e3 30#include "ircd.h"
31#include "numeric.h"
32#include "s_conf.h"
d3455e2c 33#include "logger.h"
212380e3 34#include "s_serv.h"
35#include "send.h"
36#include "msg.h"
37#include "parse.h"
38#include "modules.h"
39#include "hash.h"
40#include "s_newconf.h"
41
42static int ms_squit(struct Client *, struct Client *, int, const char **);
43static int mo_squit(struct Client *, struct Client *, int, const char **);
44
45struct Message squit_msgtab = {
46 "SQUIT", 0, 0, 0, MFLG_SLOW,
47 {mg_unreg, mg_not_oper, {ms_squit, 0}, {ms_squit, 0}, mg_ignore, {mo_squit, 2}}
48};
49
50mapi_clist_av1 squit_clist[] = { &squit_msgtab, NULL };
51
5366977b 52DECLARE_MODULE_AV1(squit, NULL, NULL, squit_clist, NULL, NULL, "$Revision: 3161 $");
212380e3 53
54struct squit_parms
55{
56 const char *server_name;
57 struct Client *target_p;
58};
59
60static struct squit_parms *find_squit(struct Client *client_p,
61 struct Client *source_p, const char *server);
62
63
64/*
65 * mo_squit - SQUIT message handler
212380e3 66 * parv[1] = server name
67 * parv[2] = comment
68 */
69static int
70mo_squit(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
71{
72 struct squit_parms *found_squit;
73 const char *comment = (parc > 2 && parv[2]) ? parv[2] : client_p->name;
74
75 if((found_squit = find_squit(client_p, source_p, parv[1])))
76 {
77 if(MyConnect(found_squit->target_p))
78 {
79 sendto_realops_snomask(SNO_GENERAL, L_ALL,
80 "Received SQUIT %s from %s (%s)",
81 found_squit->target_p->name,
82 get_client_name(source_p, HIDE_IP), comment);
83 ilog(L_SERVER, "Received SQUIT %s from %s (%s)",
84 found_squit->target_p->name, log_client_name(source_p, HIDE_IP),
85 comment);
86 }
87 else if(!IsOperRemote(source_p))
88 {
89 sendto_one(source_p, form_str(ERR_NOPRIVS),
90 me.name, source_p->name, "remote");
91 return 0;
92 }
93
94 exit_client(client_p, found_squit->target_p, source_p, comment);
95 return 0;
96 }
97 else
98 {
99 sendto_one_numeric(source_p, ERR_NOSUCHSERVER, form_str(ERR_NOSUCHSERVER), parv[1]);
100 }
101
102 return 0;
103}
104
105/*
106 * ms_squit - SQUIT message handler
212380e3 107 * parv[1] = server name
108 * parv[2] = comment
109 */
110static int
111ms_squit(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
112{
113 struct Client *target_p;
114 const char *comment = (parc > 2 && parv[2]) ? parv[2] : client_p->name;
115
116 if(parc < 2)
117 target_p = client_p;
118 else
119 {
120 if((target_p = find_server(NULL, parv[1])) == NULL)
121 return 0;
122
123 if(IsMe(target_p))
124 target_p = client_p;
125 if(!IsServer(target_p))
126 return 0;
127 }
128
129 /* Server is closing its link */
130 if (target_p == client_p)
131 {
132 sendto_realops_snomask(SNO_GENERAL, L_ALL, "Server %s closing link (%s)",
133 target_p->name, comment);
134 }
135 /*
136 ** Notify all opers, if my local link is remotely squitted
137 */
138 else if(MyConnect(target_p))
139 {
140 sendto_wallops_flags(UMODE_WALLOP, &me,
141 "Remote SQUIT %s from %s (%s)",
142 target_p->name, source_p->name, comment);
143
144 sendto_server(NULL, NULL, CAP_TS6, NOCAPS,
145 ":%s WALLOPS :Remote SQUIT %s from %s (%s)",
146 me.id, target_p->name, source_p->name, comment);
147
8e425f41 148 ilog(L_SERVER, "SQUIT From %s : %s (%s)", source_p->name, target_p->name, comment);
212380e3 149 }
150 exit_client(client_p, target_p, source_p, comment);
151 return 0;
152}
153
154
155/*
156 * find_squit
157 * inputs - local server connection
158 * -
159 * -
160 * output - pointer to struct containing found squit or none if not found
161 * side effects -
162 */
163static struct squit_parms *
164find_squit(struct Client *client_p, struct Client *source_p, const char *server)
165{
166 static struct squit_parms found_squit;
167 struct Client *target_p = NULL;
168 struct Client *p;
08d11e34 169 rb_dlink_node *ptr;
212380e3 170
171 /* must ALWAYS be reset */
172 found_squit.target_p = NULL;
173 found_squit.server_name = NULL;
174
175
176 /*
177 ** The following allows wild cards in SQUIT. Only useful
178 ** when the command is issued by an oper.
179 */
180
08d11e34 181 RB_DLINK_FOREACH(ptr, global_serv_list.head)
212380e3 182 {
183 p = ptr->data;
184 if(IsServer(p) || IsMe(p))
185 {
186 if(match(server, p->name))
187 {
188 target_p = p;
189 break;
190 }
191 }
192 }
193
194 if(target_p == NULL)
195 return NULL;
196
197 found_squit.target_p = target_p;
198 found_squit.server_name = server;
199
200 if(IsMe(target_p))
201 {
202 if(IsClient(client_p))
203 {
204 if(MyClient(client_p))
5366977b 205 sendto_one_notice(source_p, ":You are trying to squit me.");
206
212380e3 207 return NULL;
208 }
209 else
210 {
211 found_squit.target_p = client_p;
212 found_squit.server_name = client_p->name;
213 }
214 }
215
216 if(found_squit.target_p != NULL)
217 return &found_squit;
218 else
219 return (NULL);
220}