]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc-info.c
New "chroot" feature (from Benjamin Pineau), introducing new configuration
[ngircd-alex.git] / src / ngircd / irc-info.c
index 3ce821a275e3d20205c659a141fcaa827c14cb95..26306949ed865ecc014d0299770c73e5ee4ab790 100644 (file)
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: irc-info.c,v 1.13 2002/12/30 17:15:42 alex Exp $";
+static char UNUSED id[] = "$Id: irc-info.c,v 1.22 2004/05/07 11:19:21 alex Exp $";
 
 #include "imp.h"
 #include <assert.h>
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
+#include <strings.h>
 
 #include "ngircd.h"
+#include "cvs-version.h"
 #include "conn-func.h"
 #include "conn-zip.h"
 #include "client.h"
@@ -63,7 +65,7 @@ IRC_ADMIN(CLIENT *Client, REQUEST *Req )
        /* An anderen Server weiterleiten? */
        if( target != Client_ThisServer( ))
        {
-               if( ! target ) return IRC_WriteStrClient( prefix, ERR_NOSUCHSERVER_MSG, Client_ID( prefix ), Req->argv[0] );
+               if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( prefix, ERR_NOSUCHSERVER_MSG, Client_ID( prefix ), Req->argv[0] );
 
                /* forwarden */
                IRC_WriteStrClientPrefix( target, prefix, "ADMIN %s", Req->argv[0] );
@@ -76,6 +78,7 @@ IRC_ADMIN(CLIENT *Client, REQUEST *Req )
        if( ! IRC_WriteStrClient( Client, RPL_ADMINLOC2_MSG, Client_ID( prefix ), Conf_ServerAdmin2 )) return DISCONNECTED;
        if( ! IRC_WriteStrClient( Client, RPL_ADMINEMAIL_MSG, Client_ID( prefix ), Conf_ServerAdminMail )) return DISCONNECTED;
 
+       IRC_SetPenalty( Client, 1 );
        return CONNECTED;
 } /* IRC_ADMIN */
 
@@ -142,7 +145,7 @@ IRC_LINKS( CLIENT *Client, REQUEST *Req )
        if( Req->argc == 2 )
        {
                target = Client_Search( Req->argv[0] );
-               if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] );
+               if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] );
                else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LINKS %s %s", Req->argv[0], Req->argv[1] );
        }
 
@@ -160,7 +163,8 @@ IRC_LINKS( CLIENT *Client, REQUEST *Req )
                }
                c = Client_Next( c );
        }
-
+       
+       IRC_SetPenalty( target, 1 );
        return IRC_WriteStrClient( target, RPL_ENDOFLINKS_MSG, Client_ID( target ), mask );
 } /* IRC_LINKS */
 
@@ -185,7 +189,7 @@ IRC_LUSERS( CLIENT *Client, REQUEST *Req )
        if( Req->argc == 2 )
        {
                target = Client_Search( Req->argv[1] );
-               if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
+               if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
                else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LUSERS %s %s", Req->argv[0], Req->argv[1] );
        }
 
@@ -196,6 +200,7 @@ IRC_LUSERS( CLIENT *Client, REQUEST *Req )
 
        IRC_Send_LUSERS( target );
 
+       IRC_SetPenalty( target, 1 );
        return CONNECTED;
 } /* IRC_LUSERS */
 
@@ -220,7 +225,7 @@ IRC_MOTD( CLIENT *Client, REQUEST *Req )
        {
                /* an anderen Server forwarden */
                target = Client_Search( Req->argv[0] );
-               if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] );
+               if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] );
 
                if( target != Client_ThisServer( ))
                {
@@ -229,6 +234,7 @@ IRC_MOTD( CLIENT *Client, REQUEST *Req )
                }
        }
 
+       IRC_SetPenalty( from, 3 );
        return IRC_Show_MOTD( from );
 } /* IRC_MOTD */
 
@@ -255,7 +261,7 @@ IRC_NAMES( CLIENT *Client, REQUEST *Req )
        {
                /* an anderen Server forwarden */
                target = Client_Search( Req->argv[1] );
-               if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
+               if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
 
                if( target != Client_ThisServer( ))
                {
@@ -323,6 +329,7 @@ IRC_NAMES( CLIENT *Client, REQUEST *Req )
                if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
        }
 
+       IRC_SetPenalty( from, 1 );
        return IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), "*" );
 } /* IRC_NAMES */
 
