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 |
|
|
#include "client.h" |
27 |
|
|
#include "ircd.h" |
28 |
|
|
#include "irc_string.h" |
29 |
|
|
#include "numeric.h" |
30 |
|
|
#include "fdlist.h" |
31 |
|
|
#include "s_bsd.h" |
32 |
|
|
#include "s_conf.h" |
33 |
|
|
#include "s_log.h" |
34 |
|
|
#include "s_serv.h" |
35 |
|
|
#include "send.h" |
36 |
|
|
#include "parse.h" |
37 |
|
|
#include "hash.h" |
38 |
|
|
#include "modules.h" |
39 |
|
|
|
40 |
|
|
|
41 |
|
|
/* |
42 |
|
|
* mo_connect - CONNECT command handler |
43 |
|
|
* |
44 |
|
|
* Added by Jto 11 Feb 1989 |
45 |
|
|
* |
46 |
|
|
* m_connect |
47 |
|
|
* parv[0] = sender prefix |
48 |
|
|
* parv[1] = servername |
49 |
|
|
* parv[2] = port number |
50 |
|
|
* parv[3] = remote server |
51 |
|
|
*/ |
52 |
|
|
static void |
53 |
michael |
971 |
mo_connect(struct Client *client_p, struct Client *source_p, |
54 |
|
|
int parc, char *parv[]) |
55 |
adx |
30 |
{ |
56 |
|
|
int port; |
57 |
|
|
int tmpport; |
58 |
|
|
struct ConfItem *conf = NULL; |
59 |
|
|
struct AccessItem *aconf = NULL; |
60 |
michael |
971 |
const struct Client *target_p = NULL; |
61 |
adx |
30 |
|
62 |
michael |
971 |
if (EmptyString(parv[1])) |
63 |
adx |
30 |
{ |
64 |
michael |
971 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
65 |
|
|
me.name, source_p->name, "CONNECT"); |
66 |
adx |
30 |
return; |
67 |
|
|
} |
68 |
|
|
|
69 |
michael |
971 |
if (parc > 3) |
70 |
|
|
{ |
71 |
michael |
1219 |
if (!HasOFlag(source_p, OPER_FLAG_REMOTE)) |
72 |
michael |
971 |
{ |
73 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS), |
74 |
|
|
me.name, source_p->name, "connect"); |
75 |
|
|
return; |
76 |
|
|
} |
77 |
adx |
30 |
|
78 |
michael |
971 |
if (hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3, |
79 |
|
|
parc, parv) != HUNTED_ISME) |
80 |
|
|
return; |
81 |
adx |
30 |
} |
82 |
|
|
|
83 |
michael |
1169 |
if ((target_p = hash_find_server(parv[1]))) |
84 |
adx |
30 |
{ |
85 |
|
|
sendto_one(source_p, |
86 |
|
|
":%s NOTICE %s :Connect: Server %s already exists from %s.", |
87 |
|
|
me.name, source_p->name, parv[1], target_p->from->name); |
88 |
|
|
return; |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
/* |
92 |
|
|
* try to find the name, then host, if both fail notify ops and bail |
93 |
|
|
*/ |
94 |
|
|
if ((conf = find_matching_name_conf(SERVER_TYPE, |
95 |
|
|
parv[1], NULL, NULL, 0)) != NULL) |
96 |
|
|
aconf = (struct AccessItem *)map_to_conf(conf); |
97 |
|
|
else if ((conf = find_matching_name_conf(SERVER_TYPE, |
98 |
|
|
NULL, NULL, parv[1], 0)) != NULL) |
99 |
|
|
aconf = (struct AccessItem *)map_to_conf(conf); |
100 |
|
|
|
101 |
michael |
971 |
if (conf == NULL || aconf == NULL) |
102 |
adx |
30 |
{ |
103 |
|
|
sendto_one(source_p, |
104 |
|
|
":%s NOTICE %s :Connect: Host %s not listed in ircd.conf", |
105 |
|
|
me.name, source_p->name, parv[1]); |
106 |
|
|
return; |
107 |
|
|
} |
108 |
michael |
971 |
|
109 |
adx |
30 |
/* Get port number from user, if given. If not specified, |
110 |
|
|
* use the default form configuration structure. If missing |
111 |
|
|
* from there, then use the precompiled default. |
112 |
|
|
*/ |
113 |
|
|
tmpport = port = aconf->port; |
114 |
|
|
|
115 |
|
|
if (parc > 2 && !EmptyString(parv[2])) |
116 |
|
|
{ |
117 |
|
|
if ((port = atoi(parv[2])) <= 0) |
118 |
|
|
{ |
119 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal port number", |
120 |
|
|
me.name, source_p->name); |
121 |
|
|
return; |
122 |
|
|
} |
123 |
|
|
} |
124 |
|
|
else if (port <= 0 && (port = PORTNUM) <= 0) |
125 |
|
|
{ |
126 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Connect: missing port number", |
127 |
|
|
me.name, source_p->name); |
128 |
|
|
return; |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
if (find_servconn_in_progress(conf->name)) |
132 |
|
|
{ |
133 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Connect: a connection to %s " |
134 |
|
|
"is already in progress.", me.name, source_p->name, conf->name); |
135 |
|
|
return; |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
/* |
139 |
|
|
* Notify all operators about remote connect requests |
140 |
|
|
*/ |
141 |
|
|
ilog(L_TRACE, "CONNECT From %s : %s %s", |
142 |
|
|
source_p->name, parv[1], parv[2] ? parv[2] : ""); |
143 |
|
|
|
144 |
|
|
aconf->port = port; |
145 |
|
|
|
146 |
|
|
/* at this point we should be calling connect_server with a valid |
147 |
|
|
* C:line and a valid port in the C:line |
148 |
|
|
*/ |
149 |
|
|
if (serv_connect(aconf, source_p)) |
150 |
|
|
{ |
151 |
michael |
1219 |
if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN)) |
152 |
adx |
30 |
sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s[%s].%d", |
153 |
|
|
me.name, source_p->name, aconf->host, |
154 |
|
|
conf->name, aconf->port); |
155 |
|
|
else |
156 |
|
|
sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d", |
157 |
|
|
me.name, source_p->name, conf->name, aconf->port); |
158 |
|
|
} |
159 |
|
|
else |
160 |
|
|
{ |
161 |
|
|
sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d", |
162 |
|
|
me.name, source_p->name, conf->name, aconf->port); |
163 |
|
|
} |
164 |
|
|
|
165 |
|
|
/* client is either connecting with all the data it needs or has been |
166 |
|
|
* destroyed |
167 |
|
|
*/ |
168 |
|
|
aconf->port = tmpport; |
169 |
|
|
} |
170 |
|
|
|
171 |
|
|
/* |
172 |
|
|
* ms_connect - CONNECT command handler |
173 |
|
|
* |
174 |
|
|
* Added by Jto 11 Feb 1989 |
175 |
|
|
* |
176 |
|
|
* m_connect |
177 |
|
|
* parv[0] = sender prefix |
178 |
|
|
* parv[1] = servername |
179 |
|
|
* parv[2] = port number |
180 |
|
|
* parv[3] = remote server |
181 |
|
|
*/ |
182 |
|
|
static void |
183 |
|
|
ms_connect(struct Client *client_p, struct Client *source_p, |
184 |
|
|
int parc, char *parv[]) |
185 |
|
|
{ |
186 |
|
|
int port; |
187 |
|
|
int tmpport; |
188 |
|
|
struct ConfItem *conf = NULL; |
189 |
|
|
struct AccessItem *aconf = NULL; |
190 |
michael |
971 |
const struct Client *target_p = NULL; |
191 |
adx |
30 |
|
192 |
|
|
if (hunt_server(client_p, source_p, |
193 |
|
|
":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME) |
194 |
|
|
return; |
195 |
|
|
|
196 |
|
|
if (*parv[1] == '\0') |
197 |
|
|
{ |
198 |
|
|
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
199 |
|
|
me.name, source_p->name, "CONNECT"); |
200 |
|
|
return; |
201 |
|
|
} |
202 |
|
|
|
203 |
michael |
1169 |
if ((target_p = hash_find_server(parv[1]))) |
204 |
adx |
30 |
{ |
205 |
|
|
sendto_one(source_p, |
206 |
|
|
":%s NOTICE %s :Connect: Server %s already exists from %s.", |
207 |
|
|
me.name, source_p->name, parv[1], target_p->from->name); |
208 |
|
|
return; |
209 |
|
|
} |
210 |
|
|
|
211 |
|
|
/* |
212 |
|
|
* try to find the name, then host, if both fail notify ops and bail |
213 |
|
|
*/ |
214 |
|
|
if ((conf = find_matching_name_conf(SERVER_TYPE, |
215 |
|
|
parv[1], NULL, NULL, 0)) != NULL) |
216 |
michael |
971 |
aconf = map_to_conf(conf); |
217 |
adx |
30 |
else if ((conf = find_matching_name_conf(SERVER_TYPE, |
218 |
|
|
NULL, NULL, parv[1], 0)) != NULL) |
219 |
michael |
971 |
aconf = map_to_conf(conf); |
220 |
adx |
30 |
|
221 |
michael |
971 |
if (conf == NULL || aconf == NULL) |
222 |
adx |
30 |
{ |
223 |
|
|
sendto_one(source_p, |
224 |
|
|
":%s NOTICE %s :Connect: Host %s not listed in ircd.conf", |
225 |
|
|
me.name, source_p->name, parv[1]); |
226 |
|
|
return; |
227 |
|
|
} |
228 |
|
|
|
229 |
|
|
/* Get port number from user, if given. If not specified, |
230 |
|
|
* use the default form configuration structure. If missing |
231 |
|
|
* from there, then use the precompiled default. |
232 |
|
|
*/ |
233 |
|
|
tmpport = port = aconf->port; |
234 |
|
|
|
235 |
|
|
if (parc > 2 && !EmptyString(parv[2])) |
236 |
|
|
{ |
237 |
|
|
port = atoi(parv[2]); |
238 |
|
|
|
239 |
|
|
/* if someone sends port 0, and we have a config port.. use it */ |
240 |
|
|
if (port == 0 && aconf->port) |
241 |
|
|
port = aconf->port; |
242 |
|
|
else if (port <= 0) |
243 |
|
|
{ |
244 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal port number", |
245 |
|
|
me.name, source_p->name); |
246 |
|
|
return; |
247 |
|
|
} |
248 |
|
|
} |
249 |
|
|
else if (port <= 0 && (port = PORTNUM) <= 0) |
250 |
|
|
{ |
251 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Connect: missing port number", |
252 |
|
|
me.name, source_p->name); |
253 |
|
|
return; |
254 |
|
|
} |
255 |
|
|
|
256 |
|
|
if (find_servconn_in_progress(conf->name)) |
257 |
|
|
{ |
258 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Connect: a connection to %s " |
259 |
|
|
"is already in progress.", me.name, source_p->name, conf->name); |
260 |
|
|
return; |
261 |
|
|
} |
262 |
|
|
|
263 |
|
|
/* |
264 |
|
|
* Notify all operators about remote connect requests |
265 |
|
|
*/ |
266 |
|
|
sendto_wallops_flags(UMODE_WALLOP, &me, "Remote CONNECT %s %d from %s", |
267 |
|
|
parv[1], port, source_p->name); |
268 |
michael |
885 |
sendto_server(NULL, NULL, NOCAPS, NOCAPS, |
269 |
adx |
30 |
":%s WALLOPS :Remote CONNECT %s %d from %s", |
270 |
|
|
me.name, parv[1], port, source_p->name); |
271 |
|
|
|
272 |
|
|
ilog(L_TRACE, "CONNECT From %s : %s %d", |
273 |
|
|
source_p->name, parv[1], port); |
274 |
|
|
|
275 |
|
|
aconf->port = port; |
276 |
|
|
|
277 |
michael |
885 |
/* |
278 |
|
|
* At this point we should be calling connect_server with a valid |
279 |
adx |
30 |
* C:line and a valid port in the C:line |
280 |
|
|
*/ |
281 |
|
|
if (serv_connect(aconf, source_p)) |
282 |
|
|
sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d", |
283 |
|
|
me.name, source_p->name, conf->name, aconf->port); |
284 |
|
|
else |
285 |
|
|
sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d", |
286 |
|
|
me.name, source_p->name, conf->name, aconf->port); |
287 |
michael |
885 |
/* |
288 |
|
|
* Client is either connecting with all the data it needs or has been |
289 |
adx |
30 |
* destroyed |
290 |
|
|
*/ |
291 |
|
|
aconf->port = tmpport; |
292 |
|
|
} |
293 |
michael |
1230 |
|
294 |
|
|
static struct Message connect_msgtab = { |
295 |
|
|
"CONNECT", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
296 |
|
|
{ m_unregistered, m_not_oper, ms_connect, m_ignore, mo_connect, m_ignore } |
297 |
|
|
}; |
298 |
|
|
|
299 |
|
|
static void |
300 |
|
|
module_init(void) |
301 |
|
|
{ |
302 |
|
|
mod_add_cmd(&connect_msgtab); |
303 |
|
|
} |
304 |
|
|
|
305 |
|
|
static void |
306 |
|
|
module_exit(void) |
307 |
|
|
{ |
308 |
|
|
mod_del_cmd(&connect_msgtab); |
309 |
|
|
} |
310 |
|
|
|
311 |
|
|
struct module module_entry = { |
312 |
|
|
.node = { NULL, NULL, NULL }, |
313 |
|
|
.name = NULL, |
314 |
|
|
.version = "$Revision$", |
315 |
|
|
.handle = NULL, |
316 |
|
|
.modinit = module_init, |
317 |
|
|
.modexit = module_exit, |
318 |
|
|
.flags = 0 |
319 |
|
|
}; |