Clean up Validate_Prefix(); don't send punctuation in ERROR commands

This commit is contained in:
Alexander Barton 2011-01-29 16:05:55 +01:00
parent 8700f4d93c
commit 493ccd57f4
2 changed files with 20 additions and 13 deletions

View File

@ -980,7 +980,7 @@ Conn_Close( CONN_ID Idx, const char *LogMsg, const char *FwdMsg, bool InformClie
if (FwdMsg) if (FwdMsg)
Conn_WriteStr(Idx, "ERROR :%s", FwdMsg); Conn_WriteStr(Idx, "ERROR :%s", FwdMsg);
else else
Conn_WriteStr(Idx, "ERROR :Closing connection."); Conn_WriteStr(Idx, "ERROR :Closing connection");
} }
/* Try to write out the write buffer. Note: Handle_Write() eventually /* 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!", "Refused connection from %s: too may connections (%ld) from this IP address!",
ip_str, cnt); ip_str, cnt);
Simple_Message(new_sock, 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); close(new_sock);
return -1; return -1;
} }

View File

@ -178,7 +178,7 @@ Parse_Request( CONN_ID Idx, char *Request )
if( ! ptr ) if( ! ptr )
{ {
LogDebug("Connection %d: Parse error: prefix without command!?", Idx); 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'; *ptr = '\0';
#ifndef STRICT_RFC #ifndef STRICT_RFC
@ -278,8 +278,9 @@ Validate_Prefix( CONN_ID Idx, REQUEST *Req, bool *Closed )
assert( client != NULL ); assert( client != NULL );
/* only validate if this connection is already registered */ /* 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 */ /* not registered, ignore prefix */
Req->prefix = NULL; Req->prefix = NULL;
return true; return true;
@ -287,19 +288,25 @@ Validate_Prefix( CONN_ID Idx, REQUEST *Req, bool *Closed )
/* check if client in prefix is known */ /* check if client in prefix is known */
c = Client_Search( Req->prefix ); c = Client_Search( Req->prefix );
if( ! c ) if (!c) {
{ Log(LOG_ERR,
Log( LOG_ERR, "Invalid prefix \"%s\", client not known (connection %d, command %s)!?", Req->prefix, Idx, Req->command ); "Invalid prefix \"%s\", client not known (connection %d, command \"%s\")!?",
if( ! Conn_WriteStr( Idx, "ERROR :Invalid prefix \"%s\", client not known!?", Req->prefix )) *Closed = true; Req->prefix, Idx, Req->command);
if (!Conn_WriteStr(Idx,
"ERROR :Invalid prefix \"%s\", client not known",
Req->prefix))
*Closed = true;
return false; return false;
} }
/* check if the client named in the prefix is expected /* check if the client named in the prefix is expected
* to come from that direction */ * to come from that direction */
if( Client_NextHop( c ) != client ) if (Client_NextHop(c) != client) {
{ Log(LOG_ERR,
Log( LOG_ERR, "Spoofed prefix \"%s\" from \"%s\" (connection %d, command %s)!", Req->prefix, Client_Mask( Conn_GetClient( Idx )), Idx, Req->command ); "Spoofed prefix \"%s\" from \"%s\" (connection %d, command \"%s\")!",
Conn_Close( Idx, NULL, "Spoofed prefix", true); Req->prefix, Client_Mask(Conn_GetClient(Idx)), Idx,
Req->command);
Conn_Close(Idx, NULL, "Spoofed prefix", true);
*Closed = true; *Closed = true;
return false; return false;
} }