Commit Graph

53 Commits

Author SHA1 Message Date
Lennart Poettering 6a01ea4a2f json: port various tools to the new JSON_FORMAT_OFF flag
These are the obvious cases.
2021-01-09 17:36:24 +01:00
Lennart Poettering 889914ef6c repart: optionally lock encrypted partitions to TPM2
This useful for bootstrapping encrypted systems: on first boot let's
create a /var/ partition that is locked to the local TPM2.
2020-12-17 20:02:20 +01:00
Lennart Poettering 986311c2da fileio: teach read_full_file_full() to read from offset/with maximum size 2020-12-01 14:17:47 +01:00
Lennart Poettering 8b3c3a4973 repart: warn about world writable key files
We have easy support for this, hence use it for privileged key data.
2020-12-01 14:17:46 +01:00
Lennart Poettering 2824aa0796 specifiers: introduce common macros for generating specifier tables
In many cases the tables are largely the same, hence define a common set
of macros to generate the common parts.

This adds in a couple of missing specifiers here and there, so is more
thant just refactoring: it actually fixes accidental omissions.

Note that some entries that look like they could be unified under these
macros can't really be unified, since they are slightly different. For
example in the DNSSD service logic we want to use the DNSSD hostname for
%H rather than the unmodified kernel one.
2020-11-25 14:13:02 +09:00
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Lennart Poettering d3dcf4e3b9 fileio: beef up READ_FULL_FILE_CONNECT_SOCKET to allow setting sender socket name
This beefs up the READ_FULL_FILE_CONNECT_SOCKET logic of
read_full_file_full() a bit: when used a sender socket name may be
specified. If specified as NULL behaviour is as before: the client
socket name is picked by the kernel. But if specified as non-NULL the
client can pick a socket name to use when connecting. This is useful to
communicate a minimal amount of metainformation from client to server,
outside of the transport payload.

Specifically, these beefs up the service credential logic to pass an
abstract AF_UNIX socket name as client socket name when connecting via
READ_FULL_FILE_CONNECT_SOCKET, that includes the requesting unit name
and the eventual credential name. This allows servers implementing the
trivial credential socket logic to distinguish clients: via a simple
getpeername() it can be determined which unit is requesting a
credential, and which credential specifically.

Example: with this patch in place, in a unit file "waldo.service" a
configuration line like the following:

    LoadCredential=foo:/run/quux/creds.sock

will result in a connection to the AF_UNIX socket /run/quux/creds.sock,
originating from an abstract namespace AF_UNIX socket:

    @$RANDOM/unit/waldo.service/foo

(The $RANDOM is replaced by some randomized string. This is included in
the socket name order to avoid namespace squatting issues: the abstract
socket namespace is open to unprivileged users after all, and care needs
to be taken not to use guessable names)

The services listening on the /run/quux/creds.sock socket may thus
easily retrieve the name of the unit the credential is requested for
plus the credential name, via a simpler getpeername(), discarding the
random preifx and the /unit/ string.

This logic uses "/" as separator between the fields, since both unit
names and credential names appear in the file system, and thus are
designed to use "/" as outer separators. Given that it's a good safe
choice to use as separators here, too avoid any conflicts.

This is a minimal patch only: the new logic is used only for the unit
file credential logic. For other places where we use
READ_FULL_FILE_CONNECT_SOCKET it is probably a good idea to use this
scheme too, but this should be done carefully in later patches, since
the socket names become API that way, and we should determine the right
amount of info to pass over.
2020-11-03 09:48:04 +01:00
Harald Seiler 448b782cb2 repart: correctly handle "uninitialized" machine-id
When systemd-repart runs from initramfs, it reads out /etc/machine-id
from the rootfs as a seed for partition UUIDs.  However, the machine-id
could be in an "uninitialized" state from a previous failed first boot.
In this situation the -ENOMEDIUM code-path (no machine-id set) should be
taken.
2020-10-19 16:28:21 +02:00
Lennart Poettering 911ba62408 repart: use proper API to check if block device can do partition scanning
We have the API wrapper already, hence use it, instead of using a
limited version of it that only works for loopback devices.
2020-09-26 18:31:48 +02:00
Lennart Poettering 511a8cfe30 mount-util: switch most mount_verbose() code over to not follow symlinks 2020-09-23 18:57:36 +02:00
masmullin2000 3dd8ae5c70
Fix compilation without libcryptsetup (#17071) 2020-09-17 09:07:03 +02:00
Lennart Poettering 5332d7c6ff repart: don't mark image files generated with --empty=create executable 2020-09-16 18:48:36 +02:00
Frantisek Sumsal 69e3234db7 tree-wide: fix typos found by codespell
Reported by Fossies.org
2020-09-14 15:32:37 +02:00
Zbigniew Jędrzejewski-Szmek f8bff7805e
Merge pull request #16933 from poettering/copy-hardlinks
copy: optionally recreate hardlinks when copying file trees
2020-09-10 19:04:52 +02:00
Yu Watanabe e459258f19 repart: downgrade log level 2020-09-10 15:08:13 +09:00
Lennart Poettering 652d90407a tree-wide: copy hardlinks wherever we deal with possibly large OS-style trees
Fixes: #7382
2020-09-09 20:21:49 +02:00
Lennart Poettering 67f0ac8c79 btrfs: if BTRFS_IOC_DEV_INFO returns /dev/root generate a friendly error message
On systems that boot without initrd on a btrfs root file systems the
BTRFS_IOC_DEV_INFO ioctl returns /dev/root as backing device. That
sucks, since that is not a real device visible to userspace.

Since this has been that way since forever, and it doesn't look like the
kernel will get fixed soon for this, let's at least generate a useful
error message in this case.

This is not a bug fix, just a tweak to make this more recognizable.

Once the kernel gets fixed to report the correct device nodes in this
case, in a way userspace can make sense of them things will magically
work for systemd, too.

(Note that this doesn't add a log message about this to really all cases
we call get_device() in, but just the main ones that are called in early
boot context, after all all there's no benefit in seeing this message
too many times.)

https://github.com/systemd/systemd/issues/16953
https://bugs.freedesktop.org/show_bug.cgi?id=84689
https://bugzilla.kernel.org/show_bug.cgi?id=89721
2020-09-08 18:10:26 +02:00
Lennart Poettering 0d12936d9a shared: make libcryptsetup dep dlopen
Let's make libcryptsetup a dlopen() style dep for PID 1 (i.e. for
RootImage= and stuff), systemd-growfs and systemd-repart. (But leave to
be a regulra dep in systemd-cryptsetup, systemd-veritysetup and
systemd-homed since for them the libcryptsetup support is not auxiliary
but pretty much at the core of what they do.)

