From 254def3584402e5f5ee877ef4904c9a8783dd440 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Tue, 14 Jul 2015 13:14:02 -0400 Subject: [PATCH] main: Fix UID check based on sysroot path This is another place where we were hard-coding a default. Create the OstreeSysroot first and THEN check if its path is the root directory. --- src/ostree/ot-main.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/ostree/ot-main.c b/src/ostree/ot-main.c index 7f45b2b4..d3a7fd45 100644 --- a/src/ostree/ot-main.c +++ b/src/ostree/ot-main.c @@ -33,7 +33,7 @@ #include "otutil.h" static char *opt_repo; -static char *opt_sysroot = "/"; +static char *opt_sysroot; static gboolean opt_verbose; static gboolean opt_version; static gboolean opt_print_current_dir; @@ -323,10 +323,17 @@ ostree_admin_option_context_parse (GOptionContext *context, if (!ostree_option_context_parse (context, main_entries, argc, argv, OSTREE_BUILTIN_FLAG_NO_REPO, NULL, cancellable, error)) goto out; + if (opt_sysroot != NULL) + sysroot_path = g_file_new_for_path (opt_sysroot); + + sysroot = ostree_sysroot_new (sysroot_path); + if (flags & OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER) { - if ((opt_sysroot == NULL || strcmp (opt_sysroot, "/") == 0) - && getuid () != 0) + GFile *path = ostree_sysroot_get_path (sysroot); + + /* If sysroot path is "/" then user must be root. */ + if (!g_file_has_parent (path, NULL) && getuid () != 0) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED, "You must be root to perform this command"); @@ -334,9 +341,6 @@ ostree_admin_option_context_parse (GOptionContext *context, } } - sysroot_path = g_file_new_for_path (opt_sysroot); - sysroot = ostree_sysroot_new (sysroot_path); - if (opt_print_current_dir) { g_autoptr(GPtrArray) deployments = NULL;