1 |
adx |
30 |
/* |
2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
2820 |
* Copyright (c) 1997-2014 ircd-hybrid development team |
5 |
adx |
30 |
* |
6 |
|
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
|
|
* USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
michael |
2820 |
/*! \file m_connect.c |
23 |
|
|
* \brief Includes required functions for processing the CONNECT command. |
24 |
|
|
* \version $Id$ |
25 |
|
|
*/ |
26 |
|
|
|
27 |
adx |
30 |
#include "stdinc.h" |
28 |
|
|
#include "client.h" |
29 |
|
|
#include "ircd.h" |
30 |
|
|
#include "irc_string.h" |
31 |
|
|
#include "numeric.h" |
32 |
|
|
#include "fdlist.h" |
33 |
|
|
#include "s_bsd.h" |
34 |
michael |
1309 |
#include "conf.h" |
35 |
|
|
#include "log.h" |
36 |
adx |
30 |
#include "s_serv.h" |
37 |
|
|
#include "send.h" |
38 |
|
|
#include "parse.h" |
39 |
|
|
#include "hash.h" |
40 |
|
|
#include "modules.h" |
41 |
|
|
|
42 |
|
|
|
43 |
|
|
/* |
44 |
|
|
* mo_connect - CONNECT command handler |
45 |
|
|
* |
46 |
|
|
* Added by Jto 11 Feb 1989 |
47 |
|
|
* |
48 |
|
|
* m_connect |
49 |
|
|
* parv[0] = sender prefix |
50 |
|
|
* parv[1] = servername |
51 |
|
|
* parv[2] = port number |
52 |
|
|
* parv[3] = remote server |
53 |
|
|
*/ |
54 |
michael |
2820 |
static int |
55 |
michael |
971 |
mo_connect(struct Client *client_p, struct Client *source_p, |
56 |
|
|
int parc, char *parv[]) |
57 |
adx |
30 |
{ |
58 |
|
|
int port; |
59 |
|
|
int tmpport; |
60 |
michael |
1632 |
struct MaskItem *conf = NULL; |
61 |
michael |
971 |
const struct Client *target_p = NULL; |
62 |
adx |
30 |
|
63 |
michael |
971 |
if (EmptyString(parv[1])) |
64 |
adx |
30 |
{ |
65 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
66 |
michael |
971 |
me.name, source_p->name, "CONNECT"); |
67 |
michael |
2820 |
return 0; |
68 |
adx |
30 |
} |
69 |
|
|
|
70 |
michael |
971 |
if (parc > 3) |
71 |
|
|
{ |
72 |
michael |
2012 |
if (!HasOFlag(source_p, OPER_FLAG_CONNECT_REMOTE)) |
73 |
michael |
971 |
{ |
74 |
michael |
2801 |
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, |
75 |
|
|
source_p->name, "connect:remote"); |
76 |
michael |
2820 |
return 0; |
77 |
michael |
971 |
} |
78 |
adx |
30 |
|
79 |
michael |
971 |
if (hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3, |
80 |
|
|
parc, parv) != HUNTED_ISME) |
81 |
michael |
2820 |
return 0; |
82 |
adx |
30 |
} |
83 |
michael |
2012 |
else if (!HasOFlag(source_p, OPER_FLAG_CONNECT)) |
84 |
|
|
{ |
85 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS), |
86 |
|
|
me.name, source_p->name, "connect"); |
87 |
michael |
2820 |
return 0; |
88 |
michael |
2012 |
} |
89 |
adx |
30 |
|
90 |
michael |
1169 |
if ((target_p = hash_find_server(parv[1]))) |
91 |
adx |
30 |
{ |
92 |
|
|
sendto_one(source_p, |
93 |
michael |
2345 |
":%s NOTICE %s :Connect: Server %s already exists from %s.", |
94 |
adx |
30 |
me.name, source_p->name, parv[1], target_p->from->name); |
95 |
michael |
2820 |
return 0; |
96 |
adx |
30 |
} |
97 |
|
|
|
98 |
|
|
/* |
99 |
michael |
2820 |
* Try to find the name, then host, if both fail notify ops and bail |
100 |
adx |
30 |
*/ |
101 |
michael |
1636 |
if (!(conf = find_matching_name_conf(CONF_SERVER, parv[1], NULL, NULL, 0))) |
102 |
adx |
30 |
{ |
103 |
michael |
1636 |
if (!(conf = find_matching_name_conf(CONF_SERVER, NULL, NULL, parv[1], 0))) |
104 |
|
|
{ |
105 |
|
|
sendto_one(source_p, |
106 |
|
|
":%s NOTICE %s :Connect: Host %s not listed in ircd.conf", |
107 |
|
|
me.name, source_p->name, parv[1]); |
108 |
michael |
2820 |
return 0; |
109 |
michael |
1636 |
} |
110 |
adx |
30 |
} |
111 |
michael |
971 |
|
112 |
michael |
2345 |
/* |
113 |
|
|
* Get port number from user, if given. If not specified, |
114 |
adx |
30 |
* use the default form configuration structure. If missing |
115 |
|
|
* from there, then use the precompiled default. |
116 |
|
|
*/ |
117 |
michael |
1632 |
tmpport = port = conf->port; |
118 |
adx |
30 |
|
119 |
|
|
if (parc > 2 && !EmptyString(parv[2])) |
120 |
|
|
{ |
121 |
|
|
if ((port = atoi(parv[2])) <= 0) |
122 |
|
|
{ |
123 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal port number", |
124 |
|
|
me.name, source_p->name); |
125 |
michael |
2820 |
return 0; |
126 |
adx |
30 |
} |
127 |
|
|
} |
128 |
|
|
else if (port <= 0 && (port = PORTNUM) <= 0) |
129 |
|
|
{ |
130 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Connect: missing port number", |
131 |
|
|
me.name, source_p->name); |
132 |
michael |
2820 |
return 0; |
133 |
adx |
30 |
} |
134 |
|
|
|
135 |
|
|
if (find_servconn_in_progress(conf->name)) |
136 |
|
|
{ |
137 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Connect: a connection to %s " |
138 |
|
|
"is already in progress.", me.name, source_p->name, conf->name); |
139 |
michael |
2820 |
return 0; |
140 |
adx |
30 |
} |
141 |
|
|
|
142 |
|
|
/* |
143 |
|
|
* Notify all operators about remote connect requests |
144 |
|
|
*/ |
145 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "CONNECT From %s : %s %s", |
146 |
adx |
30 |
source_p->name, parv[1], parv[2] ? parv[2] : ""); |
147 |
|
|
|
148 |
michael |
1632 |
conf->port = port; |
149 |
adx |
30 |
|
150 |
michael |
2345 |
/* |
151 |
michael |
2820 |
* At this point we should be calling connect_server with a valid |
152 |
adx |
30 |
* C:line and a valid port in the C:line |
153 |
|
|
*/ |
154 |
michael |
1632 |
if (serv_connect(conf, source_p)) |
155 |
adx |
30 |
{ |
156 |
michael |
1219 |
if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN)) |
157 |
adx |
30 |
sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s[%s].%d", |
158 |
michael |
1632 |
me.name, source_p->name, conf->host, |
159 |
|
|
conf->name, conf->port); |
160 |
adx |
30 |
else |
161 |
|
|
sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d", |
162 |
michael |
1632 |
me.name, source_p->name, conf->name, conf->port); |
163 |
adx |
30 |
} |
164 |
|
|
else |
165 |
|
|
{ |
166 |
|
|
sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d", |
167 |
michael |
1632 |
me.name, source_p->name, conf->name, conf->port); |
168 |
adx |
30 |
} |
169 |
|
|
|
170 |
michael |
2345 |
/* |
171 |
|
|
* Client is either connecting with all the data it needs or has been |
172 |
adx |
30 |
* destroyed |
173 |
|
|
*/ |
174 |
michael |
1632 |
conf->port = tmpport; |
175 |
michael |
2820 |
return 0; |
176 |
adx |
30 |
} |
177 |
|
|
|
178 |
|
|
/* |
179 |
|
|
* ms_connect - CONNECT command handler |
180 |
|
|
* |
181 |
|
|
* Added by Jto 11 Feb 1989 |
182 |
|
|
* |
183 |
|
|
* m_connect |
184 |
|
|
* parv[0] = sender prefix |
185 |
|
|
* parv[1] = servername |
186 |
|
|
* parv[2] = port number |
187 |
|
|
* parv[3] = remote server |
188 |
|
|
*/ |
189 |
michael |
2820 |
static int |
190 |
adx |
30 |
ms_connect(struct Client *client_p, struct Client *source_p, |
191 |
|
|
int parc, char *parv[]) |
192 |
|
|
{ |
193 |
|
|
int port; |
194 |
|
|
int tmpport; |
195 |
michael |
1632 |
struct MaskItem *conf = NULL; |
196 |
michael |
971 |
const struct Client *target_p = NULL; |
197 |
adx |
30 |
|
198 |
michael |
2345 |
if (hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", |
199 |
|
|
3, parc, parv) != HUNTED_ISME) |
200 |
michael |
2820 |
return 0; |
201 |
adx |
30 |
|
202 |
michael |
1413 |
if (EmptyString(parv[1])) |
203 |
adx |
30 |
{ |
204 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
205 |
adx |
30 |
me.name, source_p->name, "CONNECT"); |
206 |
michael |
2820 |
return 0; |
207 |
adx |
30 |
} |
208 |
|
|
|
209 |
michael |
1169 |
if ((target_p = hash_find_server(parv[1]))) |
210 |
adx |
30 |
{ |
211 |
|
|
sendto_one(source_p, |
212 |
michael |
2345 |
":%s NOTICE %s :Connect: Server %s already exists from %s.", |
213 |
adx |
30 |
me.name, source_p->name, parv[1], target_p->from->name); |
214 |
michael |
2820 |
return 0; |
215 |
adx |
30 |
} |
216 |
|
|
|
217 |
|
|
/* |
218 |
michael |
2820 |
* Try to find the name, then host, if both fail notify ops and bail |
219 |
adx |
30 |
*/ |
220 |
michael |
1636 |
if (!(conf = find_matching_name_conf(CONF_SERVER, parv[1], NULL, NULL, 0))) |
221 |
|
|
{ |
222 |
|
|
if (!(conf = find_matching_name_conf(CONF_SERVER, NULL, NULL, parv[1], 0))) |
223 |
|
|
{ |
224 |
|
|
sendto_one(source_p, |
225 |
|
|
":%s NOTICE %s :Connect: Host %s not listed in ircd.conf", |
226 |
|
|
me.name, source_p->name, parv[1]); |
227 |
michael |
2820 |
return 0; |
228 |
michael |
1636 |
} |
229 |
adx |
30 |
} |
230 |
|
|
|
231 |
michael |
2345 |
/* |
232 |
|
|
* Get port number from user, if given. If not specified, |
233 |
adx |
30 |
* use the default form configuration structure. If missing |
234 |
|
|
* from there, then use the precompiled default. |
235 |
|
|
*/ |
236 |
michael |
1632 |
tmpport = port = conf->port; |
237 |
adx |
30 |
|
238 |
|
|
if (parc > 2 && !EmptyString(parv[2])) |
239 |
|
|
{ |
240 |
|
|
port = atoi(parv[2]); |
241 |
|
|
|
242 |
michael |
2345 |
/* |
243 |
michael |
2820 |
* If someone sends port 0, and we have a config port.. use it |
244 |
michael |
2345 |
*/ |
245 |
michael |
1632 |
if (port == 0 && conf->port) |
246 |
|
|
port = conf->port; |
247 |
adx |
30 |
else if (port <= 0) |
248 |
|
|
{ |
249 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal port number", |
250 |
|
|
me.name, source_p->name); |
251 |
michael |
2820 |
return 0; |
252 |
adx |
30 |
} |
253 |
|
|
} |
254 |
|
|
else if (port <= 0 && (port = PORTNUM) <= 0) |
255 |
|
|
{ |
256 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Connect: missing port number", |
257 |
|
|
me.name, source_p->name); |
258 |
michael |
2820 |
return 0; |
259 |
adx |
30 |
} |
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 |
michael |
2820 |
return 0; |
266 |
adx |
30 |
} |
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 |
1474 |
sendto_server(NULL, NOCAPS, CAP_TS6, |
274 |
adx |
30 |
":%s WALLOPS :Remote CONNECT %s %d from %s", |
275 |
|
|
me.name, parv[1], port, source_p->name); |
276 |
michael |
1474 |
sendto_server(NULL, CAP_TS6, NOCAPS, |
277 |
michael |
1463 |
":%s WALLOPS :Remote CONNECT %s %d from %s", |
278 |
|
|
me.id, parv[1], port, source_p->name); |
279 |
adx |
30 |
|
280 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "CONNECT From %s : %s %d", |
281 |
adx |
30 |
source_p->name, parv[1], port); |
282 |
|
|
|
283 |
michael |
1632 |
conf->port = port; |
284 |
adx |
30 |
|
285 |
michael |
885 |
/* |
286 |
|
|
* At this point we should be calling connect_server with a valid |
287 |
adx |
30 |
* C:line and a valid port in the C:line |
288 |
|
|
*/ |
289 |
michael |
1632 |
if (serv_connect(conf, source_p)) |
290 |
adx |
30 |
sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d", |
291 |
michael |
1632 |
me.name, source_p->name, conf->name, conf->port); |
292 |
adx |
30 |
else |
293 |
|
|
sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d", |
294 |
michael |
1632 |
me.name, source_p->name, conf->name, conf->port); |
295 |
michael |
885 |
/* |
296 |
|
|
* Client is either connecting with all the data it needs or has been |
297 |
adx |
30 |
* destroyed |
298 |
|
|
*/ |
299 |
michael |
1632 |
conf->port = tmpport; |
300 |
michael |
2820 |
return 0; |
301 |
adx |
30 |
} |
302 |
michael |
1230 |
|
303 |
michael |
2820 |
static struct Message connect_msgtab = |
304 |
|
|
{ |
305 |
michael |
1230 |
"CONNECT", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
306 |
|
|
{ m_unregistered, m_not_oper, ms_connect, m_ignore, mo_connect, m_ignore } |
307 |
|
|
}; |
308 |
|
|
|
309 |
|
|
static void |
310 |
|
|
module_init(void) |
311 |
|
|
{ |
312 |
|
|
mod_add_cmd(&connect_msgtab); |
313 |
|
|
} |
314 |
|
|
|
315 |
|
|
static void |
316 |
|
|
module_exit(void) |
317 |
|
|
{ |
318 |
|
|
mod_del_cmd(&connect_msgtab); |
319 |
|
|
} |
320 |
|
|
|
321 |
michael |
2820 |
struct module module_entry = |
322 |
|
|
{ |
323 |
michael |
1230 |
.node = { NULL, NULL, NULL }, |
324 |
|
|
.name = NULL, |
325 |
|
|
.version = "$Revision$", |
326 |
|
|
.handle = NULL, |
327 |
|
|
.modinit = module_init, |
328 |
|
|
.modexit = module_exit, |
329 |
|
|
.flags = 0 |
330 |
|
|
}; |