summaryrefslogtreecommitdiffstats
path: root/bus/bus.c
diff options
context:
space:
mode:
Diffstat (limited to 'bus/bus.c')
-rw-r--r--bus/bus.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/bus/bus.c b/bus/bus.c
index 5df7864b..e6f36b14 100644
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -531,7 +531,8 @@ bus_context_new (const DBusString *config_file,
{
BusContext *context;
BusConfigParser *parser;
-
+ DBusCredentials creds;
+
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
context = NULL;
@@ -657,7 +658,25 @@ bus_context_new (const DBusString *config_file,
BUS_SET_OOM (error);
goto failed;
}
-
+
+ /* check user before we fork */
+ if (context->user != NULL)
+ {
+ DBusString u;
+
+ _dbus_string_init_const (&u, context->user);
+
+ if (!_dbus_credentials_from_username (&u, &creds) ||
+ creds.uid < 0 ||
+ creds.gid < 0)
+ {
+ dbus_set_error (error, DBUS_ERROR_FAILED,
+ "Could not get UID and GID for username \"%s\"",
+ context->user);
+ goto failed;
+ }
+ }
+
/* Now become a daemon if appropriate */
if ((force_fork != FORK_NEVER && context->fork) || force_fork == FORK_ALWAYS)
{
@@ -749,21 +768,6 @@ bus_context_new (const DBusString *config_file,
*/
if (context->user != NULL)
{
- DBusCredentials creds;
- DBusString u;
-
- _dbus_string_init_const (&u, context->user);
-
- if (!_dbus_credentials_from_username (&u, &creds) ||
- creds.uid < 0 ||
- creds.gid < 0)
- {
- dbus_set_error (error, DBUS_ERROR_FAILED,
- "Could not get UID and GID for username \"%s\"",
- context->user);
- goto failed;
- }
-
if (!_dbus_change_identity (creds.uid, creds.gid, error))
{
_DBUS_ASSERT_ERROR_IS_SET (error);