app: Check for root privileges where required early
Rather than sending a dbus message that gets denied, which is ugly. Closes: #565 Closes: #570 Approved by: jlebon
This commit is contained in:
parent
185fba0551
commit
4a511fa011
@ -125,6 +125,14 @@ rpmostree_option_context_parse (GOptionContext *context,
|
||||
|
||||
use_daemon = ((flags & RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD) == 0);
|
||||
|
||||
if ((flags & RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT) > 0
|
||||
&& getuid () != 0)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"This command requires root privileges");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (main_entries != NULL)
|
||||
g_option_context_add_main_entries (context, main_entries, NULL);
|
||||
|
||||
|
@ -81,7 +81,7 @@ rpmostree_builtin_deploy (int argc,
|
||||
if (!rpmostree_option_context_parse (context,
|
||||
option_entries,
|
||||
&argc, &argv,
|
||||
RPM_OSTREE_BUILTIN_FLAG_NONE,
|
||||
RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
|
||||
cancellable,
|
||||
&sysroot_proxy,
|
||||
error))
|
||||
|
@ -63,7 +63,7 @@ rpmostree_builtin_rollback (int argc,
|
||||
if (!rpmostree_option_context_parse (context,
|
||||
option_entries,
|
||||
&argc, &argv,
|
||||
RPM_OSTREE_BUILTIN_FLAG_NONE,
|
||||
RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
|
||||
cancellable,
|
||||
&sysroot_proxy,
|
||||
error))
|
||||
|
@ -79,7 +79,7 @@ rpmostree_builtin_upgrade (int argc,
|
||||
if (!rpmostree_option_context_parse (context,
|
||||
option_entries,
|
||||
&argc, &argv,
|
||||
RPM_OSTREE_BUILTIN_FLAG_NONE,
|
||||
RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
|
||||
cancellable,
|
||||
&sysroot_proxy,
|
||||
error))
|
||||
|
@ -31,7 +31,8 @@ G_BEGIN_DECLS
|
||||
|
||||
typedef enum {
|
||||
RPM_OSTREE_BUILTIN_FLAG_NONE = 0,
|
||||
RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD = 1 << 0
|
||||
RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD = 1 << 0,
|
||||
RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT = 1 << 1,
|
||||
} RpmOstreeBuiltinFlags;
|
||||
|
||||
typedef struct {
|
||||
|
@ -626,7 +626,7 @@ rpmostree_compose_builtin_tree (int argc,
|
||||
if (!rpmostree_option_context_parse (context,
|
||||
option_entries,
|
||||
&argc, &argv,
|
||||
RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
|
||||
RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
|
||||
cancellable,
|
||||
NULL,
|
||||
error))
|
||||
@ -644,13 +644,6 @@ rpmostree_compose_builtin_tree (int argc,
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (getuid () != 0)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"compose tree must presently be run as uid 0 (root)");
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Test whether or not bwrap is going to work - we will fail inside e.g. a Docker
|
||||
* container without --privileged or userns exposed.
|
||||
*/
|
||||
|
@ -144,7 +144,7 @@ rpmostree_builtin_pkg_add (int argc,
|
||||
if (!rpmostree_option_context_parse (context,
|
||||
option_entries,
|
||||
&argc, &argv,
|
||||
RPM_OSTREE_BUILTIN_FLAG_NONE,
|
||||
RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
|
||||
cancellable,
|
||||
&sysroot_proxy,
|
||||
error))
|
||||
@ -178,7 +178,7 @@ rpmostree_builtin_pkg_remove (int argc,
|
||||
if (!rpmostree_option_context_parse (context,
|
||||
option_entries,
|
||||
&argc, &argv,
|
||||
RPM_OSTREE_BUILTIN_FLAG_NONE,
|
||||
RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
|
||||
cancellable,
|
||||
&sysroot_proxy,
|
||||
error))
|
||||
|
@ -34,6 +34,12 @@ vm_send_test_repo
|
||||
# make sure the package is not already layered
|
||||
vm_assert_layered_pkg foo absent
|
||||
|
||||
# Be sure an unprivileged user exists
|
||||
vm_cmd getent passwd bin
|
||||
if vm_cmd "runuser -u bin rpm-ostree pkg-add foo-1.0"; then
|
||||
assert_not_reached "Was able to install a package as non-root!"
|
||||
fi
|
||||
|
||||
vm_cmd rpm-ostree pkg-add foo-1.0
|
||||
echo "ok pkg-add foo"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user