auth: factor out CA store and cert lookup into own fn

This will be needed by the AD authenticator as well, so avoid duplicate
code.

No functional changes.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Christoph Heiss 2024-01-12 17:16:00 +01:00 committed by Thomas Lamprecht
parent 30c34f0b50
commit ab09f409be

View File

@ -185,16 +185,7 @@ impl LdapAuthenticator {
servers.push(server.clone()); servers.push(server.clone());
} }
let (ca_store, trusted_cert) = if let Some(capath) = config.capath.as_deref() { let (ca_store, trusted_cert) = lookup_ca_store_or_cert_path(config.capath.as_deref());
let path = PathBuf::from(capath);
if path.is_dir() {
(Some(path), None)
} else {
(None, Some(vec![path]))
}
} else {
(None, None)
};
Ok(Config { Ok(Config {
servers, servers,
@ -219,6 +210,19 @@ fn ldap_to_conn_mode(mode: LdapMode) -> ConnectionMode {
} }
} }
fn lookup_ca_store_or_cert_path(capath: Option<&str>) -> (Option<PathBuf>, Option<Vec<PathBuf>>) {
if let Some(capath) = capath {
let path = PathBuf::from(capath);
if path.is_dir() {
(Some(path), None)
} else {
(None, Some(vec![path]))
}
} else {
(None, None)
}
}
/// Lookup the authenticator for the specified realm /// Lookup the authenticator for the specified realm
pub(crate) fn lookup_authenticator( pub(crate) fn lookup_authenticator(
realm: &RealmRef, realm: &RealmRef,