This should be useful for container images that want systemd in the
payload but don't care for the cryptsetup logic since dm-crypt and stuff
isn't available in containers anyway.

Fixes: #8249
2020-09-02 15:04:06 +02:00
Lennart Poettering 1e2f32305c shared: rename crypt-util.c → cryptsetup-util.c
"crypt-util.c" is such a generic name, let's avoid that, in particular
as libc's/libcrypt's crypt() function is so generically named too that
one might thing this is about that. Let's hence be more precise, and
make clear that this is about cryptsetup, and nothing else.

We already had cryptsetup-util.[ch] in src/cryptsetup/ doing keyfile
management. To avoid the needless confusion, let's rename that file to
cryptsetup-keyfile.[ch].
2020-09-02 15:00:32 +02:00
Lennart Poettering 170c982345 repart: if --size= is specified as "auto" determine minimal size for disk image
When assembling a disk image locally, using --size=auto can be used to
generate the minimal image based on the provided definitions. THis is
useful to prepare images that are grown on first boot.
2020-08-24 22:00:45 +02:00
Lennart Poettering b9df353689 repart: add support for optionally encrypting partitions we create 2020-08-24 22:00:42 +02:00
Lennart Poettering 8a794850e7 repart: add new CopyFiles= setting, for copying files into freshly made file systems
This makes the tool a lot more useful for streaming OS images onto
disks.
2020-08-24 22:00:38 +02:00
Lennart Poettering f0cb1b951c repart: wipe partition first, then discard
Wiping means writing zero sectors to disk. Hence it's better to do this
before we discard, so that the zeroes we use to overwrite are properly
discarded. If we'd do it the other way round we'd discard the data and
then reallocte it just to write zeroes.
2020-08-24 22:00:31 +02:00
Lennart Poettering 5b5109e225 repart: talk about future partitions
We initialize the partition contents before the partitions actually
exist, hence to reduce confusion let's talk about "future partitions" up
to the point where they are actually realized.
2020-08-24 22:00:28 +02:00
Lennart Poettering 81873a6b6c repart: let's wipe the partition table ourselves
Let's issue the wiping ourselves, so that we know it's done before we
write partition data onto the disk, and before the disk label
is written. Before this commit the writing of the disk label would imply
the wiping step, potentially overriding again what we just wrote into
the disk data section.

(Normally this shouldn't matter, since the partition table metadata
that the wiping process deletes is at the start and end of the disk
while we write our data to the middle, but you never know what kind of
weird signatures might exist that depart from that.)

(And effectively this ends up using the same wiping code, since that's
implemented in libblkkid, and libfdisk just acts as frontend to that
anyway. We now simply call it directly.)
2020-08-24 22:00:24 +02:00
Lennart Poettering f28d4f42f4 repart: split out code that mangles part table entries into function of its own
Just some refactoring, no actual code change.
2020-08-24 22:00:21 +02:00
Lennart Poettering 53171c0453 repart: add support for formatting newly created partitions 2020-08-24 22:00:14 +02:00
Lennart Poettering aa2a74ad9d repart: make error code when operating on non-existing file a bit more useful 2020-08-24 22:00:10 +02:00
Lennart Poettering 15d43e3065 repart: don't unload data we configured explicitly, and fully free all data we match to disk
The context_unload_partition_table() call is supposed to remove all
data from the loaded partitions about how we mapped it to existing
partitions on disk, but it should leave everything we parsed from the
definition files in place.

