diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2015-07-14 13:14:02 -0400 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2015-07-16 12:49:28 -0400 |
commit | 254def3584402e5f5ee877ef4904c9a8783dd440 (patch) | |
tree | c632878a0c32c3658dd3e89119db4f64f2cbdac1 | |
parent | 708d923125bd94815c7ba4969dadc3fba842ec3f (diff) | |
download | ostree-254def3584402e5f5ee877ef4904c9a8783dd440.tar.gz |
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.
-rw-r--r-- | src/ostree/ot-main.c | 16 |
1 files 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; |