]> arthur.barton.de Git - ngircd-alex.git/commitdiff
Server links: detect RFC 1459 mode direct after SERVER command
authorAlexander Barton <alex@barton.de>
Thu, 14 Aug 2008 21:23:04 +0000 (23:23 +0200)
committerAlexander Barton <alex@barton.de>
Tue, 23 Sep 2008 09:47:17 +0000 (11:47 +0200)
This patch allows ngIRCd to detect right after receiving the SERVER command
from the peer whether the RFC 1459 compatibility mode must be used or not.
And it fixes the announcement of users during establishing new server links
with such peers.

src/ngircd/client.h
src/ngircd/irc-login.c
src/ngircd/irc-server.c
src/ngircd/numeric.c

index 63406f203c13db57c3f9c9b615ed3d07687b881d..75b99b272d0d38f3e1108b651171452d88c8eb49 100644 (file)
@@ -26,6 +26,7 @@
 #define CLIENT_SERVER 32               /* client is a server */
 #define CLIENT_SERVICE 64              /* client is a service */
 #define CLIENT_UNKNOWNSERVER 128       /* unregistered server connection */
 #define CLIENT_SERVER 32               /* client is a server */
 #define CLIENT_SERVICE 64              /* client is a service */
 #define CLIENT_UNKNOWNSERVER 128       /* unregistered server connection */
+#define CLIENT_GOTPASS_2813 256                /* client did send PASS, RFC 2813 style */
 
 #define CLIENT_TYPE int
 
 
 #define CLIENT_TYPE int
 
index 5a68d5e823f1438928712796884b7b8436251145..e709612a97adc04873f1822880530b163bd92d66 100644 (file)
@@ -81,7 +81,7 @@ IRC_PASS( CLIENT *Client, REQUEST *Req )
                /* Not yet registered "unknown" connection, PASS with one
                 * argument: either a regular client, service, or server
                 * using the old RFC 1459 section 4.1.1 syntax. */
                /* Not yet registered "unknown" connection, PASS with one
                 * argument: either a regular client, service, or server
                 * using the old RFC 1459 section 4.1.1 syntax. */
-               LogDebug("Connection %d: got PASS command ...",
+               LogDebug("Connection %d: got PASS command (RFC 1459) ...",
                         Client_Conn(Client));
        } else if ((Client_Type(Client) == CLIENT_UNKNOWN ||
                    Client_Type(Client) == CLIENT_UNKNOWNSERVER) &&
                         Client_Conn(Client));
        } else if ((Client_Type(Client) == CLIENT_UNKNOWN ||
                    Client_Type(Client) == CLIENT_UNKNOWNSERVER) &&
@@ -89,7 +89,7 @@ IRC_PASS( CLIENT *Client, REQUEST *Req )
                /* Not yet registered "unknown" connection or outgoing server
                 * link, PASS with three or four argument: server using the
                 * RFC 2813 section 4.1.1 syntax. */
                /* Not yet registered "unknown" connection or outgoing server
                 * link, PASS with three or four argument: server using the
                 * RFC 2813 section 4.1.1 syntax. */
-               LogDebug("Connection %d: got PASS command (new server link) ...",
+               LogDebug("Connection %d: got PASS command (RFC 2813, new server link) ...",
                         Client_Conn(Client));
        } else if (Client_Type(Client) == CLIENT_UNKNOWN ||
                   Client_Type(Client) == CLIENT_UNKNOWNSERVER) {
                         Client_Conn(Client));
        } else if (Client_Type(Client) == CLIENT_UNKNOWN ||
                   Client_Type(Client) == CLIENT_UNKNOWNSERVER) {
@@ -103,7 +103,6 @@ IRC_PASS( CLIENT *Client, REQUEST *Req )
        }
 
        Client_SetPassword(Client, Req->argv[0]);
        }
 
        Client_SetPassword(Client, Req->argv[0]);
