mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-09 00:00:04 +03:00
Merge commit '41df701a089fbf19fe16d65fbb6df46854b1f3df' of https://github.com/tmuehlbacher/bcachefs-tools
This commit is contained in:
commit
02aa11829a
@ -28,3 +28,7 @@ indent_size = 4
|
|||||||
[*.rs]
|
[*.rs]
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
|
|
||||||
|
[*.sh]
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
|
@ -16,7 +16,7 @@ impl log::Log for SimpleLogger {
|
|||||||
Level::Debug => "DEBUG".bright_blue(),
|
Level::Debug => "DEBUG".bright_blue(),
|
||||||
Level::Trace => "TRACE".into(),
|
Level::Trace => "TRACE".into(),
|
||||||
};
|
};
|
||||||
println!(
|
eprintln!(
|
||||||
"{} - {}: {}",
|
"{} - {}: {}",
|
||||||
debug_prefix,
|
debug_prefix,
|
||||||
record.module_path().unwrap_or_default().bright_black(),
|
record.module_path().unwrap_or_default().bright_black(),
|
||||||
|
29
src/key.rs
29
src/key.rs
@ -110,25 +110,32 @@ impl KeyHandle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_from_search(uuid: &Uuid) -> Result<Self> {
|
fn search_keyring(keyring: i32, key_name: &CStr) -> Result<i64> {
|
||||||
let key_name = Self::format_key_name(uuid);
|
let key_name = CStr::as_ptr(key_name);
|
||||||
let key_name = CStr::as_ptr(&key_name);
|
|
||||||
let key_type = c_str!("user");
|
let key_type = c_str!("user");
|
||||||
|
|
||||||
let key_id =
|
let key_id = unsafe { keyctl_search(keyring, key_type, key_name, 0) };
|
||||||
unsafe { keyctl_search(keyutils::KEY_SPEC_USER_KEYRING, key_type, key_name, 0) };
|
|
||||||
|
|
||||||
if key_id > 0 {
|
if key_id > 0 {
|
||||||
info!("Found key in keyring");
|
info!("Found key in keyring");
|
||||||
Ok(Self {
|
Ok(key_id)
|
||||||
_uuid: *uuid,
|
|
||||||
_id: key_id,
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
Err(ErrnoError(errno::errno()).into())
|
Err(ErrnoError(errno::errno()).into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_from_search(uuid: &Uuid) -> Result<Self> {
|
||||||
|
let key_name = Self::format_key_name(uuid);
|
||||||
|
|
||||||
|
Self::search_keyring(keyutils::KEY_SPEC_SESSION_KEYRING, &key_name)
|
||||||
|
.or_else(|_| Self::search_keyring(keyutils::KEY_SPEC_USER_KEYRING, &key_name))
|
||||||
|
.or_else(|_| Self::search_keyring(keyutils::KEY_SPEC_USER_SESSION_KEYRING, &key_name))
|
||||||
|
.map(|id| Self {
|
||||||
|
_uuid: *uuid,
|
||||||
|
_id: id,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn wait_for_unlock(uuid: &Uuid) -> Result<Self> {
|
fn wait_for_unlock(uuid: &Uuid) -> Result<Self> {
|
||||||
loop {
|
loop {
|
||||||
match Self::new_from_search(uuid) {
|
match Self::new_from_search(uuid) {
|
||||||
@ -158,7 +165,7 @@ impl Passphrase {
|
|||||||
line
|
line
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Self(CString::new(passphrase.as_str())?))
|
Ok(Self(CString::new(passphrase.trim_end_matches('\n'))?))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_from_file(sb: &bch_sb_handle, passphrase_file: impl AsRef<Path>) -> Result<Self> {
|
pub fn new_from_file(sb: &bch_sb_handle, passphrase_file: impl AsRef<Path>) -> Result<Self> {
|
||||||
@ -172,6 +179,6 @@ impl Passphrase {
|
|||||||
|
|
||||||
let passphrase = Zeroizing::new(fs::read_to_string(passphrase_file)?);
|
let passphrase = Zeroizing::new(fs::read_to_string(passphrase_file)?);
|
||||||
|
|
||||||
Ok(Self(CString::new(passphrase.as_str())?))
|
Ok(Self(CString::new(passphrase.trim_end_matches('\n'))?))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user