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-07-01 05:04:00 +02:00
|
|
|
#include <ircd/stdinc.h>
|
|
|
|
#include <ircd/client.h>
|
|
|
|
#include <ircd/ircd.h>
|
|
|
|
#include <ircd/match.h>
|
|
|
|
#include <ircd/numeric.h>
|
|
|
|
#include <ircd/s_conf.h>
|
|
|
|
#include <ircd/s_newconf.h>
|
|
|
|
#include <ircd/logger.h>
|
|
|
|
#include <ircd/s_serv.h>
|
|
|
|
#include <ircd/send.h>
|
|
|
|
#include <ircd/msg.h>
|
|
|
|
#include <ircd/parse.h>
|
|
|
|
#include <ircd/hash.h>
|
|
|
|
#include <ircd/modules.h>
|
|
|
|
#include <ircd/sslproc.h>
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-03-09 08:29:41 +01:00
|
|
|
static const char connect_desc[] =
|
|
|
|
"Provides the CONNECT command to introduce servers to the network";
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void mo_connect(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
static void ms_connect(struct MsgBuf *, struct Client *, struct 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-02-11 03:54:17 +01:00
|
|
|
mo_connect(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
int port;
|
|
|
|
int tmpport;
|
|
|
|
struct server_conf *server_p;
|
|
|
|
struct Client *target_p;
|
|
|
|
|
|
|
|
/* always privileged with handlers */
|
|
|
|
|
|
|
|
if(MyConnect(source_p) && !IsOperRemote(source_p) && parc > 3)
|
|
|
|
{
|
|
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
|
|
|
me.name, source_p->name, "remote");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(hunt_server(client_p, source_p, ":%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(source_p, parv[1])))
|
|
|
|
{
|
2014-03-03 05:25:47 +01:00
|
|
|
sendto_one_notice(source_p, ":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)
|
|
|
|
{
|
2007-01-25 08:23:01 +01:00
|
|
|
sendto_one_notice(source_p, ":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
|
|
|
{
|
|
|
|
sendto_one_notice(source_p,
|
|
|
|
":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-01-12 12:54:04 +01:00
|
|
|
sendto_one_notice(source_p, ":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
|
|
|
|
*/
|
|
|
|
|
2009-01-17 01:18:19 +01:00
|
|
|
ilog(L_SERVER, "CONNECT From %s : %s %s", source_p->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
|
|
|
|
*/
|
|
|
|
if(serv_connect(server_p, source_p))
|
|
|
|
{
|
2007-01-25 08:23:01 +01:00
|
|
|
sendto_one_notice(source_p, ":*** Connecting to %s.%d",
|
|
|
|
server_p->name, server_p->port);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-01-25 08:23:01 +01:00
|
|
|
sendto_one_notice(source_p, ":*** Couldn't connect to %s.%d",
|
|
|
|
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-02-11 03:54:17 +01:00
|
|
|
ms_connect(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
int port;
|
|
|
|
int tmpport;
|
|
|
|
struct server_conf *server_p;
|
|
|
|
struct Client *target_p;
|
|
|
|
|
|
|
|
if(hunt_server(client_p, source_p, ":%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])))
|
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":Connect: Server %s already exists from %s.",
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":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
|
|
|
{
|
|
|
|
sendto_one_notice(source_p,
|
|
|
|
":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)
|
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":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
|
|
|
|
*/
|
|
|
|
sendto_wallops_flags(UMODE_WALLOP, &me,
|
2014-03-03 05:25:47 +01:00
|
|
|
"Remote CONNECT %s %d from %s",
|
2007-01-25 07:40:21 +01:00
|
|
|
parv[1], port, source_p->name);
|
|
|
|
sendto_server(NULL, NULL, CAP_TS6, NOCAPS,
|
|
|
|
":%s WALLOPS :Remote CONNECT %s %d from %s",
|
|
|
|
me.id, parv[1], port, source_p->name);
|
|
|
|
|
|
|
|
ilog(L_SERVER, "CONNECT From %s : %s %d", source_p->name, parv[1], port);
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
if(serv_connect(server_p, source_p))
|
|
|
|
sendto_one_notice(source_p, ":*** Connecting to %s.%d",
|
|
|
|
server_p->name, server_p->port);
|
|
|
|
else
|
|
|
|
sendto_one_notice(source_p, ":*** Couldn't connect to %s.%d",
|
|
|
|
server_p->name, server_p->port);
|
|
|
|
/*
|
|
|
|
* client is either connecting with all the data it needs or has been
|
|
|
|
* destroyed
|
|
|
|
*/
|
|
|
|
server_p->port = tmpport;
|
|
|
|
}
|