summaryrefslogtreecommitdiffstats
path: root/lib/canonicalize.c
Commit message (Collapse)AuthorAgeFilesLines
* lib/canonicalize: fix compiler warning [-Wsign-compare]Karel Zak2019-06-101-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/canonicalize: verify DM paths [coverity scan]Karel Zak2019-05-141-1/+1
| | | | | | | | | | | | | Now the code only checks that /sys/.../dm/name exists, but never verify the device node in /dev (because path prefix is never NULL). The prefix is used to redirect hardcoded paths to /sys dumps (e.g. lsblk regression tests, etc.) This bug has been introduced in v2.33. Fortunately, it's probably no big issue as /dev is always in sync with /sys (thanks to udevd). Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/canonicalize: fix typoKarel Zak2018-11-301-1/+1
| | | | | Addresses: https://github.com/karelzak/util-linux/commit/8b8277b7a812c04f2288460f3a8d23cdd53ff66d#commitcomment-31491031 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/canonicalize: do restricted canonicalize in a subprocessRian Hunter2018-11-301-22/+77
| | | | | | | | | | | | | | | | | | | Accessing FUSE mounts require suid/sgid (saved uid) to be equal to the owner of the mount. If mount is running as a setuid process, swapping creds by only setting the euid/egid isn't enough to change the suid/sgid as well. We must do a full setuid()/setgid(), but that removes our ability to re-assume the identity of the original euid. The solution is swap creds in a child process, preserving the creds of the parent. [kzak@redhat.com: - use switch() rather than if() for fork - use all-io.h - close unused pipe[] ends - be more strict about used types] Addresses: https://github.com/karelzak/util-linux/pull/705 Co-Author: Karel Zak <kzak@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lsblk: use prefix for DM nameKarel Zak2018-06-211-3/+11
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/canonicalize: fix truncation warningSami Kerola2018-05-101-2/+3
| | | | | | | | | | | | | | | | | | lib/canonicalize.c: In function ‘canonicalize_dm_name’: lib/canonicalize.c:42:45: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 244 [-Wformat-truncation=] snprintf(path, sizeof(path), "/dev/mapper/%s", name); Notice that this warnign fix does not improve code enormously. The earlier snprintf() truncation will not happen a bit earlier when fgets() is called. In that sense this change merely makes one easy to silence warning to disappear, and therefore improve change of noticing useful messaging as such crops up. [kzak@redhat.com: - use macro rather than hardcoded string for mapper path] Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: Fix various typosSebastian Rasmussen2016-05-311-1/+1
| | | | | | | Fix various typos in error messages, warnings, debug strings, comments and names of static functions. Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
* libmount: try absolute target before canonicalizeKarel Zak2016-04-131-1/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The path canonicalization is expensive and in many cases unwanted due to problems with readlink() on unreachable NFS and automounters. This patch add a possibility to search also by $(CWD)/<path> if the <path> is relative to reduce number of situation when we convert the path to the canonical absolute path. The common use-case: # cd /some/long/path # umount ./mountpoint old version: 15543: libmount: TAB: [0x560a99a54230]: lookup TARGET: './test' 15543: libmount: CACHE: [0x560a99a54290]: canonicalize path ./test 15543: libmount: CACHE: [0x560a99a54290]: add entry [ 1] (path): /mnt/test: ./test 15543: libmount: TAB: [0x560a99a54230]: lookup canonical TARGET: '/mnt/test' 15543: libmount: CXT: [0x560a99a54050]: umount fs: /mnt/test new version: 15597: libmount: TAB: [0xabf230]: lookup TARGET: './test' 15597: libmount: TAB: [0xabf230]: lookup absolute TARGET: '/mnt/test' 15597: libmount: CXT: [0xabf050]: umount fs: /mnt/test Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/canonicalize: make DM canonicalization more robustKarel Zak2014-05-201-15/+30
| | | | | | | | The current code cares about filenames, but it's too fragile, we have to check the path is really path to the block device. Addresses: https://github.com/karelzak/util-linux/issues/83 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/canonical: use realpath() from libcKarel Zak2013-07-011-151/+29Star
| | | | | | | .. after many many years it seems that we can follow libc code rather than duplicate realpath(3) implementation. Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: be robust for empty target/source stringsKarel Zak2013-06-171-2/+5
| | | | | | | | | | * 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>
* lib: use O_CLOEXEC in libcommonKarel Zak2013-04-031-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/canonicalize: don't use /dev/mapper/<name> if the node does not existKarel Zak2013-04-031-1/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/canonicalize: add canonicalize_path_restricted() to canonicalize without ↵Karel Zak2012-11-261-0/+42
| | | | | | suid permisssions Signed-off-by: Karel Zak <kzak@redhat.com>
* Revert "lib/canonicalize: always remove tailing slash"Karel Zak2012-03-261-10/+3Star
| | | | | | | | | | | | | | | | | | | It's overkill to modify unknown paths in a generic function like canonicalize_path(). for example: mount -t fuse 'sshfs#marty@thee:/' /media/thee will be canonicalized to mount -t fuse 'sshfs#marty@thee:' /media/thee and this obvious bug. Reported-by: Martin Panter <vadmium+floss@gmail.com> This reverts commit 28074a0952469aebf021821d95238cfb964d13ff.
* lib/canonicalize: always remove tailing slashKarel Zak2012-02-241-3/+10
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: [loopdev.c] add module for work loop devicesKarel Zak2011-05-301-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: add test program to canonicalize.cKarel Zak2010-10-251-0/+14
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: remove duplicate #includesKarel Zak2010-02-121-1/+0Star
| | | | | | | | | | | $ make checkincludes fsck/fsck.c: errno.h is included more than once. lib/canonicalize.c: string.h is included more than once. shlibs/blkid/src/blkidP.h: stdio.h is included more than once. shlibs/blkid/src/devname.c: string.h is included more than once. shlibs/blkid/src/devno.c: string.h is included more than once. Signed-off-by: Karel Zak <kzak@redhat.com>
* mount: and libblkid: covert /dev/dm-N to /dev/mapper/<name>Karel Zak2009-10-261-4/+44
| | | | | | | | | | | | | * mount(8) uses private device-mapper names in mtab * libblkid returns private device-mapper names when evaluate udev /dev/disk-by symlinks. * on systems where DM is fully integrated with udev the /dev/mapper/<name> files are symlinks to /dev/dm-N. It means we need a special care to hide private device-mapper names. Signed-off-by: Karel Zak <kzak@redhat.com>
* mount: move realpath.c code to lib/Karel Zak2009-02-111-0/+152
Signed-off-by: Karel Zak <kzak@redhat.com>