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)) {
/*
*/
if (mnt_context_is_restricted(cxt))
exit_non_root(NULL);
+
mnt_context_set_source(cxt, argv[0]);
mnt_context_set_target(cxt, argv[1]);