]> jfr.im git - solanum.git/blob - modules/core/m_squit.c
9c72969d880451abce33377f8195c70c64aa4151
[solanum.git] / modules / core / m_squit.c
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 */
24
25 #include "stdinc.h"
26 #include "client.h"
27 #include "common.h" /* FALSE bleah */
28 #include "match.h"
29 #include "ircd.h"
30 #include "numeric.h"
31 #include "s_conf.h"
32 #include "logger.h"
33 #include "s_serv.h"
34 #include "send.h"
35 #include "msg.h"
36 #include "parse.h"
37 #include "modules.h"
38 #include "hash.h"
39 #include "s_newconf.h"
40
41 static int ms_squit(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
42 static int mo_squit(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
43
44 struct Message squit_msgtab = {
45 "SQUIT", 0, 0, 0, 0,
46 {mg_unreg, mg_not_oper, {ms_squit, 0}, {ms_squit, 0}, mg_ignore, {mo_squit, 2}}
47 };
48
49 mapi_clist_av1 squit_clist[] = { &squit_msgtab, NULL };
50
51 DECLARE_MODULE_AV2(squit, NULL, NULL, squit_clist, NULL, NULL, NULL, NULL, NULL);
52
53 struct squit_parms
54 {
55 const char *server_name;
56 struct Client *target_p;
57 };
58
59 static struct squit_parms *find_squit(struct Client *client_p,
60 struct Client *source_p, const char *server);
61
62
63 /*
64 * mo_squit - SQUIT message handler
65 * parv[1] = server name
66 * parv[2] = comment
67 */
68 static int
69 mo_squit(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
70 {
71 struct squit_parms *found_squit;
72 const char *comment = (parc > 2 && parv[2]) ? parv[2] : client_p->name;
73
74 if((found_squit = find_squit(client_p, source_p, parv[1])))
75 {
76 if(MyConnect(found_squit->target_p))
77 {
78 sendto_realops_snomask(SNO_GENERAL, L_ALL,
79 "Received SQUIT %s from %s (%s)",
80 found_squit->target_p->name,
81 get_client_name(source_p, HIDE_IP), comment);
82 ilog(L_SERVER, "Received SQUIT %s from %s (%s)",
83 found_squit->target_p->name, log_client_name(source_p, HIDE_IP),
84 comment);
85 }
86 else if(!IsOperRemote(source_p))
87 {
88 sendto_one(source_p, form_str(ERR_NOPRIVS),
89 me.name, source_p->name, "remote");
90 return 0;
91 }
92
93 exit_client(client_p, found_squit->target_p, source_p, comment);
94 return 0;
95 }
96 else
97 {
98 sendto_one_numeric(source_p, ERR_NOSUCHSERVER, form_str(ERR_NOSUCHSERVER), parv[1]);
99 }
100
101 return 0;
102 }
103
104 /*
105 * ms_squit - SQUIT message handler
106 * parv[1] = server name
107 * parv[2] = comment
108 */
109 static int
110 ms_squit(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
111 {
112 struct Client *target_p;
113 const char *comment = (parc > 2 && parv[2]) ? parv[2] : client_p->name;
114
115 if(parc < 2)
116 target_p = client_p;
117 else
118 {
119 if((target_p = find_server(NULL, parv[1])) == NULL)
120 return 0;
121
122 if(IsMe(target_p))
123 target_p = client_p;
124 if(!IsServer(target_p))
125 return 0;
126 }
127
128 /* Server is closing its link */
129 if (target_p == client_p)
130 {
131 sendto_realops_snomask(SNO_GENERAL, L_ALL, "Server %s closing link (%s)",
132 target_p->name, comment);
133 }
134 /*
135 ** Notify all opers, if my local link is remotely squitted
136 */
137 else if(MyConnect(target_p))
138 {
139 sendto_wallops_flags(UMODE_WALLOP, &me,
140 "Remote SQUIT %s from %s (%s)",
141 target_p->name, source_p->name, comment);
142
143 sendto_server(NULL, NULL, CAP_TS6, NOCAPS,
144 ":%s WALLOPS :Remote SQUIT %s from %s (%s)",
145 me.id, target_p->name, source_p->name, comment);
146
147 ilog(L_SERVER, "SQUIT From %s : %s (%s)", source_p->name, target_p->name, comment);
148 }
149 exit_client(client_p, target_p, source_p, comment);
150 return 0;
151 }
152
153
154 /*
155 * find_squit
156 * inputs - local server connection
157 * -
158 * -
159 * output - pointer to struct containing found squit or none if not found
160 * side effects -
161 */
162 static struct squit_parms *
163 find_squit(struct Client *client_p, struct Client *source_p, const char *server)
164 {
165 static struct squit_parms found_squit;
166 struct Client *target_p = NULL;
167 struct Client *p;
168 rb_dlink_node *ptr;
169
170 /* must ALWAYS be reset */
171 found_squit.target_p = NULL;
172 found_squit.server_name = NULL;
173
174
175 /*
176 ** The following allows wild cards in SQUIT. Only useful
177 ** when the command is issued by an oper.
178 */
179
180 RB_DLINK_FOREACH(ptr, global_serv_list.head)
181 {
182 p = ptr->data;
183 if(IsServer(p) || IsMe(p))
184 {
185 if(match(server, p->name))
186 {
187 target_p = p;
188 break;
189 }
190 }
191 }
192
193 if(target_p == NULL)
194 return NULL;
195
196 found_squit.target_p = target_p;
197 found_squit.server_name = server;
198
199 if(IsMe(target_p))
200 {
201 if(IsClient(client_p))
202 {
203 if(MyClient(client_p))
204 sendto_one_notice(source_p, ":You are trying to squit me.");
205
206 return NULL;
207 }
208 else
209 {
210 found_squit.target_p = client_p;
211 found_squit.server_name = client_p->name;
212 }
213 }
214
215 if(found_squit.target_p != NULL)
216 return &found_squit;
217 else
218 return (NULL);
219 }