2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
|
|
|
* m_connect.c: Connects to a remote IRC server.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
|
|
|
* Copyright (C) 2002-2005 ircd-ratbox development team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
using namespace ircd;
|
|
|
|
|
2016-03-09 08:29:41 +01:00
|
|
|
static const char connect_desc[] =
|
|
|
|
"Provides the CONNECT command to introduce servers to the network";
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
static void mo_connect(struct MsgBuf *, client::client &, client::client &, int, const char **);
|
|
|
|
static void ms_connect(struct MsgBuf *, client::client &, client::client &, int, const char **);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
struct Message connect_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"CONNECT", 0, 0, 0, 0,
|
2007-01-25 07:40:21 +01:00
|
|
|
{mg_unreg, mg_not_oper, {ms_connect, 4}, {ms_connect, 4}, mg_ignore, {mo_connect, 2}}
|
|
|
|
};
|
|
|
|
|
|
|
|
mapi_clist_av1 connect_clist[] = { &connect_msgtab, NULL };
|
2016-03-07 08:52:16 +01:00
|
|
|
|
|
|
|
DECLARE_MODULE_AV2(connect, NULL, NULL, connect_clist, NULL, NULL, NULL, NULL, connect_desc);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* mo_connect - CONNECT command handler
|
2014-03-03 05:25:47 +01:00
|
|
|
*
|
2007-01-25 07:40:21 +01:00
|
|
|
* Added by Jto 11 Feb 1989
|
|
|
|
*
|
|
|
|
* m_connect
|
|
|
|
* parv[1] = servername
|
|
|
|
* parv[2] = port number
|
|
|
|
* parv[3] = remote server
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
mo_connect(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
int port;
|
|
|
|
int tmpport;
|
|
|
|
struct server_conf *server_p;
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *target_p;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* always privileged with handlers */
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my_connect(source) && !IsOperRemote(&source) && parc > 3)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(ERR_NOPRIVS),
|
|
|
|
me.name, source.name, "remote");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
if(hunt_server(&client, &source, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
if((target_p = find_server(&source, parv[1])))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_notice(&source, ":Connect: Server %s already exists from %s.", parv[1],
|
2007-01-25 08:23:01 +01:00
|
|
|
target_p->from->name);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* try to find the name, then host, if both fail notify ops and bail
|
|
|
|
*/
|
|
|
|
if((server_p = find_server_conf(parv[1])) == NULL)
|
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_notice(&source, ":Connect: Host %s not listed in ircd.conf", parv[1]);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-03-19 06:57:32 +01:00
|
|
|
if(ServerConfSSL(server_p) && (!ircd_ssl_ok || !get_ssld_count()))
|
2008-04-13 17:54:23 +02:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_notice(&source,
|
2008-04-13 17:54:23 +02:00
|
|
|
":Connect: Server %s is set to use SSL/TLS but SSL/TLS is not configured.",
|
|
|
|
parv[1]);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2008-04-06 16:52:42 +02:00
|
|
|
}
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* Get port number from user, if given. If not specified,
|
|
|
|
* use the default form configuration structure. If missing
|
|
|
|
* from there, then use the precompiled default.
|
|
|
|
*/
|
2016-03-02 23:32:27 +01:00
|
|
|
port = 0;
|
2007-01-25 07:40:21 +01:00
|
|
|
if(parc > 2 && !EmptyString(parv[2]))
|
2016-01-12 12:54:04 +01:00
|
|
|
port = atoi(parv[2]);
|
|
|
|
if(port == 0 && server_p->port)
|
|
|
|
port = server_p->port;
|
|
|
|
else if(port <= 0)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_notice(&source, ":Connect: illegal port number");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
2016-03-07 08:52:16 +01:00
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* Notify all operators about remote connect requests
|
|
|
|
*/
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
ilog(L_SERVER, "CONNECT From %s : %s %s", source.name, parv[1], parc > 2 ? parv[2] : "");
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-03-02 23:32:27 +01:00
|
|
|
tmpport = server_p->port;
|
2007-01-25 07:40:21 +01:00
|
|
|
server_p->port = port;
|
2016-03-02 23:32:27 +01:00
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* at this point we should be calling connect_server with a valid
|
|
|
|
* C:line and a valid port in the C:line
|
|
|
|
*/
|
2016-08-23 02:37:07 +02:00
|
|
|
if(serv_connect(server_p, &source))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_notice(&source, ":*** Connecting to %s.%d",
|
2007-01-25 08:23:01 +01:00
|
|
|
server_p->name, server_p->port);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_notice(&source, ":*** Couldn't connect to %s.%d",
|
2007-01-25 08:23:01 +01:00
|
|
|
server_p->name, server_p->port);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* client is either connecting with all the data it needs or has been
|
2016-03-02 23:32:27 +01:00
|
|
|
* destroyed, so reset it back to the configured settings
|
2007-01-25 07:40:21 +01:00
|
|
|
*/
|
|
|
|
server_p->port = tmpport;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ms_connect - CONNECT command handler
|
2014-03-03 05:25:47 +01:00
|
|
|
*
|
2007-01-25 07:40:21 +01:00
|
|
|
* Added by Jto 11 Feb 1989
|
|
|
|
*
|
|
|
|
* m_connect
|
|
|
|
* parv[1] = servername
|
|
|
|
* parv[2] = port number
|
|
|
|
* parv[3] = remote server
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
ms_connect(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
int port;
|
|
|
|
int tmpport;
|
|
|
|
struct server_conf *server_p;
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *target_p;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
if(hunt_server(&client, &source, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if((target_p = find_server(NULL, parv[1])))
|
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_notice(&source, ":Connect: Server %s already exists from %s.",
|
2007-01-25 07:40:21 +01:00
|
|
|
parv[1], target_p->from->name);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* try to find the name, then host, if both fail notify ops and bail
|
|
|
|
*/
|
|
|
|
if((server_p = find_server_conf(parv[1])) == NULL)
|
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_notice(&source, ":Connect: Host %s not listed in ircd.conf",
|
2007-01-25 07:40:21 +01:00
|
|
|
parv[1]);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-03-19 06:57:32 +01:00
|
|
|
if(ServerConfSSL(server_p) && (!ircd_ssl_ok || !get_ssld_count()))
|
2008-04-13 17:54:23 +02:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_notice(&source,
|
2008-04-13 17:54:23 +02:00
|
|
|
":Connect: Server %s is set to use SSL/TLS but SSL/TLS is not configured.",
|
|
|
|
parv[1]);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2008-04-06 16:52:42 +02:00
|
|
|
}
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* Get port number from user, if given. If not specified,
|
|
|
|
* use the default form configuration structure. If missing
|
|
|
|
* from there, then use the precompiled default.
|
|
|
|
*/
|
|
|
|
tmpport = server_p->port;
|
|
|
|
|
|
|
|
port = atoi(parv[2]);
|
|
|
|
|
|
|
|
/* if someone sends port 0, and we have a config port.. use it */
|
|
|
|
if(port == 0 && server_p->port)
|
|
|
|
port = server_p->port;
|
|
|
|
else if(port <= 0)
|
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_notice(&source, ":Connect: Illegal port number");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Notify all operators about remote connect requests
|
|
|
|
*/
|
2016-08-24 00:25:09 +02:00
|
|
|
sendto_wallops_flags(umode::WALLOP, &me,
|
2014-03-03 05:25:47 +01:00
|
|
|
"Remote CONNECT %s %d from %s",
|
2016-08-23 02:37:07 +02:00
|
|
|
parv[1], port, source.name);
|
2007-01-25 07:40:21 +01:00
|
|
|
sendto_server(NULL, NULL, CAP_TS6, NOCAPS,
|
|
|
|
":%s WALLOPS :Remote CONNECT %s %d from %s",
|
2016-08-23 02:37:07 +02:00
|
|
|
me.id, parv[1], port, source.name);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
ilog(L_SERVER, "CONNECT From %s : %s %d", source.name, parv[1], port);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
server_p->port = port;
|
|
|
|
/*
|
|
|
|
* at this point we should be calling connect_server with a valid
|
|
|
|
* C:line and a valid port in the C:line
|
|
|
|
*/
|
2016-08-23 02:37:07 +02:00
|
|
|
if(serv_connect(server_p, &source))
|
|
|
|
sendto_one_notice(&source, ":*** Connecting to %s.%d",
|
2007-01-25 07:40:21 +01:00
|
|
|
server_p->name, server_p->port);
|
|
|
|
else
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_notice(&source, ":*** Couldn't connect to %s.%d",
|
2007-01-25 07:40:21 +01:00
|
|
|
server_p->name, server_p->port);
|
|
|
|
/*
|
|
|
|
* client is either connecting with all the data it needs or has been
|
|
|
|
* destroyed
|
|
|
|
*/
|
|
|
|
server_p->port = tmpport;
|
|
|
|
}
|