]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
Always normalize cache inputs to lowercase
authorDavid Mulder <dmulder@samba.org>
Thu, 22 Aug 2024 18:54:32 +0000 (12:54 -0600)
committerDavid Mulder <dmulder@samba.org>
Wed, 23 Oct 2024 14:21:34 +0000 (14:21 +0000)
This prevents mixed case issues when storing/
retrieving data from the cache.

Signed-off-by: David Mulder <dmulder@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
rust/himmelblaud/src/cache.rs

index ad1e44c9c5cf9005e6933132a0f2db02fd495f75..12a2cd97640acd353e227e68554f380ead2f6cfc 100644 (file)
@@ -48,7 +48,8 @@ impl BasicCache {
     }
 
     fn fetch_str(&self, key: &str) -> Option<String> {
-        let exists = match self.tdb.exists(key) {
+        let key = key.to_string().to_lowercase();
+        let exists = match self.tdb.exists(&key) {
             Ok(exists) => exists,
             Err(e) => {
                 DBG_ERR!("Failed to fetch {}: {:?}", key, e);
@@ -56,7 +57,7 @@ impl BasicCache {
             }
         };
         if exists {
-            match self.tdb.fetch(key) {
+            match self.tdb.fetch(&key) {
                 Ok(val) => Some(val),
                 Err(e) => {
                     DBG_ERR!("Failed to fetch {}: {:?}", key, e);
@@ -72,7 +73,8 @@ impl BasicCache {
     where
         T: for<'de> Deserialize<'de>,
     {
-        match self.fetch_str(key) {
+        let key = key.to_string().to_lowercase();
+        match self.fetch_str(&key) {
             Some(val) => match json_from_slice::<T>(val.as_bytes()) {
                 Ok(res) => Some(res),
                 Err(e) => {
@@ -91,6 +93,7 @@ impl BasicCache {
         key: &str,
         val: &[u8],
     ) -> Result<(), Box<NTSTATUS>> {
+        let key = key.to_string().to_lowercase();
         match self.tdb.transaction_start() {
             Ok(start) => {
                 if !start {
@@ -104,7 +107,7 @@ impl BasicCache {
             }
         };
 
-        let res = match self.tdb.store(key, val, None) {
+        let res = match self.tdb.store(&key, val, None) {
             Ok(res) => Some(res),
             Err(e) => {
                 DBG_ERR!("Unable to persist {}: {:?}", key, e);
@@ -145,6 +148,7 @@ impl BasicCache {
     where
         T: Serialize,
     {
+        let key = key.to_string().to_lowercase();
         let val_bytes = match json_to_vec(&val) {
             Ok(val_bytes) => val_bytes,
             Err(e) => {
@@ -152,7 +156,7 @@ impl BasicCache {
                 return Err(Box::new(NT_STATUS_UNSUCCESSFUL));
             }
         };
-        self.store_bytes(key, &val_bytes)
+        self.store_bytes(&key, &val_bytes)
     }
 
     fn keys(&self) -> Result<Vec<String>, Box<NTSTATUS>> {
@@ -241,6 +245,7 @@ impl UidCache {
         upn: &str,
     ) -> Result<(), Box<NTSTATUS>> {
         let key = format!("{}", uid);
+        let upn = upn.to_string().to_lowercase();
         self.cache.store_bytes(&key, upn.as_bytes())
     }