X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Fparse.c;h=6d1efef660a00ddc6cdc9168440bf71c3f7b2a90;hp=a1348fe2d45333acfa69b4d106b71e205f55d29b;hb=5502fb271db2b9466a571d0c8b7b3352e43ae537;hpb=9d2407dbc50ccebc8cfc3bb1748665a51cf506a0 diff --git a/src/ngircd/parse.c b/src/ngircd/parse.c index a1348fe2..6d1efef6 100644 --- a/src/ngircd/parse.c +++ b/src/ngircd/parse.c @@ -9,7 +9,7 @@ * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS. * - * $Id: parse.c,v 1.32 2002/04/23 19:50:27 alex Exp $ + * $Id: parse.c,v 1.41 2002/09/16 09:20:27 alex Exp $ * * parse.c: Parsen der Client-Anfragen */ @@ -24,36 +24,41 @@ #include #include "ngircd.h" -#include "client.h" -#include "conn.h" #include "defines.h" +#include "conn.h" +#include "client.h" +#include "channel.h" +#include "log.h" +#include "messages.h" +#include "tool.h" + +#include "exp.h" +#include "parse.h" + +#include "imp.h" #include "irc.h" #include "irc-channel.h" #include "irc-login.h" #include "irc-mode.h" +#include "irc-op.h" #include "irc-oper.h" #include "irc-server.h" #include "irc-write.h" -#include "log.h" -#include "messages.h" -#include "tool.h" #include "exp.h" -#include "parse.h" -LOCAL VOID Init_Request( REQUEST *Req ); +LOCAL VOID Init_Request PARAMS(( REQUEST *Req )); -LOCAL BOOLEAN Parse_Error( CONN_ID Idx, CHAR *Error ); +LOCAL BOOLEAN Validate_Prefix PARAMS(( CONN_ID Idx, REQUEST *Req, BOOLEAN *Closed )); +LOCAL BOOLEAN Validate_Command PARAMS(( CONN_ID Idx, REQUEST *Req, BOOLEAN *Closed )); +LOCAL BOOLEAN Validate_Args PARAMS(( CONN_ID Idx, REQUEST *Req, BOOLEAN *Closed )); -LOCAL BOOLEAN Validate_Prefix( REQUEST *Req ); -LOCAL BOOLEAN Validate_Command( REQUEST *Req ); -LOCAL BOOLEAN Validate_Args( REQUEST *Req ); +LOCAL BOOLEAN Handle_Request PARAMS(( CONN_ID Idx, REQUEST *Req )); -LOCAL BOOLEAN Handle_Request( CONN_ID Idx, REQUEST *Req ); - -GLOBAL BOOLEAN Parse_Request( CONN_ID Idx, CHAR *Request ) +GLOBAL BOOLEAN +Parse_Request( CONN_ID Idx, CHAR *Request ) { /* Client-Request parsen. Bei einem schwerwiegenden Fehler wird * die Verbindung geschlossen und FALSE geliefert. @@ -61,6 +66,7 @@ GLOBAL BOOLEAN Parse_Request( CONN_ID Idx, CHAR *Request ) REQUEST req; CHAR *start, *ptr; + BOOLEAN closed; assert( Idx >= 0 ); assert( Request != NULL ); @@ -68,7 +74,7 @@ GLOBAL BOOLEAN Parse_Request( CONN_ID Idx, CHAR *Request ) #ifdef SNIFFER if( NGIRCd_Sniffer ) Log( LOG_DEBUG, " <- connection %d: '%s'.", Idx, Request ); #endif - + Init_Request( &req ); /* Fuehrendes und folgendes "Geraffel" verwerfen */ @@ -80,7 +86,11 @@ GLOBAL BOOLEAN Parse_Request( CONN_ID Idx, CHAR *Request ) /* Prefix vorhanden */ req.prefix = Request + 1; ptr = strchr( Request, ' ' ); - if( ! ptr ) return Parse_Error( Idx, "Prefix without command!?" ); + if( ! ptr ) + { + Log( LOG_DEBUG, "Connection %d: Parse error: prefix without command!?", Idx ); + return Conn_WriteStr( Idx, "ERROR :Prefix without command!?" ); + } *ptr = '\0'; #ifndef STRICT_RFC /* multiple Leerzeichen als Trenner zwischen @@ -91,7 +101,7 @@ GLOBAL BOOLEAN Parse_Request( CONN_ID Idx, CHAR *Request ) } else start = Request; - if( ! Validate_Prefix( &req )) return Parse_Error( Idx, "Invalid prefix"); + if( ! Validate_Prefix( Idx, &req, &closed )) return ! closed; /* Befehl */ ptr = strchr( start, ' ' ); @@ -106,7 +116,7 @@ GLOBAL BOOLEAN Parse_Request( CONN_ID Idx, CHAR *Request ) } req.command = start; - if( ! Validate_Command( &req )) return Parse_Error( Idx, "Invalid command" ); + if( ! Validate_Command( Idx, &req, &closed )) return ! closed; /* Argumente, Parameter */ if( ptr ) @@ -135,29 +145,30 @@ GLOBAL BOOLEAN Parse_Request( CONN_ID Idx, CHAR *Request ) #endif } } - + req.argc++; if( start[0] == ':' ) break; if( req.argc > 14 ) break; - + if( ptr ) start = ptr + 1; else start = NULL; } } - - if( ! Validate_Args( &req )) return Parse_Error( Idx, "Invalid argument(s)" ); + + if( ! Validate_Args( Idx, &req, &closed )) return ! closed; return Handle_Request( Idx, &req ); } /* Parse_Request */ -LOCAL VOID Init_Request( REQUEST *Req ) +LOCAL VOID +Init_Request( REQUEST *Req ) { /* Neue Request-Struktur initialisieren */ INT i; - + assert( Req != NULL ); Req->prefix = NULL; @@ -167,42 +178,83 @@ LOCAL VOID Init_Request( REQUEST *Req ) } /* Init_Request */ -LOCAL BOOLEAN Parse_Error( CONN_ID Idx, CHAR *Error ) +LOCAL BOOLEAN +Validate_Prefix( CONN_ID Idx, REQUEST *Req, BOOLEAN *Closed ) { - /* Fehler beim Parsen. Fehlermeldung an den Client schicken. - * TRUE: Connection wurde durch diese Funktion nicht geschlossen, - * FALSE: Connection wurde terminiert. */ - + CLIENT *client, *c; + assert( Idx >= 0 ); - assert( Error != NULL ); + assert( Req != NULL ); - Log( LOG_DEBUG, "Connection %d: Parse error: %s", Idx, Error ); - return Conn_WriteStr( Idx, "ERROR :Parse error: %s", Error ); -} /* Parse_Error */ + *Closed = FALSE; + /* ist ueberhaupt ein Prefix vorhanden? */ + if( ! Req->prefix ) return TRUE; + + /* Client-Struktur der Connection ermitteln */ + client = Client_GetFromConn( Idx ); + assert( client != NULL ); + + /* nur validieren, wenn bereits registrierte Verbindung */ + if(( Client_Type( client ) != CLIENT_USER ) && ( Client_Type( client ) != CLIENT_SERVER ) && ( Client_Type( client ) != CLIENT_SERVICE )) + { + /* noch nicht registrierte Verbindung. + * Das Prefix wird ignoriert. */ + Req->prefix = NULL; + return TRUE; + } + + /* pruefen, ob der im Prefix angegebene Client bekannt ist */ + c = Client_Search( Req->prefix ); + if( ! c ) + { + /* im Prefix angegebener Client ist nicht bekannt */ + Log( LOG_ERR, "Invalid prefix, client not known (connection %d)!?", Idx ); + if( ! Conn_WriteStr( Idx, "ERROR :Invalid prefix, client not known!?" )) *Closed = TRUE; + return FALSE; + } + + /* pruefen, ob der Client mit dem angegebenen Prefix in Richtung + * des Senders liegt, d.h. sicherstellen, dass das Prefix nicht + * gefaelscht ist */ + if( Client_NextHop( c ) != client ) + { + /* das angegebene Prefix ist aus dieser Richtung, also + * aus der gegebenen Connection, ungueltig! */ + Log( LOG_ERR, "Spoofed prefix \"%s\" from \"%s\" (connection %d)!", Req->prefix, Client_Mask( Client_GetFromConn( Idx )), Idx ); + Conn_Close( Idx, NULL, "Spoofed prefix", TRUE ); + *Closed = TRUE; + return FALSE; + } -LOCAL BOOLEAN Validate_Prefix( REQUEST *Req ) -{ - assert( Req != NULL ); return TRUE; } /* Validate_Prefix */ -LOCAL BOOLEAN Validate_Command( REQUEST *Req ) +LOCAL BOOLEAN +Validate_Command( CONN_ID Idx, REQUEST *Req, BOOLEAN *Closed ) { + assert( Idx >= 0 ); assert( Req != NULL ); + *Closed = FALSE; + return TRUE; } /* Validate_Comman */ -LOCAL BOOLEAN Validate_Args( REQUEST *Req ) +LOCAL BOOLEAN +Validate_Args( CONN_ID Idx, REQUEST *Req, BOOLEAN *Closed ) { + assert( Idx >= 0 ); assert( Req != NULL ); + *Closed = FALSE; + return TRUE; } /* Validate_Args */ -LOCAL BOOLEAN Handle_Request( CONN_ID Idx, REQUEST *Req ) +LOCAL BOOLEAN +Handle_Request( CONN_ID Idx, REQUEST *Req ) { /* Client-Request verarbeiten. Bei einem schwerwiegenden Fehler * wird die Verbindung geschlossen und FALSE geliefert. */ @@ -293,6 +345,13 @@ LOCAL BOOLEAN Handle_Request( CONN_ID Idx, REQUEST *Req ) else if( strcasecmp( Req->command, "TOPIC" ) == 0 ) return IRC_TOPIC( client, Req ); else if( strcasecmp( Req->command, "WHO" ) == 0 ) return IRC_WHO( client, Req ); else if( strcasecmp( Req->command, "LIST" ) == 0 ) return IRC_LIST( client, Req ); + else if( strcasecmp( Req->command, "INVITE" ) == 0 ) return IRC_INVITE( client, Req ); + else if( strcasecmp( Req->command, "KICK" ) == 0 ) return IRC_KICK( client, Req ); + else if( strcasecmp( Req->command, "CONNECT" ) == 0 ) return IRC_CONNECT( client, Req ); + else if( strcasecmp( Req->command, "ADMIN" ) == 0 ) return IRC_ADMIN( client, Req ); +#ifdef IRCPLUS + else if( strcasecmp( Req->command, "CHANINFO" ) == 0 ) return IRC_CHANINFO( client, Req ); +#endif /* Unbekannter Befehl */ if( Client_Type( client ) != CLIENT_SERVER ) IRC_WriteStrClient( client, ERR_UNKNOWNCOMMAND_MSG, Client_ID( client ), Req->command );