]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_connect.c
Some declarations connected to removed servlink gone
[irc/rqf/shadowircd.git] / modules / m_connect.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_connect.c: Connects to a remote IRC server.
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_connect.c 3161 2007-01-25 07:23:01Z nenolod $
212380e3 25 */
26
27#include "stdinc.h"
28#include "client.h"
29#include "ircd.h"
30#include "irc_string.h"
31#include "numeric.h"
212380e3 32#include "s_conf.h"
33#include "s_newconf.h"
d3455e2c 34#include "logger.h"
212380e3 35#include "s_serv.h"
36#include "send.h"
37#include "msg.h"
38#include "parse.h"
39#include "hash.h"
40#include "modules.h"
41
42static int mo_connect(struct Client *, struct Client *, int, const char **);
43static int ms_connect(struct Client *, struct Client *, int, const char **);
44
45struct Message connect_msgtab = {
46 "CONNECT", 0, 0, 0, MFLG_SLOW,
47 {mg_unreg, mg_not_oper, {ms_connect, 4}, {ms_connect, 4}, mg_ignore, {mo_connect, 2}}
48};
49
50mapi_clist_av1 connect_clist[] = { &connect_msgtab, NULL };
5366977b 51DECLARE_MODULE_AV1(connect, NULL, NULL, connect_clist, NULL, NULL, "$Revision: 3161 $");
212380e3 52
53/*
54 * mo_connect - CONNECT command handler
55 *
56 * Added by Jto 11 Feb 1989
57 *
58 * m_connect
59 * parv[0] = sender prefix
60 * parv[1] = servername
61 * parv[2] = port number
62 * parv[3] = remote server
63 */
64static int
65mo_connect(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
66{
67 int port;
68 int tmpport;
69 struct server_conf *server_p;
70 struct Client *target_p;
71
72 /* always privileged with handlers */
73
74 if(MyConnect(source_p) && !IsOperRemote(source_p) && parc > 3)
75 {
76 sendto_one(source_p, form_str(ERR_NOPRIVS),
77 me.name, source_p->name, "remote");
78 return 0;
79 }
80
81 if(hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
82 return 0;
83
84 if((target_p = find_server(source_p, parv[1])))
85 {
5366977b 86 sendto_one_notice(source_p, ":Connect: Server %s already exists from %s.", parv[1],
87 target_p->from->name);
212380e3 88 return 0;
89 }
90
91 /*
92 * try to find the name, then host, if both fail notify ops and bail
93 */
94 if((server_p = find_server_conf(parv[1])) == NULL)
95 {
5366977b 96 sendto_one_notice(source_p, ":Connect: Host %s not listed in ircd.conf", parv[1]);
212380e3 97 return 0;
98 }
99
8db00894
VY
100 if(ServerConfSSL(server_p) && (!ssl_ok || !get_ssld_count()))\r
101 {\r
102 sendto_one_notice(source_p,\r
103 ":Connect: Server %s is set to use SSL/TLS but SSL/TLS is not configured.",\r
104 parv[1]);\r
105 return 0;\r
106 }
107
212380e3 108 /*
109 * 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 = server_p->port;
114 if(parc > 2 && !EmptyString(parv[2]))
115 {
116 if((port = atoi(parv[2])) <= 0)
117 {
5366977b 118 sendto_one_notice(source_p, ":Connect: Illegal port number");
212380e3 119 return 0;
120 }
121 }
122 else if(port <= 0 && (port = PORTNUM) <= 0)
123 {
5366977b 124 sendto_one_notice(source_p, ":Connect: missing port number");
212380e3 125 return 0;
126 }
127 /*
128 * Notify all operators about remote connect requests
129 */
130
131 ilog(L_SERVER, "CONNECT From %s : %s %s", parv[0], parv[1], parc > 2 ? parv[2] : "");
132
133 server_p->port = port;
134 /*
135 * at this point we should be calling connect_server with a valid
136 * C:line and a valid port in the C:line
137 */
138 if(serv_connect(server_p, source_p))
139 {
140#ifndef HIDE_SERVERS_IPS
5366977b 141 sendto_one_notice(source_p, ":*** Connecting to %s[%s].%d",
142 server_p->host, server_p->name, server_p->port);
212380e3 143#else
5366977b 144 sendto_one_notice(source_p, ":*** Connecting to %s.%d",
145 server_p->name, server_p->port);
212380e3 146#endif
147
148 }
149 else
150 {
5366977b 151 sendto_one_notice(source_p, ":*** Couldn't connect to %s.%d",
152 server_p->name, server_p->port);
212380e3 153 }
154
155 /*
156 * client is either connecting with all the data it needs or has been
157 * destroyed
158 */
159 server_p->port = tmpport;
160 return 0;
161}
162
163/*
164 * ms_connect - CONNECT command handler
165 *
166 * Added by Jto 11 Feb 1989
167 *
168 * m_connect
169 * parv[0] = sender prefix
170 * parv[1] = servername
171 * parv[2] = port number
172 * parv[3] = remote server
173 */
174static int
175ms_connect(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
176{
177 int port;
178 int tmpport;
179 struct server_conf *server_p;
180 struct Client *target_p;
181
182 if(hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
183 return 0;
184
185 if((target_p = find_server(NULL, parv[1])))
186 {
187 sendto_one_notice(source_p, ":Connect: Server %s already exists from %s.",
188 parv[1], target_p->from->name);
189 return 0;
190 }
191
192 /*
193 * try to find the name, then host, if both fail notify ops and bail
194 */
195 if((server_p = find_server_conf(parv[1])) == NULL)
196 {
197 sendto_one_notice(source_p, ":Connect: Host %s not listed in ircd.conf",
198 parv[1]);
199 return 0;
200 }
201
8db00894
VY
202 if(ServerConfSSL(server_p) && (!ssl_ok || !get_ssld_count()))\r
203 {\r
204 sendto_one_notice(source_p,\r
205 ":Connect: Server %s is set to use SSL/TLS but SSL/TLS is not configured.",\r
206 parv[1]);\r
207 return 0;\r
208 }
209
212380e3 210 /*
211 * Get port number from user, if given. If not specified,
212 * use the default form configuration structure. If missing
213 * from there, then use the precompiled default.
214 */
215 tmpport = server_p->port;
216
217 port = atoi(parv[2]);
218
219 /* if someone sends port 0, and we have a config port.. use it */
220 if(port == 0 && server_p->port)
221 port = server_p->port;
222 else if(port <= 0)
223 {
224 sendto_one_notice(source_p, ":Connect: Illegal port number");
225 return 0;
226 }
227
228 /*
229 * Notify all operators about remote connect requests
230 */
231 sendto_wallops_flags(UMODE_WALLOP, &me,
232 "Remote CONNECT %s %d from %s",
233 parv[1], port, source_p->name);
234 sendto_server(NULL, NULL, CAP_TS6, NOCAPS,
235 ":%s WALLOPS :Remote CONNECT %s %d from %s",
236 me.id, parv[1], port, source_p->name);
237 sendto_server(NULL, NULL, NOCAPS, CAP_TS6,
238 ":%s WALLOPS :Remote CONNECT %s %d from %s",
239 me.name, parv[1], port, source_p->name);
240
241 ilog(L_SERVER, "CONNECT From %s : %s %d", source_p->name, parv[1], port);
242
243 server_p->port = port;
244 /*
245 * at this point we should be calling connect_server with a valid
246 * C:line and a valid port in the C:line
247 */
248 if(serv_connect(server_p, source_p))
249 sendto_one_notice(source_p, ":*** Connecting to %s.%d",
250 server_p->name, server_p->port);
251 else
252 sendto_one_notice(source_p, ":*** Couldn't connect to %s.%d",
253 server_p->name, server_p->port);
254 /*
255 * client is either connecting with all the data it needs or has been
256 * destroyed
257 */
258 server_p->port = tmpport;
259 return 0;
260}