From 998e3de74b2bc9a78fb66fa110c272e06f7015ce Mon Sep 17 00:00:00 2001 From: Alex Wright Date: Sat, 29 Feb 2020 16:49:24 +0100 Subject: [PATCH] Add LDAP group memberships to returned data --- src/main.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 9164b2a..886f24c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,6 +48,7 @@ pub enum AuthError { #[derive(Debug)] struct LdapUser { pub dn: String, + pub groups: Vec, pub mail: Vec, pub services: Vec, } @@ -69,7 +70,7 @@ fn auth_user(auth: &BasicAuthentication) -> Result { }; let filter = format!("(uid={})", auth.username); - let s = match ldap.search(&base, Scope::Subtree, &filter, vec!["mail", "enabledService"]) { + let s = match ldap.search(&base, Scope::Subtree, &filter, vec!["mail", "enabledService", "memberOf"]) { Ok(result) => { let (rs, _) = result.success().unwrap(); rs @@ -87,10 +88,15 @@ fn auth_user(auth: &BasicAuthentication) -> Result { Some(mail) => mail.to_vec(), None => [].to_vec(), }; + let groups = match se.attrs.get("memberOf") { + Some(groups) => groups.to_vec(), + None => [].to_vec(), + }; info!("Authentication success for {:?}", base); Ok(LdapUser { dn: base, + groups: groups, mail: mail, services: services, })