Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 6490 - Add a new macro function and print rounds on startup #6496

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dirsrvtests/tests/suites/pwp_storage/storage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_pbkdf2_default_rounds(topo, new_user, scheme_name, plugin_class, defaul
topo.standalone.simple_bind_s(new_user.dn, 'Secret123')

assert topo.standalone.searchErrorsLog(
f'Number of iterations for {scheme_name} password scheme set to {default_rounds} from default'
f'{scheme_name} - Number of iterations set to {default_rounds} from default'
)
finally:
topo.standalone.simple_bind_s(DN_DM, PASSWORD)
Expand Down Expand Up @@ -205,7 +205,7 @@ def test_pbkdf2_rounds_reset(topo, new_user, scheme_name, plugin_class, default_
topo.standalone.simple_bind_s(new_user.dn, 'Secret123')

assert topo.standalone.searchErrorsLog(
f'Number of iterations for {scheme_name} password scheme set to {default_rounds} from default'
f'{scheme_name} - Number of iterations set to {default_rounds} from default'
)
finally:
topo.standalone.simple_bind_s(DN_DM, PASSWORD)
Expand Down Expand Up @@ -256,7 +256,7 @@ def test_pbkdf2_custom_rounds(topo, new_user, scheme_name, plugin_class, _, roun
topo.standalone.simple_bind_s(new_user.dn, 'Secret123')

assert topo.standalone.searchErrorsLog(
f'Number of iterations for {scheme_name}'
f'{scheme_name} - Number of iterations set'
)
finally:
topo.standalone.simple_bind_s(DN_DM, PASSWORD)
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/pwdchan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,19 +317,19 @@ impl PwdChanCrypto {
Self::set_pbkdf2_rounds(digest, rounds)?;

let digest_name = if digest == MessageDigest::sha1() {
"SHA1"
"PBKDF2-SHA1"
} else if digest == MessageDigest::sha256() {
"SHA256"
"PBKDF2-SHA256"
} else if digest == MessageDigest::sha512() {
"SHA512"
"PBKDF2-SHA512"
} else {
"Unknown"
};

log_error!(
ErrorLevel::Plugin,
"handle_pbkdf2_rounds_config -> Number of iterations for PBKDF2-{} password scheme set to {} from {}",
log_error_ext!(
ErrorLevel::Info,
digest_name,
"Number of iterations set to {} from {}",
rounds,
source
);
Expand Down
26 changes: 20 additions & 6 deletions src/slapi_r_plugin/src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
#[macro_export]
#[cfg(not(feature = "test_log_direct"))]
macro_rules! log_error {
($level:expr, $($arg:tt)*) => ({
macro_rules! log_error_ext {
($level:expr, $source:expr, $($arg:tt)*) => ({
use std::fmt;
match log_error(
$level,
format!("{}:{}", file!(), line!()),
$source.to_string(),
format!("{}\n", fmt::format(format_args!($($arg)*)))
) {
Ok(_) => {},
Err(e) => {
eprintln!("A logging error occured {}, {} -> {:?}", file!(), line!(), e);
eprintln!("A logging error occurred {}, {} -> {:?}", file!(), line!(), e);
}
};
})
}

#[macro_export]
#[cfg(feature = "test_log_direct")]
macro_rules! log_error_ext {
($level:expr, $source:expr, $($arg:tt)*) => ({
use std::fmt;
eprintln!("{} -> {}", $source, fmt::format(format_args!($($arg)*)));
})
}

#[macro_export]
macro_rules! log_error {
($level:expr, $($arg:tt)*) => ({
use std::fmt;
eprintln!("{}:{} -> {}", file!(), line!(), fmt::format(format_args!($($arg)*)));
log_error_ext!($level, format!("{}:{}", file!(), line!()), $($arg)*)
})
}

#[macro_export]
macro_rules! log_error_fn {
($level:expr, $funcname:expr, $($arg:tt)*) => ({
log_error_ext!($level, $funcname, $($arg)*)
})
}

Expand Down
Loading