From 87ab1fd7edf331cdb5fe3e447d18e9447e1b2149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BChlbacher?= Date: Mon, 10 Jun 2024 23:14:50 +0200 Subject: [PATCH 1/4] chore(editorconfig): extend for sh scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To match with what's already in the repo. Signed-off-by: Thomas Mühlbacher --- .editorconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.editorconfig b/.editorconfig index 2d9a31096..9270938df 100644 --- a/.editorconfig +++ b/.editorconfig @@ -28,3 +28,7 @@ indent_size = 4 [*.rs] indent_style = space indent_size = 4 + +[*.sh] +indent_size = 4 +indent_style = space From e4271d7a3e5c0197b2a71eb001b93c3d7601847f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BChlbacher?= Date: Sat, 15 Jun 2024 23:45:06 +0200 Subject: [PATCH 2/4] fix(key): remove any newlines from passphrase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To match the behavior of the C code and because there may be newlines under some conditions. Signed-off-by: Thomas Mühlbacher --- src/key.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/key.rs b/src/key.rs index 54959d6e6..44f2ad678 100644 --- a/src/key.rs +++ b/src/key.rs @@ -158,7 +158,7 @@ impl Passphrase { 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) -> Result { @@ -172,6 +172,6 @@ impl Passphrase { 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'))?)) } } From f72ded6a4f80117b794236018ba301ae30e2d93d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BChlbacher?= Date: Sat, 15 Jun 2024 23:48:31 +0200 Subject: [PATCH 3/4] fix(key): search for key in all relevant keyrings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, using `bcachefs unlock -k session` would still cause mount to ask for a passphrase. Signed-off-by: Thomas Mühlbacher --- src/key.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/key.rs b/src/key.rs index 44f2ad678..96eb491d2 100644 --- a/src/key.rs +++ b/src/key.rs @@ -110,25 +110,32 @@ impl KeyHandle { } } - pub fn new_from_search(uuid: &Uuid) -> Result { - let key_name = Self::format_key_name(uuid); - let key_name = CStr::as_ptr(&key_name); + fn search_keyring(keyring: i32, key_name: &CStr) -> Result { + let key_name = CStr::as_ptr(key_name); let key_type = c_str!("user"); - let key_id = - unsafe { keyctl_search(keyutils::KEY_SPEC_USER_KEYRING, key_type, key_name, 0) }; + let key_id = unsafe { keyctl_search(keyring, key_type, key_name, 0) }; if key_id > 0 { info!("Found key in keyring"); - Ok(Self { - _uuid: *uuid, - _id: key_id, - }) + Ok(key_id) } else { Err(ErrnoError(errno::errno()).into()) } } + pub fn new_from_search(uuid: &Uuid) -> Result { + 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 { loop { match Self::new_from_search(uuid) { From 41df701a089fbf19fe16d65fbb6df46854b1f3df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BChlbacher?= Date: Sat, 15 Jun 2024 23:56:56 +0200 Subject: [PATCH 4/4] fix(logger): log to stderr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Mühlbacher --- src/commands/logger.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/logger.rs b/src/commands/logger.rs index 2cd7b3638..a24bcbda7 100644 --- a/src/commands/logger.rs +++ b/src/commands/logger.rs @@ -16,7 +16,7 @@ impl log::Log for SimpleLogger { Level::Debug => "DEBUG".bright_blue(), Level::Trace => "TRACE".into(), }; - println!( + eprintln!( "{} - {}: {}", debug_prefix, record.module_path().unwrap_or_default().bright_black(),