summaryrefslogtreecommitdiff
path: root/src/basic/fs-util.c
Commit message (Collapse)AuthorAge
...
* tree-wide: replace all readdir cycles with FOREACH_DIRENT{,_ALL} (#4853)Reverend Homer2017-07-17
|
* util-lib: accept invoking chase_symlinks() with a NULL return parameterLennart Poettering2017-07-17
| | | | | | Let's permit invoking chase_symlinks() with a NULL return parameter. If so, the resolved name is not returned, and call is useful for checking for existance of a file, without actually returning its ultimate path.
* util-lib: rename CHASE_NON_EXISTING → CHASE_NONEXISTENTLennart Poettering2017-07-17
| | | | As suggested by @keszybz
* fs-util: add new CHASE_NON_EXISTING flag to chase_symlinks()Lennart Poettering2017-07-17
| | | | | | | | | | | | | | | | | This new flag controls whether to consider a problem if the referenced path doesn't actually exist. If specified it's OK if the final file doesn't exist. Note that this permits one or more final components of the path not to exist, but these must not contain "../" for safety reasons (or, to be extra safe, neither "./" and a couple of others, i.e. what path_is_safe() permits). This new flag is useful when resolving paths before issuing an mkdir() or open(O_CREAT) on a path, as it permits that the file or directory is created later. The return code of chase_symlinks() is changed to return 1 if the file exists, and 0 if it doesn't. The latter is only returned in case CHASE_NON_EXISTING is set.
* fs-util: add flags parameter to chase_symlinks()Lennart Poettering2017-07-17
| | | | | | Let's remove chase_symlinks_prefix() and instead introduce a flags parameter to chase_symlinks(), with a flag CHASE_PREFIX_ROOT that exposes the behaviour of chase_symlinks_prefix().
* fs-util: change chase_symlinks() behaviour in regards to escaping the root dirLennart Poettering2017-07-17
| | | | | | | | | Previously, we'd generate an EINVAL error if it is attempted to escape a root directory with relative ".." symlinks. With this commit this is changed so that ".." from the root directory is a NOP, following the kernel's own behaviour where /.. is equivalent to /. As suggested by @keszybz.
* fs-util: add chase_symlinks_prefix() and extend commentsLennart Poettering2017-07-17
| | | | | | | | chase_symlinks() currently expects a fully qualified, absolute path, relative to the host's root as first argument. Which is useful in many ways, and similar to the paths unlink(), rename(), open(), … expect. Sometimes it's however useful to first prefix the specified path with the specified root directory. Add a new call chase_symlinks_prefix() for this, that is a simple wrapper.
* tree-wide: stop using canonicalize_file_name(), use chase_symlinks() insteadLennart Poettering2017-07-17
| | | | | | | | Let's use chase_symlinks() everywhere, and stop using GNU canonicalize_file_name() everywhere. For most cases this should not change behaviour, however increase exposure of our function to get better tested. Most importantly in a few cases (most notably nspawn) it can take the correct root directory into account when chasing symlinks.
* tree-wide: drop NULL sentinel from strjoinZbigniew Jędrzejewski-Szmek2017-07-17
| | | | | | | | | | | | | This makes strjoin and strjoina more similar and avoids the useless final argument. spatch -I . -I ./src -I ./src/basic -I ./src/basic -I ./src/shared -I ./src/shared -I ./src/network -I ./src/locale -I ./src/login -I ./src/journal -I ./src/journal -I ./src/timedate -I ./src/timesync -I ./src/nspawn -I ./src/resolve -I ./src/resolve -I ./src/elogind -I ./src/core -I ./src/core -I ./src/libudev -I ./src/udev -I ./src/udev/net -I ./src/udev -I ./src/libelogind/sd-bus -I ./src/libelogind/sd-event -I ./src/libelogind/sd-login -I ./src/libelogind/sd-netlink -I ./src/libelogind/sd-network -I ./src/libelogind/sd-hwdb -I ./src/libelogind/sd-device -I ./src/libelogind/sd-id128 -I ./src/libelogind-network --sp-file coccinelle/strjoin.cocci --in-place $(git ls-files src/*.c) git grep -e '\bstrjoin\b.*NULL' -l|xargs sed -i -r 's/strjoin\((.*), NULL\)/strjoin(\1)/' This might have missed a few cases (spatch has a really hard time dealing with _cleanup_ macros), but that's no big issue, they can always be fixed later.
* Prep v232.2: Mask more unneeded functionsSven Eden2017-07-07
|
* tree-wide: introduce free_and_replace helperZbigniew Jędrzejewski-Szmek2017-07-05
| | | | | | It's a common pattern, so add a helper for it. A macro is necessary because a function that takes a pointer to a pointer would be type specific, similarly to cleanup functions. Seems better to use a macro.
* namespace: chase symlinks for mounts to set up in userspaceLennart Poettering2017-07-05
| | | | | | | | | | | | | | | | This adds logic to chase symlinks for all mount points that shall be created in a namespace environment in userspace, instead of leaving this to the kernel. This has the advantage that we can correctly handle absolute symlinks that shall be taken relative to a specific root directory. Moreover, we can properly handle mounts created on symlinked files or directories as we can merge their mounts as necessary. (This also drops the "done" flag in the namespace logic, which was never actually working, but was supposed to permit a partial rollback of the namespace logic, which however is only mildly useful as it wasn't clear in which case it would or would not be able to roll back.) Fixes: #3867
* util-lib: rework /tmp and /var/tmp handling codeLennart Poettering2017-07-05
| | | | | | | | | | | | | | | | | | | | Beef up the existing var_tmp() call, rename it to var_tmp_dir() and add a matching tmp_dir() call (the former looks for the place for /var/tmp, the latter for /tmp). Both calls check $TMPDIR, $TEMP, $TMP, following the algorithm Python3 uses. All dirs are validated before use. secure_getenv() is used in order to limite exposure in suid binaries. This also ports a couple of users over to these new APIs. The var_tmp() return parameter is changed from an allocated buffer the caller will own to a const string either pointing into environ[], or into a static const buffer. Given that environ[] is mostly considered constant (and this is exposed in the very well-known getenv() call), this should be OK behaviour and allows us to avoid memory allocations in most cases. Note that $TMPDIR and friends override both /var/tmp and /tmp usage if set.
* Prep v231: Apply missing fixes from upstream (1/6) src/basicSven Eden2017-06-16
|
* Prep v230: Apply missing upstream fixes and updates (2/8) src/basic.Sven Eden2017-06-16
|
* Prep v229: Add missing fixes from upstream [1/6] src/basicSven Eden2017-05-17
|
* basic: fix touch() creating files with 07777 modeMantas Mikulėnas2017-05-17
| | | | | | | mode_t is unsigned, so MODE_INVALID < 0 can never be true. This fixes a possible DoS where any user could fill /run by writing to a world-writable /run/elogind/show-status.
* tree-wide: check if errno is greater than zero (2)Zbigniew Jędrzejewski-Szmek2017-05-17
| | | | | Compare errno with zero in a way that tells gcc that (if the condition is true) errno is positive.
* Prep v228: Condense elogind source masks (1/5)Sven Eden2017-04-26
| | | | | | | | | | | | Although having a two line mask like /// UNNEEDED by elogind #if 0 it is much more easier to read (and patch!) if those two lines were condense into a one-line mask start like #if 0 /// UNNEEDED by elogind
* Prep v228: Clean up the new src/basic/*-util-[hc] files:Sven Eden2017-04-26
| | | | | | | | | | | | | - src/basic/capability-util.[hc] - src/basic/cgroup-util.[hc] - src/basic/fd-util.[hc] - src/basic/fs-util.[hc] - src/basic/memfd-util.[hc] - src/basic/path-util.[hc] - src/basic/socket-util.[hc] - src/basic/terminal-util.[hc] - src/basic/user-util.[hc] - src/basic/xattr-util.[hc]
* Prep v228: Add remaining updates from upstream (1/3)Sven Eden2017-04-26
The util.[hc] files have been stripped of a lot of functions, that got sorted into various new files representing the type of utility. This commit adds the missing files.