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