summaryrefslogtreecommitdiff
path: root/src/cryptsetup
Commit message (Collapse)AuthorAgeFilesLines
* coccinelle: make use of SYNTHETIC_ERRNOZbigniew Jędrzejewski-Szmek2018-11-222-22/+19
| | | | | | | | | | | Ideally, coccinelle would strip unnecessary braces too. But I do not see any option in coccinelle for this, so instead, I edited the patch text using search&replace to remove the braces. Unfortunately this is not fully automatic, in particular it didn't deal well with if-else-if-else blocks and ifdefs, so there is an increased likelikehood be some bugs in such spots. I also removed part of the patch that coccinelle generated for udev, where we returns -1 for failure. This should be fixed independently.
* generators: drop umask callsZbigniew Jędrzejewski-Szmek2018-11-211-2/+0
| | | | | | | | | systemd already sets the umask (see e3b8d0637dd755b3426f3363b2cdad63f738116c). When running under systemd, we don't need to set it. And when *not* running under systemd, for example during development, there is no reason to override the user config. Let's just drop those calls. $ git grep -e 'umask\(' -l 'src/*generator*' |xargs perl -i -0pe 's|^[^\n]*umask\([^\n]+\n\n||gms'
* Split out pretty-print.c and move pager.c and main-func.h to shared/Zbigniew Jędrzejewski-Szmek2018-11-201-1/+1
| | | | | This is high-level functionality, and fits better in shared/ (which is for our executables), than in basic/ (which is also for libraries).
* cryptsetup: use static destructor and DEFINE_MAIN_FUNCTION() macroYu Watanabe2018-11-201-43/+31
|
* log: introduce new helper call log_setup_service()Lennart Poettering2018-11-201-3/+1
| | | | | Let's reduce the common boilerplate and have a single setup function used by all service code to setup logging.
* generators: introduce a common implementation for the log setup boilerplateLennart Poettering2018-11-201-4/+1
|
* Move LONG_LINE_MAX definition to fileio.hZbigniew Jędrzejewski-Szmek2018-11-141-1/+0
| | | | | | | | | | | All users of the macro (except for one, in serialize.c), use the macro in connection with read_line(), so they must include fileio.h. Let's not play libc games and require multiple header file to be included for the most common use of a function. The removal of def.h includes is not exact. I mostly went over the commits that switch over to use read_line() and add def.h at the same time and reverted the addition of def.h in those files.
* cryptsetup-generator: allow whitespace characters in keydev specificationMichal Sekletar2018-10-301-21/+43
| | | | | | For example, <luks.uuid>=/keyfile:LABEL="KEYFILE FS" previously wouldn't work, because we truncated label at the first whitespace character, i.e. LABEL="KEYFILE".
* cryptsetup-generator: don't return error if target directory already existsMichal Sekletar2018-10-301-4/+4
|
* cryptsetup-generator: fgets() excorcismLennart Poettering2018-10-181-7/+12
|
* More polite passphrase promptMarko Myllynen2018-10-091-2/+2
| | | | | | | | | | | | Instead of Please enter passphrase for disk <disk-name>! use Please enter passphrase for disk <disk-name>: which is more polite and matches Plymouth convention.
* cryptsetup: use PATH_IN_SET() instead of STR_IN_SET() when comparing pathsLennart Poettering2018-10-051-1/+1
| | | | It's formally more correct.
* cryptsetup: don't use %m if there's no error to showLennart Poettering2018-10-051-2/+4
| | | | | | We are not the ones receiving an error here, but the ones generating it, hence we shouldn't show it with %m, that's just confusing, as it suggests we received an error from some other call.
* tree-wide: do not assign unused return valuesYu Watanabe2018-09-231-11/+5
|
* cryptsetup-generator: introduce basic keydev supportMichal Sekletar2018-09-041-4/+101
| | | | | | | | | | | | | | | | | | | | | Dracut has a support for unlocking encrypted drives with keyfile stored on the external drive. This support is included in the generated initrd only if systemd module is not included. When systemd is used in initrd then attachment of encrypted drives is handled by systemd-cryptsetup tools. Our generator has support for keyfile, however, it didn't support keyfile on the external block device (keydev). This commit introduces basic keydev support. Keydev can be specified per luks.uuid on the kernel command line. Keydev is automatically mounted during boot and we look for keyfile in the keydev mountpoint (i.e. keyfile path is prefixed with the keydev mount point path). After crypt device is attached we automatically unmount where keyfile resides. Example: rd.luks.key=70bc876b-f627-4038-9049-3080d79d2165=/key:LABEL=KEYDEV
* cryptsetup: do not define arg_sector_size if libgcrypt is v1.x (#9990)Yu Watanabe2018-09-011-0/+2
| | | Follow-up for #9936.
* cryptsetup: add support for sector-size= option (#9936)Dimitri John Ledkov2018-08-291-0/+30
| | | | | Bug-Ubuntu: https://launchpad.net/bugs/1776626 Closes #8881.
* tree-wide: add clickable man page link to all --help textsLennart Poettering2018-08-201-3/+13
| | | | | | | | | | This is a bit like the info link in most of GNU's --help texts, but we don't do info but man pages, and we make them properly clickable on terminal supporting that, because awesome. I think it's generally advisable to link up our (brief) --help texts and our (more comprehensive) man pages a bit, so this should be an easy and straight-forward way to do it.
* cryptsetup: Add dependency on loopback setup to generated unitsLorenz Hübschle-Schneider2018-06-271-1/+6
| | | | | | | | For loopback volumes, the generated unit needs to depend on systemd-tmpfiles-setup-dev.service to ensure that loopback support is loaded. Fixes #9308
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-142-6/+0
| | | | | | | | | | | These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-06-142-4/+0
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* tree-wide: drop spurious newlines (#8764)Lennart Poettering2018-04-191-1/+0
| | | | | | | | Double newlines (i.e. one empty lines) are great to structure code. But let's avoid triple newlines (i.e. two empty lines), quadruple newlines, quintuple newlines, …, that's just spurious whitespace. It's an easy way to drop 121 lines of code, and keeps the coding style of our sources a bit tigther.
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-062-26/+0
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* macro: introduce TAKE_PTR() macroLennart Poettering2018-03-221-2/+1
| | | | | | | | | | | | | | | | This macro will read a pointer of any type, return it, and set the pointer to NULL. This is useful as an explicit concept of passing ownership of a memory area between pointers. This takes inspiration from Rust: https://doc.rust-lang.org/std/option/enum.Option.html#method.take and was suggested by Alan Jenkins (@sourcejedi). It drops ~160 lines of code from our codebase, which makes me like it. Also, I think it clarifies passing of ownership, and thus helps readability a bit (at least for the initiated who know the new macro)
* log: remove LOG_TARGET_SAFE pseudo log targetLennart Poettering2018-01-241-1/+2
| | | | | | | | | | | | | This removes LOG_TARGET_SAFE. It's made redundant by the new "prohibit-ipc" logging flag, as it used to have a similar effect: avoid logging to the journal/syslog, i.e. any local services in order to avoid deadlocks when we lock from PID 1 or its utility processes (such as generators). All previous users of LOG_TARGET_SAFE are switched over to the new setting. This makes things a bit safer for all, as not even the SYSTEMD_LOG_TARGET env var can be used to accidentally log to the journal anymore in these programs.
* cryptsetup: small if check improvement (#7747)Lennart Poettering2017-12-271-6/+10
| | | | | | | It's a bit weird to test these strings after the fact instead of before. Let's make sure that we don't even attempt the string escaping if the strings are NULL. Follow-up for #7688
* cryptsetup: use uint64_t for keyfile-offset= (#7689)Zbigniew Jędrzejewski-Szmek2017-12-191-2/+11
| | | | | | On 32bit, refuse large offsets. Once https://gitlab.com/cryptsetup/cryptsetup/issues/359 is resolved, we should switch to the new api, whatever it is. Fixes #7677.
* cryptsetup-generator: Don't mistake NULL input as OOM (#7688)Jan Alexander Steffens2017-12-181-2/+2
| | | | | | | | | | | | | | | | | Since systemd v236, several Arch users complained that systemd-cryptsetup-generator exits with an OOM error and that it prevents the boot from continuing. Investigating the diff of cryptsetup-generator between v235 and v236 I noticed that create_disk allowed for the `password` and `filtered` variables to be NULL (they're handled with `strempty()`) but not their `*_escaped` versions, and returned OOM errors in those cases. Fix this by checking that the input string is non-NULL before deciding that `specifier_escape` had an OOM error. I could not test this fix myself, but some users have reported success. Downstream bug: https://bugs.archlinux.org/task/56733
* generator: add helper function for writing unit filesZbigniew Jędrzejewski-Szmek2017-12-151-16/+9
| | | | | It doesn't save too much, but it's a common pattern so I think it's worth to factor this out.
* tree-wide: use __fsetlocking() instead of fxyz_unlocked()Lennart Poettering2017-12-141-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | Let's replace usage of fputc_unlocked() and friends by __fsetlocking(f, FSETLOCKING_BYCALLER). This turns off locking for the entire FILE*, instead of doing individual per-call decision whether to use normal calls or _unlocked() calls. This has various benefits: 1. It's easier to read and easier not to forget 2. It's more comprehensive, as fprintf() and friends are covered too (as these functions have no _unlocked() counterpart) 3. Philosophically, it's a bit more correct, because it's more a property of the file handle really whether we ever pass it on to another thread, not of the operations we then apply to it. This patch reworks all pieces of codes that so far used fxyz_unlocked() calls to use __fsetlocking() instead. It also reworks all places that use open_memstream(), i.e. use stdio FILE* for string manipulations. Note that this in some way a revert of 4b61c8751135c58be043d86b9fef4c8ec7aadf18.
* cryptsetup: use more descriptive name for the variable and drop redundant ↵Michal Sekletar2017-12-121-32/+7
| | | | | | | | | | | | | | function Let's rename escaped_name to disk_path since this is an actual content that pointer refers to. It is either path to encrypted block device or path to encrypted image file. Also drop redundant function disk_major_minor(). src is always set, and it always points to either encrypted block device path (or symlink to such device) or to encrypted image. In case it is set to device path there is no need to reset it to /dev/block/major:minor symlink since those paths are equivalent.
* cryptsetup: when unlocking always put path to the object into IdMichal Sekletar2017-12-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Some ask-password agents (e.g. clevis-luks-askpass) use Id option from /run/systemd/ask-password/ask* file in order to obtain the password for the device. Id option should be in the following format, e.g. Id=subsystem:data. Where data part is supposed to identify object that ask-password query is done for. Since e51b9486d1b59e72c293028fed1384f4e4ef09aa this field has format Id=cryptsetup:/dev/block/major:minor when systemd-cryptsetup is unlocking encrypted block device. However, crypttab also supports encrypted image files in which case we usually set data part of Id to "vol on mountpoint". This is unexpected and actually breaks network based device encryption as implemented by clevis. Example: $ cat /etc/crypttab clevis-unlocked /clevis-test-disk-image none luks,_netdev $ systemctl start 'systemd-cryptsetup@clevis\x2dunlocked.service' $ grep Id /run/systemd/ask-password/ask* Before: $ Id=cryptsetup:clevis-unlocked on /clevis-test-disk-image-mnt After: $ Id=cryptsetup:/clevis-test-disk-image
* Define CRYPT_LUKS in crypt-util.hZbigniew Jędrzejewski-Szmek2017-11-301-6/+0
| | | | | Also do not include libcryptsetup.h directly, but only through crypt-util.h. This way we do not have to repeat the define in every file where it is used.
* util-lib: export cryptsetup logging glue functionZbigniew Jędrzejewski-Szmek2017-11-301-6/+2
|
* util-lib: add cleanup function for crypt_freeZbigniew Jędrzejewski-Szmek2017-11-301-4/+2
|
* generators: be more careful when writing unit settings that support ↵Lennart Poettering2017-11-291-7/+25
| | | | | | | | specifier expansion Let's always escape strings we receive from the user before writing them out to unit file settings that suppor specifier expansion, so that user strings are transported as-is.
* cryptsetup-generator: add helper function and use hashmap_free_with_destructorZbigniew Jędrzejewski-Szmek2017-11-281-13/+7
|
* Replace free and reassignment with free_and_replaceDaniel Lockyer2017-11-241-3/+1
|
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-192-0/+2
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* Merge pull request #7089 from oniko/luks2-supportLennart Poettering2017-11-101-6/+14
|\ | | | | LUKS2 support for systemd-cryptsetup and dissect-image
| * cryptsetup: support LUKS2 on-disk formatOndrej Kozina2017-10-131-6/+14
| | | | | | | | | | | | | | | | Allow cryptsetup utility to activate LUKS2 devices (with appropriate libcryptsetup) The change itself doesn't enforce new libcryptsetup 2.x and is backward compatible with versions 1.x
* | cryptsetup: ignore _netdev, since it is used in generator (#7282)Lukáš Nykrýn2017-11-091-1/+1
| |
* | units: replace remote-cryptsetup-pre.target with remote-fs-pre.targetZbigniew Jędrzejewski-Szmek2017-10-171-1/+1
|/ | | | | | | | | | | | | | | | | remote-cryptsetup-pre.target was designed as an active unit (that pulls in network-online.target), the opposite of remote-fs-pre.target (a passive unit, with individual provider services ordering itself before it and pulling it in, for example iscsi.service and nfs-client.target). To make remote-cryptsetup-pre.target really work, those services should be ordered before it too. But this would require updates to all those services, not just changes from systemd side. But the requirements for remote-fs-pre.target and remote-cryptset-pre.target are fairly similar (e.g. iscsi devices can certainly be used for both), so let's reuse remote-fs-pre.target also for remote cryptsetup units. This loses a bit of flexibility, but does away with the requirement for various provider services to know about remote-cryptsetup-pre.target.
* tree-wide: use IN_SET macro (#6977)Yu Watanabe2017-10-041-1/+1
|
* tree-wide: use IN_SET where possibleAndreas Rammhold2017-10-021-1/+1
| | | | | In addition to the changes from #6933 this handles cases that could be matched with the included cocci file.
* cryptsetup: make sure we invoke the cryptsetup tools with a shared keyringLennart Poettering2017-09-151-0/+1
| | | | | | | | We want that cryptsetup can cache keys between multiple invocations, and it does so via the root user's user keyring, hence let's share it among services. Replaces: #6286
* cryptsetup: fix unused variable (#6833)Martin Pitt2017-09-151-0/+2
| | | | | | | | When building without veracrypt, gcc warns ../src/cryptsetup/cryptsetup.c:55:13: warning: ‘arg_tcrypt_veracrypt’ defined but not used [-Wunused-variable] static bool arg_tcrypt_veracrypt = false; Fix this by conditionalizing the declaration.
* cryptsetup-generator: use remote-cryptsetup.target when _netdev is presentZbigniew Jędrzejewski-Szmek2017-09-051-13/+17
| | | | | | | This allows such devices to depend on the network. Their startup will be delayed similarly to network mount units. Fixes #4642.
* 6647 - use path_startswith("/dev") in cryptsetup (#6732)ettavolt2017-09-041-2/+2
| | | For both key and partition paths.
* cryptsetup-generator: do not bind to the decrypted device unit (#6538)Ivan Shapovalov2017-08-301-1/+0
| | | | | | | This breaks things when the decrypted device is not immediately `SYSTEMD_READY=1` (e. g. when a multi-device btrfs system is placed on multiple cryptsetup devices). Fixes #6537.