@@ -350,7 +357,7 @@ IRC_STATS( CLIENT *Client, REQUEST *Req )
        {
                /* an anderen Server forwarden */
                target = Client_Search( Req->argv[1] );
-               if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
+               if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
 
                if( target != Client_ThisServer( ))
                {
@@ -373,7 +380,7 @@ IRC_STATS( CLIENT *Client, REQUEST *Req )
                                if( cl && (( Client_Type( cl ) == CLIENT_SERVER ) || ( cl == Client )))
                                {
                                        /* Server link or our own connection */
-#ifdef USE_ZLIB
+#ifdef ZLIB
                                        if( Conn_Options( con ) & CONN_ZIP )
                                        {
                                                if( ! IRC_WriteStrClient( from, RPL_STATSLINKINFOZIP_MSG, Client_ID( from ), Client_Mask( cl ), Conn_SendQ( con ), Conn_SendMsg( con ), Zip_SendBytes( con ), Conn_SendBytes( con ), Conn_RecvMsg( con ), Zip_RecvBytes( con ), Conn_RecvBytes( con ), (LONG)( time( NULL ) - Conn_StartTime( con )))) return DISCONNECTED;
@@ -401,6 +408,7 @@ IRC_STATS( CLIENT *Client, REQUEST *Req )
                        break;
        }
 
+       IRC_SetPenalty( from, 2 );
        return IRC_WriteStrClient( from, RPL_ENDOFSTATS_MSG, Client_ID( from ), query );
 } /* IRC_STATS */
 
@@ -427,7 +435,7 @@ IRC_TIME( CLIENT *Client, REQUEST *Req )
        {
                /* an anderen Server forwarden */
                target = Client_Search( Req->argv[0] );
-               if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
+               if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
 
                if( target != Client_ThisServer( ))
                {
@@ -437,7 +445,7 @@ IRC_TIME( CLIENT *Client, REQUEST *Req )
        }
 
        t = time( NULL );
-       (VOID)strftime( t_str, 60, "%A %B %d %Y -- %H:%M %z", localtime( &t ));
+       (VOID)strftime( t_str, 60, "%A %B %d %Y -- %H:%M %Z", localtime( &t ));
        return IRC_WriteStrClient( from, RPL_TIME_MSG, Client_ID( from ), Client_ID( Client_ThisServer( )), t_str );
 } /* IRC_TIME */
 
@@ -486,6 +494,9 @@ GLOBAL BOOLEAN
 IRC_VERSION( CLIENT *Client, REQUEST *Req )
 {
        CLIENT *target, *prefix;
+#ifdef CVSDATE
+       CHAR ver[12], vertxt[30];
+#endif
 
        assert( Client != NULL );
        assert( Req != NULL );
@@ -505,7 +516,7 @@ IRC_VERSION( CLIENT *Client, REQUEST *Req )
        /* An anderen Server weiterleiten? */
        if( target != Client_ThisServer( ))
        {
-               if( ! target ) return IRC_WriteStrClient( prefix, ERR_NOSUCHSERVER_MSG, Client_ID( prefix ), Req->argv[0] );
+               if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( prefix, ERR_NOSUCHSERVER_MSG, Client_ID( prefix ), Req->argv[0] );
 
                /* forwarden */
                IRC_WriteStrClientPrefix( target, prefix, "VERSION %s", Req->argv[0] );
@@ -513,7 +524,16 @@ IRC_VERSION( CLIENT *Client, REQUEST *Req )
        }
 
        /* mit Versionsinfo antworten */
-       return IRC_WriteStrClient( Client, RPL_VERSION_MSG, Client_ID( prefix ), PACKAGE, VERSION, NGIRCd_DebugLevel, Conf_ServerName, NGIRCd_VersionAddition( ));
+       IRC_SetPenalty( Client, 1 );
+#ifdef CVSDATE
+       strlcpy( ver, CVSDATE, sizeof( ver ));
+       strncpy( ver + 4, ver + 5, 2 );
+       strncpy( ver + 6, ver + 8, 3 );
+       snprintf( vertxt, sizeof( vertxt ), "%s(%s)", PACKAGE_VERSION, ver );
+       return IRC_WriteStrClient( Client, RPL_VERSION_MSG, Client_ID( prefix ), PACKAGE_NAME, vertxt, NGIRCd_DebugLevel, Conf_ServerName, NGIRCd_VersionAddition( ));
+#else
+       return IRC_WriteStrClient( Client, RPL_VERSION_MSG, Client_ID( prefix ), PACKAGE_NAME, PACKAGE_VERSION, NGIRCd_DebugLevel, Conf_ServerName, NGIRCd_VersionAddition( ));
+#endif
 } /* IRC_VERSION */
 
 
@@ -597,40 +617,39 @@ GLOBAL BOOLEAN
 IRC_WHOIS( CLIENT *Client, REQUEST *Req )
 {
        CLIENT *from, *target, *c;
-       CHAR str[LINE_LEN + 1], *ptr = NULL;
+       CHAR str[LINE_LEN + 1];
        CL2CHAN *cl2chan;
        CHANNEL *chan;
 
        assert( Client != NULL );
        assert( Req != NULL );
 
-       /* Falsche Anzahl Parameter? */
+       /* Bad number of parameters? */
        if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
 
-       /* Client suchen */
+       /* Search client */
        c = Client_Search( Req->argv[Req->argc - 1] );
        if(( ! c ) || ( Client_Type( c ) != CLIENT_USER )) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[Req->argc - 1] );
 
-       /* Empfaenger des WHOIS suchen */
+       /* Search sender of the WHOIS */
        if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
        else from = Client;
        if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
 
-       /* Forwarden an anderen Server? */
+       /* Forward to other server? */
        if( Req->argc > 1 )
        {
-               /* angegebenen Ziel-Server suchen */
-               target = Client_Search( Req->argv[1] );
-               if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
-               ptr = Req->argv[1];
+               /* Search target server (can be specified as nick of that server!) */
+               target = Client_Search( Req->argv[0] );
+               if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] );
        }
        else target = Client_ThisServer( );
 
        assert( target != NULL );
 
