summaryrefslogtreecommitdiffstats
path: root/sys-utils/mount.c
diff options
context:
space:
mode:
authorKarel Zak2013-11-19 17:44:21 +0100
committerKarel Zak2013-11-19 17:44:21 +0100
commit6751f0627d9e2fddc63a50b003982ec4bbf0b197 (patch)
tree53789a1b766db6f5eea3443973d7e3a10811c341 /sys-utils/mount.c
parentlibmount: add mnt_tag_is_valid() (diff)
downloadkernel-qcow2-util-linux-6751f0627d9e2fddc63a50b003982ec4bbf0b197.tar.gz
kernel-qcow2-util-linux-6751f0627d9e2fddc63a50b003982ec4bbf0b197.tar.xz
kernel-qcow2-util-linux-6751f0627d9e2fddc63a50b003982ec4bbf0b197.zip
mount: make NAME=value tags usable for non-root
The libmount does not care if we set source or target, it's able to swap it, but the mount.c function sanitize_paths() does not work as expected if we set NAME=value as target. It means that $ mount LABEL=foo does not work for non-root users (since 51e3530cdcb1d4f3ab91ae953ebc5adcdc5f9239, v2.24). This patch also checks if source or target is specified more than once. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/mount.c')
-rw-r--r--sys-utils/mount.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/sys-utils/mount.c b/sys-utils/mount.c
index fa1ce15c3..ed814ca49 100644
--- a/sys-utils/mount.c
+++ b/sys-utils/mount.c
@@ -1030,25 +1030,42 @@ int main(int argc, char **argv)
mnt_context_get_target(cxt))) {
/*
* B) mount -L|-U|--source|--target
+ *
+ * non-root may specify source *or* target, but not both
*/
if (mnt_context_is_restricted(cxt) &&
mnt_context_get_source(cxt) &&
mnt_context_get_target(cxt))
exit_non_root(NULL);
- } else if (argc == 1) {
+ } else if (argc == 1 && (!mnt_context_get_source(cxt) ||
+ !mnt_context_get_target(cxt))) {
/*
* C) mount [-L|-U|--source] <target>
+ * mount [--target <dir>] <source>
* mount <source|target>
*
* non-root may specify source *or* target, but not both
+ *
+ * It does not matter for libmount if we set source or target
+ * here (the library is able to swap it), but it matters for
+ * sanitize_paths().
*/
+ int istag = mnt_tag_is_valid(argv[0]);
+
+ if (istag && mnt_context_get_source(cxt))
+ /* -L, -U or --source together with LABEL= or UUID= */
+ errx(MOUNT_EX_USAGE, _("source specified more than once"));
+ else if (istag || mnt_context_get_target(cxt))
+ mnt_context_set_source(cxt, argv[0]);
+ else
+ mnt_context_set_target(cxt, argv[0]);
+
if (mnt_context_is_restricted(cxt) &&
- mnt_context_get_source(cxt))
+ mnt_context_get_source(cxt) &&
+ mnt_context_get_target(cxt))
exit_non_root(NULL);
- mnt_context_set_target(cxt, argv[0]);
-
} else if (argc == 2 && !mnt_context_get_source(cxt)
&& !mnt_context_get_target(cxt)) {
/*
@@ -1056,6 +1073,7 @@ int main(int argc, char **argv)
*/
if (mnt_context_is_restricted(cxt))
exit_non_root(NULL);
+
mnt_context_set_source(cxt, argv[0]);
mnt_context_set_target(cxt, argv[1]);