summaryrefslogtreecommitdiff
path: root/src/test/test-fs-util.c
Commit message (Collapse)AuthorAgeFilesLines
* fs-util: make sure open_mkdir_at() does something roughly sensible when ↵Lennart Poettering2023-04-251-0/+17
| | | | invoked with '/'
* test: split-out tests for chase() and friends to test-chase.cYu Watanabe2023-03-301-591/+1
|
* chase-symlinks: Add chase_and_open_parent() + at() variantDaan De Meyer2023-03-261-5/+29
| | | | | Helper to chase a path, pin its parent directory and return the filename of the resolved path in its parent directory.
* chase-symlinks: Rename chase_symlinks() to chase()Daan De Meyer2023-03-241-90/+90
| | | | | | | | | Chasing symlinks is a core function that's used in a lot of places so it deservers a less verbose names so let's rename it to chase() and chaseat(). We also slightly change the pattern used for the chaseat() helpers so we get chase_and_openat() and similar.
* fs-util: Allow xopenat() to reopen existing file descriptorsDaan De Meyer2023-03-231-1/+6
|
* fs-util: Add xopenat_lock()Daan De Meyer2023-03-221-1/+52
| | | | open/create a file/directory and lock it using the given lock type.
* copy: Move chattr arguments to full function signaturesDaan De Meyer2023-03-211-1/+1
| | | | | These are almost never used, so let's move them to the _full() functions signatures.
* chase-symlinks: Add more chase_symlinks_at() helpersDaan De Meyer2023-03-211-0/+40
| | | | Copies of the corresponding chase_symlinks() helpers.
* chase-symlinks: Add CHASE_EXTRACT_FILENAME flagDaan De Meyer2023-03-211-0/+22
| | | | | | | Useful in combination with CHASE_PARENT to get a directory file descriptor to the parent directory of the resolved path and the filename of the resolved path in the parent directory (which might not be the same as the filename of the input path because of symlinks).
* Merge pull request #26784 from DaanDeMeyer/chase-fixDaan De Meyer2023-03-151-21/+68
|\ | | | | Allow creating files and directories with chase_symlinks_open() and further improvements
| * chase-symlinks: Rework open() functions and some chase flagsDaan De Meyer2023-03-151-21/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, when CHASE_PARENT is specified, we chase the parent directory of the symlink itself. Let's change this and chase the parent directory of the symlink target so that trying to open the actual file later with O_NOFOLLOW doesn't fail with ELOOP. To get the current behavior, callers can add CHASE_NOFOLLOW to chase the parent directory of the symlink itself. Currently, when CHASE_MKDIR_0755 is specified, we create all components of the path as directories. Instead, let's change the flag to only create parent directories and leave the final component of the PATH untouched. Also, allow CHASE_NONEXISTENT with CHASE_MKDIR_0755 now that it doesn't create all components anymore. Finally, rework chase_symlinks_and_open() and chase_symlinkat_at_and_open() to always chase the parent directory and use xopenat() to open the final component of the path. This allows us to pass O_CREAT to create the file or directory (O_DIRECTORY) if it is missing. If CHASE_PARENT is configured, we just reopen the parent directory that we chased.
| * fs-util: Add xopenat()Daan De Meyer2023-03-141-0/+25
| | | | | | | | | | xopenat() will create directories if O_DIRECTORY and O_CREAT are specified. Note that this is not an atomic operation.
* | fs-util: Drop unlink_noerrno()Daan De Meyer2023-03-151-19/+0
|/
* chase-symlinks: Add chase_symlinks_at_and_open()Daan De Meyer2023-03-061-0/+6
|
* chase-symlinks: Add CHASE_MKDIR_0755Daan De Meyer2023-03-061-0/+14
|
* chase-symlinks: Add CHASE_PARENTDaan De Meyer2023-03-061-1/+23
| | | | | Let's simplify chasing the parent directory of some path by adding CHASE_PARENT.
* chase-symlinks: chase_symlinks_at() AT_FDCWD fixesDaan De Meyer2023-02-071-0/+36
| | | | | | | | | | | | | | | | | - Whether we should return an absolute path or not is irrelevant to whether CHASE_AT_RESOLVE_IN_ROOT is set. We should only return an absolute path if we are provided one and the directory file descriptor is AT_FDCWD - When the directory file descriptor is AT_FDCWD, we should always resolve symlinks against "/". Currently, if the directory file descriptor is AT_FDCWD and CHASE_AT_RESOLVE_IN_ROOT is set, we resolve symlinks against the current working directory which is almost always not going to be what the caller wants. - Currently, if we provide an absolute path with a positive directory file descriptor without CHASE_AT_RESOLVE_IN_ROOT SET, we interpret the path relative to "/" instead of the given directory file descriptor. Let's make sure that when we're given a positive directory file descriptor, we always resolve the given path relative to it.
* chase-symlinks: new chase_symlinks_and_unlink()Ludwig Nussel2023-01-191-0/+7
|
* tree-wide: use -EBADF for fd initializationZbigniew Jędrzejewski-Szmek2022-12-191-8/+8
| | | | | | | | | | | | | | | | -1 was used everywhere, but -EBADF or -EBADFD started being used in various places. Let's make things consistent in the new style. Note that there are two candidates: EBADF 9 Bad file descriptor EBADFD 77 File descriptor in bad state Since we're initializating the fd, we're just assigning a value that means "no fd yet", so it's just a bad file descriptor, and the first errno fits better. If instead we had a valid file descriptor that became invalid because of some operation or state change, the other errno would fit better. In some places, initialization is dropped if unnecessary.
* test-fs-util: skip part of test_chase_symlinks if machine-id is not initializedNick Rosbrook2022-12-141-1/+1
| | | | | | The part of test_chase_symlink in test-fs-util that calls sd_id128_get_machine will fail if /etc/machine-id is empty, so skip this block if the machine-id is not initialized.
* sd-id128: make id128_read() or friends return -ENOPKG when the file contents ↵Yu Watanabe2022-12-121-1/+1
| | | | | | | | | is "uninitialized" Then, this drops ID128_PLAIN_OR_UNINIT. Also, this renames Id128Format -> Id128FormatFlag, and make it bitfield. Fixes #25634.
* test-fs-util: Add relative path chase_symlinks() testsDaan De Meyer2022-12-071-1/+25
|
* chase-symlinks: add new flag for prohibiting any following of symlinksLennart Poettering2022-11-131-0/+9
| | | | | | This is useful when operating in the ESP, which is untrusted territory, and where under no circumstances we should be tricked by symlinks into doing anything we don't want to.
* basic: rename util.h to logarithm.hZbigniew Jędrzejewski-Szmek2022-11-081-1/+0
| | | | | util.h is now about logarithms only, so we can rename it. Many files included util.h for no apparent reason… Those includes are dropped.
* test-fs-util: do not fail if machine-id is missingLuca Boccassi2022-10-251-1/+1
| | | | When building in a chroot there might not be any machine-id
* tree-wide: drop de-constifying casts for strv iterationZbigniew Jędrzejewski-Szmek2022-05-081-2/+2
| | | | | | | When the the iterator variable is declared automatically, it "inherits" the const/non-const status from the argument. We don't need to cast a const table to non-const. If we had a programming error and tried to modify the string, the compiler could now catch this.
* fs-util: make sure openat_report_new() initializes return param also on shortcutLennart Poettering2022-03-231-0/+18
| | | | | | | | | Our coding style dictates that return parameters should be initialized always on success, hence do so here also in the shortcut codepath. Issue discovered by @fbuihuu: https://github.com/systemd/systemd/pull/22808/files/ca8503f168d0632c606110da909aba3057777395#r831911069
* fs-util: add openat_report_new() wrapper around openat()Lennart Poettering2022-03-211-0/+50
| | | | | | This is a wrapper around openat(). It works mostly the same, except for one thing: it race-freely reports whether we just created the indicated file in case O_CREAT is passed without O_EXCL.
* strv: make iterator in STRV_FOREACH() declaread in the loopYu Watanabe2022-03-191-1/+0
| | | | This also avoids multiple evaluations in STRV_FOREACH_BACKWARDS()
* test: fix file descriptor leak in test-fs-utilYu Watanabe2022-02-231-1/+4
| | | | Fixes an issue reported in #22576.
* test: allow to set NULL to intro or outroYu Watanabe2022-02-021-1/+1
| | | | Addresses https://github.com/systemd/systemd/pull/22338#discussion_r796741033.
* tests: rework test macros to not take code as parametersLennart Poettering2022-02-021-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | C macros are nasty. We use them, but we try to be conservative with them. In particular passing literal, complex code blocks as argument is icky, because of "," handling of C, and also because it's quite a challange for most code highlighters and similar. Hence, let's avoid that. Using macros for genreating functions is OK but if so, the parameters should be simple words, not full code blocks. hence, rework DEFINE_CUSTOM_TEST_MAIN() to take a function name instead of code block as argument. As side-effect this also fixes a bunch of cases where we might end up returning a negative value from main(). Some uses of DEFINE_CUSTOM_TEST_MAIN() inserted local variables into the main() functions, these are replaced by static variables, and their destructors by the static destructor logic. This doesn't fix any bugs or so, it's just supposed to make the code easier to work with and improve it easthetically. Or in other words: let's use macros where it really makes sense, but let's not go overboard with it. (And yes, FOREACH_DIRENT() is another one of those macros that take code, and I dislike that too and regret I ever added that.)
* test: Use TEST macroJan Janssen2021-11-251-67/+17
| | | | | | | | | This converts to TEST macro where it is trivial. Some additional notable changes: - simplify HAVE_LIBIDN #ifdef in test-dns-domain.c - use saved_argc/saved_argv in test-copy.c, test-path-util.c, test-tmpfiles.c and test-unit-file.c
* fs-util: add new helper open_mkdir_at()Lennart Poettering2021-11-171-0/+44
|
* umask-util: add helper that resets umask until end of current code blockLennart Poettering2021-11-121-1/+2
|
* fs-util: add helper that can split CIFS services namesLennart Poettering2021-10-271-0/+31
|
* basic: spit out chase_symlinks() from fs-util.[ch] → chase-symlinks.[ch]Lennart Poettering2021-10-051-0/+1
|
* basic: split out sync() family of calls from fs-util.[ch] into new c/h fileLennart Poettering2021-10-051-0/+1
| | | | No changes in code, just some splitting out.
* fs-util: rewrite rmdir_parents() with path_find_last_component()Yu Watanabe2021-09-071-0/+55
|
* basic,shared: move a bunch of files to src/shared/Zbigniew Jędrzejewski-Szmek2021-06-241-33/+0
| | | | | | | | | | | | The goal is to move everything that requires selinux or smack away from src/basic/. This means that src/basic/label.[ch] must move, which implies btrfs-util.[ch], copy.[ch], and a bunch of other files which form a cluster of internal use. This is just moving text around, so there should be no functional difference. test-blockdev-util is new, because path_is_encrypted() is moved to blockdev-util.c, and so far we didn't have any tests for code there.
* tree-wide: add missing whitespace at the end of commentsYu Watanabe2021-06-151-1/+1
|
* fs-util: make chase_symlinks() use path_find_first_component()Yu Watanabe2021-05-281-2/+2
| | | | | The previous commit about path_compare() breaks chase_symlinks(). This commit fixes it.
* tree-wide: use UINT64_MAX or friendsYu Watanabe2021-03-051-1/+1
|
* test-fs-util: beef up test for conservative_renameat()Lennart Poettering2021-02-041-6/+22
| | | | | | Instead of using a short fixed string, let's use a huge blob for testing, with randomized size and contents, that definitely is above the 16K buffer size conservative_renameat() uses internally.
* fs-util: rename conservative_rename() -> conservative_renameat()Yu Watanabe2021-01-221-7/+7
| | | | And this introduces conservative_rename() which does not take dirfd.
* fs-util: add conservative_rename() that suppresses unnecessary renamesLennart Poettering2020-12-021-0/+48
| | | | | | | | if the source and destination file match in contents and basic file attributes, don#t rename, but just remove source. This is a simple way to suppress inotify events + mtime changes when atomically updating files.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* fs-util: drop chmod_and_chown_unsafe() which is unused nowLennart Poettering2020-09-231-45/+0
|
* test: accept that char device 0/0 can now be created witout privilegesLennart Poettering2020-08-171-6/+6
| | | | Fixes: #16721
* test-fs-util: skip encrypted path test if we get EACCESTopi Miettinen2020-08-171-5/+6
| | | | | | Unprivileged test-fs-util fails on my system since /sys/dev/block is inaccessible for unprivileged users, so let's skip encrypted path test if we get EACCES or similar.