X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Firc-server.c;h=204942c96167fca60ca4381661f23ce759f4f3ae;hp=53884517c9f88fc12155bc93ae90342dd8da46ff;hb=65f3adca21aa7066bea2e8842e533aa0e25583f4;hpb=9fc7e66f6664130c27fc7e06884af1021d22d592 diff --git a/src/ngircd/irc-server.c b/src/ngircd/irc-server.c index 53884517..204942c9 100644 --- a/src/ngircd/irc-server.c +++ b/src/ngircd/irc-server.c @@ -9,41 +9,37 @@ * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS. * - * $Id: irc-server.c,v 1.3 2002/03/11 17:33:40 alex Exp $ + * $Id: irc-server.c,v 1.21 2002/11/26 23:07:24 alex Exp $ * * irc-server.c: IRC-Befehle fuer Server-Links - * - * $Log: irc-server.c,v $ - * Revision 1.3 2002/03/11 17:33:40 alex - * - Log-Level von SQUIT und QUIT bei unbekannten Clients auf DEBUG herabgesetzt. - * - * Revision 1.2 2002/03/06 15:50:14 alex - * - kleine Code-Umstellungen. - * - * Revision 1.1 2002/03/03 17:15:11 alex - * - Source in weitere Module fuer IRC-Befehle aufgesplitted. */ -#include -#include "global.h" +#include "portab.h" -#include +#include "imp.h" #include #include #include #include +#include "resolve.h" #include "conf.h" +#include "conn.h" +#include "client.h" +#include "channel.h" #include "irc-write.h" #include "log.h" #include "messages.h" +#include "parse.h" +#include "ngircd.h" -#include +#include "exp.h" #include "irc-server.h" -GLOBAL BOOLEAN IRC_SERVER( CLIENT *Client, REQUEST *Req ) +GLOBAL BOOLEAN +IRC_SERVER( CLIENT *Client, REQUEST *Req ) { CHAR str[LINE_LEN], *ptr; CLIENT *from, *c, *cl; @@ -51,6 +47,7 @@ GLOBAL BOOLEAN IRC_SERVER( CLIENT *Client, REQUEST *Req ) INT max_hops, i; CHANNEL *chan; BOOLEAN ok; + CONN_ID con; assert( Client != NULL ); assert( Req != NULL ); @@ -75,10 +72,10 @@ GLOBAL BOOLEAN IRC_SERVER( CLIENT *Client, REQUEST *Req ) Conn_Close( Client_Conn( Client ), NULL, "Server not configured here", TRUE ); return DISCONNECTED; } - if( strcmp( Client_Password( Client ), Conf_Server[i].pwd ) != 0 ) + if( strcmp( Client_Password( Client ), Conf_Server[i].pwd_in ) != 0 ) { /* Falsches Passwort */ - Log( LOG_ERR, "Connection %d: Bad password for server \"%s\"!", Client_Conn( Client ), Req->argv[0] ); + Log( LOG_ERR, "Connection %d: Got bad password from server \"%s\"!", Client_Conn( Client ), Req->argv[0] ); Conn_Close( Client_Conn( Client ), NULL, "Bad password", TRUE ); return DISCONNECTED; } @@ -90,27 +87,48 @@ GLOBAL BOOLEAN IRC_SERVER( CLIENT *Client, REQUEST *Req ) Client_SetID( Client, Req->argv[0] ); Client_SetHops( Client, 1 ); Client_SetInfo( Client, Req->argv[Req->argc - 1] ); - - /* Meldet sich der Server bei uns an? */ - if( Req->argc == 2 ) + + /* Meldet sich der Server bei uns an (d.h., bauen nicht wir + * selber die Verbindung zu einem anderen Server auf)? */ + con = Client_Conn( Client ); + if( Client_Token( Client ) != TOKEN_OUTBOUND ) { - /* Unseren SERVER- und PASS-Befehl senden */ + /* Eingehende Verbindung: Unseren SERVER- und PASS-Befehl senden */ ok = TRUE; - if( ! IRC_WriteStrClient( Client, "PASS %s "PASSSERVERADD, Conf_Server[i].pwd )) ok = FALSE; + if( ! IRC_WriteStrClient( Client, "PASS %s %s", Conf_Server[i].pwd_out, NGIRCd_ProtoID )) ok = FALSE; else ok = IRC_WriteStrClient( Client, "SERVER %s 1 :%s", Conf_ServerName, Conf_ServerInfo ); if( ! ok ) { - Conn_Close( Client_Conn( Client ), "Unexpected server behavior!", NULL, FALSE ); + Conn_Close( con, "Unexpected server behavior!", NULL, FALSE ); return DISCONNECTED; } Client_SetIntroducer( Client, Client ); Client_SetToken( Client, 1 ); } - else Client_SetToken( Client, atoi( Req->argv[1] )); + else + { + /* Ausgehende verbindung, SERVER und PASS wurden von uns bereits + * an die Gegenseite uerbermittelt */ + Client_SetToken( Client, atoi( Req->argv[1] )); + } - Log( LOG_NOTICE, "Server \"%s\" registered (connection %d, 1 hop - direct link).", Client_ID( Client ), Client_Conn( Client )); + Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" registered (connection %d, 1 hop - direct link).", Client_ID( Client ), con ); Client_SetType( Client, CLIENT_SERVER ); + Conn_SetServer( con, i ); + +#ifdef USE_ZLIB + /* Kompression initialisieren, wenn erforderlich */ + if( strchr( Client_Flags( Client ), 'Z' )) + { + if( ! Conn_InitZip( con )) + { + /* Fehler! */ + Conn_Close( con, "Can't inizialize compression (zlib)!", NULL, FALSE ); + return DISCONNECTED; + } + } +#endif /* maximalen Hop Count ermitteln */ max_hops = 0; @@ -160,6 +178,15 @@ GLOBAL BOOLEAN IRC_SERVER( CLIENT *Client, REQUEST *Req ) chan = Channel_First( ); while( chan ) { +#ifdef IRCPLUS + /* Wenn unterstuetzt, CHANINFO senden */ + if( strchr( Client_Flags( Client ), 'C' )) + { + /* CHANINFO senden */ + if( ! IRC_WriteStrClient( Client, "CHANINFO %s +%s :%s", Channel_Name( chan ), Channel_Modes( chan ), Channel_Topic( chan ))) return DISCONNECTED; + } +#endif + /* alle Member suchen */ cl2chan = Channel_FirstMember( chan ); sprintf( str, "NJOIN %s :", Channel_Name( chan )); @@ -177,7 +204,7 @@ GLOBAL BOOLEAN IRC_SERVER( CLIENT *Client, REQUEST *Req ) if( strlen( str ) > ( LINE_LEN - CLIENT_NICK_LEN - 8 )) { /* Zeile senden */ - if( ! IRC_WriteStrClient( Client, str )) return DISCONNECTED; + if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED; sprintf( str, "NJOIN %s :", Channel_Name( chan )); } @@ -188,7 +215,7 @@ GLOBAL BOOLEAN IRC_SERVER( CLIENT *Client, REQUEST *Req ) if( str[strlen( str ) - 1] != ':') { /* Ja; Also senden ... */ - if( ! IRC_WriteStrClient( Client, str )) return DISCONNECTED; + if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED; } /* naechsten Channel suchen */ @@ -211,7 +238,7 @@ GLOBAL BOOLEAN IRC_SERVER( CLIENT *Client, REQUEST *Req ) ptr = strchr( Req->argv[3] + 2, '[' ); if( ! ptr ) ptr = Req->argv[3]; - from = Client_GetFromID( Req->prefix ); + from = Client_Search( Req->prefix ); if( ! from ) { /* Hm, Server, der diesen einfuehrt, ist nicht bekannt!? */ @@ -233,7 +260,7 @@ GLOBAL BOOLEAN IRC_SERVER( CLIENT *Client, REQUEST *Req ) /* Log-Meldung zusammenbauen und ausgeben */ if(( Client_Hops( c ) > 1 ) && ( Req->prefix[0] )) sprintf( str, "connected to %s, ", Client_ID( from )); else strcpy( str, "" ); - Log( LOG_NOTICE, "Server \"%s\" registered (via %s, %s%d hop%s).", Client_ID( c ), Client_ID( Client ), str, Client_Hops( c ), Client_Hops( c ) > 1 ? "s": "" ); + Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" registered (via %s, %s%d hop%s).", Client_ID( c ), Client_ID( Client ), str, Client_Hops( c ), Client_Hops( c ) > 1 ? "s": "" ); /* Andere Server informieren */ IRC_WriteStrServersPrefix( Client, from, "SERVER %s %d %d :%s", Client_ID( c ), Client_Hops( c ) + 1, Client_MyToken( c ), Client_Info( c )); @@ -244,9 +271,10 @@ GLOBAL BOOLEAN IRC_SERVER( CLIENT *Client, REQUEST *Req ) } /* IRC_SERVER */ -GLOBAL BOOLEAN IRC_NJOIN( CLIENT *Client, REQUEST *Req ) +GLOBAL BOOLEAN +IRC_NJOIN( CLIENT *Client, REQUEST *Req ) { - CHAR *channame, *ptr, modes[8]; + CHAR str[COMMAND_LEN], *channame, *ptr, modes[8]; BOOLEAN is_op, is_voiced; CHANNEL *chan; CLIENT *c; @@ -259,8 +287,11 @@ GLOBAL BOOLEAN IRC_NJOIN( CLIENT *Client, REQUEST *Req ) /* Falsche Anzahl Parameter? */ if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); + strncpy( str, Req->argv[1], COMMAND_LEN - 1 ); + str[COMMAND_LEN - 1] = '\0'; + channame = Req->argv[0]; - ptr = strtok( Req->argv[1], "," ); + ptr = strtok( str, "," ); while( ptr ) { is_op = is_voiced = FALSE; @@ -273,7 +304,7 @@ GLOBAL BOOLEAN IRC_NJOIN( CLIENT *Client, REQUEST *Req ) ptr++; } - c = Client_GetFromID( ptr ); + c = Client_Search( ptr ); if( c ) { Channel_Join( c, channame ); @@ -307,7 +338,8 @@ GLOBAL BOOLEAN IRC_NJOIN( CLIENT *Client, REQUEST *Req ) } /* IRC_NJOIN */ -GLOBAL BOOLEAN IRC_SQUIT( CLIENT *Client, REQUEST *Req ) +GLOBAL BOOLEAN +IRC_SQUIT( CLIENT *Client, REQUEST *Req ) { CLIENT *target; CHAR msg[LINE_LEN + 64]; @@ -326,11 +358,11 @@ GLOBAL BOOLEAN IRC_SQUIT( CLIENT *Client, REQUEST *Req ) /* SQUIT an alle Server weiterleiten */ IRC_WriteStrServers( Client, "SQUIT %s :%s", Req->argv[0], Req->argv[1] ); - target = Client_GetFromID( Req->argv[0] ); + target = Client_Search( Req->argv[0] ); if( ! target ) { /* Den Server kennen wir nicht (mehr), also nichts zu tun. */ - Log( LOG_DEBUG, "Got SQUIT from %s for unknown server \"%s\"!?", Client_ID( Client ), Req->argv[0] ); + Log( LOG_WARNING, "Got SQUIT from %s for unknown server \"%s\"!?", Client_ID( Client ), Req->argv[0] ); return CONNECTED; } @@ -351,7 +383,7 @@ GLOBAL BOOLEAN IRC_SQUIT( CLIENT *Client, REQUEST *Req ) else { /* Verbindung hielt anderer Server */ - Client_Destroy( target, msg, Req->argv[1] ); + Client_Destroy( target, msg, Req->argv[1], FALSE ); return CONNECTED; } } /* IRC_SQUIT */