]> arthur.barton.de Git - ngircd-alex.git/commitdiff
If ServerUID is defined change the working directory to the home directory
authorAlexander Barton <alex@barton.de>
Sat, 4 Sep 2004 20:28:51 +0000 (20:28 +0000)
committerAlexander Barton <alex@barton.de>
Sat, 4 Sep 2004 20:28:51 +0000 (20:28 +0000)
of this user.

ChangeLog
src/ngircd/ngircd.c

index 578af8e78d40f76eb019473b74ef1ff0c6ca2a51..5f6f21027283f4622e4d6a6576ee727db7271709 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 
 ngIRCd CVSHEAD
 
 
 ngIRCd CVSHEAD
 
+  - When the daemon should switch to another user ID (ServerID is defined in
+    the configuration file) and is not running in a chroot environment, it
+    changes it's working directory to the home directory of this user. This
+    should enable the system to write proper core files when not running with
+    root privileges ...
   - Enhanced the "test suite": please have a look at src/testsuite/README!
 
 ngIRCd 0.8.0 (2004-06-26)
   - Enhanced the "test suite": please have a look at src/testsuite/README!
 
 ngIRCd 0.8.0 (2004-06-26)
@@ -534,4 +539,4 @@ ngIRCd 0.0.1, 31.12.2001
 
 
 -- 
 
 
 -- 
-$Id: ChangeLog,v 1.239 2004/09/04 19:39:24 alex Exp $
+$Id: ChangeLog,v 1.240 2004/09/04 20:28:51 alex Exp $
index 94d323ed91c241413ffde6a081746f352a3eb70e..e02861007eadda6d6be6ca2dee3186cf12d8e1c0 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: ngircd.c,v 1.85 2004/05/11 00:01:11 alex Exp $";
+static char UNUSED id[] = "$Id: ngircd.c,v 1.86 2004/09/04 20:28:51 alex Exp $";
 
 #include "imp.h"
 #include <assert.h>
 
 #include "imp.h"
 #include <assert.h>
@@ -285,6 +285,25 @@ main( int argc, const char *argv[] )
                        chdir( "/" );
                }
 
                        chdir( "/" );
                }
 
+               /* 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( ));
+
+               /* Change working directory to home directory of the user
+                * we are running as (when not running chroot()'ed!) */
+               if( Conf_UID != 0 && ! Conf_Chroot[0] )
+               {
+                       struct passwd *pwd;
+
+                       pwd = getpwuid( Conf_UID );
+                       if( pwd != NULL )
+                       {
+                               if( chdir( pwd->pw_dir ) == 0 ) Log( LOG_DEBUG, "Changed working directory to \"%s\" ...", pwd->pw_dir );
+                               else Log( LOG_ERR, "Can't change working directory to \"%s\": %s", pwd->pw_dir, strerror( errno ));
+                       }
+                       else Log( LOG_ERR, "Can't get user informaton for UID %d!?", Conf_UID );
+               }
+
                /* Initialize modules, part II: these functions are eventually
                 * called with already dropped privileges ... */
                Resolve_Init( );
                /* Initialize modules, part II: these functions are eventually
                 * called with already dropped privileges ... */
                Resolve_Init( );
@@ -296,10 +315,6 @@ main( int argc, const char *argv[] )
 #endif
                Conn_Init( );
 
 #endif
                Conn_Init( );
 
-               /* 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( ));
-
                /* 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.
                /* 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.