2007-01-25 06:40:21 +00: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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdinc.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "ircd.h"
|
2008-04-20 05:47:38 +00:00
|
|
|
#include "match.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "numeric.h"
|
|
|
|
#include "s_conf.h"
|
|
|
|
#include "s_newconf.h"
|
2008-04-03 02:52:01 +00:00
|
|
|
#include "logger.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "s_serv.h"
|
|
|
|
#include "send.h"
|
|
|
|
#include "msg.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "hash.h"
|
|
|
|
#include "modules.h"
|
2008-04-07 11:29:39 +00:00
|
|
|
#include "sslproc.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2016-03-09 07:29:41 +00:00
|
|
|
static const char connect_desc[] =
|
|
|
|
"Provides the CONNECT command to introduce servers to the network";
|
|
|
|
|
2016-03-09 07:37:03 +00: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 06:40:21 +00:00
|
|
|
|
|
|
|
struct Message connect_msgtab = {
|
2016-02-19 22:42:40 +00:00
|
|
|
"CONNECT", 0, 0, 0, 0,
|
2007-01-25 06:40:21 +00: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 07:52:16 +00:00
|
|
|
|
|
|
|
DECLARE_MODULE_AV2(connect, NULL, NULL, connect_clist, NULL, NULL, NULL, NULL, connect_desc);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* mo_connect - CONNECT command handler
|
2014-03-03 04:25:47 +00:00
|
|
|
*
|
2007-01-25 06:40:21 +00:00
|
|
|
* Added by Jto 11 Feb 1989
|
|
|
|
*
|
|
|
|
* m_connect
|
|
|
|
* parv[1] = servername
|
|
|
|
* parv[2] = port number
|
|
|
|
* parv[3] = remote server
|
|
|
|
*/
|
2016-03-09 07:37:03 +00:00
|
|
|
static void
|
2016-02-11 02:54:17 +00:00
|
|
|
mo_connect(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2007-01-25 06:40:21 +00: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 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
if((target_p = find_server(source_p, parv[1])))
|
|
|
|
{
|
2014-03-03 04:25:47 +00:00
|
|
|
sendto_one_notice(source_p, ":Connect: Server %s already exists from %s.", parv[1],
|
2007-01-25 07:23:01 +00:00
|
|
|
target_p->from->name);
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00: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 07:23:01 +00:00
|
|
|
sendto_one_notice(source_p, ":Connect: Host %s not listed in ircd.conf", parv[1]);
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2008-04-13 15:54:23 +00:00
|
|
|
if(ServerConfSSL(server_p) && (!ssl_ok || !get_ssld_count()))
|
|
|
|
{
|
|
|
|
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 07:37:03 +00:00
|
|
|
return;
|
2008-04-06 14:52:42 +00:00
|
|
|
}
|
|
|
|
|
2007-01-25 06:40:21 +00: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 22:32:27 +00:00
|
|
|
port = 0;
|
2007-01-25 06:40:21 +00:00
|
|
|
if(parc > 2 && !EmptyString(parv[2]))
|
2016-01-12 11:54:04 +00:00
|
|
|
port = atoi(parv[2]);
|
|
|
|
if(port == 0 && server_p->port)
|
|
|
|
port = server_p->port;
|
|
|
|
else if(port <= 0)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
2016-01-12 11:54:04 +00:00
|
|
|
sendto_one_notice(source_p, ":Connect: illegal port number");
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
2016-03-07 07:52:16 +00:00
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
/*
|
|
|
|
* Notify all operators about remote connect requests
|
|
|
|
*/
|
|
|
|
|
2009-01-17 00:18:19 +00:00
|
|
|
ilog(L_SERVER, "CONNECT From %s : %s %s", source_p->name, parv[1], parc > 2 ? parv[2] : "");
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2016-03-02 22:32:27 +00:00
|
|
|
tmpport = server_p->port;
|
2007-01-25 06:40:21 +00:00
|
|
|
server_p->port = port;
|
2016-03-02 22:32:27 +00:00
|
|
|
|
2007-01-25 06:40:21 +00: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 07:23:01 +00:00
|
|
|
sendto_one_notice(source_p, ":*** Connecting to %s.%d",
|
|
|
|
server_p->name, server_p->port);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-01-25 07:23:01 +00:00
|
|
|
sendto_one_notice(source_p, ":*** Couldn't connect to %s.%d",
|
|
|
|
server_p->name, server_p->port);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* client is either connecting with all the data it needs or has been
|
2016-03-02 22:32:27 +00:00
|
|
|
* destroyed, so reset it back to the configured settings
|
2007-01-25 06:40:21 +00:00
|
|
|
*/
|
|
|
|
server_p->port = tmpport;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ms_connect - CONNECT command handler
|
2014-03-03 04:25:47 +00:00
|
|
|
*
|
2007-01-25 06:40:21 +00:00
|
|
|
* Added by Jto 11 Feb 1989
|
|
|
|
*
|
|
|
|
* m_connect
|
|
|
|
* parv[1] = servername
|
|
|
|
* parv[2] = port number
|
|
|
|
* parv[3] = remote server
|
|
|
|
*/
|
2016-03-09 07:37:03 +00:00
|
|
|
static void
|
2016-02-11 02:54:17 +00:00
|
|
|
ms_connect(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2007-01-25 06:40:21 +00: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 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00: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 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00: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 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2008-04-13 15:54:23 +00:00
|
|
|
if(ServerConfSSL(server_p) && (!ssl_ok || !get_ssld_count()))
|
|
|
|
{
|
|
|
|
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 07:37:03 +00:00
|
|
|
return;
|
2008-04-06 14:52:42 +00:00
|
|
|
}
|
|
|
|
|
2007-01-25 06:40:21 +00: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 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Notify all operators about remote connect requests
|
|
|
|
*/
|
|
|
|
sendto_wallops_flags(UMODE_WALLOP, &me,
|
2014-03-03 04:25:47 +00:00
|
|
|
"Remote CONNECT %s %d from %s",
|
2007-01-25 06:40:21 +00: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;
|
|
|
|
}
|