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