1
0
mirror of https://github.com/osmarks/ngircd.git synced 2025-01-19 03:52:52 +00:00

Allow forwarding of CONNECT commands.

The syntax of the CONNECT command now is:

  - CONNECT <server-id>
  - CONNECT <server-id> <port>
  - CONNECT <server-id> <port> <target>
  - CONNECT <server-id> <port> <host> <my-pwd> <peer-pwd>
  - CONNECT <server-id> <port> <host> <my-pwd> <peer-pwd> <target>

Note: the configuration option "AllowRemoteOper" mus be enabled on the
target server to allow forwarding of CONNECT commands.
This commit is contained in:
Alexander Barton 2008-07-22 18:38:05 +02:00
parent 4a3e40bc95
commit 113bd34878
2 changed files with 49 additions and 14 deletions

View File

@ -230,6 +230,8 @@ IRC_RESTART( CLIENT *Client, REQUEST *Req )
GLOBAL bool GLOBAL bool
IRC_CONNECT(CLIENT * Client, REQUEST * Req) IRC_CONNECT(CLIENT * Client, REQUEST * Req)
{ {
CLIENT *from, *target;
assert(Client != NULL); assert(Client != NULL);
assert(Req != NULL); assert(Req != NULL);
@ -237,7 +239,8 @@ IRC_CONNECT(CLIENT * Client, REQUEST * Req)
return No_Privileges(Client, Req); return No_Privileges(Client, Req);
/* Bad number of parameters? */ /* Bad number of parameters? */
if ((Req->argc != 1) && (Req->argc != 2) && (Req->argc != 5)) if (Req->argc != 1 && Req->argc != 2 && Req->argc != 3 &&
Req->argc != 5 && Req->argc != 6)
return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
Client_ID(Client), Req->command); Client_ID(Client), Req->command);
@ -246,27 +249,59 @@ IRC_CONNECT(CLIENT * Client, REQUEST * Req)
return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
Client_ID(Client), Req->command); Client_ID(Client), Req->command);
IRC_SendWallops(Client_ThisServer(), Client_ThisServer(), from = Client;
"Received CONNECT %s from %s", target = Client_ThisServer();
Req->argv[0], Client_ID(Client));
if (Req->argc == 3 || Req->argc == 6) {
/* This CONNECT has a target parameter */
if (Client_Type(Client) == CLIENT_SERVER)
from = Client_Search(Req->prefix);
if (! from)
return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
Client_ID(Client), Req->prefix);
target = (Req->argc == 3) ? Client_Search(Req->argv[2])
: Client_Search(Req->argv[5]);
if (! target || Client_Type(target) != CLIENT_SERVER)
return IRC_WriteStrClient(from, ERR_NOSUCHSERVER_MSG,
Client_ID(from), Req->argv[0]);
}
if (target != Client_ThisServer()) {
/* Forward CONNECT command ... */
if (Req->argc == 3)
IRC_WriteStrClientPrefix(target, from,
"CONNECT %s %s :%s", Req->argv[0],
Req->argv[1], Req->argv[2]);
else
IRC_WriteStrClientPrefix(target, from,
"CONNECT %s %s %s %s %s :%s", Req->argv[0],
Req->argv[1], Req->argv[2], Req->argv[3],
Req->argv[4], Req->argv[5]);
return CONNECTED;
}
Log(LOG_NOTICE | LOG_snotice, Log(LOG_NOTICE | LOG_snotice,
"Got CONNECT command from \"%s\" for \"%s\".", Client_Mask(Client), "Got CONNECT command from \"%s\" for \"%s\".", Client_Mask(from),
Req->argv[0]); Req->argv[0]);
IRC_SendWallops(Client_ThisServer(), Client_ThisServer(),
"Received CONNECT %s from %s",
Req->argv[0], Client_ID(from));
switch (Req->argc) { switch (Req->argc) {
case 1: case 1:
if (!Conf_EnablePassiveServer(Req->argv[0])) if (!Conf_EnablePassiveServer(Req->argv[0]))
return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG, return IRC_WriteStrClient(from, ERR_NOSUCHSERVER_MSG,
Client_ID(Client), Client_ID(from),
Req->argv[0]); Req->argv[0]);
break; break;
case 2: case 2:
case 3:
/* Connect configured server */ /* Connect configured server */
if (!Conf_EnableServer if (!Conf_EnableServer
(Req->argv[0], (UINT16) atoi(Req->argv[1]))) (Req->argv[0], (UINT16) atoi(Req->argv[1])))
return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG, return IRC_WriteStrClient(from, ERR_NOSUCHSERVER_MSG,
Client_ID(Client), Client_ID(from),
Req->argv[0]); Req->argv[0]);
break; break;
default: default:
@ -274,8 +309,8 @@ IRC_CONNECT(CLIENT * Client, REQUEST * Req)
if (!Conf_AddServer if (!Conf_AddServer
(Req->argv[0], (UINT16) atoi(Req->argv[1]), Req->argv[2], (Req->argv[0], (UINT16) atoi(Req->argv[1]), Req->argv[2],
Req->argv[3], Req->argv[4])) Req->argv[3], Req->argv[4]))
return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG, return IRC_WriteStrClient(from, ERR_NOSUCHSERVER_MSG,
Client_ID(Client), Client_ID(from),
Req->argv[0]); Req->argv[0]);
} }

View File

@ -59,7 +59,7 @@ static COMMAND My_Commands[] =
{ {
{ "ADMIN", IRC_ADMIN, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 }, { "ADMIN", IRC_ADMIN, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
{ "AWAY", IRC_AWAY, CLIENT_USER, 0, 0, 0 }, { "AWAY", IRC_AWAY, CLIENT_USER, 0, 0, 0 },
{ "CONNECT", IRC_CONNECT, CLIENT_USER, 0, 0, 0 }, { "CONNECT", IRC_CONNECT, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
{ "DIE", IRC_DIE, CLIENT_USER, 0, 0, 0 }, { "DIE", IRC_DIE, CLIENT_USER, 0, 0, 0 },
{ "DISCONNECT", IRC_DISCONNECT, CLIENT_USER, 0, 0, 0 }, { "DISCONNECT", IRC_DISCONNECT, CLIENT_USER, 0, 0, 0 },
{ "ERROR", IRC_ERROR, 0xFFFF, 0, 0, 0 }, { "ERROR", IRC_ERROR, 0xFFFF, 0, 0, 0 },