summaryrefslogtreecommitdiffstats
path: root/src/shared (follow)
Commit message (Collapse)AuthorAgeFilesLines
* cryptsetup-pkcs11: move pkcs11_callback and data in shared utils.Ondrej Kozina2021-08-192-0/+90
| | | | | To be used later by both (future) systemd-pkcs11 libcryptsetup plugin and cryptsetup-pkcs11.
* creds-util: fix possible divide-by-zeroYu Watanabe2021-08-191-2/+2
| | | | | | input_size may be zero. Fixes #20469.
* udev: make RxChannels= or friends also accept "max"Yu Watanabe2021-08-182-133/+73
| | | | | | | | | | Follow-up for 406041b7de767316674eb6a2f98ad466577ce8a4. Also, this makes - the settings accept an empty string, - if the specified value is too large, also use the advertised maximum value. - mention the range of the value in the man page.
* tree-wide: fix typoYu Watanabe2021-08-182-5/+5
|
* udev: Support "max" string for BufferSize options (#20458)Daan De Meyer2021-08-182-14/+28
| | | | | | | | "max" indicates the hardware advertised maximum queue buffer size should be used. The max sizes can be checked by running `ethtool -g <dev>` (Preset maximums). Since the buffer sizes can't be set to 0 by users, internally we use 0 to indicate that the hardware advertised maximum should be used.
* extension-release: search for other files if expected name not foundLuca Boccassi2021-08-171-20/+23
| | | | | | | | | | | | In some cases image names are unpredictable - some orchestrators/deployment tools like to mangle names to suit their internal formats. In these cases, the requirement that the extension-release file matches exactly the image name where it's contained cannot work. Allow falling back to loading the first regular file which name starts with 'extension-release' located in /usr/lib/extension-release.d/ and tagged with a user.extension-release.strict extended attribute with a true value, if the one with the expected name cannot be found.
* env-util: add unsetenv_erase() helperLennart Poettering2021-08-171-3/+2
| | | | Let's unify how we remove secrets from the env block.
* shared: add generic helper tools for installing files/dir treesLennart Poettering2021-08-173-0/+285
| | | | | | | | | | | | | | This adds a bit of generic helper tools for installing files/dir trees. "installing" is supposed to mean the final step when preparing a disk image or directory tree, where the result is renamed to its final name. It has some bells and whistles, as it is able to replace existing files sanely, can fsync() things carefully and can mark things read-only in a nice way. This is supposed to be generic, unified code that can be used eventually for any of our tools that prepare disk images/directory trees, including importd, nspawn's --template= mechanism, the discover-image.c logic, and more.
* ethtool: make ethtool_set_features() return earlier when nothing is requestedYu Watanabe2021-08-161-3/+13
|
* ethtool: make the size of 'features' array staticYu Watanabe2021-08-162-2/+2
|
* hostname: introduce gethostname_full() and use it in various gethostname() ↵Yu Watanabe2021-08-122-26/+11
| | | | variants
* hostname: fix off-by-one issue in gethostname()Yu Watanabe2021-08-121-4/+4
| | | | | | gethostname() returns null-terminated hostname. Fixes #20309 and #20417.
* shared/copy: add a new flag COPY_ALL_XATTRSAndrej Lajovic2021-08-113-7/+9
| | | | | | | | When the flag COPY_ALL_XATTRS is set, it causes the complete set of xattrs to be copied. If the flag is unset, only xattrs from the "user" namespace are copied. Fixes #17178.
* Get rid of dangling setutxent()MertsA2021-08-111-2/+4
| | | utmp_wall() and utmp_put_dead_process() called setutxent() directly instead of the stub in utmp-wtmp.h and never called endutxent(). This would leave /run/utmp left open by PID 1 or journald. This can be reproduced by e.g. lsof /run/utmp and systemd-cat -p 0 echo test. For utmp_put_dead_process() it would only leave it open if it returned early before calling write_utmp_wtmp()
* Merge pull request #20368 from keszybz/drop-assert-not-reached-textLuca Boccassi2021-08-0315-28/+28
|\ | | | | Drop the text argument from assert_not_reached()
| * Drop the text argument from assert_not_reached()Zbigniew Jędrzejewski-Szmek2021-08-0315-28/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In general we almost never hit those asserts in production code, so users see them very rarely, if ever. But either way, we just need something that users can pass to the developers. We have quite a few of those asserts, and some have fairly nice messages, but many are like "WTF?" or "???" or "unexpected something". The error that is printed includes the file location, and function name. In almost all functions there's at most one assert, so the function name alone is enough to identify the failure for a developer. So we don't get much extra from the message, and we might just as well drop them. Dropping them makes our code a tiny bit smaller, and most importantly, improves development experience by making it easy to insert such an assert in the code without thinking how to phrase the argument.
* | creds: assert that credential read from file fits in data structLuca Boccassi2021-08-031-0/+2
|/ | | | Coverity CID#1458114
* time-set: adjust system clock if rtc is far in futureEgor Ignatov2021-08-022-4/+25
|
* Merge pull request #20352 from poettering/copy-tweaksLuca Boccassi2021-08-024-59/+229
|\ | | | | various tweaks to copy.c
| * btrfs-util: expose COPY_SIGTERM for btrfs_snapshot() tooLennart Poettering2021-08-022-3/+11
| |
| * copy: add COPY_SIGTERM, matching the existing COPY_SIGINTLennart Poettering2021-08-022-20/+30
| |
| * copy: add COPY_SYNCFS flagLennart Poettering2021-08-022-11/+28
| | | | | | | | | | | | | | | | | | When copying large directory trees it should be a better idea to sync the whole fs once when we are done instead of individually for each file, hence add COPY_SYNCFS. As opposed to COPY_FSYNC/COPY_FSYNC_FULL this only really applies to the top-level directory, after completion of the whole copy.
| * copy: optionally fsync() files after copying themLennart Poettering2021-08-022-16/+118
| | | | | | | | | | | | As a safety precaution it makes sense to fsync() files after copying them, and maybe even the directories they are contained in. Let's add a flag for these two cases.
| * copy: tighten destination checks when copying filesLennart Poettering2021-08-021-6/+27
| | | | | | | | | | | | | | | | let's make sure we only operate on regular files when copying files. Also, make sure to copy file attributes only over if target is a regular file (so that copying a file to /dev/null won't alter the access mode/ownership of that device node...)
| * copy: move to single clean-up pathLennart Poettering2021-08-021-21/+33
| | | | | | | | | | | | | | | | | | (This might not look like a big improvement, but will shortly, when we add fsync() support to the copy logic, at which point there are more error paths we can unify that way.) While we are at it, tweak a clean-up path: only unlink a copied file if we are definitely the ones who created them, i.e. if O_EXCL is set.
* | Use correct `<poll.h>` includeDavid Seifert2021-08-022-2/+2
|/ | | | * `<sys/poll.h>` is not specified in POSIX
* Merge pull request #20172 from poettering/import-util-tweaksLennart Poettering2021-07-302-23/+93
|\ | | | | Import-util: URL processing tweaks
| * import-util: tweak url patching helperLennart Poettering2021-07-302-23/+93
| | | | | | | | | | | | | | | | | | | | let's share some code between import_url_last_component() and import_url_change_last_component(), and make sure we never eat up the hostname component of the URL when parsing out the last component. Let's also make import_url_change_last_component() more generic so that we can also use it for append components to paths, instead of replacing suffixes.
* | tpm2-util: auto-detect supported PCR banksLennart Poettering2021-07-303-10/+163
|/ | | | | | | | | | | | | | | | | | | Previously, we'd encode PCR policies strictly with the SHA256 PCR bank set. However, as it appears not all hw implement those. Sad. Let's add some minimal logic to auto-detect supported PCR banks: if SHA256 is supported, use that. But if not, automatically fall back to SHA1. This then changes both the LUKS code, and the credentials code to serialize the selected bank, along with the rest of the data in order to make this robust. This extends the LUK2 JSON metadata in a compatible way. The credentials encryption format is modified in an incompatible way however, but given that this is not part of any official release should be OK. Fixes: #20134
* rm-rf: refactor rm_rf_children(), split out body of directory iteration loopLennart Poettering2021-07-302-95/+131
| | | | | | This splits out rm_rf_children_inner() as body of the loop. We can use that to implement rm_rf_child() for deleting one specific entry in a directory.
* seccomp: move sched_getaffinity() from @system-service to @defaultLennart Poettering2021-07-271-1/+1
| | | | | | | | | | | | | | See: https://github.com/systemd/systemd/pull/20191#issuecomment-881982739 In general, we shouldn't blanket move syscalls like this into @default, given that glibc actually does have fallbacks, afaics. However, as long as the syscalls are "read-only" and thus benign, I figure it's a safe thing to do. But we should probably stick to a "if in doubt, don't" rule, and put these syscalls in @system-service as default, but not into @default. I think in the real world @system-service is the sensible group people should use, and not @default actually.
* seccomp: drop getrandom() from @system-serviceLennart Poettering2021-07-271-1/+0
| | | | | | | | It's included in @default now, since 14f4b1b568907350d023d1429c1aa4aaa8925f22, and since @system-service pulls that in we can drop it from @system-service. Follow-up for #20191
* Add support for systemd-tpm2 libcryptsetup plugin.Ondrej Kozina2021-07-261-0/+5
| | | | | | | | | | | Add support for systemd-tpm2 based LUKS2 device activation via libcryptsetup plugin. This make the feature (tpm2 sealed LUKS2 keyslot passphrase) usable from both systemd utilities and cryptsetup cli. The feature is configured via -Dlibcryptsetup-plugins combo with default value set to 'auto'. It get's enabled automatically when cryptsetup 2.4.0 or later is installed in build system.
* Merge pull request #20288 from keszybz/freeze-no-mallocLuca Boccassi2021-07-235-3/+104
|\ | | | | Don't call malloc from freeze which is called in a signal handler
| * Add variant of close_all_fds() that does not allocate and use it in freeze()Zbigniew Jędrzejewski-Szmek2021-07-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Even though it's just a fallback path, let's not be sloppy and allocate in the crash handler. > The deadlock happens because systemd crash in malloc() then in signal > handler, it calls malloc() (close_all_fds()-> opendir()-> __alloc_dir()) > again. malloc() is not a signal-safe function, maybe we should re-think > the logic here. Fixes #20266.
| * Move freeze() into shared/Zbigniew Jędrzejewski-Szmek2021-07-233-3/+27
| | | | | | | | | | | | | | | | Library code should not call freeze(), this is something that should only be done by "application code", so moving it into shared/ is appropriate. The fallback to call _exit() is dropped: let's trust that the infinite loop is infinite.
| * Move fork_agent() into shared/Zbigniew Jędrzejewski-Szmek2021-07-234-0/+77
| | | | | | | | | | | | | | Currently it's only used in two places in src/shared/, so the function was already included just once in compiled code. But it seems appropriate to move it there anyway, because library code should have no need to fork agents, so it doesn't belong in basic/.
* | discover-image: mount as read-only when extracting metadataLuca Boccassi2021-07-231-0/+1
| | | | | | | | We don't need to modify the image, and the loopback device is already set to read-only.
* | malloc() uses getrandom nowCristian Rodríguez2021-07-231-0/+1
|/ | | glibc master uses getrandom in malloc since https://sourceware.org/git/?p=glibc.git;a=commit;h=fc859c304898a5ec72e0ba5269ed136ed0ea10e1 , getrandom should be in the default set so to avoid all non trivial programs to fallback to a PRNG.
* gpt: reformat for restoring vertical alignmentWANG Xuerui2021-07-202-87/+87
|
* gpt: support LoongArch 64-bitWANG Xuerui2021-07-202-2/+22
|
* Add meson option to disable urlify.James Hilliard2021-07-191-0/+4
| | | | | Useful for systems that don't use a version of less with hyperlink support.
* Merge pull request #20109 from keszybz/timestamp-macrosYu Watanabe2021-07-1412-140/+77
|\ | | | | Add macros that define scratch buffer internally for timestamp/timespan formatting
| * shared/killall: replace one trivial asprintf with xsprintfZbigniew Jędrzejewski-Szmek2021-07-091-5/+5
| |
| * tree-wide: do not use (void) asprintfZbigniew Jędrzejewski-Szmek2021-07-091-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | asprintf(3) says that the pointer is "undefined" after a failed call. In the current glibc implementation it is just NULL. In principle the call could return a valid pointer with bad contents or something. We have two styles of error handling: in a majority of cases we would check the return value, but sometimes we used (void) and relied on the pointer not being set. In practice both styles should be equivalent, but gcc doesn't like the second one with -Wunused-result. (Though only sometimes. E.g. on my F34 box I don't get the same warnings as in CI, even though the compiler version is very similar and the compilation options are the same…). It's also nice to be consistent in our code base. So let's always use the first style of error checking.
| * tree-wide: add FORMAT_BYTES()Zbigniew Jędrzejewski-Szmek2021-07-093-47/+24
| |
| * shared/format-table: allocate buffer of sufficient sizeZbigniew Jędrzejewski-Szmek2021-07-091-2/+2
| |
| * tree-wide: add FORMAT_TIMESPAN()Zbigniew Jędrzejewski-Szmek2021-07-097-52/+27
| |
| * tree-wide: use FORMAT_TIMESTAMP()Zbigniew Jędrzejewski-Szmek2021-07-093-34/+17
| |
* | tree-wide: make cunescape*() functions return ssize_tZbigniew Jędrzejewski-Szmek2021-07-095-21/+27
| | | | | | | | | | Strictly speaking, we are returning the size of a memory chunk of arbitrary size, so ssize_t is more appropriate than int.