]> arthur.barton.de Git - ngircd-alex.git/commitdiff
Clean up Validate_Prefix(); don't send punctuation in ERROR commands
authorAlexander Barton <alex@barton.de>
Sat, 29 Jan 2011 15:05:55 +0000 (16:05 +0100)
committerAlexander Barton <alex@barton.de>
Sat, 29 Jan 2011 15:05:55 +0000 (16:05 +0100)
src/ngircd/conn.c
src/ngircd/parse.c

index af79c13feddbbb208a2b887aafef7e73a5e4c95f..032a6e91e08b83f41bfd220ad8d527ddeb76f6c1 100644 (file)
@@ -980,7 +980,7 @@ Conn_Close( CONN_ID Idx, const char *LogMsg, const char *FwdMsg, bool InformClie
                if (FwdMsg)
                        Conn_WriteStr(Idx, "ERROR :%s", FwdMsg);
                else
-                       Conn_WriteStr(Idx, "ERROR :Closing connection.");
+                       Conn_WriteStr(Idx, "ERROR :Closing connection");
        }
 
        /* Try to write out the write buffer. Note: Handle_Write() eventually
@@ -1276,7 +1276,7 @@ New_Connection(int Sock)
                    "Refused connection from %s: too may connections (%ld) from this IP address!",
                    ip_str, cnt);
                Simple_Message(new_sock,
-                              "ERROR :Connection refused, too many connections from your IP address!");
+                              "ERROR :Connection refused, too many connections from your IP address");
                close(new_sock);
                return -1;
        }
index 479b300450e4dcfd4f601b703bc4a573fc3f8a77..7c56a03d3478be3fe0111580d294f99e73ae111c 100644 (file)
@@ -178,7 +178,7 @@ Parse_Request( CONN_ID Idx, char *Request )
                if( ! ptr )
                {
                        LogDebug("Connection %d: Parse error: prefix without command!?", Idx);
-                       return Conn_WriteStr( Idx, "ERROR :Prefix without command!?" );
+                       return Conn_WriteStr(Idx, "ERROR :Prefix without command");
                }
                *ptr = '\0';
 #ifndef STRICT_RFC
@@ -278,8 +278,9 @@ Validate_Prefix( CONN_ID Idx, REQUEST *Req, bool *Closed )
        assert( client != NULL );
 
        /* only validate if this connection is already registered */
-       if(( Client_Type( client ) != CLIENT_USER ) && ( Client_Type( client ) != CLIENT_SERVER ) && ( Client_Type( client ) != CLIENT_SERVICE ))
-       {
+       if (Client_Type(client) != CLIENT_USER
+           && Client_Type(client) != CLIENT_SERVER
+           && Client_Type(client) != CLIENT_SERVICE) {
                /* not registered, ignore prefix */
                Req->prefix = NULL;
                return true;
@@ -287,19 +288,25 @@ Validate_Prefix( CONN_ID Idx, REQUEST *Req, bool *Closed )
 
        /* check if client in prefix is known */
        c = Client_Search( Req->prefix );
-       if( ! c )
-       {
-               Log( LOG_ERR, "Invalid prefix \"%s\", client not known (connection %d, command %s)!?", Req->prefix, Idx, Req->command );
-               if( ! Conn_WriteStr( Idx, "ERROR :Invalid prefix \"%s\", client not known!?", Req->prefix )) *Closed = true;
+       if (!c) {
+               Log(LOG_ERR,
+                   "Invalid prefix \"%s\", client not known (connection %d, command \"%s\")!?",
+                   Req->prefix, Idx, Req->command);
+               if (!Conn_WriteStr(Idx,
+                                  "ERROR :Invalid prefix \"%s\", client not known",
+                                  Req->prefix))
+                       *Closed = true;
                return false;
        }
 
        /* check if the client named in the prefix is expected
         * to come from that direction */
-       if( Client_NextHop( c ) != client )
-       {
-               Log( LOG_ERR, "Spoofed prefix \"%s\" from \"%s\" (connection %d, command %s)!", Req->prefix, Client_Mask( Conn_GetClient( Idx )), Idx, Req->command );
-               Conn_Close( Idx, NULL, "Spoofed prefix", true);
+       if (Client_NextHop(c) != client) {
+               Log(LOG_ERR,
+                   "Spoofed prefix \"%s\" from \"%s\" (connection %d, command \"%s\")!",
+                   Req->prefix, Client_Mask(Conn_GetClient(Idx)), Idx,
+                   Req->command);
+               Conn_Close(Idx, NULL, "Spoofed prefix", true);
                *Closed = true;
                return false;
        }