diff --git a/src/conffile.c b/src/conffile.c index 030a1161..1799086c 100644 --- a/src/conffile.c +++ b/src/conffile.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2010 Julien BLACHE + * Copyright (C) 2009-2011 Julien BLACHE * * 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 @@ -25,7 +25,9 @@ #include #include +#include #include +#include #include @@ -96,6 +98,8 @@ static cfg_opt_t toplvl_cfg[] = cfg_t *cfg; uint64_t libhash; +uid_t runas_uid; +gid_t runas_gid; static int @@ -241,6 +245,8 @@ int conffile_load(char *file) { cfg_t *lib; + struct passwd *pw; + char *runas; int ret; cfg = cfg_init(toplvl_cfg, CFGF_NONE); @@ -260,6 +266,19 @@ conffile_load(char *file) goto out_fail; } + /* Resolve runas username */ + runas = cfg_getstr(cfg_getsec(cfg, "general"), "uid"); + pw = getpwnam(runas); + if (!pw) + { + DPRINTF(E_FATAL, L_CONF, "Could not lookup user %s: %s\n", runas, strerror(errno)); + + goto out_fail; + } + + runas_uid = pw->pw_uid; + runas_gid = pw->pw_gid; + lib = cfg_getsec(cfg, "library"); if (cfg_size(lib, "directories") == 0) diff --git a/src/conffile.h b/src/conffile.h index b531a603..6b35d0b0 100644 --- a/src/conffile.h +++ b/src/conffile.h @@ -2,12 +2,16 @@ #ifndef __CONFFILE_H__ #define __CONFFILE_H__ +#include + #include #define CONFFILE CONFDIR "/forked-daapd.conf" extern cfg_t *cfg; extern uint64_t libhash; +extern uid_t runas_uid; +extern gid_t runas_gid; int conffile_load(char *file);