about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlexander Barton <alex@barton.de>2004-09-04 20:28:51 +0000
committerAlexander Barton <alex@barton.de>2004-09-04 20:28:51 +0000
commit8ca1e4d54861790040e430128326e5455420a39a (patch)
treee8f1b1463679ce9df5724e1e91850f90c58bab64 /src
parente07cc4bb63f55a533ba9bd84298edf83d8126b6a (diff)
downloadngircd-8ca1e4d54861790040e430128326e5455420a39a.tar.gz
ngircd-8ca1e4d54861790040e430128326e5455420a39a.zip
If ServerUID is defined change the working directory to the home directory
of this user.
Diffstat (limited to 'src')
-rw-r--r--src/ngircd/ngircd.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/ngircd/ngircd.c b/src/ngircd/ngircd.c
index 94d323ed..e0286100 100644
--- a/src/ngircd/ngircd.c
+++ b/src/ngircd/ngircd.c
@@ -14,7 +14,7 @@
 
 #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>
@@ -285,6 +285,25 @@ main( int argc, const char *argv[] )
 			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( );
@@ -296,10 +315,6 @@ main( int argc, const char *argv[] )
 #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.