X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fngircd%2Fparse.c;h=1a81b62950572d145408c2c0fd87d368c0cce09b;hb=ee2c0f770166a446d19f00585cc89e386baf94cf;hp=54b022d1fd90566e798543a4ad4bbed7869732ee;hpb=e0ed3aa1416037cc83996a9a30ff76863975c9c6;p=ngircd-alex.git diff --git a/src/ngircd/parse.c b/src/ngircd/parse.c index 54b022d1..1a81b629 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.34 2002/07/26 21:12:24 alex Exp $ + * $Id: parse.c,v 1.47 2002/11/28 11:02:50 alex Exp $ * * parse.c: Parsen der Client-Anfragen */ @@ -101,8 +101,6 @@ Parse_Request( CONN_ID Idx, CHAR *Request ) } else start = Request; - if( ! Validate_Prefix( Idx, &req, &closed )) return ! closed; - /* Befehl */ ptr = strchr( start, ' ' ); if( ptr ) @@ -116,8 +114,6 @@ Parse_Request( CONN_ID Idx, CHAR *Request ) } req.command = start; - if( ! Validate_Command( Idx, &req, &closed )) return ! closed; - /* Argumente, Parameter */ if( ptr ) { @@ -156,6 +152,9 @@ Parse_Request( CONN_ID Idx, CHAR *Request ) } } + /* Daten validieren */ + if( ! Validate_Prefix( Idx, &req, &closed )) return ! closed; + if( ! Validate_Command( Idx, &req, &closed )) return ! closed; if( ! Validate_Args( Idx, &req, &closed )) return ! closed; return Handle_Request( Idx, &req ); @@ -181,34 +180,47 @@ Init_Request( REQUEST *Req ) LOCAL BOOLEAN Validate_Prefix( CONN_ID Idx, REQUEST *Req, BOOLEAN *Closed ) { - CLIENT *c; + CLIENT *client, *c; assert( Idx >= 0 ); assert( Req != NULL ); *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; + 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; } - + /* 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_GetFromConn( Idx )) + 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 ); + Log( LOG_ERR, "Spoofed prefix \"%s\" from \"%s\" (connection %d, command %s)!", Req->prefix, Client_Mask( Client_GetFromConn( Idx )), Idx, Req->command ); Conn_Close( Idx, NULL, "Spoofed prefix", TRUE ); *Closed = TRUE; return FALSE; @@ -267,8 +279,8 @@ Handle_Request( CONN_ID Idx, REQUEST *Req ) else target = NULL; if( ! target ) { - if( Req->argc > 0 ) Log( LOG_WARNING, "Unknown target for status code: \"%s\"", Req->argv[0] ); - else Log( LOG_WARNING, "Unknown target for status code!" ); + if( Req->argc > 0 ) Log( LOG_WARNING, "Unknown target for status code %s: \"%s\"", Req->command, Req->argv[0] ); + else Log( LOG_WARNING, "Unknown target for status code %s!", Req->command ); return TRUE; } if( target == Client_ThisServer( )) @@ -298,44 +310,51 @@ Handle_Request( CONN_ID Idx, REQUEST *Req ) else strcat( str, " :" ); strcat( str, Req->argv[i] ); } - return IRC_WriteStrClientPrefix( target, prefix, str ); + return IRC_WriteStrClientPrefix( target, prefix, "%s", str ); } - if( strcasecmp( Req->command, "PASS" ) == 0 ) return IRC_PASS( client, Req ); + if( strcasecmp( Req->command, "ADMIN" ) == 0 ) return IRC_ADMIN( client, Req ); + else if( strcasecmp( Req->command, "AWAY" ) == 0 ) return IRC_AWAY( client, Req ); + else if( strcasecmp( Req->command, "CONNECT" ) == 0 ) return IRC_CONNECT( client, Req ); + else if( strcasecmp( Req->command, "DIE" ) == 0 ) return IRC_DIE( client, Req ); + else if( strcasecmp( Req->command, "ERROR" ) == 0 ) return IRC_ERROR( client, Req ); + else if( strcasecmp( Req->command, "INVITE" ) == 0 ) return IRC_INVITE( client, Req ); + else if( strcasecmp( Req->command, "ISON" ) == 0 ) return IRC_ISON( client, Req ); + else if( strcasecmp( Req->command, "JOIN" ) == 0 ) return IRC_JOIN( client, Req ); + else if( strcasecmp( Req->command, "KICK" ) == 0 ) return IRC_KICK( client, Req ); + else if( strcasecmp( Req->command, "KILL" ) == 0 ) return IRC_KILL( client, Req ); + else if( strcasecmp( Req->command, "LINKS" ) == 0 ) return IRC_LINKS( client, Req ); + else if( strcasecmp( Req->command, "LIST" ) == 0 ) return IRC_LIST( client, Req ); + else if( strcasecmp( Req->command, "LUSERS" ) == 0 ) return IRC_LUSERS( client, Req ); + else if( strcasecmp( Req->command, "MODE" ) == 0 ) return IRC_MODE( client, Req ); + else if( strcasecmp( Req->command, "MOTD" ) == 0 ) return IRC_MOTD( client, Req ); + else if( strcasecmp( Req->command, "NAMES" ) == 0 ) return IRC_NAMES( client, Req ); else if( strcasecmp( Req->command, "NICK" ) == 0 ) return IRC_NICK( client, Req ); - else if( strcasecmp( Req->command, "USER" ) == 0 ) return IRC_USER( client, Req ); - else if( strcasecmp( Req->command, "SERVER" ) == 0 ) return IRC_SERVER( client, Req ); else if( strcasecmp( Req->command, "NJOIN" ) == 0 ) return IRC_NJOIN( client, Req ); - else if( strcasecmp( Req->command, "QUIT" ) == 0 ) return IRC_QUIT( client, Req ); - else if( strcasecmp( Req->command, "SQUIT" ) == 0 ) return IRC_SQUIT( client, Req ); + else if( strcasecmp( Req->command, "NOTICE" ) == 0 ) return IRC_NOTICE( client, Req ); + else if( strcasecmp( Req->command, "OPER" ) == 0 ) return IRC_OPER( client, Req ); + else if( strcasecmp( Req->command, "PART" ) == 0 ) return IRC_PART( client, Req ); + else if( strcasecmp( Req->command, "PASS" ) == 0 ) return IRC_PASS( client, Req ); else if( strcasecmp( Req->command, "PING" ) == 0 ) return IRC_PING( client, Req ); else if( strcasecmp( Req->command, "PONG" ) == 0 ) return IRC_PONG( client, Req ); - else if( strcasecmp( Req->command, "MOTD" ) == 0 ) return IRC_MOTD( client, Req ); else if( strcasecmp( Req->command, "PRIVMSG" ) == 0 ) return IRC_PRIVMSG( client, Req ); - else if( strcasecmp( Req->command, "NOTICE" ) == 0 ) return IRC_NOTICE( client, Req ); - else if( strcasecmp( Req->command, "MODE" ) == 0 ) return IRC_MODE( client, Req ); - else if( strcasecmp( Req->command, "NAMES" ) == 0 ) return IRC_NAMES( client, Req ); - else if( strcasecmp( Req->command, "ISON" ) == 0 ) return IRC_ISON( client, Req ); - else if( strcasecmp( Req->command, "WHOIS" ) == 0 ) return IRC_WHOIS( client, Req ); - else if( strcasecmp( Req->command, "USERHOST" ) == 0 ) return IRC_USERHOST( client, Req ); - else if( strcasecmp( Req->command, "OPER" ) == 0 ) return IRC_OPER( client, Req ); - else if( strcasecmp( Req->command, "DIE" ) == 0 ) return IRC_DIE( client, Req ); + else if( strcasecmp( Req->command, "QUIT" ) == 0 ) return IRC_QUIT( client, Req ); + else if( strcasecmp( Req->command, "REHASH" ) == 0 ) return IRC_REHASH( client, Req ); else if( strcasecmp( Req->command, "RESTART" ) == 0 ) return IRC_RESTART( client, Req ); - else if( strcasecmp( Req->command, "ERROR" ) == 0 ) return IRC_ERROR( client, Req ); - else if( strcasecmp( Req->command, "LUSERS" ) == 0 ) return IRC_LUSERS( client, Req ); - else if( strcasecmp( Req->command, "LINKS" ) == 0 ) return IRC_LINKS( client, Req ); - else if( strcasecmp( Req->command, "JOIN" ) == 0 ) return IRC_JOIN( client, Req ); - else if( strcasecmp( Req->command, "PART" ) == 0 ) return IRC_PART( client, Req ); - else if( strcasecmp( Req->command, "VERSION" ) == 0 ) return IRC_VERSION( client, Req ); - else if( strcasecmp( Req->command, "KILL" ) == 0 ) return IRC_KILL( client, Req ); - else if( strcasecmp( Req->command, "AWAY" ) == 0 ) return IRC_AWAY( client, Req ); + else if( strcasecmp( Req->command, "SERVER" ) == 0 ) return IRC_SERVER( client, Req ); + else if( strcasecmp( Req->command, "SQUIT" ) == 0 ) return IRC_SQUIT( client, Req ); + else if( strcasecmp( Req->command, "TIME" ) == 0 ) return IRC_TIME( client, Req ); else if( strcasecmp( Req->command, "TOPIC" ) == 0 ) return IRC_TOPIC( client, Req ); + else if( strcasecmp( Req->command, "USER" ) == 0 ) return IRC_USER( client, Req ); + else if( strcasecmp( Req->command, "USERHOST" ) == 0 ) return IRC_USERHOST( client, Req ); + else if( strcasecmp( Req->command, "VERSION" ) == 0 ) return IRC_VERSION( 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, "BAN" ) == 0 ) return IRC_BAN( client, Req ); - + else if( strcasecmp( Req->command, "WHOIS" ) == 0 ) return IRC_WHOIS( client, Req ); + else if( strcasecmp( Req->command, "WHOWAS" ) == 0 ) return IRC_WHOWAS( 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 ); Log( LOG_DEBUG, "Connection %d: Unknown command \"%s\", %d %s,%s prefix.", Client_Conn( client ), Req->command, Req->argc, Req->argc == 1 ? "parameter" : "parameters", Req->prefix ? "" : " no" );