Clean up Validate_Prefix(); don't send punctuation in ERROR commands
This commit is contained in:
parent
8700f4d93c
commit
493ccd57f4
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,18 +288,24 @@ 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 );
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue