Debian Codegraph @

src/shared/varlink-io.systemd.MountFileSystem.c

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include "bus-polkit.h"
4 #include "varlink-io.systemd.MountFileSystem.h"
5
6 SD_VARLINK_DEFINE_ENUM_TYPE(
7 PartitionDesignator,
8 SD_VARLINK_DEFINE_ENUM_VALUE(root),
9 SD_VARLINK_DEFINE_ENUM_VALUE(usr),
10 SD_VARLINK_DEFINE_ENUM_VALUE(home),
11 SD_VARLINK_DEFINE_ENUM_VALUE(srv),
12 SD_VARLINK_DEFINE_ENUM_VALUE(esp),
13 SD_VARLINK_DEFINE_ENUM_VALUE(xbootldr),
14 SD_VARLINK_DEFINE_ENUM_VALUE(swap),
15 SD_VARLINK_DEFINE_ENUM_VALUE(root_verity),
16 SD_VARLINK_DEFINE_ENUM_VALUE(usr_verity),
17 SD_VARLINK_DEFINE_ENUM_VALUE(root_verity_sig),
18 SD_VARLINK_DEFINE_ENUM_VALUE(usr_verity_sig),
19 SD_VARLINK_DEFINE_ENUM_VALUE(tmp),
20 SD_VARLINK_DEFINE_ENUM_VALUE(var));
21
22 static SD_VARLINK_DEFINE_STRUCT_TYPE(
23 PartitionInfo,
24 SD_VARLINK_FIELD_COMMENT("The designator of this partition."),
25 SD_VARLINK_DEFINE_FIELD_BY_TYPE(designator, PartitionDesignator, 0),
26 SD_VARLINK_FIELD_COMMENT("Indicates whether this partition is marked for writable (non-read-only) operations."),
27 SD_VARLINK_DEFINE_FIELD(writable, SD_VARLINK_BOOL, 0),
28 SD_VARLINK_FIELD_COMMENT("Indicates whether this partition is marked for automatic growing."),
29 SD_VARLINK_DEFINE_FIELD(growFileSystem, SD_VARLINK_BOOL, 0),
30 SD_VARLINK_FIELD_COMMENT("Indicates the numeric partition number of this partition, or null if the image does not carry a partition table, and this object covers the whole block device."),
31 SD_VARLINK_DEFINE_FIELD(partitionNumber, SD_VARLINK_INT, SD_VARLINK_NULLABLE),
32 SD_VARLINK_FIELD_COMMENT("Indicates the intended CPU architecture of the partition, in case the partition type encodes such information."),
33 SD_VARLINK_DEFINE_FIELD(architecture, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
34 SD_VARLINK_FIELD_COMMENT("The partition UUID identifying the partition."),
35 SD_VARLINK_DEFINE_FIELD(partitionUuid, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
36 SD_VARLINK_FIELD_COMMENT("The file system type for the mount"),
37 SD_VARLINK_DEFINE_FIELD(fileSystemType, SD_VARLINK_STRING, 0),
38 SD_VARLINK_FIELD_COMMENT("The partition label string of this partition."),
39 SD_VARLINK_DEFINE_FIELD(partitionLabel, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
40 SD_VARLINK_FIELD_COMMENT("The size of the partition in bytes."),
41 SD_VARLINK_DEFINE_FIELD(size, SD_VARLINK_INT, 0),
42 SD_VARLINK_FIELD_COMMENT("The start offset of the partition in bytes."),
43 SD_VARLINK_DEFINE_FIELD(offset, SD_VARLINK_INT, 0),
44 SD_VARLINK_FIELD_COMMENT("A mount file descriptor to assign to a location."),
45 SD_VARLINK_DEFINE_FIELD(mountFileDescriptor, SD_VARLINK_INT, 0),
46 SD_VARLINK_FIELD_COMMENT("A relative path indicating the intended mount point for this file system, if applicable. May contain multiple paths, for certain partitions that can be mounted to multiple distinct places."),
47 SD_VARLINK_DEFINE_FIELD(mountPoint, SD_VARLINK_STRING, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY));
48
49 static SD_VARLINK_DEFINE_METHOD(
50 MountImage,
51 SD_VARLINK_FIELD_COMMENT("File descriptor of the image file to mount and to assign to the user namespace. Must be a regular, i.e. non-O_PATH file descriptor."),
52 SD_VARLINK_DEFINE_INPUT(imageFileDescriptor, SD_VARLINK_INT, 0),
53 SD_VARLINK_FIELD_COMMENT("File descriptor to the user namespace to assign this image to. If not specified uses the host user namespace."),
54 SD_VARLINK_DEFINE_INPUT(userNamespaceFileDescriptor, SD_VARLINK_INT, SD_VARLINK_NULLABLE),
55 SD_VARLINK_FIELD_COMMENT("Mounts the image read-only."),
56 SD_VARLINK_DEFINE_INPUT(readOnly, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE),
57 SD_VARLINK_FIELD_COMMENT("Grows the contained file systems if necessary and indicated, before mounting them."),
58 SD_VARLINK_DEFINE_INPUT(growFileSystems, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE),
59 SD_VARLINK_FIELD_COMMENT("Takes a literal password in case of an encrypted image"),
60 SD_VARLINK_DEFINE_INPUT(password, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
61 SD_VARLINK_FIELD_COMMENT("Takes an image policy string (see systemd.image-policy(7) for details) to apply while mounting the image"),
62 SD_VARLINK_DEFINE_INPUT(imagePolicy, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
63 SD_VARLINK_FIELD_COMMENT("The mount options to be used for the partitions of the image, keyed by the partition designator. Requires elevated privileges via polkit if specified, the polkit request details will list them in the 'mount_options' field."),
64 SD_VARLINK_DEFINE_INPUT(mountOptions, SD_VARLINK_STRING, SD_VARLINK_MAP|SD_VARLINK_NULLABLE),
65 SD_VARLINK_FIELD_COMMENT("Whether to relax the extension release checks when mounting the image."),
66 SD_VARLINK_DEFINE_INPUT(relaxExtensionReleaseChecks, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE),
67 SD_VARLINK_FIELD_COMMENT("Whether to automatically reuse already set up dm-verity devices that share the same roothash."),
68 SD_VARLINK_DEFINE_INPUT(veritySharing, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE),
69 SD_VARLINK_FIELD_COMMENT("File descriptor of the file containing the dm-verity data, if the image is a bare filesystem rather than a DDI."),
70 SD_VARLINK_DEFINE_INPUT(verityDataFileDescriptor, SD_VARLINK_INT, SD_VARLINK_NULLABLE),
71 SD_VARLINK_FIELD_COMMENT("The expected dm-verity root hash as an hex encoded string, if the image is a bare filesystem rather than a DDI."),
72 SD_VARLINK_DEFINE_INPUT(verityRootHash, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
73 SD_VARLINK_FIELD_COMMENT("The expected signature for the dm-verity root hash as a Base64 encoded string, if the image is a bare filesystem rather than a DDI."),
74 SD_VARLINK_DEFINE_INPUT(verityRootHashSignature, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
75 VARLINK_DEFINE_POLKIT_INPUT,
76 SD_VARLINK_FIELD_COMMENT("An array with information about contained partitions that have been prepared for mounting, as well as their mount file descriptors."),
77 SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(partitions, PartitionInfo, SD_VARLINK_ARRAY),
78 SD_VARLINK_FIELD_COMMENT("Indicates whether the image contains only a single file system, i.e. no partition table."),
79 SD_VARLINK_DEFINE_OUTPUT(singleFileSystem, SD_VARLINK_BOOL, 0),
80 SD_VARLINK_FIELD_COMMENT("The used image policy."),
81 SD_VARLINK_DEFINE_OUTPUT(imagePolicy, SD_VARLINK_STRING, 0),
82 SD_VARLINK_FIELD_COMMENT("The size of the image in bytes."),
83 SD_VARLINK_DEFINE_OUTPUT(imageSize, SD_VARLINK_INT, 0),
84 SD_VARLINK_FIELD_COMMENT("The sector size of the image in bytes"),
85 SD_VARLINK_DEFINE_OUTPUT(sectorSize, SD_VARLINK_INT, 0),
86 SD_VARLINK_FIELD_COMMENT("The name of the image"),
87 SD_VARLINK_DEFINE_OUTPUT(imageName, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
88 SD_VARLINK_FIELD_COMMENT("The UUID of the image"),
89 SD_VARLINK_DEFINE_OUTPUT(imageUuid, SD_VARLINK_STRING, SD_VARLINK_NULLABLE));
90
91 static SD_VARLINK_DEFINE_ENUM_TYPE(
92 MountMapMode,
93 SD_VARLINK_FIELD_COMMENT("Map the caller's UID to root in the user namespace, do not map anything else."),
94 SD_VARLINK_DEFINE_ENUM_VALUE(root),
95 SD_VARLINK_FIELD_COMMENT("Map the foreign UID range to the base UID range in the user namespace (i.e. UID zero and above), covering 64K users."),
96 SD_VARLINK_DEFINE_ENUM_VALUE(foreign),
97 SD_VARLINK_FIELD_COMMENT("Apply an identity (1:1) mapping, but limit it to 64K users."),
98 SD_VARLINK_DEFINE_ENUM_VALUE(identity),
99 SD_VARLINK_FIELD_COMMENT("Determine automatically based on provided directory and caller."),
100 SD_VARLINK_DEFINE_ENUM_VALUE(auto));
101
102 static SD_VARLINK_DEFINE_METHOD(
103 MountDirectory,
104 SD_VARLINK_FIELD_COMMENT("Directory file descriptor of the directory to assign to the user namespace. Must be a regular, i.e. non-O_PATH file descriptor."),
105 SD_VARLINK_DEFINE_INPUT(directoryFileDescriptor, SD_VARLINK_INT, 0),
106 SD_VARLINK_FIELD_COMMENT("File descriptor to the user namespace to assign this directory to. If not specified uses the host user namespace."),
107 SD_VARLINK_DEFINE_INPUT(userNamespaceFileDescriptor, SD_VARLINK_INT, SD_VARLINK_NULLABLE),
108 SD_VARLINK_FIELD_COMMENT("Whether to mark the resulting mount file descriptor as read-only. If not specified defaults to false."),
109 SD_VARLINK_DEFINE_INPUT(readOnly, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE),
110 SD_VARLINK_FIELD_COMMENT("Which kind of UID/GID mapping to apply to the resulting mount file descriptor."),
111 SD_VARLINK_DEFINE_INPUT_BY_TYPE(mode, MountMapMode, SD_VARLINK_NULLABLE),
112 VARLINK_DEFINE_POLKIT_INPUT,
113 SD_VARLINK_FIELD_COMMENT("The freshly allocated mount file descriptor for the mount."),
114 SD_VARLINK_DEFINE_OUTPUT(mountFileDescriptor, SD_VARLINK_INT, 0));
115
116 static SD_VARLINK_DEFINE_METHOD(
117 MakeDirectory,
118 SD_VARLINK_FIELD_COMMENT("File descriptor of the directory to create the new directory in. Must be a regular, i.e. non-O_PATH file descriptor."),
119 SD_VARLINK_DEFINE_INPUT(parentFileDescriptor, SD_VARLINK_INT, 0),
120 SD_VARLINK_FIELD_COMMENT("Name of the directory to create."),
121 SD_VARLINK_DEFINE_INPUT(name, SD_VARLINK_STRING, 0),
122 SD_VARLINK_FIELD_COMMENT("Access mode of the directory to create. Note that the suid, sgid, sticky, world-writable bit is unconditionally masked off."),
123 SD_VARLINK_DEFINE_INPUT(mode, SD_VARLINK_INT, SD_VARLINK_NULLABLE),
124 VARLINK_DEFINE_POLKIT_INPUT,
125 SD_VARLINK_FIELD_COMMENT("File descriptor referencing the newly created directory."),
126 SD_VARLINK_DEFINE_OUTPUT(directoryFileDescriptor, SD_VARLINK_INT, 0));
127
128 static SD_VARLINK_DEFINE_ERROR(IncompatibleImage);
129 static SD_VARLINK_DEFINE_ERROR(MultipleRootPartitionsFound);
130 static SD_VARLINK_DEFINE_ERROR(RootPartitionNotFound);
131 static SD_VARLINK_DEFINE_ERROR(DeniedByImagePolicy);
132 static SD_VARLINK_DEFINE_ERROR(KeyNotFound);
133 static SD_VARLINK_DEFINE_ERROR(VerityFailure);
134 static SD_VARLINK_DEFINE_ERROR(BadFileDescriptorFlags,
135 SD_VARLINK_FIELD_COMMENT("Name of the parameter referencing the file descriptor with one or more bad flags."),
136 SD_VARLINK_DEFINE_FIELD(parameter, SD_VARLINK_STRING, 0));
137
138 SD_VARLINK_DEFINE_INTERFACE(
139 io_systemd_MountFileSystem,
140 "io.systemd.MountFileSystem",
141 SD_VARLINK_INTERFACE_COMMENT("APIs for unprivileged mounting."),
142 SD_VARLINK_SYMBOL_COMMENT("Encodes the designated purpose of a partition."),
143 &vl_type_PartitionDesignator,
144 SD_VARLINK_SYMBOL_COMMENT("Information about a specific partition."),
145 &vl_type_PartitionInfo,
146 SD_VARLINK_SYMBOL_COMMENT("Selects the type of UID/GID mapping to apply."),
147 &vl_type_MountMapMode,
148 SD_VARLINK_SYMBOL_COMMENT("Takes a disk image file descriptor as input, returns a set of mount file descriptors for it, plus meta information about the image and the partitions selected for mounting."),
149 &vl_method_MountImage,
150 SD_VARLINK_SYMBOL_COMMENT("Takes a directory file descriptor as input, returns a mount file descriptor."),
151 &vl_method_MountDirectory,
152 SD_VARLINK_SYMBOL_COMMENT("Creates an empty directory, owned by the foreign UID/GID range's root user, returns an open file descriptor to the directory. Access mode will be set to 0700."),
153 &vl_method_MakeDirectory,
154 SD_VARLINK_SYMBOL_COMMENT("Disk image is not compatible with this service."),
155 &vl_error_IncompatibleImage,
156 SD_VARLINK_SYMBOL_COMMENT("Multiple suitable root partitions found."),
157 &vl_error_MultipleRootPartitionsFound,
158 SD_VARLINK_SYMBOL_COMMENT("No suitable root partition found."),
159 &vl_error_RootPartitionNotFound,
160 SD_VARLINK_SYMBOL_COMMENT("The specified image policy disallows mounting this disk image"),
161 &vl_error_DeniedByImagePolicy,
162 SD_VARLINK_SYMBOL_COMMENT("The authentication key for this image is not available."),
163 &vl_error_KeyNotFound,
164 SD_VARLINK_SYMBOL_COMMENT("Verity could not be set up."),
165 &vl_error_VerityFailure,
166 SD_VARLINK_SYMBOL_COMMENT("A passed file descriptor has unexpected/forbidden flags set."),
167 &vl_error_BadFileDescriptorFlags);