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