s4:registry - "LDB backend" - reg_key_get_info - adapt max. subkey and value length
authorMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>
Sun, 21 Mar 2010 14:33:52 +0000 (15:33 +0100)
committerMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>
Sun, 21 Mar 2010 14:33:52 +0000 (15:33 +0100)
Those lengths are measured in UTF8 string lengths and not in UTF16 ones (the
returned strings are generally in this format). Discovered this by checking the
s3 registry code.
Therefore we have to multiply the both numbers by two.

Discovered with the "regedt32" (old NT registry editor).

source4/lib/registry/ldb.c

index 5f1a06c501fbcbc6290dba2df3a4bf375a17510f..46b340da881b6744e53186fc6bcdedcd6411b3b1 100644 (file)
@@ -991,12 +991,13 @@ static WERROR ldb_get_key_info(TALLOC_CTX *mem_ctx,
                unsigned int i;
                struct ldb_message_element *el;
 
-               *max_subkeynamelen = 0;
-
                for (i = 0; i < kd->subkey_count; i++) {
                        el = ldb_msg_find_element(kd->subkeys[i], "key");
                        *max_subkeynamelen = MAX(*max_subkeynamelen, el->values[0].length);
                }
+
+               /* for UTF16 encoding */
+               *max_subkeynamelen *= 2;
        }
 
        if (max_valnamelen != NULL || max_valbufsize != NULL) {
@@ -1004,12 +1005,6 @@ static WERROR ldb_get_key_info(TALLOC_CTX *mem_ctx,
                struct ldb_message_element *el;
                W_ERROR_NOT_OK_RETURN(cache_values(kd));
 
-               if (max_valbufsize != NULL)
-                       *max_valbufsize = 0;
-
-               if (max_valnamelen != NULL)
-                       *max_valnamelen = 0;
-
                for (i = 0; i < kd->value_count; i++) {
                        if (max_valnamelen != NULL) {
                                el = ldb_msg_find_element(kd->values[i], "value");
@@ -1026,6 +1021,11 @@ static WERROR ldb_get_key_info(TALLOC_CTX *mem_ctx,
                                talloc_free(data.data);
                        }
                }
+
+               if (max_valnamelen != NULL) {
+                       /* for UTF16 encoding */
+                       *max_valnamelen *= 2;
+               }
        }
 
        return WERR_OK;