For example for hierarchy:
$ findmnt -oTARGET,ID,PARENT
TARGET ID PARENT
/mnt/A 802 62
└─/mnt/A/B 937 802
├─/mnt/A/B/C 964 937
│ └─/mnt/A/B/C 991 964
└─/mnt/A/B 1018 937
└─/mnt/A/B 1045 1018
we need umount in order (id): 1045, 1018, 991, 964, 937, 802. The current
code first tries 991 in 937 branch.
Reported-by: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
It seems better to ignore this option than drop-permissions and later
exit with EPERMs. This change makes umount(8) more compatible with
fuser user umounts by systemd where -c is used to reduce overhead etc.
Addresses: https://github.com/karelzak/util-linux/issues/1192
Signed-off-by: Karel Zak <kzak@redhat.com>
The commands mount and umount sanitize environment variables as it
works with suid permissions by default. Since v2.36 it's possible
that the commands drop the permissions and continue as regular user.
It seems we also need to restore the original environ to keep things
consistent for users (e.g. HOME=).
The implementation is pretty simple -- it keeps in memory removed
variables and use it after switch to non-suid mode.
Addresses: https://github.com/karelzak/util-linux/issues/880
Signed-off-by: Karel Zak <kzak@redhat.com>
The current libmount assumes that mount(8) and umount(8) are suid
binaries. For this reason it implements internal rules which
restrict what is allowed for non-root users. Unfortunately, it's
out of reality for some use-cases where root permissions are no
required. Nice example are fuse filesystems.
So, the current situation is to call exit() always when mount, umount or
libmount are unsure with non-root user rights. This patch removes the
exit() call and replaces it with suid permissions drop, after that it
continues as usually. It means after suid-drop all depend on kernel
and no another security rule is used by libmount (simply because any
rule is no more necessary).
Example:
old version:
$ mount -t fuse.sshfs kzak@192.168.111.1:/home/kzak /home/kzak/mnt
mount: only root can use "--types" option
new version:
$ mount -t fuse.sshfs kzak@192.168.111.1:/home/kzak /home/kzak/mnt
kzak@192.168.111.1's password:
$ findmnt /home/kzak/mnt
TARGET SOURCE FSTYPE OPTIONS
/home/kzak/mnt kzak@192.168.111.1:/home/kzak fuse.sshfs rw,nosuid,nodev,relatime,user_id=1000,group_id=1000
$ umount /home/kzak/mnt
$ echo $?
0
Note that fuse user umount is supported since v2.34 due to user_id= in
kernel mount table.
Signed-off-by: Karel Zak <kzak@redhat.com>
If you by accident execute
umount ls -al /mnt/
then umount --all is executed and another arguments silently ignored.
It seems better to be more strict in this case.
Reported-by: Harald Dunkel <harald.dunkel@aixigo.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Let's consolidate the version printing code. It also seems better to
use exit() after --version, because it's handled in different way by
ASAN.
It's strange, but ASAN reports leaks after return in main(). Note that
we do not use free-before-exit.
Signed-off-by: Karel Zak <kzak@redhat.com>
The command umount supports things like --all-targets and --recursive
to umount all nodes in specified tree. Sometimes it makes sense to
aggressively use wildcards like /dev/sdb* and in this case --quiet
seems like a good choice
umount --quiet --all-targets /dev/sdb*
to suppress 'not mounted' error messages. The new option suppress only
these error messages and nothing else.
Addresses: https://github.com/karelzak/util-linux/issues/672
Signed-off-by: Karel Zak <kzak@redhat.com>
While looking earlier commit I noticed everything but formatting was removed
from a message in namei.c file. That inspired me to look if there are more
strings that does not need translation project attention. This change
removes at least some of them, if not all.
Reference: e19cc7b65b
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
changed in include/c.h and applied via sed:
sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c")
sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c")
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Consolidate --help and --version descriptions. We are
now able to align them to the other options.
We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer
Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.
Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.
Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
The libmount provides way how to deal with parsing errors in fstab --
on error callback function is executed and according to the return
libmount manipulate with the malformed line, possible are three
states:
1/ fatal error; all file ignored (callback rc < 0)
2/ recoverable error; malformed line ignored (callback rc > 0)
3/ ignore the error (callback rc == 0)
The 2/ is the default if no callback specified.
Unfortunately our utils uses 3/. The correct way is to use 2/.
Signed-off-by: Karel Zak <kzak@redhat.com>
This adds a concise description of a tool to its usage text.
A first form of this patch was proposed by Steven Honeyman
(see http://www.spinics.net/lists/util-linux-ng/msg09994.html).
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
POSIX exit code is only 8-bit, and since umount sums up error
codes, it can sometimes report success (exit code 0) even though
a number of operations failed.
For example, running, in an empty directory:
umount `seq 1 7`
returns 224 (7*32), since none of the 7 mount point exists but
umount `seq 1 8`
returns 0 (8*32=256)
This patch clips the return value to 255.
Signed-off-by: Nicolas Boichat <nicolas@boichat.ch>
$ umount LABEL=foo
currently does not work for non-root users as umount uses the
LABEL= as a path in sanitize_path().
Signed-off-by: Karel Zak <kzak@redhat.com>
non-root user on device that is not mounted:
$ umount /mnt/flash
umount: /mnt/flash: umount failed: Operation not permitted
this is true, because we cannot evaluate permissions as there is no
entry in mtab, but users expect something more helpful -- for example
umount: /mnt/flash: not mounted
References: https://bugs.archlinux.org/task/31647
Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/canonicalize.c: don't interpret empty strings as relative paths
* libmount: more robust libmnt_table find function and debug messages
References: https://bugzilla.novell.com/show_bug.cgi?id=825150
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
# mount -t tmpfs tmp /mnt/A
# mount --bind /mnt/A /mnt/B
# mount -t tmpfs tmp /mnt/C
the command:
umount --all-targets /mnt/A
has to umount only A and B, but not C. The C is a another filesystem.
Signed-off-by: Karel Zak <kzak@redhat.com>
The same source (whole filesystem or filesystems subvolume) could be
mounted on more targets (mountpoints). For example bind mounts or
btrfs sub-volumes.
If you want to detach the source device from the system then you need
to unmount all the mountpoints.
umount --all-targets <device|mountpoint>
provides this functionality. This option could be used together with
--recursive. Then all nested mountpoints within the filesystem are
unmounted too. For example:
umount --recursive --all-targets /dev/sdb1
should be a way how to make the device unmounted at all.
Signed-off-by: Karel Zak <kzak@redhat.com>
Without this table libmount will not resolve paths, meaning that
umounting by relative path will fail.
[kzak@redhat.com: - use mnt_context_get_cache() to make it sensitive
to --no-canonicalize cmdline option]
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Karel Zak <kzak@redhat.com>