-       Client_SetType(Client, CLIENT_GOTPASS);
 
        /* Protocol version */
        if (Req->argc >= 2 && strlen(Req->argv[1]) >= 4) {
 
        /* Protocol version */
        if (Req->argc >= 2 && strlen(Req->argv[1]) >= 4) {
@@ -119,8 +118,12 @@ IRC_PASS( CLIENT *Client, REQUEST *Req )
 
                Req->argv[1][2] = c2;
                Req->argv[1][4] = c4;
 
                Req->argv[1][2] = c2;
                Req->argv[1][4] = c4;
-       } else
+
+               Client_SetType(Client, CLIENT_GOTPASS_2813);
+       } else {
                protohigh = protolow = 0;
                protohigh = protolow = 0;
+               Client_SetType(Client, CLIENT_GOTPASS);
+       }
 
        /* Protocol type, see doc/Protocol.txt */
        if (Req->argc >= 2 && strlen(Req->argv[1]) > 4)
 
        /* Protocol type, see doc/Protocol.txt */
        if (Req->argc >= 2 && strlen(Req->argv[1]) > 4)
@@ -185,7 +188,6 @@ GLOBAL bool
 IRC_NICK( CLIENT *Client, REQUEST *Req )
 {
        CLIENT *intr_c, *target, *c;
 IRC_NICK( CLIENT *Client, REQUEST *Req )
 {
        CLIENT *intr_c, *target, *c;
-       CONN_ID conn;
        char *nick, *user, *hostname, *modes, *info;
        int token, hops;
 
        char *nick, *user, *hostname, *modes, *info;
        int token, hops;
 
@@ -340,15 +342,6 @@ IRC_NICK( CLIENT *Client, REQUEST *Req )
                        token = atoi(Req->argv[1]);
                        modes = "";
                        info = Req->argv[0];
                        token = atoi(Req->argv[1]);
                        modes = "";
                        info = Req->argv[0];
-
-                       conn = Client_Conn(Client);
-                       if (conn != NONE &&
-                           !(Conn_Options(conn) & CONN_RFC1459)) {
-                               Log(LOG_INFO,
-                                   "Switching connection %d (\"%s\") to RFC 1459 compatibility mode.",
-                                   conn, Client_ID(Client));
-                               Conn_SetOption(conn, CONN_RFC1459);
-                       }
                }
 
                /* Nick ueberpruefen */
                }
 
                /* Nick ueberpruefen */
index d342ffab754f463ce423f842c41f56e9f37c192c..f1b817c033dd2bcdb0d84246bcc4f6b8c6d8bfa5 100644 (file)
@@ -14,8 +14,6 @@
 
 #include "portab.h"
 
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: irc-server.c,v 1.46 2007/11/21 12:16:36 alex Exp $";
-
 #include "imp.h"
 #include <assert.h>
 #include <stdio.h>
 #include "imp.h"
 #include <assert.h>
 #include <stdio.h>
@@ -26,6 +24,7 @@ static char UNUSED id[] = "$Id: irc-server.c,v 1.46 2007/11/21 12:16:36 alex Exp
 #include "defines.h"
 #include "resolve.h"
 #include "conn.h"
 #include "defines.h"
 #include "resolve.h"
 #include "conn.h"
+#include "conn-func.h"
 #include "conn-zip.h"
 #include "conf.h"
 #include "client.h"
 #include "conn-zip.h"
 #include "conf.h"
 #include "client.h"
@@ -64,7 +63,8 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
                return IRC_WriteStrClient(Client, ERR_UNKNOWNCOMMAND_MSG,
                                          Client_ID(Client), Req->command);
 
                return IRC_WriteStrClient(Client, ERR_UNKNOWNCOMMAND_MSG,
                                          Client_ID(Client), Req->command);
 
