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=eaa4f46c436fe9b2e1e0d0e9920e5e3907db47cb;hp=90a5014d64fd7f1668a7efdde952c0a2395b5171;hb=feafb6cb2e1979918d934689ac7186cf7e963663;hpb=1e59617d2c70ebc4e5008a4233cc759fee715c8f diff --git a/src/ngircd/irc-server.c b/src/ngircd/irc-server.c index 90a5014d..eaa4f46c 100644 --- a/src/ngircd/irc-server.c +++ b/src/ngircd/irc-server.c @@ -2,21 +2,20 @@ * ngIRCd -- The Next Generation IRC Daemon * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de) * - * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen - * der GNU General Public License (GPL), wie von der Free Software Foundation - * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2 - * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version. - * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste - * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * Please read the file COPYING, README and AUTHORS for more information. * - * $Id: irc-server.c,v 1.23 2002/11/30 15:04:57 alex Exp $ - * - * irc-server.c: IRC-Befehle fuer Server-Links + * IRC commands for server links */ #include "portab.h" +static char UNUSED id[] = "$Id: irc-server.c,v 1.32 2003/04/20 23:09:26 alex Exp $"; + #include "imp.h" #include #include @@ -24,8 +23,9 @@ #include #include "resolve.h" -#include "conf.h" #include "conn.h" +#include "conn-zip.h" +#include "conf.h" #include "client.h" #include "channel.h" #include "irc-write.h" @@ -41,7 +41,7 @@ GLOBAL BOOLEAN IRC_SERVER( CLIENT *Client, REQUEST *Req ) { - CHAR str[LINE_LEN], *ptr; + CHAR str[LINE_LEN], *ptr, *modes, *topic; CLIENT *from, *c, *cl; CL2CHAN *cl2chan; INT max_hops, i; @@ -64,8 +64,8 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req ) if(( Req->argc != 2 ) && ( Req->argc != 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); /* Ist dieser Server bei uns konfiguriert? */ - for( i = 0; i < Conf_Server_Count; i++ ) if( strcasecmp( Req->argv[0], Conf_Server[i].name ) == 0 ) break; - if( i >= Conf_Server_Count ) + for( i = 0; i < MAX_SERVERS; i++ ) if( strcasecmp( Req->argv[0], Conf_Server[i].name ) == 0 ) break; + if( i >= MAX_SERVERS ) { /* Server ist nicht konfiguriert! */ Log( LOG_ERR, "Connection %d: Server \"%s\" not configured here!", Client_Conn( Client ), Req->argv[0] ); @@ -115,13 +115,13 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req ) 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 ); + Conf_SetServer( i, con ); #ifdef USE_ZLIB /* Kompression initialisieren, wenn erforderlich */ if( strchr( Client_Flags( Client ), 'Z' )) { - if( ! Conn_InitZip( con )) + if( ! Zip_InitConn( con )) { /* Fehler! */ Conn_Close( con, "Can't inizialize compression (zlib)!", NULL, FALSE ); @@ -179,33 +179,53 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req ) while( chan ) { #ifdef IRCPLUS - /* Wenn unterstuetzt, CHANINFO senden */ + /* Send CHANINFO if the peer supports it */ 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; + modes = Channel_Modes( chan ); + topic = Channel_Topic( chan ); + + if( *modes || *topic ) + { + /* send CHANINFO */ + if(( ! strchr( Channel_Modes( chan ), 'k' )) && ( ! strchr( Channel_Modes( chan ), 'l' )) && ( ! *topic )) + { + /* "CHANINFO +" */ + if( ! IRC_WriteStrClient( Client, "CHANINFO %s +%s", Channel_Name( chan ), modes )) return DISCONNECTED; + } + else if(( ! strchr( Channel_Modes( chan ), 'k' )) && ( ! strchr( Channel_Modes( chan ), 'l' ))) + { + /* "CHANINFO + :" */ + if( ! IRC_WriteStrClient( Client, "CHANINFO %s +%s :%s", Channel_Name( chan ), modes, topic )) return DISCONNECTED; + } + else + { + /* "CHANINFO + :" */ + if( ! IRC_WriteStrClient( Client, "CHANINFO %s +%s %s %ld :%s", Channel_Name( chan ), modes, strchr( Channel_Modes( chan ), 'k' ) ? Channel_Key( chan ) : "*", strchr( Channel_Modes( chan ), 'l' ) ? Channel_MaxUsers( chan ) : 0L, topic )) return DISCONNECTED; + } + } } #endif /* alle Member suchen */ cl2chan = Channel_FirstMember( chan ); - sprintf( str, "NJOIN %s :", Channel_Name( chan )); + snprintf( str, sizeof( str ), "NJOIN %s :", Channel_Name( chan )); while( cl2chan ) { cl = Channel_GetClient( cl2chan ); assert( cl != NULL ); /* Nick, ggf. mit Modes, anhaengen */ - if( str[strlen( str ) - 1] != ':' ) strcat( str, "," ); - if( strchr( Channel_UserModes( chan, cl ), 'v' )) strcat( str, "+" ); - if( strchr( Channel_UserModes( chan, cl ), 'o' )) strcat( str, "@" ); - strcat( str, Client_ID( cl )); + if( str[strlen( str ) - 1] != ':' ) strlcat( str, ",", sizeof( str )); + if( strchr( Channel_UserModes( chan, cl ), 'v' )) strlcat( str, "+", sizeof( str )); + if( strchr( Channel_UserModes( chan, cl ), 'o' )) strlcat( str, "@", sizeof( str )); + strlcat( str, Client_ID( cl ), sizeof( str )); if( strlen( str ) > ( LINE_LEN - CLIENT_NICK_LEN - 8 )) { /* Zeile senden */ if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED; - sprintf( str, "NJOIN %s :", Channel_Name( chan )); + snprintf( str, sizeof( str ), "NJOIN %s :", Channel_Name( chan )); } cl2chan = Channel_NextMember( chan, cl2chan ); @@ -258,7 +278,7 @@ 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 )); + if(( Client_Hops( c ) > 1 ) && ( Req->prefix[0] )) snprintf( str, sizeof( str ), "connected to %s, ", Client_ID( from )); else strcpy( str, "" ); 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": "" ); @@ -274,7 +294,7 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req ) GLOBAL BOOLEAN IRC_NJOIN( CLIENT *Client, REQUEST *Req ) { - CHAR str[COMMAND_LEN], *channame, *ptr, modes[8]; + CHAR nick_in[COMMAND_LEN], nick_out[COMMAND_LEN], *channame, *ptr, modes[8]; BOOLEAN is_op, is_voiced; CHANNEL *chan; CLIENT *c; @@ -285,11 +305,11 @@ 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'; + strlcpy( nick_in, Req->argv[1], sizeof( nick_in )); + strcpy( nick_out, "" ); channame = Req->argv[0]; - ptr = strtok( str, "," ); + ptr = strtok( nick_in, "," ); while( ptr ) { is_op = is_voiced = FALSE; @@ -316,12 +336,15 @@ IRC_NJOIN( CLIENT *Client, REQUEST *Req ) IRC_WriteStrChannelPrefix( Client, chan, c, FALSE, "JOIN :%s", channame ); /* Channel-User-Modes setzen */ - strcpy( modes, Channel_UserModes( chan, c )); + strlcpy( modes, Channel_UserModes( chan, c ), sizeof( modes )); if( modes[0] ) { /* Modes im Channel bekannt machen */ IRC_WriteStrChannelPrefix( Client, chan, Client, FALSE, "MODE %s +%s %s", channame, modes, Client_ID( c )); } + + if( nick_out[0] != '\0' ) strlcat( nick_out, ",", sizeof( nick_out )); + strlcat( nick_out, ptr, sizeof( nick_out )); } else Log( LOG_ERR, "Got NJOIN for unknown nick \"%s\" for channel \"%s\"!", ptr, channame ); @@ -330,7 +353,7 @@ IRC_NJOIN( CLIENT *Client, REQUEST *Req ) } /* an andere Server weiterleiten */ - IRC_WriteStrServersPrefix( Client, Client_ThisServer( ), "NJOIN %s :%s", Req->argv[0], Req->argv[1] ); + if( nick_out[0] != '\0' ) IRC_WriteStrServersPrefix( Client, Client_ThisServer( ), "NJOIN %s :%s", Req->argv[0], nick_out ); return CONNECTED; } /* IRC_NJOIN */ @@ -361,9 +384,9 @@ IRC_SQUIT( CLIENT *Client, REQUEST *Req ) if( Req->argv[1][0] ) { if( strlen( Req->argv[1] ) > LINE_LEN ) Req->argv[1][LINE_LEN] = '\0'; - sprintf( msg, "%s (SQUIT from %s).", Req->argv[1], Client_ID( Client )); + snprintf( msg, sizeof( msg ), "%s (SQUIT from %s).", Req->argv[1], Client_ID( Client )); } - else sprintf( msg, "Got SQUIT from %s.", Client_ID( Client )); + else snprintf( msg, sizeof( msg ), "Got SQUIT from %s.", Client_ID( Client )); if( Client_Conn( target ) > NONE ) {