/src/rauc/include/manifest.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include <glib.h> |
4 | | |
5 | | #include "checksum.h" |
6 | | |
7 | | #define R_MANIFEST_ERROR r_manifest_error_quark() |
8 | | GQuark r_manifest_error_quark(void); |
9 | | |
10 | 0 | #define R_MANIFEST_ERROR_NO_DATA 0 |
11 | 0 | #define R_MANIFEST_ERROR_CHECKSUM 1 |
12 | | #define R_MANIFEST_ERROR_COMPATIBLE 2 |
13 | | #define R_MANIFEST_PARSE_ERROR 3 |
14 | | #define R_MANIFEST_EMPTY_STRING 4 |
15 | 0 | #define R_MANIFEST_CHECK_ERROR 5 |
16 | | |
17 | | typedef struct { |
18 | | gboolean install_check; |
19 | | } InstallHooks; |
20 | | |
21 | | typedef struct { |
22 | | gboolean pre_install; |
23 | | gboolean install; |
24 | | gboolean post_install; |
25 | | } SlotHooks; |
26 | | |
27 | | typedef struct { |
28 | | gchar* slotclass; |
29 | | gchar* artifact; |
30 | | gchar* variant; |
31 | | RaucChecksum checksum; |
32 | | gchar* filename; |
33 | | SlotHooks hooks; |
34 | | GStrv adaptive; |
35 | | GStrv convert; |
36 | | /* String array of converted filenames. Not NULL-terminated! */ |
37 | | GPtrArray* converted; |
38 | | } RaucImage; |
39 | | |
40 | | typedef enum { |
41 | | R_MANIFEST_FORMAT_PLAIN = 0, |
42 | | R_MANIFEST_FORMAT_VERITY, |
43 | | R_MANIFEST_FORMAT_CRYPT, |
44 | | } RManifestBundleFormat; |
45 | | |
46 | | typedef struct { |
47 | | gchar *update_compatible; |
48 | | gchar *update_version; |
49 | | gchar *update_description; |
50 | | gchar *update_build; |
51 | | gchar *update_min_rauc_version; |
52 | | |
53 | | RManifestBundleFormat bundle_format; |
54 | | gchar *bundle_verity_salt; |
55 | | gchar *bundle_verity_hash; |
56 | | guint64 bundle_verity_size; |
57 | | |
58 | | /* remember if the bundle format was specified explicitly */ |
59 | | gboolean bundle_format_explicit; |
60 | | |
61 | | gchar *bundle_crypt_key; |
62 | | |
63 | | gchar *handler_name; |
64 | | gchar *handler_args; |
65 | | |
66 | | gchar *hook_name; |
67 | | InstallHooks hooks; |
68 | | |
69 | | GList *images; |
70 | | |
71 | | /* nested hash table for metadata */ |
72 | | GHashTable *meta; |
73 | | |
74 | | /* internal marker that this was encrypted */ |
75 | | gboolean was_encrypted; |
76 | | /* computed manifest hash */ |
77 | | gchar *hash; |
78 | | |
79 | | /* warnings generated during parsing */ |
80 | | GPtrArray *warnings; |
81 | | } RaucManifest; |
82 | | |
83 | | /** |
84 | | * Loads a manifest from memory. |
85 | | * |
86 | | * Use free_manifest() to free the returned manifest. |
87 | | * |
88 | | * @param mem Input data |
89 | | * @param manifest location to store manifest |
90 | | * @param error return location for a GError, or NULL |
91 | | * |
92 | | * @return TRUE on success, FALSE if an error occurred |
93 | | */ |
94 | | gboolean load_manifest_mem(GBytes *mem, RaucManifest **manifest, GError **error) |
95 | | G_GNUC_WARN_UNUSED_RESULT; |
96 | | |
97 | | /** |
98 | | * Loads a manifest file. |
99 | | * |
100 | | * Use free_manifest() to free the returned manifest. |
101 | | * |
102 | | * @param filename Name of manifest file to load |
103 | | * @param manifest Location to store manifest |
104 | | * @param error return location for a GError, or NULL |
105 | | * |
106 | | * @return TRUE on success, FALSE if an error occurred |
107 | | */ |
108 | | gboolean load_manifest_file(const gchar *filename, RaucManifest **manifest, GError **error) |
109 | | G_GNUC_WARN_UNUSED_RESULT; |
110 | | |
111 | | /** |
112 | | * Check a loaded input manifest for consistency. Manifests to be used with 'rauc |
113 | | * bundle' must pass this check. They should not contain information that will be |
114 | | * generated (such as hashes or converted filenames); |
115 | | * |
116 | | * @param manifest Pointer to the manifest to check |
117 | | * @param error return location for a GError, or NULL |
118 | | * |
119 | | * @return TRUE on success, FALSE if an error occurred |
120 | | */ |
121 | | gboolean check_manifest_input(const RaucManifest *manifest, GError **error) |
122 | | G_GNUC_WARN_UNUSED_RESULT; |
123 | | |
124 | | /** |
125 | | * Check a loaded internal manifest for consistency. Manifests generated by 'rauc |
126 | | * bundle' should pass this check if they are compatible with the running |
127 | | * version. As an internal manifest, this must only include some generated |
128 | | * values (such as hashes/sizes for images, but not for the verity format). |
129 | | * |
130 | | * @param manifest Pointer to the manifest to check |
131 | | * @param error return location for a GError, or NULL |
132 | | * |
133 | | * @return TRUE on success, FALSE if an error occurred |
134 | | */ |
135 | | gboolean check_manifest_internal(const RaucManifest *manifest, GError **error) |
136 | | G_GNUC_WARN_UNUSED_RESULT; |
137 | | |
138 | | /** |
139 | | * Check a loaded external manifest for consistency. Manifests generated by |
140 | | * 'rauc bundle' should pass this check if they are compatible with the running |
141 | | * version. As an external manifest this must contain all generated values (such |
142 | | * as hashes/sizes for images and for the verity format). |
143 | | * |
144 | | * @param manifest Pointer to the manifest to check |
145 | | * @param error return location for a GError, or NULL |
146 | | * |
147 | | * @return TRUE on success, FALSE if an error occurred |
148 | | */ |
149 | | gboolean check_manifest_external(const RaucManifest *manifest, GError **error) |
150 | | G_GNUC_WARN_UNUSED_RESULT; |
151 | | |
152 | | /** |
153 | | * Check a new manifest for consistency during bundle creation. |
154 | | * |
155 | | * This is used for checks that could otherwise break compatibility of new RAUC |
156 | | * versions with old bundles. |
157 | | * |
158 | | * @param manifest Pointer to the manifest to check |
159 | | * @param error return location for a GError, or NULL |
160 | | * |
161 | | * @return TRUE on success, FALSE if an error occurred |
162 | | */ |
163 | | gboolean check_manifest_create(const RaucManifest *mf, GError **error) |
164 | | G_GNUC_WARN_UNUSED_RESULT; |
165 | | |
166 | | /** |
167 | | * Stores the manifest to memory. |
168 | | * |
169 | | * @param mem location to store manifest |
170 | | * @param manifest pointer to the manifest |
171 | | * |
172 | | * @return TRUE on success, FALSE if an error occurred |
173 | | */ |
174 | | gboolean save_manifest_mem(GBytes **mem, const RaucManifest *mf) |
175 | | G_GNUC_WARN_UNUSED_RESULT; |
176 | | |
177 | | /** |
178 | | * Creates a manifest file. |
179 | | * |
180 | | * @param filename Name of manifest file to save |
181 | | * @param manifest pointer to the manifest |
182 | | * @param error return location for a GError, or NULL |
183 | | * |
184 | | * @return TRUE on success, FALSE if an error occurred |
185 | | */ |
186 | | gboolean save_manifest_file(const gchar *filename, const RaucManifest *manifest, GError **error) |
187 | | G_GNUC_WARN_UNUSED_RESULT; |
188 | | |
189 | | /** |
190 | | * Frees the memory allocated by a RaucManifest. |
191 | | */ |
192 | | void free_manifest(RaucManifest *manifest); |
193 | | |
194 | | G_DEFINE_AUTOPTR_CLEANUP_FUNC(RaucManifest, free_manifest); |
195 | | |
196 | | /** |
197 | | * Checks presence of image and hook files (defined in manifest) in bundle |
198 | | * content directory and updates checksums. |
199 | | * |
200 | | * @param manifest pointer to the manifest |
201 | | * @param dir Directory with the bundle content |
202 | | * @param error return location for a GError, or NULL |
203 | | * |
204 | | * @return TRUE on success, FALSE if an error occurred |
205 | | */ |
206 | | gboolean sync_manifest_with_contentdir(RaucManifest *manifest, const gchar *dir, GError **error) |
207 | | G_GNUC_WARN_UNUSED_RESULT; |
208 | | |
209 | | /** |
210 | | * Converts a manifest to a GVariant dict. |
211 | | * |
212 | | * This can be used by the D-Bus service for InspectBundle and also for the |
213 | | * 'rauc info' CLI command (by converting it to JSON). |
214 | | * |
215 | | * @param manifest pointer to the manifest |
216 | | * |
217 | | * @return new GVariant containing the dict |
218 | | */ |
219 | | GVariant *r_manifest_to_dict(const RaucManifest *manifest) |
220 | | G_GNUC_WARN_UNUSED_RESULT; |
221 | | |
222 | | /** |
223 | | * Checks if the manifest has an artifact image: |
224 | | * - for any repository |
225 | | * - for a specific repository |
226 | | * - for a specific artifact name in a specific repository |
227 | | * |
228 | | * @param manifest pointer to the manifest |
229 | | * @param repo name of the repository, or NULL. |
230 | | * Must be set if artifact is set. |
231 | | * @param artifact name of the artifact in the repository, or NULL |
232 | | * |
233 | | * @return TRUE if image was found, FALSE otherwise |
234 | | */ |
235 | | gboolean r_manifest_has_artifact_image(const RaucManifest *manifest, const gchar *repo, const gchar *artifact) |
236 | | G_GNUC_WARN_UNUSED_RESULT; |
237 | | |
238 | | /** |
239 | | * Creates a rauc image |
240 | | */ |
241 | | RaucImage *r_new_image(void) |
242 | | G_GNUC_WARN_UNUSED_RESULT; |
243 | | |
244 | | /** |
245 | | * Frees a rauc image |
246 | | */ |
247 | | void r_free_image(gpointer data); |
248 | | |
249 | | G_DEFINE_AUTOPTR_CLEANUP_FUNC(RaucImage, r_free_image); |
250 | | |
251 | | static inline const gchar *r_manifest_bundle_format_to_str(RManifestBundleFormat format) |
252 | 0 | { |
253 | 0 | switch (format) { |
254 | 0 | case R_MANIFEST_FORMAT_PLAIN: |
255 | 0 | return "plain"; |
256 | 0 | case R_MANIFEST_FORMAT_VERITY: |
257 | 0 | return "verity"; |
258 | 0 | case R_MANIFEST_FORMAT_CRYPT: |
259 | 0 | return "crypt"; |
260 | 0 | default: |
261 | 0 | return "invalid"; |
262 | 0 | } |
263 | 0 | } Unexecuted instantiation: manifest.c:r_manifest_bundle_format_to_str Unexecuted instantiation: context.c:r_manifest_bundle_format_to_str Unexecuted instantiation: event_log.c:r_manifest_bundle_format_to_str Unexecuted instantiation: signature.c:r_manifest_bundle_format_to_str Unexecuted instantiation: status_file.c:r_manifest_bundle_format_to_str Unexecuted instantiation: bootchooser.c:r_manifest_bundle_format_to_str Unexecuted instantiation: barebox.c:r_manifest_bundle_format_to_str Unexecuted instantiation: custom.c:r_manifest_bundle_format_to_str Unexecuted instantiation: efi.c:r_manifest_bundle_format_to_str Unexecuted instantiation: grub.c:r_manifest_bundle_format_to_str Unexecuted instantiation: uboot.c:r_manifest_bundle_format_to_str Unexecuted instantiation: config_file.c:r_manifest_bundle_format_to_str Unexecuted instantiation: install.c:r_manifest_bundle_format_to_str Unexecuted instantiation: mark.c:r_manifest_bundle_format_to_str Unexecuted instantiation: mount.c:r_manifest_bundle_format_to_str Unexecuted instantiation: service.c:r_manifest_bundle_format_to_str Unexecuted instantiation: shell.c:r_manifest_bundle_format_to_str Unexecuted instantiation: update_handler.c:r_manifest_bundle_format_to_str Unexecuted instantiation: update_utils.c:r_manifest_bundle_format_to_str Unexecuted instantiation: artifacts.c:r_manifest_bundle_format_to_str Unexecuted instantiation: bundle.c:r_manifest_bundle_format_to_str Unexecuted instantiation: emmc.c:r_manifest_bundle_format_to_str Unexecuted instantiation: hash_index.c:r_manifest_bundle_format_to_str Unexecuted instantiation: mbr.c:r_manifest_bundle_format_to_str |