mirror of
				https://github.com/nitnelave/lldap.git
				synced 2023-04-12 14:25:13 +00:00 
			
		
		
		
	ldap: Add support for "dn" attribute
This commit is contained in:
		
							parent
							
								
									9874449d66
								
							
						
					
					
						commit
						e227b4a520
					
				@ -88,7 +88,7 @@ fn get_user_id_from_distinguished_name(
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn get_user_attribute(user: &User, attribute: &str) -> Result<Vec<String>> {
 | 
					fn get_user_attribute(user: &User, attribute: &str, dn: &str) -> Result<Vec<String>> {
 | 
				
			||||||
    match attribute {
 | 
					    match attribute {
 | 
				
			||||||
        "objectClass" => Ok(vec![
 | 
					        "objectClass" => Ok(vec![
 | 
				
			||||||
            "inetOrgPerson".to_string(),
 | 
					            "inetOrgPerson".to_string(),
 | 
				
			||||||
@ -96,6 +96,7 @@ fn get_user_attribute(user: &User, attribute: &str) -> Result<Vec<String>> {
 | 
				
			|||||||
            "mailAccount".to_string(),
 | 
					            "mailAccount".to_string(),
 | 
				
			||||||
            "person".to_string(),
 | 
					            "person".to_string(),
 | 
				
			||||||
        ]),
 | 
					        ]),
 | 
				
			||||||
 | 
					        "dn" => Ok(vec![dn.to_string()]),
 | 
				
			||||||
        "uid" => Ok(vec![user.user_id.clone()]),
 | 
					        "uid" => Ok(vec![user.user_id.clone()]),
 | 
				
			||||||
        "mail" => Ok(vec![user.email.clone()]),
 | 
					        "mail" => Ok(vec![user.email.clone()]),
 | 
				
			||||||
        "givenName" => Ok(vec![user.first_name.clone()]),
 | 
					        "givenName" => Ok(vec![user.first_name.clone()]),
 | 
				
			||||||
@ -112,14 +113,15 @@ fn make_ldap_search_user_result_entry(
 | 
				
			|||||||
    base_dn_str: &str,
 | 
					    base_dn_str: &str,
 | 
				
			||||||
    attributes: &[String],
 | 
					    attributes: &[String],
 | 
				
			||||||
) -> Result<LdapSearchResultEntry> {
 | 
					) -> Result<LdapSearchResultEntry> {
 | 
				
			||||||
 | 
					    let dn = format!("cn={},ou=people,{}", user.user_id, base_dn_str);
 | 
				
			||||||
    Ok(LdapSearchResultEntry {
 | 
					    Ok(LdapSearchResultEntry {
 | 
				
			||||||
        dn: format!("cn={},ou=people,{}", user.user_id, base_dn_str),
 | 
					        dn: dn.clone(),
 | 
				
			||||||
        attributes: attributes
 | 
					        attributes: attributes
 | 
				
			||||||
            .iter()
 | 
					            .iter()
 | 
				
			||||||
            .map(|a| {
 | 
					            .map(|a| {
 | 
				
			||||||
                Ok(LdapPartialAttribute {
 | 
					                Ok(LdapPartialAttribute {
 | 
				
			||||||
                    atype: a.to_string(),
 | 
					                    atype: a.to_string(),
 | 
				
			||||||
                    vals: get_user_attribute(&user, a)?,
 | 
					                    vals: get_user_attribute(&user, a, &dn)?,
 | 
				
			||||||
                })
 | 
					                })
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
            .collect::<Result<Vec<LdapPartialAttribute>>>()?,
 | 
					            .collect::<Result<Vec<LdapPartialAttribute>>>()?,
 | 
				
			||||||
@ -707,6 +709,7 @@ mod tests {
 | 
				
			|||||||
            filter: LdapFilter::And(vec![]),
 | 
					            filter: LdapFilter::And(vec![]),
 | 
				
			||||||
            attrs: vec![
 | 
					            attrs: vec![
 | 
				
			||||||
                "objectClass".to_string(),
 | 
					                "objectClass".to_string(),
 | 
				
			||||||
 | 
					                "dn".to_string(),
 | 
				
			||||||
                "uid".to_string(),
 | 
					                "uid".to_string(),
 | 
				
			||||||
                "mail".to_string(),
 | 
					                "mail".to_string(),
 | 
				
			||||||
                "givenName".to_string(),
 | 
					                "givenName".to_string(),
 | 
				
			||||||
@ -729,6 +732,10 @@ mod tests {
 | 
				
			|||||||
                                "person".to_string()
 | 
					                                "person".to_string()
 | 
				
			||||||
                            ]
 | 
					                            ]
 | 
				
			||||||
                        },
 | 
					                        },
 | 
				
			||||||
 | 
					                        LdapPartialAttribute {
 | 
				
			||||||
 | 
					                            atype: "dn".to_string(),
 | 
				
			||||||
 | 
					                            vals: vec!["cn=bob_1,ou=people,dc=example,dc=com".to_string()]
 | 
				
			||||||
 | 
					                        },
 | 
				
			||||||
                        LdapPartialAttribute {
 | 
					                        LdapPartialAttribute {
 | 
				
			||||||
                            atype: "uid".to_string(),
 | 
					                            atype: "uid".to_string(),
 | 
				
			||||||
                            vals: vec!["bob_1".to_string()]
 | 
					                            vals: vec!["bob_1".to_string()]
 | 
				
			||||||
@ -763,6 +770,10 @@ mod tests {
 | 
				
			|||||||
                                "person".to_string()
 | 
					                                "person".to_string()
 | 
				
			||||||
                            ]
 | 
					                            ]
 | 
				
			||||||
                        },
 | 
					                        },
 | 
				
			||||||
 | 
					                        LdapPartialAttribute {
 | 
				
			||||||
 | 
					                            atype: "dn".to_string(),
 | 
				
			||||||
 | 
					                            vals: vec!["cn=jim,ou=people,dc=example,dc=com".to_string()]
 | 
				
			||||||
 | 
					                        },
 | 
				
			||||||
                        LdapPartialAttribute {
 | 
					                        LdapPartialAttribute {
 | 
				
			||||||
                            atype: "uid".to_string(),
 | 
					                            atype: "uid".to_string(),
 | 
				
			||||||
                            vals: vec!["jim".to_string()]
 | 
					                            vals: vec!["jim".to_string()]
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user