-       if(( Client_NextHop( target ) != Client_ThisServer( )) && ( Client_Type( Client_NextHop( target )) == CLIENT_SERVER )) return IRC_WriteStrClientPrefix( target, from, "WHOIS %s :%s", Req->argv[0], ptr );
+       if(( Client_NextHop( target ) != Client_ThisServer( )) && ( Client_Type( Client_NextHop( target )) == CLIENT_SERVER )) return IRC_WriteStrClientPrefix( target, from, "WHOIS %s :%s", Req->argv[0], Req->argv[1] );
 
-       /* Nick, User und Name */
+       /* Nick, user and name */
        if( ! IRC_WriteStrClient( from, RPL_WHOISUSER_MSG, Client_ID( from ), Client_ID( c ), Client_User( c ), Client_Hostname( c ), Client_Info( c ))) return DISCONNECTED;
 
        /* Server */
@@ -644,7 +663,7 @@ IRC_WHOIS( CLIENT *Client, REQUEST *Req )
                chan = Channel_GetChannel( cl2chan );
                assert( chan != NULL );
 
-               /* Channel-Name anhaengen */
+               /* Concatenate channel names */
                if( str[strlen( str ) - 1] != ':' ) strlcat( str, " ", sizeof( str ));
                if( strchr( Channel_UserModes( chan, c ), 'o' )) strlcat( str, "@", sizeof( str ));
                else if( strchr( Channel_UserModes( chan, c ), 'v' )) strlcat( str, "+", sizeof( str ));
@@ -652,17 +671,17 @@ IRC_WHOIS( CLIENT *Client, REQUEST *Req )
 
                if( strlen( str ) > ( LINE_LEN - CHANNEL_NAME_LEN - 4 ))
                {
-                       /* Zeile wird zu lang: senden! */
+                       /* Line becomes too long: send it! */
                        if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
                        snprintf( str, sizeof( str ), RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c ));
                }
 
-               /* naechstes Mitglied suchen */
+               /* next */
                cl2chan = Channel_NextChannelOf( c, cl2chan );
        }
        if( str[strlen( str ) - 1] != ':')
        {
-               /* Es sind noch Daten da, die gesendet werden muessen */
+               /* There is data left to send: */
                if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
        }
 
@@ -672,7 +691,7 @@ IRC_WHOIS( CLIENT *Client, REQUEST *Req )
                if( ! IRC_WriteStrClient( from, RPL_WHOISOPERATOR_MSG, Client_ID( from ), Client_ID( c ))) return DISCONNECTED;
        }
 
-       /* Idle (nur lokale Clients) */
+       /* Idle (only local clients) */
        if( Client_Conn( c ) > NONE )
        {
                if( ! IRC_WriteStrClient( from, RPL_WHOISIDLE_MSG, Client_ID( from ), Client_ID( c ), Conn_GetIdle( Client_Conn ( c )))) return DISCONNECTED;
@@ -754,6 +773,13 @@ IRC_Show_MOTD( CLIENT *Client )
 
        assert( Client != NULL );
 
+       if( Conf_MotdPhrase[0] )
+       {
+               if( ! IRC_WriteStrClient( Client, RPL_MOTDSTART_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )))) return DISCONNECTED;
+               if( ! IRC_WriteStrClient( Client, RPL_MOTD_MSG, Client_ID( Client ), Conf_MotdPhrase )) return DISCONNECTED;
+               return IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ));
+       }
+
        fd = fopen( Conf_MotdFile, "r" );
        if( ! fd )
        {
@@ -761,7 +787,7 @@ IRC_Show_MOTD( CLIENT *Client )
                return IRC_WriteStrClient( Client, ERR_NOMOTD_MSG, Client_ID( Client ) );
        }
 
-       IRC_WriteStrClient( Client, RPL_MOTDSTART_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )));
+       if( ! IRC_WriteStrClient( Client, RPL_MOTDSTART_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )))) return DISCONNECTED;
        while( TRUE )
        {
                if( ! fgets( line, 126, fd )) break;