X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Fngircd.c;h=8ced6e3f8903c8698e2aa505c8c558a15798b539;hp=20db13ed94c96a5bb2a4e02df2e398c5e37f3751;hb=7281b8dd4d917f8b7f7c36460b78b686427ce973;hpb=43a4bc5b8bb064e2dfca456ab6fcc656b4dfa813 diff --git a/src/ngircd/ngircd.c b/src/ngircd/ngircd.c index 20db13ed..8ced6e3f 100644 --- a/src/ngircd/ngircd.c +++ b/src/ngircd/ngircd.c @@ -1,6 +1,6 @@ /* * ngIRCd -- The Next Generation IRC Daemon - * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de) + * Copyright (c)2001-2004 by Alexander Barton (alex@barton.de) * * 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 @@ -14,7 +14,7 @@ #include "portab.h" -static char UNUSED id[] = "$Id: ngircd.c,v 1.65 2002/12/19 04:29:59 alex Exp $"; +static char UNUSED id[] = "$Id: ngircd.c,v 1.84 2004/05/07 11:19:21 alex Exp $"; #include "imp.h" #include @@ -24,10 +24,10 @@ static char UNUSED id[] = "$Id: ngircd.c,v 1.65 2002/12/19 04:29:59 alex Exp $"; #include #include #include +#include #include #include #include -#include #include #include @@ -43,6 +43,10 @@ static char UNUSED id[] = "$Id: ngircd.c,v 1.65 2002/12/19 04:29:59 alex Exp $"; #include "parse.h" #include "irc.h" +#ifdef RENDEZVOUS +#include "rendezvous.h" +#endif + #include "exp.h" #include "ngircd.h" @@ -73,7 +77,8 @@ main( int argc, const char *argv[] ) #ifdef SNIFFER NGIRCd_Sniffer = FALSE; #endif - strcpy( NGIRCd_ConfFile, CONFIG_FILE ); + strlcpy( NGIRCd_ConfFile, SYSCONFDIR, sizeof( NGIRCd_ConfFile )); + strlcat( NGIRCd_ConfFile, CONFIG_FILE, sizeof( NGIRCd_ConfFile )); /* Kommandozeile parsen */ for( i = 1; i < argc; i++ ) @@ -87,11 +92,10 @@ main( int argc, const char *argv[] ) { if( i + 1 < argc ) { - /* Ok, danach kommt noch ein Parameter */ - strncpy( NGIRCd_ConfFile, argv[i + 1], FNAME_LEN - 1 ); - NGIRCd_ConfFile[FNAME_LEN - 1] = '\0'; + /* Ok, there's an parameter left */ + strlcpy( NGIRCd_ConfFile, argv[i + 1], sizeof( NGIRCd_ConfFile )); - /* zum uebernaechsten Parameter */ + /* next parameter */ i++; ok = TRUE; } } @@ -154,11 +158,10 @@ main( int argc, const char *argv[] ) { if(( ! argv[i][n + 1] ) && ( i + 1 < argc )) { - /* Ok, danach kommt ein Leerzeichen */ - strncpy( NGIRCd_ConfFile, argv[i + 1], FNAME_LEN - 1 ); - NGIRCd_ConfFile[FNAME_LEN - 1] = '\0'; + /* Ok, next character is a blank */ + strlcpy( NGIRCd_ConfFile, argv[i + 1], sizeof( NGIRCd_ConfFile )); - /* zum uebernaechsten Parameter */ + /* go to the following parameter */ i++; n = (LONG)strlen( argv[i] ); ok = TRUE; } @@ -180,11 +183,16 @@ main( int argc, const char *argv[] ) ok = TRUE; } #endif + if( argv[i][n] == 't' ) + { + configtest = TRUE; + ok = TRUE; + } if( ! ok ) { - printf( "%s: invalid option \"-%c\"!\n", PACKAGE, argv[i][n] ); - printf( "Try \"%s --help\" for more information.\n", PACKAGE ); + printf( "%s: invalid option \"-%c\"!\n", PACKAGE_NAME, argv[i][n] ); + printf( "Try \"%s --help\" for more information.\n", PACKAGE_NAME ); exit( 1 ); } } @@ -192,8 +200,8 @@ main( int argc, const char *argv[] ) } if( ! ok ) { - printf( "%s: invalid option \"%s\"!\n", PACKAGE, argv[i] ); - printf( "Try \"%s --help\" for more information.\n", PACKAGE ); + printf( "%s: invalid option \"%s\"!\n", PACKAGE_NAME, argv[i] ); + printf( "Try \"%s --help\" for more information.\n", PACKAGE_NAME ); exit( 1 ); } } @@ -220,6 +228,38 @@ main( int argc, const char *argv[] ) while( ! NGIRCd_SignalQuit ) { + /* Initialize global variables */ + NGIRCd_Start = time( NULL ); + (VOID)strftime( NGIRCd_StartStr, 64, "%a %b %d %Y at %H:%M:%S (%Z)", localtime( &NGIRCd_Start )); + + NGIRCd_SignalRehash = FALSE; + NGIRCd_SignalRestart = FALSE; + NGIRCd_SignalQuit = FALSE; + + /* Initialize modules, part I */ + Log_Init( ); + Conf_Init( ); + + if( Conf_Chroot[0] ) + { + /* Chroot */ + if( chdir( Conf_Chroot ) != 0 ) Log( LOG_ERR, "Can't chdir() in ChrootDir (%s): %s", Conf_Chroot, strerror( errno )); + + if( chroot( Conf_Chroot ) != 0 ) Log( LOG_ERR, "Can't change root directory to \"%s\": %s", Conf_Chroot, strerror( errno )); + else Log( LOG_INFO, "Changed root and working directory to \"%s\".", Conf_Chroot ); + } + + if( Conf_GID != 0 ) + { + /* Set new group ID */ + if( setgid( Conf_GID ) != 0 ) Log( LOG_ERR, "Can't change group ID to %u: %s", Conf_GID, strerror( errno )); + } + if( Conf_UID != 0 ) + { + /* Set new user ID */ + if( setuid( Conf_UID ) != 0 ) Log( LOG_ERR, "Can't change user ID to %u: %s", Conf_UID, strerror( errno )); + } + /* In der Regel wird ein Sub-Prozess ge-fork()'t, der * nicht mehr mit dem Terminal verbunden ist. Mit der * Option "--nodaemon" kann dies (z.B. zum Debuggen) @@ -236,7 +276,7 @@ main( int argc, const char *argv[] ) if( pid < 0 ) { /* Fehler */ - printf( "%s: Can't fork: %s!\nFatal error, exiting now ...\n", PACKAGE, strerror( errno )); + printf( "%s: Can't fork: %s!\nFatal error, exiting now ...\n", PACKAGE_NAME, strerror( errno )); exit( 1 ); } @@ -244,45 +284,27 @@ main( int argc, const char *argv[] ) (VOID)setsid( ); chdir( "/" ); } - - /* Globale Variablen initialisieren */ - NGIRCd_Start = time( NULL ); - (VOID)strftime( NGIRCd_StartStr, 64, "%a %b %d %Y at %H:%M:%S (%Z)", localtime( &NGIRCd_Start )); - NGIRCd_SignalRehash = FALSE; - NGIRCd_SignalRestart = FALSE; - NGIRCd_SignalQuit = FALSE; - /* Module initialisieren */ - Log_Init( ); + /* Initialize modules, part II: these functions are eventually + * called with already dropped privileges ... */ Resolve_Init( ); - Conf_Init( ); Lists_Init( ); Channel_Init( ); Client_Init( ); +#ifdef RENDEZVOUS + Rendezvous_Init( ); +#endif Conn_Init( ); - /* Wenn als root ausgefuehrt und eine andere UID - * konfiguriert ist, jetzt zu dieser wechseln */ - if( getuid( ) == 0 ) - { - if( Conf_GID != 0 ) - { - /* Neue Group-ID setzen */ - if( setgid( Conf_GID ) != 0 ) Log( LOG_ERR, "Can't change Group-ID to %u: %s", Conf_GID, strerror( errno )); - } - if( Conf_UID != 0 ) - { - /* Neue User-ID setzen */ - if( setuid( Conf_UID ) != 0 ) Log( LOG_ERR, "Can't change User-ID to %u: %s", Conf_UID, strerror( errno )); - } - } - - /* User, Gruppe und Prozess-ID des Daemon ausgeben */ + /* Show user, group, and PID of the running daemon */ pwd = getpwuid( getuid( )); grp = getgrgid( getgid( )); Log( LOG_INFO, "Running as user %s(%ld), group %s(%ld), with PID %ld.", pwd ? pwd->pw_name : "unknown", (LONG)getuid( ), grp ? grp->gr_name : "unknown", (LONG)getgid( ), (LONG)getpid( )); - /* stderr in "Error-File" umlenken */ - Log_InitErrorfile( ); + /* Redirect stderr handle to "error file" for debugging. + * But don't try to write in the chroot jail, since it's more + * secure to have a chroot dir not writable by the daemon. + */ + if( ! Conf_Chroot[0] ) Log_InitErrorfile( ); /* Signal-Handler initialisieren */ Initialize_Signal_Handler( ); @@ -291,16 +313,16 @@ main( int argc, const char *argv[] ) * beim PASS-Befehl verwendete Syntax sowie die erweiterten Flags * sind in doc/Protocol.txt beschrieben. */ #ifdef IRCPLUS - sprintf( NGIRCd_ProtoID, "%s%s %s|%s:%s", PROTOVER, PROTOIRCPLUS, PACKAGE, VERSION, IRCPLUSFLAGS ); -#ifdef USE_ZLIB + sprintf( NGIRCd_ProtoID, "%s%s %s|%s:%s", PROTOVER, PROTOIRCPLUS, PACKAGE_NAME, PACKAGE_VERSION, IRCPLUSFLAGS ); +#ifdef ZLIB strcat( NGIRCd_ProtoID, "Z" ); #endif if( Conf_OperCanMode ) strcat( NGIRCd_ProtoID, "o" ); #else - sprintf( NGIRCd_ProtoID, "%s%s %s|%s", PROTOVER, PROTOIRC, PACKAGE, VERSION ); + sprintf( NGIRCd_ProtoID, "%s%s %s|%s", PROTOVER, PROTOIRC, PACKAGE_NAME, PACKAGE_VERSION ); #endif strcat( NGIRCd_ProtoID, " P" ); -#ifdef USE_ZLIB +#ifdef ZLIB strcat( NGIRCd_ProtoID, "Z" ); #endif Log( LOG_DEBUG, "Protocol and server ID is \"%s\".", NGIRCd_ProtoID ); @@ -312,7 +334,7 @@ main( int argc, const char *argv[] ) if( Conn_InitListeners( ) < 1 ) { Log( LOG_ALERT, "Server isn't listening on a single port!" ); - Log( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE ); + Log( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME ); exit( 1 ); } @@ -321,6 +343,9 @@ main( int argc, const char *argv[] ) /* Alles abmelden */ Conn_Exit( ); +#ifdef RENDEZVOUS + Rendezvous_Exit( ); +#endif Client_Exit( ); Channel_Exit( ); Lists_Exit( ); @@ -337,9 +362,9 @@ NGIRCd_Version( VOID ) STATIC CHAR version[126]; #ifdef CVSDATE - sprintf( version, "%s %s(%s)-%s", PACKAGE, VERSION, CVSDATE, NGIRCd_VersionAddition( )); + sprintf( version, "%s %s(%s)-%s", PACKAGE_NAME, PACKAGE_VERSION, CVSDATE, NGIRCd_VersionAddition( )); #else - sprintf( version, "%s %s-%s", PACKAGE, VERSION, NGIRCd_VersionAddition( )); + sprintf( version, "%s %s-%s", PACKAGE_NAME, PACKAGE_VERSION, NGIRCd_VersionAddition( )); #endif return version; } /* NGIRCd_Version */ @@ -348,18 +373,30 @@ NGIRCd_Version( VOID ) GLOBAL CHAR * NGIRCd_VersionAddition( VOID ) { - STATIC CHAR txt[64]; + STATIC CHAR txt[200]; strcpy( txt, "" ); -#ifdef USE_SYSLOG +#ifdef SYSLOG if( txt[0] ) strcat( txt, "+" ); strcat( txt, "SYSLOG" ); #endif -#ifdef USE_ZLIB +#ifdef ZLIB if( txt[0] ) strcat( txt, "+" ); strcat( txt, "ZLIB" ); #endif +#ifdef TCPWRAP + if( txt[0] ) strcat( txt, "+" ); + strcat( txt, "TCPWRAP" ); +#endif +#ifdef RENDEZVOUS + if( txt[0] ) strcat( txt, "+" ); + strcat( txt, "RENDEZVOUS" ); +#endif +#ifdef IDENTAUTH + if( txt[0] ) strcat( txt, "+" ); + strcat( txt, "IDENT" ); +#endif #ifdef DEBUG if( txt[0] ) strcat( txt, "+" ); strcat( txt, "DEBUG" ); @@ -377,12 +414,12 @@ NGIRCd_VersionAddition( VOID ) strcat( txt, "IRCPLUS" ); #endif - if( txt[0] ) strcat( txt, "-" ); - strcat( txt, TARGET_CPU ); - strcat( txt, "/" ); - strcat( txt, TARGET_VENDOR ); - strcat( txt, "/" ); - strcat( txt, TARGET_OS ); + if( txt[0] ) strlcat( txt, "-", sizeof( txt )); + strlcat( txt, TARGET_CPU, sizeof( txt )); + strlcat( txt, "/", sizeof( txt )); + strlcat( txt, TARGET_VENDOR, sizeof( txt )); + strlcat( txt, "/", sizeof( txt )); + strlcat( txt, TARGET_OS, sizeof( txt )); return txt; } /* NGIRCd_VersionAddition */ @@ -396,29 +433,31 @@ NGIRCd_Rehash( VOID ) Log( LOG_NOTICE|LOG_snotice, "Re-reading configuration NOW!" ); NGIRCd_SignalRehash = FALSE; - /* Alle Listen-Sockets schliessen */ + /* Close down all listening sockets */ Conn_ExitListeners( ); - /* Alten Server-Namen merken */ + /* Remember old server name */ strcpy( old_name, Conf_ServerName ); - /* Konfiguration neu lesen ... */ - Conf_Init( ); + /* Re-read configuration ... */ + Conf_Rehash( ); - /* Alten Server-Namen wiederherstellen: dieser - * kann nicht zur Laufzeit geaendert werden ... */ + /* Recover old server name: it can't be changed during run-time */ if( strcmp( old_name, Conf_ServerName ) != 0 ) { strcpy( Conf_ServerName, old_name ); Log( LOG_ERR, "Can't change \"ServerName\" on runtime! Ignored new name." ); } - /* neue pre-defined Channel anlegen: */ + /* Create new pre-defined channels */ Channel_InitPredefined( ); - /* Listen-Sockets neu anlegen: */ + /* Start listening on sockets */ Conn_InitListeners( ); + /* Sync configuration with established connections */ + Conn_SyncServerStruct( ); + Log( LOG_NOTICE|LOG_snotice, "Re-reading of configuration done." ); } /* NGIRCd_Rehash */ @@ -506,7 +545,7 @@ LOCAL VOID Show_Version( VOID ) { puts( NGIRCd_Version( )); - puts( "Copyright (c)2001,2002 by Alexander Barton ()." ); + puts( "Copyright (c)2001-2004 by Alexander Barton ()." ); puts( "Homepage: \n" ); puts( "This is free software; see the source for copying conditions. There is NO" ); puts( "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." ); @@ -525,7 +564,7 @@ Show_Help( VOID ) #ifdef SNIFFER puts( " -s, --sniffer enable network sniffer and display all IRC traffic" ); #endif - puts( " --configtest read, validate and display configuration; then exit" ); + puts( " -t, --configtest read, validate and display configuration; then exit" ); puts( " --version output version information and exit" ); puts( " --help display this help and exit" ); } /* Show_Help */