-       if (Client_Type(Client) == CLIENT_GOTPASS) {
+       if (Client_Type(Client) == CLIENT_GOTPASS ||
+           Client_Type(Client) == CLIENT_GOTPASS_2813) {
                /* We got a PASS command from the peer, and now a SERVER
                 * command: the peer tries to register itself as a server. */
                LogDebug("Connection %d: got SERVER command (new server link) ...",
                /* We got a PASS command from the peer, and now a SERVER
                 * command: the peer tries to register itself as a server. */
                LogDebug("Connection %d: got SERVER command (new server link) ...",
@@ -124,7 +124,18 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
 
                /* Mark this connection as belonging to an configured server */
                Conf_SetServer(i, con);
 
                /* Mark this connection as belonging to an configured server */
                Conf_SetServer(i, con);
-               
+
+               /* Check protocol level */
+               if (Client_Type(Client) == CLIENT_GOTPASS) {
+                       /* We got a "simple" PASS command, so the peer is
+                        * using the protocol as defined in RFC 1459. */
+                       if (! (Conn_Options(con) & CONN_RFC1459))
+                               Log(LOG_INFO,
+                                   "Switching connection %d (\"%s\") to RFC 1459 compatibility mode.",
+                                   con, Client_ID(Client));
+                       Conn_SetOption(con, CONN_RFC1459);
+               }
+
                Client_SetType(Client, CLIENT_UNKNOWNSERVER);
 
 #ifdef ZLIB
                Client_SetType(Client, CLIENT_UNKNOWNSERVER);
 
 #ifdef ZLIB
index dd24016bd7e4134057f5669565bf00695ed8c143..d22bf3ae348c3b2ebeccf63dc3fbad1e5f3d56a0 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2007 Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2008 Alexander Barton (alex@barton.de)
  *
  * 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
  *
  * 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
@@ -13,8 +13,6 @@
 
 #include "portab.h"
 
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: numeric.c,v 1.1 2007/11/21 12:20:32 alex Exp $";
-
 #include "imp.h"
 #include <assert.h>
 #include <stdio.h>
 #include "imp.h"
 #include <assert.h>
 #include <stdio.h>
@@ -26,6 +24,7 @@ static char UNUSED id[] = "$Id: numeric.c,v 1.1 2007/11/21 12:20:32 alex Exp $";
 #include "conn.h"
 #include "conf.h"
 #include "conn.h"
 #include "conn.h"
 #include "conf.h"
 #include "conn.h"
+#include "conn-func.h"
 #include "client.h"
 #include "channel.h"
 #include "irc-write.h"
 #include "client.h"
 #include "channel.h"
 #include "irc-write.h"
@@ -78,10 +77,27 @@ Announce_Server(CLIENT * Client, CLIENT * Server)
 static bool
 Announce_User(CLIENT * Client, CLIENT * User)
 {
 static bool
 Announce_User(CLIENT * Client, CLIENT * User)
 {
-       return IRC_WriteStrClient(Client, "NICK %s %d %s %s %d +%s :%s",
-               Client_ID(User), Client_Hops(User) + 1, Client_User(User),
-               Client_Hostname(User), Client_MyToken(Client_Introducer(User)),
-               Client_Modes(User), Client_Info(User));
+       CONN_ID conn;
+       conn = Client_Conn(Client);
+       if (Conn_Options(conn) & CONN_RFC1459) {
+               /* RFC 1459 mode: separate NICK and USER commands */
+               if (! Conn_WriteStr(conn, "NICK %s :%d",
+                                   Client_ID(User), Client_Hops(User) + 1))
+                       return DISCONNECTED;
+               return Conn_WriteStr(conn, ":%s USER %s %s %s :%s",
+                                    Client_ID(User), Client_User(User),
+                                    Client_Hostname(User),
+                                    Client_ID(Client_Introducer(User)),
+                                    Client_Info(User));
+               
+       } else {
+               /* RFC 2813 mode: one combined NICK command */
+               return IRC_WriteStrClient(Client, "NICK %s %d %s %s %d +%s :%s",
+                               Client_ID(User), Client_Hops(User) + 1,
+                               Client_User(User), Client_Hostname(User),
+                               Client_MyToken(Client_Introducer(User)),
+                               Client_Modes(User), Client_Info(User));
+       }
 } /* Announce_User */
 
 
 } /* Announce_User */