@@ -5,7 +5,7 @@ use std::{
5
5
path:: { Path , PathBuf } ,
6
6
} ;
7
7
8
- use anyhow:: { bail , Context , Result } ;
8
+ use anyhow:: { Context , Result } ;
9
9
use clap:: Parser ;
10
10
use rustix:: {
11
11
fs:: { major, minor, mkdirat, openat, stat, symlink, Mode , OFlags , CWD } ,
@@ -23,7 +23,7 @@ use composefs::{
23
23
mountcompat:: { overlayfs_set_fd, overlayfs_set_lower_and_data_fds, prepare_mount} ,
24
24
repository:: Repository ,
25
25
} ;
26
- use composefs_boot:: cmdline:: get_cmdline_value ;
26
+ use composefs_boot:: cmdline:: get_cmdline_composefs ;
27
27
28
28
// Config file
29
29
#[ derive( Clone , Copy , Debug , Deserialize ) ]
@@ -164,9 +164,10 @@ fn open_root_fs(path: &Path) -> Result<OwnedFd> {
164
164
Ok ( rootfs)
165
165
}
166
166
167
- fn mount_composefs_image ( sysroot : & OwnedFd , name : & str ) -> Result < OwnedFd > {
168
- let repo = Repository :: < Sha256HashValue > :: open_path ( sysroot, "composefs" ) ?;
169
- repo. mount ( name)
167
+ fn mount_composefs_image ( sysroot : & OwnedFd , name : & str , insecure : bool ) -> Result < OwnedFd > {
168
+ let mut repo = Repository :: < Sha256HashValue > :: open_path ( sysroot, "composefs" ) ?;
169
+ repo. set_insecure ( insecure) ;
170
+ repo. mount ( name) . context ( "Failed to mount composefs image" )
170
171
}
171
172
172
173
fn mount_subdir (
@@ -196,15 +197,6 @@ fn mount_subdir(
196
197
}
197
198
}
198
199
199
- // Implementation
200
- fn parse_composefs_cmdline < H : FsVerityHashValue > ( cmdline : & str ) -> Result < H > {
201
- let Some ( digest) = get_cmdline_value ( cmdline, "composefs=" ) else {
202
- bail ! ( "Unable to find composefs= cmdline parameter" ) ;
203
- } ;
204
-
205
- H :: from_hex ( digest) . context ( "Parsing composefs=" )
206
- }
207
-
208
200
fn gpt_workaround ( ) -> Result < ( ) > {
209
201
// https://github.com/systemd/systemd/issues/35017
210
202
let rootdev = stat ( "/dev/gpt-auto-root" ) ?;
@@ -231,11 +223,11 @@ fn setup_root(args: Args) -> Result<()> {
231
223
Some ( cmdline) => cmdline,
232
224
None => & std:: fs:: read_to_string ( "/proc/cmdline" ) ?,
233
225
} ;
234
- let image = parse_composefs_cmdline :: < Sha256HashValue > ( cmdline) ?. to_hex ( ) ;
226
+ let ( image, insecure ) = get_cmdline_composefs :: < Sha256HashValue > ( cmdline) ?;
235
227
236
228
let new_root = match args. root_fs {
237
229
Some ( path) => open_root_fs ( & path) . context ( "Failed to clone specified root fs" ) ?,
238
- None => mount_composefs_image ( & sysroot, & image) ?,
230
+ None => mount_composefs_image ( & sysroot, & image. to_hex ( ) , insecure ) ?,
239
231
} ;
240
232
241
233
// we need to clone this before the next step to make sure we get the old one
@@ -258,7 +250,7 @@ fn setup_root(args: Args) -> Result<()> {
258
250
}
259
251
260
252
// etc + var
261
- let state = open_dir ( open_dir ( & sysroot, "state" ) ?, & image) ?;
253
+ let state = open_dir ( open_dir ( & sysroot, "state" ) ?, image. to_hex ( ) ) ?;
262
254
mount_subdir ( & new_root, & state, "etc" , config. etc , MountType :: Overlay ) ?;
263
255
mount_subdir ( & new_root, & state, "var" , config. var , MountType :: Bind ) ?;
264
256
@@ -285,12 +277,11 @@ mod test {
285
277
fn test_parse ( ) {
286
278
let failing = [ "" , "foo" , "composefs" , "composefs=foo" ] ;
287
279
for case in failing {
288
- assert ! ( parse_composefs_cmdline :: <Sha256HashValue >( case) . is_err( ) ) ;
280
+ assert ! ( get_cmdline_composefs :: <Sha256HashValue >( case) . is_err( ) ) ;
289
281
}
290
282
let digest = "8b7df143d91c716ecfa5fc1730022f6b421b05cedee8fd52b1fc65a96030ad52" ;
291
- similar_asserts:: assert_eq!(
292
- parse_composefs_cmdline:: <Sha256HashValue >( & format!( "composefs={digest}" ) ) . unwrap( ) ,
293
- Sha256HashValue :: from_hex( digest) . unwrap( )
294
- ) ;
283
+ let cmdline = & format ! ( "composefs={digest}" ) ;
284
+ let ( digest_cmdline, _) = get_cmdline_composefs :: < Sha256HashValue > ( cmdline) . unwrap ( ) ;
285
+ similar_asserts:: assert_eq!( digest_cmdline, Sha256HashValue :: from_hex( digest) . unwrap( ) ) ;
295
286
}
296
287
}
0 commit comments