Commit Graph

105 Commits

Author SHA1 Message Date
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 c14ebe07a9
Merge pull request #17172 from keszybz/read-login-defs
Read /etc/login.defs
2020-10-02 11:01:30 +02:00
Zbigniew Jędrzejewski-Szmek a3709e3709 tests: when creating temp dirs, include test name in path
This makes it easier to figure out which directory we want to look at
when tests fail, and also which test left behind a directory when it
shouldn't.
2020-10-01 19:53:45 +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 d161680e7a tree-wide: if get_block_device() returns zero devno, check for it in all cases
And add a comment for the existing cases where things aren't clear
already.
2020-09-08 18:10:26 +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
Ikey Doherty 677bb0555a partition/makefs: Include missing sys/file.h header
This file must be included on non-glibc systems to ensure
the `LOCK_EX` definition is available.

Signed-off-by: Ikey Doherty <ikey.doherty@lispysnake.com>
2020-08-28 13:32:09 +02:00
Daan De Meyer f17bdf8264 Don't run test-repart when loop devices are not available 2020-08-27 17:14:58 +02:00
Lennart Poettering f7011e17f1 test: add test for new repart features 2020-08-24 22:00:49 +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 da49710ef2 makefs: port to generic make_filesystem() call 2020-08-24 22:00:07 +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
Luca Boccassi efc3b12fdb tree-wide: enable/disable libcrypsetup debug output depending on our level
Avoid always setting to debug, as it will incur in many more callbacks from
libcrypsetup that then get discarded, wasting resources.
2020-08-14 15:26:04 +01: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 e4ec8b1f51 test-repart: also print json output
This doesn't really "test" anything, but a human can look at it.
2020-07-30 16:03:53 +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
Zbigniew Jędrzejewski-Szmek f93dd4b940
Merge pull request #16282 from poettering/repart-copy-blocks
repart: add new CopyBlocks= setting
2020-06-30 15:26:06 +02:00
Zbigniew Jędrzejewski-Szmek 26b0fda9b7 test-repart: allow the test to pass on non-amd64 architectures
We specified type=root and expected to always get root-x86-64, which obviously
cannot work.
2020-06-30 11:06:48 +02: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 6b000af4f2 tree-wide: avoid some loaded terms
https://tools.ietf.org/html/draft-knodel-terminology-02
https://lwn.net/Articles/823224/

This gets rid of most but not occasions of these loaded terms:

1. scsi_id and friends are something that is supposed to be removed from
   our tree (see #7594)

2. The test suite defines an API used by the ubuntu CI. We can remove
   this too later, but this needs to be done in sync with the ubuntu CI.

3. In some cases the terms are part of APIs we call or where we expose
   concepts the kernel names the way it names them. (In particular all
   remaining uses of the word "slave" in our codebase are like this,
   it's used by the POSIX PTY layer, by the network subsystem, the mount
   API and the block device subsystem). Getting rid of the term in these
   contexts would mean doing some major fixes of the kernel ABI first.

Regarding the replacements: when whitelist/blacklist is used as noun we
replace with with allow list/deny list, and when used as verb with
allow-list/deny-list.
2020-06-25 09:00:19 +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 7b5cb4ceb4 Repart: Add simple tests for Label="" and UUID=""
Make sure Labels and UUIDs taken from destination definitions are
taken into account when no Label/UUID is currently set already.
2020-05-25 15:48:59 +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
Zbigniew Jędrzejewski-Szmek 7f6b827f36
Merge pull request #15836 from poettering/makefs-lock
lock whole block device file running makefs
2020-05-19 15:23:23 +02:00