1
0
forked from brl/citadel-tools

Don't pass config file around, it's a lazy_static now

This commit is contained in:
Bruce Leidl 2019-01-05 20:34:22 -05:00
parent 434c19433e
commit b59188311d
4 changed files with 22 additions and 32 deletions

View File

@ -1,5 +1,5 @@
use libcitadel::{Config,Partition,Result,ImageHeader}; use libcitadel::{Partition,Result,ImageHeader};
pub struct BootSelection { pub struct BootSelection {
partitions: Vec<Partition>, partitions: Vec<Partition>,
@ -62,9 +62,9 @@ impl BootSelection {
/// Perform checks for error states at boot time. /// Perform checks for error states at boot time.
pub fn scan_boot_partitions(&mut self, config: &Config) -> Result<()> { pub fn scan_boot_partitions(&mut self) -> Result<()> {
for mut p in &mut self.partitions { for mut p in &mut self.partitions {
if let Err(e) = boot_scan_partition(&mut p, config) { if let Err(e) = boot_scan_partition(&mut p) {
warn!("error in bootscan of partition {}: {}", p.path().display(), e); warn!("error in bootscan of partition {}: {}", p.path().display(), e);
} }
} }
@ -82,7 +82,7 @@ impl BootSelection {
/// Verify metainfo signature and mark `STATUS_BAD_SIG` if /// Verify metainfo signature and mark `STATUS_BAD_SIG` if
/// signature verification fails. /// signature verification fails.
/// ///
fn boot_scan_partition(p: &mut Partition, config: &Config) -> Result<()> { fn boot_scan_partition(p: &mut Partition) -> Result<()> {
if !p.is_initialized() { if !p.is_initialized() {
return Ok(()) return Ok(())
} }
@ -90,9 +90,7 @@ fn boot_scan_partition(p: &mut Partition, config: &Config) -> Result<()> {
warn!("Partition {} has STATUS_TRY_BOOT, assuming it failed boot attempt and marking STATUS_FAILED", p.path().display()); warn!("Partition {} has STATUS_TRY_BOOT, assuming it failed boot attempt and marking STATUS_FAILED", p.path().display());
p.write_status(ImageHeader::STATUS_FAILED)?; p.write_status(ImageHeader::STATUS_FAILED)?;
} }
let signature = p.header().signature(); p.header().verify_signature()?;
p.metainfo().verify(config, &signature)?;
Ok(()) Ok(())
} }

View File

@ -6,7 +6,7 @@ extern crate libc;
use std::process::exit; use std::process::exit;
use std::env; use std::env;
use libcitadel::{Result,Config,CommandLine,set_verbose,format_error,ResourceImage}; use libcitadel::{Result,CommandLine,set_verbose,format_error,ResourceImage};
mod boot_select; mod boot_select;
@ -38,20 +38,12 @@ fn main() {
set_verbose(true); set_verbose(true);
} }
let config = match Config::load_default() {
Ok(config) => config,
Err(err) => {
warn!("{}", err);
exit(1);
},
};
let mut args = env::args(); let mut args = env::args();
args.next(); args.next();
let result = match args.next() { let result = match args.next() {
Some(ref s) if s == "rootfs" => mount_rootfs(config), Some(ref s) if s == "rootfs" => mount_rootfs(),
Some(ref s) if s == "modules" => mount_modules(config), Some(ref s) if s == "modules" => mount_modules(),
Some(ref s) if s == "extra" => mount_extra(config), Some(ref s) if s == "extra" => mount_extra(),
_ => Err(format_err!("Bad or missing argument")), _ => Err(format_err!("Bad or missing argument")),
}; };
@ -61,22 +53,22 @@ fn main() {
} }
} }
fn mount_rootfs(config: Config) -> Result<()> { fn mount_rootfs() -> Result<()> {
info!("citadel-mount rootfs"); info!("citadel-mount rootfs");
let rootfs = Rootfs::new(config); let rootfs = Rootfs::new();
rootfs.setup() rootfs.setup()
} }
fn mount_modules(config: Config) -> Result<()> { fn mount_modules() -> Result<()> {
info!("citadel-mount modules"); info!("citadel-mount modules");
let mut image = ResourceImage::find("modules")?; let mut image = ResourceImage::find("modules")?;
image.mount(&config)?; image.mount()?;
Ok(()) Ok(())
} }
fn mount_extra(config: Config) -> Result<()> { fn mount_extra() -> Result<()> {
info!("citadel-mount extra"); info!("citadel-mount extra");
let mut image = ResourceImage::find("extra")?; let mut image = ResourceImage::find("extra")?;
image.mount(&config)?; image.mount()?;
Ok(()) Ok(())
} }

View File

@ -1,6 +1,6 @@
use std::path::{Path,PathBuf}; use std::path::{Path,PathBuf};
use std::fs; use std::fs;
use {Config,CommandLine,Result,ImageHeader,MetaInfo,Mount}; use {CommandLine,Result,ImageHeader,MetaInfo,Mount};
#[derive(Clone)] #[derive(Clone)]
pub struct Partition { pub struct Partition {
@ -109,7 +109,7 @@ impl Partition {
/// Verify metainfo signature and mark `STATUS_BAD_SIG` if /// Verify metainfo signature and mark `STATUS_BAD_SIG` if
/// signature verification fails. /// signature verification fails.
/// ///
pub fn boot_scan(&mut self, config: &Config) -> Result<()> { pub fn boot_scan(&mut self) -> Result<()> {
if !self.is_initialized() { if !self.is_initialized() {
return Ok(()) return Ok(())
} }
@ -118,7 +118,7 @@ impl Partition {
} }
if !CommandLine::nosignatures() { if !CommandLine::nosignatures() {
if let Err(e) = self.header().verify_signature(config) { if let Err(e) = self.header().verify_signature() {
warn!("Signature verification failed on partition: {}", e); warn!("Signature verification failed on partition: {}", e);
self.write_status(ImageHeader::STATUS_BAD_SIG)?; self.write_status(ImageHeader::STATUS_BAD_SIG)?;
} }

View File

@ -3,7 +3,7 @@ use std::ffi::OsStr;
use std::io::{self,Seek,SeekFrom}; use std::io::{self,Seek,SeekFrom};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use {CommandLine,Config,ImageHeader,MetaInfo,Result,Partition,Mount,verity,util}; use {CommandLine,ImageHeader,MetaInfo,Result,Partition,Mount,verity,util};
use failure::ResultExt; use failure::ResultExt;
@ -183,8 +183,8 @@ impl ResourceImage {
Ok(()) Ok(())
} }
fn mount_verity(&self, config: &Config) -> Result<()> { fn mount_verity(&self) -> Result<()> {
let verity_dev = self.setup_verity_device(config)?; let verity_dev = self.setup_verity_device()?;
info!("Mounting dm-verity device to {}", self.mount_path().display()); info!("Mounting dm-verity device to {}", self.mount_path().display());
@ -194,7 +194,7 @@ impl ResourceImage {
} }
pub fn setup_verity_device(&self, config: &Config) -> Result<PathBuf> { pub fn setup_verity_device(&self) -> Result<PathBuf> {
if !CommandLine::nosignatures() { if !CommandLine::nosignatures() {
self.header.verify_signature(config)?; self.header.verify_signature(config)?;
} }