1 |
adx |
30 |
/* |
2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
|
|
* m_connect.c: Connects to a remote IRC server. |
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 |
knight |
31 |
* $Id$ |
23 |
adx |
30 |
*/ |
24 |
|
|
|
25 |
|
|
#include "stdinc.h" |
26 |
adx |
719 |
#include "conf/conf.h" |
27 |
adx |
30 |
#include "handlers.h" |
28 |
|
|
#include "client.h" |
29 |
|
|
#include "ircd.h" |
30 |
|
|
#include "numeric.h" |
31 |
|
|
#include "s_serv.h" |
32 |
|
|
#include "send.h" |
33 |
|
|
#include "msg.h" |
34 |
|
|
#include "parse.h" |
35 |
|
|
#include "hash.h" |
36 |
|
|
|
37 |
michael |
348 |
static void mo_connect(struct Client *, struct Client *, int, char *[]); |
38 |
|
|
static void ms_connect(struct Client *, struct Client *, int, char *[]); |
39 |
adx |
30 |
|
40 |
|
|
struct Message connect_msgtab = { |
41 |
|
|
"CONNECT", 0, 0, 2, 0, MFLG_SLOW, 0, |
42 |
michael |
348 |
{ m_unregistered, m_not_oper, ms_connect, m_ignore, mo_connect, m_ignore } |
43 |
adx |
30 |
}; |
44 |
|
|
|
45 |
adx |
442 |
INIT_MODULE(m_connect, "$Revision$") |
46 |
adx |
30 |
{ |
47 |
|
|
mod_add_cmd(&connect_msgtab); |
48 |
|
|
} |
49 |
|
|
|
50 |
adx |
442 |
CLEANUP_MODULE |
51 |
adx |
30 |
{ |
52 |
|
|
mod_del_cmd(&connect_msgtab); |
53 |
|
|
} |
54 |
|
|
|
55 |
michael |
348 |
/*! \brief CONNECT command handler (called for operators only) |
56 |
adx |
30 |
* |
57 |
michael |
348 |
* \param client_p Pointer to allocated Client struct with physical connection |
58 |
|
|
* to this server, i.e. with an open socket connected. |
59 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
60 |
|
|
* originally comes from. This can be a local or remote client. |
61 |
|
|
* \param parc Integer holding the number of supplied arguments. |
62 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
63 |
|
|
* pointers. |
64 |
|
|
* \note Valid arguments for this command are: |
65 |
|
|
* - parv[0] = sender prefix |
66 |
|
|
* - parv[1] = servername |
67 |
|
|
* - parv[2] = port number |
68 |
|
|
* - parv[3] = remote server |
69 |
adx |
30 |
*/ |
70 |
|
|
static void |
71 |
michael |
374 |
mo_connect(struct Client *client_p, struct Client *source_p, |
72 |
|
|
int parc, char *parv[]) |
73 |
adx |
30 |
{ |
74 |
michael |
374 |
int port = 0; |
75 |
adx |
30 |
struct ConfItem *conf = NULL; |
76 |
|
|
struct AccessItem *aconf = NULL; |
77 |
michael |
374 |
struct Client *target_p = NULL; |
78 |
adx |
30 |
|
79 |
|
|
/* always privileged with handlers */ |
80 |
|
|
if (MyConnect(source_p) && !IsOperRemote(source_p) && parc > 3) |
81 |
|
|
{ |
82 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS), |
83 |
|
|
me.name, source_p->name, "connect"); |
84 |
|
|
return; |
85 |
|
|
} |
86 |
|
|
|
87 |
michael |
609 |
if (hunt_server(source_p, ":%s CONNECT %s %s :%s", 3, |
88 |
michael |
348 |
parc, parv) != HUNTED_ISME) |
89 |
adx |
30 |
return; |
90 |
|
|
|
91 |
michael |
614 |
if (EmptyString(parv[1])) |
92 |
adx |
30 |
{ |
93 |
|
|
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
94 |
|
|
me.name, source_p->name, "CONNECT"); |
95 |
|
|
return; |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
if ((target_p = find_server(parv[1]))) |
99 |
|
|
{ |
100 |
|
|
sendto_one(source_p, |
101 |
michael |
373 |
":%s NOTICE %s :Connect: Server %s already exists from %s.", |
102 |
adx |
30 |
me.name, source_p->name, parv[1], target_p->from->name); |
103 |
|
|
return; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
/* |
107 |
michael |
373 |
* Try to find the name, then host, if both fail notify ops and bail |
108 |
adx |
30 |
*/ |
109 |
|
|
if ((conf = find_matching_name_conf(SERVER_TYPE, |
110 |
michael |
373 |
parv[1], NULL, NULL, 0)) != NULL) |
111 |
db |
139 |
aconf = &conf->conf.AccessItem; |
112 |
adx |
30 |
else if ((conf = find_matching_name_conf(SERVER_TYPE, |
113 |
michael |
373 |
NULL, NULL, parv[1], 0)) != NULL) |
114 |
db |
139 |
aconf = &conf->conf.AccessItem; |
115 |
adx |
30 |
|
116 |
|
|
if (conf == NULL) |
117 |
|
|
{ |
118 |
|
|
sendto_one(source_p, |
119 |
michael |
373 |
":%s NOTICE %s :Connect: Host %s not listed in ircd.conf", |
120 |
|
|
me.name, source_p->name, parv[1]); |
121 |
adx |
30 |
return; |
122 |
|
|
} |
123 |
michael |
373 |
|
124 |
|
|
/* |
125 |
|
|
* Get port number from user, if given. If not specified, |
126 |
|
|
* use the default from configuration structure. |
127 |
adx |
30 |
*/ |
128 |
michael |
374 |
port = aconf->port; |
129 |
adx |
30 |
|
130 |
|
|
if (parc > 2 && !EmptyString(parv[2])) |
131 |
michael |
374 |
port = atoi(parv[2]); |
132 |
|
|
|
133 |
|
|
if (port <= 0 || port > 0xFFFF) |
134 |
adx |
30 |
{ |
135 |
michael |
374 |
sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal or missing port number", |
136 |
adx |
30 |
me.name, source_p->name); |
137 |
|
|
return; |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
if (find_servconn_in_progress(conf->name)) |
141 |
|
|
{ |
142 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Connect: a connection to %s " |
143 |
|
|
"is already in progress.", me.name, source_p->name, conf->name); |
144 |
|
|
return; |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
/* |
148 |
|
|
* Notify all operators about remote connect requests |
149 |
|
|
*/ |
150 |
michael |
614 |
ilog(L_TRACE, "CONNECT From %s : %s %s", |
151 |
|
|
get_oper_name(source_p), parv[1], parv[2] ? parv[2] : ""); |
152 |
adx |
30 |
|
153 |
michael |
373 |
/* |
154 |
|
|
* At this point we should be calling connect_server with a valid |
155 |
|
|
* connect{} and a valid port in the connect{} |
156 |
adx |
30 |
*/ |
157 |
michael |
374 |
if (serv_connect(aconf, source_p, port)) |
158 |
adx |
30 |
{ |
159 |
|
|
if (!ConfigServerHide.hide_server_ips && IsAdmin(source_p)) |
160 |
|
|
sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s[%s].%d", |
161 |
|
|
me.name, source_p->name, aconf->host, |
162 |
michael |
374 |
conf->name, port); |
163 |
adx |
30 |
else |
164 |
|
|
sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d", |
165 |
michael |
374 |
me.name, source_p->name, conf->name, port); |
166 |
adx |
30 |
} |
167 |
|
|
else |
168 |
|
|
sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d", |
169 |
michael |
374 |
me.name, source_p->name, conf->name, port); |
170 |
michael |
348 |
/* |
171 |
michael |
373 |
* Client is either connecting with all the data it needs or has been |
172 |
adx |
30 |
* destroyed |
173 |
|
|
*/ |
174 |
|
|
} |
175 |
|
|
|
176 |
michael |
348 |
/*! \brief CONNECT command handler (called for remote clients only) |
177 |
adx |
30 |
* |
178 |
michael |
348 |
* \param client_p Pointer to allocated Client struct with physical connection |
179 |
|
|
* to this server, i.e. with an open socket connected. |
180 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
181 |
|
|
* originally comes from. This can be a local or remote client. |
182 |
|
|
* \param parc Integer holding the number of supplied arguments. |
183 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
184 |
|
|
* pointers. |
185 |
|
|
* \note Valid arguments for this command are: |
186 |
|
|
* - parv[0] = sender prefix |
187 |
|
|
* - parv[1] = servername |
188 |
|
|
* - parv[2] = port number |
189 |
|
|
* - parv[3] = remote server |
190 |
adx |
30 |
*/ |
191 |
|
|
static void |
192 |
|
|
ms_connect(struct Client *client_p, struct Client *source_p, |
193 |
|
|
int parc, char *parv[]) |
194 |
|
|
{ |
195 |
michael |
374 |
int port = 0; |
196 |
adx |
30 |
struct ConfItem *conf = NULL; |
197 |
|
|
struct AccessItem *aconf = NULL; |
198 |
michael |
374 |
struct Client *target_p = NULL; |
199 |
adx |
30 |
|
200 |
michael |
609 |
if (hunt_server(source_p, ":%s CONNECT %s %s :%s", 3, |
201 |
michael |
348 |
parc, parv) != HUNTED_ISME) |
202 |
adx |
30 |
return; |
203 |
|
|
|
204 |
michael |
614 |
if (EmptyString(parv[1])) |
205 |
adx |
30 |
{ |
206 |
|
|
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
207 |
|
|
me.name, source_p->name, "CONNECT"); |
208 |
|
|
return; |
209 |
|
|
} |
210 |
|
|
|
211 |
|
|
if ((target_p = find_server(parv[1]))) |
212 |
|
|
{ |
213 |
|
|
sendto_one(source_p, |
214 |
michael |
373 |
":%s NOTICE %s :Connect: Server %s already exists from %s.", |
215 |
adx |
30 |
me.name, source_p->name, parv[1], target_p->from->name); |
216 |
|
|
return; |
217 |
|
|
} |
218 |
|
|
|
219 |
|
|
/* |
220 |
michael |
373 |
* Try to find the name, then host, if both fail notify ops and bail |
221 |
adx |
30 |
*/ |
222 |
|
|
if ((conf = find_matching_name_conf(SERVER_TYPE, |
223 |
michael |
373 |
parv[1], NULL, NULL, 0)) != NULL) |
224 |
db |
139 |
aconf = &conf->conf.AccessItem; |
225 |
adx |
30 |
else if ((conf = find_matching_name_conf(SERVER_TYPE, |
226 |
michael |
373 |
NULL, NULL, parv[1], 0)) != NULL) |
227 |
db |
139 |
aconf = &conf->conf.AccessItem; |
228 |
adx |
30 |
|
229 |
|
|
if (aconf == NULL) |
230 |
|
|
{ |
231 |
|
|
sendto_one(source_p, |
232 |
michael |
373 |
":%s NOTICE %s :Connect: Host %s not listed in ircd.conf", |
233 |
|
|
me.name, source_p->name, parv[1]); |
234 |
adx |
30 |
return; |
235 |
|
|
} |
236 |
|
|
|
237 |
|
|
assert(aconf != NULL); |
238 |
|
|
|
239 |
michael |
373 |
/* |
240 |
|
|
* Get port number from user, if given. If not specified, |
241 |
|
|
* use the default from configuration structure. |
242 |
adx |
30 |
*/ |
243 |
michael |
374 |
port = aconf->port; |
244 |
adx |
30 |
|
245 |
|
|
if (parc > 2 && !EmptyString(parv[2])) |
246 |
|
|
{ |
247 |
|
|
port = atoi(parv[2]); |
248 |
|
|
|
249 |
michael |
374 |
/* if someone sends port 0, use the config port instead */ |
250 |
|
|
if (port == 0) |
251 |
adx |
30 |
port = aconf->port; |
252 |
|
|
} |
253 |
michael |
374 |
|
254 |
|
|
if (port <= 0 || port > 0xFFFF) |
255 |
adx |
30 |
{ |
256 |
michael |
374 |
sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal or missing port number", |
257 |
adx |
30 |
me.name, source_p->name); |
258 |
|
|
return; |
259 |
|
|
} |
260 |
|
|
|
261 |
|
|
if (find_servconn_in_progress(conf->name)) |
262 |
|
|
{ |
263 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Connect: a connection to %s " |
264 |
|
|
"is already in progress.", me.name, source_p->name, conf->name); |
265 |
|
|
return; |
266 |
|
|
} |
267 |
|
|
|
268 |
|
|
/* |
269 |
|
|
* Notify all operators about remote connect requests |
270 |
|
|
*/ |
271 |
|
|
sendto_wallops_flags(UMODE_WALLOP, &me, "Remote CONNECT %s %d from %s", |
272 |
|
|
parv[1], port, source_p->name); |
273 |
michael |
405 |
sendto_server(NULL, NULL, NULL, NOCAPS, NOCAPS, |
274 |
adx |
30 |
":%s WALLOPS :Remote CONNECT %s %d from %s", |
275 |
|
|
me.name, parv[1], port, source_p->name); |
276 |
|
|
|
277 |
|
|
ilog(L_TRACE, "CONNECT From %s : %s %d", |
278 |
michael |
614 |
get_oper_name(source_p), parv[1], port); |
279 |
adx |
30 |
|
280 |
michael |
373 |
/* |
281 |
|
|
* At this point we should be calling connect_server with a valid |
282 |
|
|
* connect{} and a valid port in the connect{} |
283 |
adx |
30 |
*/ |
284 |
michael |
374 |
if (serv_connect(aconf, source_p, port)) |
285 |
adx |
30 |
sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d", |
286 |
michael |
374 |
me.name, source_p->name, conf->name, port); |
287 |
adx |
30 |
else |
288 |
|
|
sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d", |
289 |
michael |
374 |
me.name, source_p->name, conf->name, port); |
290 |
michael |
348 |
|
291 |
|
|
/* |
292 |
michael |
373 |
* Client is either connecting with all the data it needs or has been |
293 |
adx |
30 |
* destroyed |
294 |
|
|
*/ |
295 |
|
|
} |