From 9e1b58d03357bc803300f9fcd4b72a6d2136e244 Mon Sep 17 00:00:00 2001 From: Valentin Tolmer Date: Thu, 29 Jun 2023 11:39:33 +0200 Subject: [PATCH] server,ldap: add encoding for lists and integers --- server/src/domain/ldap/utils.rs | 47 ++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/server/src/domain/ldap/utils.rs b/server/src/domain/ldap/utils.rs index bbd3830..ade2e1f 100644 --- a/server/src/domain/ldap/utils.rs +++ b/server/src/domain/ldap/utils.rs @@ -200,6 +200,12 @@ pub fn get_custom_attribute( attribute_name: &str, schema: &Schema, ) -> Option>> { + let convert_date = |date| { + chrono::Utc + .from_utc_datetime(&date) + .to_rfc3339() + .into_bytes() + }; schema .user_attributes .get_attribute_type(attribute_name) @@ -211,18 +217,41 @@ pub fn get_custom_attribute( (AttributeType::String, false) => { vec![attribute.value.unwrap::().into_bytes()] } - (AttributeType::Integer, false) => todo!(), + (AttributeType::Integer, false) => { + // LDAP integers are encoded as strings. + vec![attribute.value.unwrap::().to_string().into_bytes()] + } (AttributeType::JpegPhoto, false) => { vec![attribute.value.unwrap::().into_bytes()] } - (AttributeType::DateTime, false) => vec![chrono::Utc - .from_utc_datetime(&attribute.value.unwrap::()) - .to_rfc3339() - .into_bytes()], - (AttributeType::String, true) => todo!(), - (AttributeType::Integer, true) => todo!(), - (AttributeType::JpegPhoto, true) => todo!(), - (AttributeType::DateTime, true) => todo!(), + (AttributeType::DateTime, false) => { + vec![convert_date(attribute.value.unwrap::())] + } + (AttributeType::String, true) => attribute + .value + .unwrap::>() + .into_iter() + .map(String::into_bytes) + .collect(), + (AttributeType::Integer, true) => attribute + .value + .unwrap::>() + .into_iter() + .map(|i| i.to_string()) + .map(String::into_bytes) + .collect(), + (AttributeType::JpegPhoto, true) => attribute + .value + .unwrap::>() + .into_iter() + .map(JpegPhoto::into_bytes) + .collect(), + (AttributeType::DateTime, true) => attribute + .value + .unwrap::>() + .into_iter() + .map(convert_date) + .collect(), }) }) }