X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Fngircd.c;h=cef1cff58d5b6690b03b3dfdcfdb027aa33134d4;hp=38beb78f3835b590ae8d61f6fd61200f11b11466;hb=6626395c88fc46eeb110942b17eb9245a1d0021b;hpb=25f32ce8b801d62d50c24440d7827cda801adf9d diff --git a/src/ngircd/ngircd.c b/src/ngircd/ngircd.c index 38beb78f..cef1cff5 100644 --- a/src/ngircd/ngircd.c +++ b/src/ngircd/ngircd.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: ngircd.c,v 1.56 2002/10/07 21:16:13 alex Exp $ - * - * ngircd.c: Hier beginnt alles ;-) + * Main program -- main() */ #include "portab.h" +static char UNUSED id[] = "$Id: ngircd.c,v 1.68 2002/12/26 16:48:14 alex Exp $"; + #include "imp.h" #include #include @@ -29,6 +28,8 @@ #include #include #include +#include +#include #include "resolve.h" #include "conn.h" @@ -49,8 +50,6 @@ LOCAL VOID Initialize_Signal_Handler PARAMS(( VOID )); LOCAL VOID Signal_Handler PARAMS(( INT Signal )); -LOCAL VOID Initialize_Listen_Ports PARAMS(( VOID )); - LOCAL VOID Show_Version PARAMS(( VOID )); LOCAL VOID Show_Help PARAMS(( VOID )); @@ -58,23 +57,24 @@ LOCAL VOID Show_Help PARAMS(( VOID )); GLOBAL int main( int argc, const char *argv[] ) { + struct passwd *pwd; + struct group *grp; BOOLEAN ok, configtest = FALSE; - INT32 pid, n; + LONG pid, n; INT i; umask( 0077 ); - NGIRCd_Restart = FALSE; - NGIRCd_Quit = FALSE; - NGIRCd_NoDaemon = FALSE; - NGIRCd_Passive = FALSE; + NGIRCd_SignalQuit = NGIRCd_SignalRestart = NGIRCd_SignalRehash = FALSE; + NGIRCd_NoDaemon = NGIRCd_Passive = FALSE; #ifdef DEBUG NGIRCd_Debug = FALSE; #endif #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++ ) @@ -88,11 +88,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; } } @@ -141,7 +140,7 @@ main( int argc, const char *argv[] ) { /* Kurze Option */ - for( n = 1; n < (INT32)strlen( argv[i] ); n++ ) + for( n = 1; n < (LONG)strlen( argv[i] ); n++ ) { ok = FALSE; #ifdef DEBUG @@ -155,12 +154,11 @@ 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 */ - i++; n = (INT32)strlen( argv[i] ); + /* go to the following parameter */ + i++; n = (LONG)strlen( argv[i] ); ok = TRUE; } } @@ -219,7 +217,7 @@ main( int argc, const char *argv[] ) exit( Conf_Test( )); } - while( ! NGIRCd_Quit ) + while( ! NGIRCd_SignalQuit ) { /* In der Regel wird ein Sub-Prozess ge-fork()'t, der * nicht mehr mit dem Terminal verbunden ist. Mit der @@ -228,7 +226,7 @@ main( int argc, const char *argv[] ) if( ! NGIRCd_NoDaemon ) { /* Daemon im Hintergrund erzeugen */ - pid = (INT32)fork( ); + pid = (LONG)fork( ); if( pid > 0 ) { /* "alter" Prozess */ @@ -249,8 +247,9 @@ main( int argc, const char *argv[] ) /* 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_Restart = FALSE; - NGIRCd_Quit = FALSE; + NGIRCd_SignalRehash = FALSE; + NGIRCd_SignalRestart = FALSE; + NGIRCd_SignalQuit = FALSE; /* Module initialisieren */ Log_Init( ); @@ -276,8 +275,12 @@ main( int argc, const char *argv[] ) if( setuid( Conf_UID ) != 0 ) Log( LOG_ERR, "Can't change User-ID to %u: %s", Conf_UID, strerror( errno )); } } - Log( LOG_INFO, "Running as user %ld, group %ld, with PID %ld.", (INT32)getuid( ), (INT32)getgid( ), (INT32)getpid( )); + + /* User, Gruppe und Prozess-ID des Daemon ausgeben */ + 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( ); /* Signal-Handler initialisieren */ @@ -288,19 +291,30 @@ main( int argc, const char *argv[] ) * sind in doc/Protocol.txt beschrieben. */ #ifdef IRCPLUS sprintf( NGIRCd_ProtoID, "%s%s %s|%s:%s", PROTOVER, PROTOIRCPLUS, PACKAGE, VERSION, IRCPLUSFLAGS ); +#ifdef USE_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 ); #endif strcat( NGIRCd_ProtoID, " P" ); +#ifdef USE_ZLIB + strcat( NGIRCd_ProtoID, "Z" ); +#endif Log( LOG_DEBUG, "Protocol and server ID is \"%s\".", NGIRCd_ProtoID ); /* Vordefinierte Channels anlegen */ Channel_InitPredefined( ); /* Listen-Ports initialisieren */ - Initialize_Listen_Ports( ); - + 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 ); + exit( 1 ); + } + /* Hauptschleife */ Conn_Handler( ); @@ -341,6 +355,10 @@ NGIRCd_VersionAddition( VOID ) if( txt[0] ) strcat( txt, "+" ); strcat( txt, "SYSLOG" ); #endif +#ifdef USE_ZLIB + if( txt[0] ) strcat( txt, "+" ); + strcat( txt, "ZLIB" ); +#endif #ifdef DEBUG if( txt[0] ) strcat( txt, "+" ); strcat( txt, "DEBUG" ); @@ -358,17 +376,52 @@ 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 */ +GLOBAL VOID +NGIRCd_Rehash( VOID ) +{ + CHAR old_name[CLIENT_ID_LEN]; + + Log( LOG_NOTICE|LOG_snotice, "Re-reading configuration NOW!" ); + NGIRCd_SignalRehash = FALSE; + + /* Alle Listen-Sockets schliessen */ + Conn_ExitListeners( ); + + /* Alten Server-Namen merken */ + strcpy( old_name, Conf_ServerName ); + + /* Konfiguration neu lesen ... */ + Conf_Init( ); + + /* Alten Server-Namen wiederherstellen: dieser + * kann nicht zur Laufzeit geaendert werden ... */ + 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: */ + Channel_InitPredefined( ); + + /* Listen-Sockets neu anlegen: */ + Conn_InitListeners( ); + + Log( LOG_NOTICE|LOG_snotice, "Re-reading of configuration done." ); +} /* NGIRCd_Rehash */ + + LOCAL VOID Initialize_Signal_Handler( VOID ) { @@ -429,51 +482,25 @@ Signal_Handler( INT Signal ) case SIGINT: case SIGQUIT: /* wir soll(t)en uns wohl beenden ... */ - if( Signal == SIGTERM ) Log( LOG_WARNING, "Got TERM signal, terminating now ..." ); - else if( Signal == SIGINT ) Log( LOG_WARNING, "Got INT signal, terminating now ..." ); - else if( Signal == SIGQUIT ) Log( LOG_WARNING, "Got QUIT signal, terminating now ..." ); - NGIRCd_Quit = TRUE; + NGIRCd_SignalQuit = TRUE; break; case SIGHUP: - /* neu starten */ - Log( LOG_WARNING, "Got HUP signal, restarting now ..." ); - NGIRCd_Restart = TRUE; + /* Konfiguration neu einlesen: */ + NGIRCd_SignalRehash = TRUE; break; case SIGCHLD: /* Child-Prozess wurde beendet. Zombies vermeiden: */ while( waitpid( -1, NULL, WNOHANG ) > 0); break; +#ifdef DEBUG default: /* unbekanntes bzw. unbehandeltes Signal */ - Log( LOG_NOTICE, "Got signal %d! Ignored.", Signal ); + Log( LOG_DEBUG, "Got signal %d! Ignored.", Signal ); +#endif } } /* Signal_Handler */ -LOCAL VOID -Initialize_Listen_Ports( VOID ) -{ - /* Ports, auf denen der Server Verbindungen entgegennehmen - * soll, initialisieren */ - - INT created, i; - - created = 0; - for( i = 0; i < Conf_ListenPorts_Count; i++ ) - { - if( Conn_NewListener( Conf_ListenPorts[i] )) created++; - else Log( LOG_ERR, "Can't listen on port %u!", Conf_ListenPorts[i] ); - } - - if( created < 1 ) - { - Log( LOG_ALERT, "Server isn't listening on a single port!" ); - Log( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE ); - exit( 1 ); - } -} /* Initialize_Listen_Ports */ - - LOCAL VOID Show_Version( VOID ) { @@ -492,7 +519,7 @@ Show_Help( VOID ) puts( " -d, --debug log extra debug messages" ); #endif puts( " -f, --config use file as configuration file" ); - puts( " -n, --nodaemon don't fork and don't detatch from controlling terminal" ); + puts( " -n, --nodaemon don't fork and don't detach from controlling terminal" ); puts( " -p, --passive disable automatic connections to other servers" ); #ifdef SNIFFER puts( " -s, --sniffer enable network sniffer and display all IRC traffic" );