We mostly got this right, except for two cases:

1. new_uuid is parsed from the definition files and should stay

2. current_label is read from the existing partition table and should be
   freed
2020-08-24 21:58:53 +02:00
Lennart Poettering de8231b007 dissect: add support for outputting JSON 2020-08-12 22:39:43 +02:00
Zbigniew Jędrzejewski-Szmek 18dbc899ff
Merge pull request #16258 from hunger/master
systemd-repart: Add an option to generate a JSON report
2020-08-03 10:05:32 +02:00
Zbigniew Jędrzejewski-Szmek 2d2d0a57e7 repart: adjust --help and test output width 2020-07-30 16:02:45 +02:00
Lennart Poettering c8f3d7672c repart: log fixes 2020-07-30 15:17:08 +02:00
Tobias Hunger a015fbe7ef Repart: Add support for machine readably report
Add --json command line argument that prints all relevant information
in a machine-readable format.
2020-07-30 12:26:15 +02:00
Zbigniew Jędrzejewski-Szmek 46072ae35a repart: include more relevant information in the warning message, fix test
The test would always fail with a long uname. In F33 this is right
now "5.8.0-0.rc2.20200622git625d3449788f.1.fc33.x86_64" which caused the
test to always fail.
2020-07-13 03:43:26 +09:00
fangxiuning f987a261b4 userdbctl homectl use table_log_add_error()
Signed-off-by: fangxiuning <fangxiuning123@126.com>
2020-07-06 21:32:22 +08:00
Lennart Poettering 757bc2e4c1 repart: add new CopyBlocks= setting
This allows copying in arbitrary file systems on the block level into
newly created partitions.

Usecase: simple replicating OS installers or OS image builders.
2020-06-25 18:52:52 +02:00
Lennart Poettering fb08381c14 repart: if now minimal size is specified, default to 10M
Prompted by this discussion:

https://lists.freedesktop.org/archives/systemd-devel/2020-June/044669.html
2020-06-16 15:48:58 +02:00
Lennart Poettering e031166e15 repart: add simple specifier expansion in Label=
Strictly speaking this is a compat breakage, but given the tool was
added only in the last release, let's try to sail under the radar, and
fix this early before anyone notices it wasn't supported always.
2020-06-16 15:48:10 +02:00
Lennart Poettering 4f9ff96a55 conf-parser: return mtime in config_parse() and friends
This is a follow-up for 9f83091e3c.

Instead of reading the mtime off the configuration files after reading,
let's do so before reading, but with the fd we read the data from. This
is not only cleaner (as it allows us to save one stat()), but also has
the benefit that we'll detect changes that happen while we read the
files.

This also reworks unit file drop-ins to use the common code for
determining drop-in mtime, instead of reading system clock for that.
2020-06-02 19:32:20 +02:00
Tobias Hunger 129635333d repart: Add UUID option to config files
Add a option to provide a UUID for the partition that will get
created and document that.
2020-05-25 15:48:59 +02:00
Lennart Poettering feb13fca97 repart: don't insist on coming up on partition label ourselves
If the user specified a label, use that.

Fixes: #15841
2020-05-19 15:04:01 +02:00
Lennart Poettering a26f4a49f4 repart: add support for create/growing loopback files
This adds --empty=create and --size= for creating loopback files from
scratch of a specified size, or growing loopback files to the specified
size when they already exist.

This is useful when operating on disk image files, as a manual
invocation of fallocate(1) becomes unnecessary.
2020-05-14 23:59:23 +02:00
Lennart Poettering 9a1deb8578 repart: suppress complaints about lack of BLKRRPART when operating on regular file 2020-05-14 23:01:09 +02:00
Lennart Poettering e2d65cd299 repart: explain when we exit early and don't do a thing 2020-05-14 23:00:52 +02:00
Benjamin Robin f391597c67 tree-wide: Fix, replace assert() by assert_se() when there is side effect 2020-05-06 23:03:25 +02:00
Emmanuel Garette db1442260a repart: fix partition maximum size segfault
Discovered, tracked down and fix proposed by Emmanuel Garette.

See: https://lists.freedesktop.org/archives/systemd-devel/2020-April/044435.html

(Lennart turned this into a PR)

Fixes: #15608
2020-05-01 17:31:45 +02:00
Zbigniew Jędrzejewski-Szmek 162392b75a tree-wide: spellcheck using codespell
Fixes #15436.
2020-04-16 18:00:40 +02:00
Alin Popa ad5555b42e systemd: Fix busctl crash on aarch64 when setting output table format
The enum used for column names is integer type while table_set_display() is parsing
arguments on size_t alignment which may result in assert in table_set_display() if
the size between types missmatch. This patch cast the enums to size_t.
It also fixes all other occurences for table_set_display() and
table_set_sort().
2020-02-16 02:09:26 +09:00
Yu Watanabe 03b76a1977 repart: do not quit earlier when --empty=force
Follow-up for 0ae5ffe063.
2020-02-07 13:48:16 +01:00