aboutsummaryrefslogtreecommitdiffstats
path: root/unix.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2007-12-02 23:18:25 +0000
committerWilmer van der Gaast <wilmer@gaast.net>2007-12-02 23:18:25 +0000
commitaaf92a9eb64327892e39fdbd7113d797d1d68cec (patch)
treeb907c7e55f32b073453a327231a9e76ab1604145 /unix.c
parent80e9db97776bfd6c6192135d65027abd8f50887c (diff)
Imported setuid() patch from Simo Leone <simo@archlinux...> with some
modifications. Also adding some missing g_free()s to conf.c.
Diffstat (limited to 'unix.c')
-rw-r--r--unix.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/unix.c b/unix.c
index 0abf43ea..75ffcf95 100644
--- a/unix.c
+++ b/unix.c
@@ -33,6 +33,7 @@
#include <unistd.h>
#include <sys/time.h>
#include <sys/wait.h>
+#include <pwd.h>
global_t global; /* Against global namespace pollution */
@@ -44,8 +45,6 @@ int main( int argc, char *argv[], char **envp )
char *old_cwd = NULL;
struct sigaction sig, old;
- memset( &global, 0, sizeof( global_t ) );
-
log_init();
CONF_FILE = g_strdup( CONF_FILE_DEF );
global.conf = conf_load( argc, argv );
@@ -86,12 +85,26 @@ int main( int argc, char *argv[], char **envp )
if( i != 0 )
return( i );
+ if( ( global.conf->user && *global.conf->user ) &&
+ ( global.conf->runmode == RUNMODE_DAEMON ||
+ global.conf->runmode == RUNMODE_FORKDAEMON ) &&
+ ( !getuid() || !geteuid() ) )
+ {
+ struct passwd *pw = NULL;
+ pw = getpwnam( global.conf->user );
+ if( pw )
+ {
+ setgid( pw->pw_gid );
+ setuid( pw->pw_uid );
+ }
+ }
+
global.storage = storage_init( global.conf->primary_storage, global.conf->migrate_storage );
- if ( global.storage == NULL) {
+ if( global.storage == NULL )
+ {
log_message( LOGLVL_ERROR, "Unable to load storage backend '%s'", global.conf->primary_storage );
return( 1 );
}
-
/* Catch some signals to tell the user what's happening before quitting */
memset( &sig, 0, sizeof( sig ) );