]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/ngircd.c
- replaced a lot of strcat() calls with strlcat() which is more secure.
[ngircd-alex.git] / src / ngircd / ngircd.c
index f2da99085941dc02b5c5d50045349ce05b10e000..cef1cff58d5b6690b03b3dfdcfdb027aa33134d4 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id";
+static char UNUSED id[] = "$Id: ngircd.c,v 1.68 2002/12/26 16:48:14 alex Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -65,17 +65,16 @@ main( int argc, const char *argv[] )
 
        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++ )
@@ -89,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;
                                }
                        }
@@ -156,11 +154,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;
                                        }
@@ -220,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
@@ -250,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( );
@@ -378,12 +376,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 */
@@ -393,7 +391,10 @@ 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( );
 
@@ -417,7 +418,7 @@ NGIRCd_Rehash( VOID )
        /* Listen-Sockets neu anlegen: */
        Conn_InitListeners( );
 
-       Log( LOG_INFO, "Re-reading of configuration done." );
+       Log( LOG_NOTICE|LOG_snotice, "Re-reading of configuration done." );
 } /* NGIRCd_Rehash */
 
 
@@ -481,23 +482,21 @@ Signal_Handler( INT Signal )
                case SIGINT:
                case SIGQUIT:
                        /* wir soll(t)en uns wohl beenden ... */
-                       if( Signal == SIGTERM ) Log( LOG_WARNING|LOG_snotice, "Got TERM signal, terminating now ..." );
-                       else if( Signal == SIGINT ) Log( LOG_WARNING|LOG_snotice, "Got INT signal, terminating now ..." );
-                       else if( Signal == SIGQUIT ) Log( LOG_WARNING|LOG_snotice, "Got QUIT signal, terminating now ..." );
-                       NGIRCd_Quit = TRUE;
+                       NGIRCd_SignalQuit = TRUE;
                        break;
                case SIGHUP:
                        /* Konfiguration neu einlesen: */
-                       Log( LOG_WARNING|LOG_snotice, "Got HUP signal, re-reading configuration ..." );
-                       NGIRCd_Rehash( );
+                       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 */