diff --git a/server/src/infra/ldap_handler.rs b/server/src/infra/ldap_handler.rs index f9150c3..ebb1233 100644 --- a/server/src/infra/ldap_handler.rs +++ b/server/src/infra/ldap_handler.rs @@ -88,7 +88,7 @@ fn get_user_id_from_distinguished_name( } } -fn get_user_attribute(user: &User, attribute: &str) -> Result> { +fn get_user_attribute(user: &User, attribute: &str, dn: &str) -> Result> { match attribute { "objectClass" => Ok(vec![ "inetOrgPerson".to_string(), @@ -96,6 +96,7 @@ fn get_user_attribute(user: &User, attribute: &str) -> Result> { "mailAccount".to_string(), "person".to_string(), ]), + "dn" => Ok(vec![dn.to_string()]), "uid" => Ok(vec![user.user_id.clone()]), "mail" => Ok(vec![user.email.clone()]), "givenName" => Ok(vec![user.first_name.clone()]), @@ -112,14 +113,15 @@ fn make_ldap_search_user_result_entry( base_dn_str: &str, attributes: &[String], ) -> Result { + let dn = format!("cn={},ou=people,{}", user.user_id, base_dn_str); Ok(LdapSearchResultEntry { - dn: format!("cn={},ou=people,{}", user.user_id, base_dn_str), + dn: dn.clone(), attributes: attributes .iter() .map(|a| { Ok(LdapPartialAttribute { atype: a.to_string(), - vals: get_user_attribute(&user, a)?, + vals: get_user_attribute(&user, a, &dn)?, }) }) .collect::>>()?, @@ -707,6 +709,7 @@ mod tests { filter: LdapFilter::And(vec![]), attrs: vec![ "objectClass".to_string(), + "dn".to_string(), "uid".to_string(), "mail".to_string(), "givenName".to_string(), @@ -729,6 +732,10 @@ mod tests { "person".to_string() ] }, + LdapPartialAttribute { + atype: "dn".to_string(), + vals: vec!["cn=bob_1,ou=people,dc=example,dc=com".to_string()] + }, LdapPartialAttribute { atype: "uid".to_string(), vals: vec!["bob_1".to_string()] @@ -763,6 +770,10 @@ mod tests { "person".to_string() ] }, + LdapPartialAttribute { + atype: "dn".to_string(), + vals: vec!["cn=jim,ou=people,dc=example,dc=com".to_string()] + }, LdapPartialAttribute { atype: "uid".to_string(), vals: vec!["jim".to_string()]