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.
This commit is contained in:
Matthew Barnes 2015-07-14 13:14:02 -04:00
parent 708d923125
commit 254def3584

View File

@ -33,7 +33,7 @@
#include "otutil.h" #include "otutil.h"
static char *opt_repo; static char *opt_repo;
static char *opt_sysroot = "/"; static char *opt_sysroot;
static gboolean opt_verbose; static gboolean opt_verbose;
static gboolean opt_version; static gboolean opt_version;
static gboolean opt_print_current_dir; 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)) if (!ostree_option_context_parse (context, main_entries, argc, argv, OSTREE_BUILTIN_FLAG_NO_REPO, NULL, cancellable, error))
goto out; 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 (flags & OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER)
{ {
if ((opt_sysroot == NULL || strcmp (opt_sysroot, "/") == 0) GFile *path = ostree_sysroot_get_path (sysroot);
&& getuid () != 0)
/* 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, g_set_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
"You must be root to perform this command"); "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) if (opt_print_current_dir)
{ {
g_autoptr(GPtrArray) deployments = NULL; g_autoptr(GPtrArray) deployments = NULL;