2 Unix SMB/CIFS implementation.
4 Copyright (C) 2004-2007, Jelmer Vernooij, jelmer@samba.org
5 Copyright (C) 2008-2010, Matthias Dieter Wallnöfer, mdw@samba.org
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "lib/ldb/include/ldb.h"
24 #include "lib/ldb/include/ldb_errors.h"
26 #include "librpc/gen_ndr/winreg.h"
27 #include "param/param.h"
29 static struct hive_operations reg_backend_ldb
;
34 struct ldb_context
*ldb
;
36 struct ldb_message
**subkeys
, **values
;
37 unsigned int subkey_count
, value_count
;
40 static void reg_ldb_unpack_value(TALLOC_CTX
*mem_ctx
,
41 struct ldb_message
*msg
,
42 const char **name
, uint32_t *type
,
45 const struct ldb_val
*val
;
49 *name
= talloc_strdup(mem_ctx
,
50 ldb_msg_find_attr_as_string(msg
, "value",
54 value_type
= ldb_msg_find_attr_as_uint(msg
, "type", 0);
57 val
= ldb_msg_find_ldb_val(msg
, "data");
64 convert_string_talloc(mem_ctx
, CH_UTF8
, CH_UTF16
,
65 val
->data
, val
->length
,
66 (void **)&data
->data
, &data
->length
, false);
75 uint32_t tmp
= strtoul((char *)val
->data
, NULL
, 0);
76 *data
= data_blob_talloc(mem_ctx
, NULL
, 4);
77 SIVAL(data
->data
, 0, tmp
);
87 *data
= data_blob_talloc(mem_ctx
, val
->data
, val
->length
);
96 static struct ldb_message
*reg_ldb_pack_value(struct ldb_context
*ctx
,
99 uint32_t type
, DATA_BLOB data
)
102 struct ldb_message
*msg
= talloc_zero(mem_ctx
, struct ldb_message
);
105 ldb_msg_add_string(msg
, "value", talloc_strdup(mem_ctx
, name
));
110 if ((data
.length
> 0) && (data
.data
!= NULL
)
111 && (data
.data
[0] != '\0')) {
112 convert_string_talloc(mem_ctx
, CH_UTF16
, CH_UTF8
,
115 (void **)&val
.data
, &val
.length
, false);
116 ldb_msg_add_value(msg
, "data", &val
, NULL
);
118 ldb_msg_add_empty(msg
, "data", LDB_FLAG_MOD_DELETE
, NULL
);
123 if ((data
.length
> 0) && (data
.data
!= NULL
)) {
124 ldb_msg_add_string(msg
, "data",
125 talloc_asprintf(mem_ctx
, "0x%x",
126 IVAL(data
.data
, 0)));
128 ldb_msg_add_empty(msg
, "data", LDB_FLAG_MOD_DELETE
, NULL
);
134 if ((data
.length
> 0) && (data
.data
!= NULL
)
135 && (data
.data
[0] != '\0')) {
136 ldb_msg_add_value(msg
, "data", &data
, NULL
);
138 ldb_msg_add_empty(msg
, "data", LDB_FLAG_MOD_DELETE
, NULL
);
143 type_s
= talloc_asprintf(mem_ctx
, "%u", type
);
144 ldb_msg_add_string(msg
, "type", type_s
);
149 static char *reg_ldb_escape(TALLOC_CTX
*mem_ctx
, const char *value
)
153 val
.data
= discard_const_p(uint8_t, value
);
154 val
.length
= strlen(value
);
156 return ldb_dn_escape_value(mem_ctx
, val
);
159 static int reg_close_ldb_key(struct ldb_key_data
*key
)
161 if (key
->subkeys
!= NULL
) {
162 talloc_free(key
->subkeys
);
166 if (key
->values
!= NULL
) {
167 talloc_free(key
->values
);
173 static struct ldb_dn
*reg_path_to_ldb(TALLOC_CTX
*mem_ctx
,
174 const struct hive_key
*from
,
175 const char *path
, const char *add
)
177 TALLOC_CTX
*local_ctx
;
179 char *mypath
= talloc_strdup(mem_ctx
, path
);
181 struct ldb_key_data
*kd
= talloc_get_type(from
, struct ldb_key_data
);
182 struct ldb_context
*ldb
= kd
->ldb
;
184 local_ctx
= talloc_new(mem_ctx
);
186 ret
= ldb_dn_new(mem_ctx
, ldb
, add
);
187 if (!ldb_dn_validate(ret
)) {
189 talloc_free(local_ctx
);
196 begin
= strrchr(mypath
, '\\');
198 if (begin
) keyname
= begin
+ 1;
199 else keyname
= mypath
;
201 if (keyname
[0] != '\0') {
202 if (!ldb_dn_add_base_fmt(ret
, "key=%s",
203 reg_ldb_escape(local_ctx
,
206 talloc_free(local_ctx
);
218 ldb_dn_add_base(ret
, kd
->dn
);
220 talloc_free(local_ctx
);
225 static WERROR
cache_subkeys(struct ldb_key_data
*kd
)
227 struct ldb_context
*c
= kd
->ldb
;
228 struct ldb_result
*res
;
231 ret
= ldb_search(c
, c
, &res
, kd
->dn
, LDB_SCOPE_ONELEVEL
, NULL
, "(key=*)");
233 if (ret
!= LDB_SUCCESS
) {
234 DEBUG(0, ("Error getting subkeys for '%s': %s\n",
235 ldb_dn_get_linearized(kd
->dn
), ldb_errstring(c
)));
239 kd
->subkey_count
= res
->count
;
240 kd
->subkeys
= talloc_steal(kd
, res
->msgs
);
246 static WERROR
cache_values(struct ldb_key_data
*kd
)
248 struct ldb_context
*c
= kd
->ldb
;
249 struct ldb_result
*res
;
252 ret
= ldb_search(c
, c
, &res
, kd
->dn
, LDB_SCOPE_ONELEVEL
,
255 if (ret
!= LDB_SUCCESS
) {
256 DEBUG(0, ("Error getting values for '%s': %s\n",
257 ldb_dn_get_linearized(kd
->dn
), ldb_errstring(c
)));
261 kd
->value_count
= res
->count
;
262 kd
->values
= talloc_steal(kd
, res
->msgs
);
269 static WERROR
ldb_get_subkey_by_id(TALLOC_CTX
*mem_ctx
,
270 const struct hive_key
*k
, uint32_t idx
,
272 const char **classname
,
273 NTTIME
*last_mod_time
)
275 struct ldb_message_element
*el
;
276 struct ldb_key_data
*kd
= talloc_get_type(k
, struct ldb_key_data
);
281 if (classname
!= NULL
)
282 *classname
= NULL
; /* TODO: Store properly */
283 if (last_mod_time
!= NULL
)
284 *last_mod_time
= 0; /* TODO: we need to add this to the
285 ldb backend properly */
287 /* Do a search if necessary */
288 if (kd
->subkeys
== NULL
) {
289 W_ERROR_NOT_OK_RETURN(cache_subkeys(kd
));
292 if (idx
>= kd
->subkey_count
)
293 return WERR_NO_MORE_ITEMS
;
295 el
= ldb_msg_find_element(kd
->subkeys
[idx
], "key");
296 SMB_ASSERT(el
!= NULL
);
297 SMB_ASSERT(el
->num_values
!= 0);
300 *name
= talloc_strdup(mem_ctx
, (char *)el
->values
[0].data
);
305 static WERROR
ldb_get_default_value(TALLOC_CTX
*mem_ctx
, struct hive_key
*k
,
306 const char **name
, uint32_t *data_type
,
309 struct ldb_key_data
*kd
= talloc_get_type(k
, struct ldb_key_data
);
310 struct ldb_context
*c
= kd
->ldb
;
311 const char* attrs
[] = { "data", "type", NULL
};
312 struct ldb_result
*res
;
315 ret
= ldb_search(c
, mem_ctx
, &res
, kd
->dn
, LDB_SCOPE_BASE
, attrs
, "%s", "");
317 if (ret
!= LDB_SUCCESS
) {
318 DEBUG(0, ("Error getting default value for '%s': %s\n",
319 ldb_dn_get_linearized(kd
->dn
), ldb_errstring(c
)));
323 if (res
->count
== 0 || res
->msgs
[0]->num_elements
== 0)
326 reg_ldb_unpack_value(mem_ctx
,
327 res
->msgs
[0], name
, data_type
, data
);
334 static WERROR
ldb_get_value_by_id(TALLOC_CTX
*mem_ctx
, struct hive_key
*k
,
335 uint32_t idx
, const char **name
,
336 uint32_t *data_type
, DATA_BLOB
*data
)
338 struct ldb_key_data
*kd
= talloc_get_type(k
, struct ldb_key_data
);
340 /* if default value exists, give it back */
341 if (W_ERROR_IS_OK(ldb_get_default_value(mem_ctx
, k
, name
, data_type
,
349 /* Do the search if necessary */
350 if (kd
->values
== NULL
) {
351 W_ERROR_NOT_OK_RETURN(cache_values(kd
));
354 if (idx
>= kd
->value_count
)
355 return WERR_NO_MORE_ITEMS
;
357 reg_ldb_unpack_value(mem_ctx
, kd
->values
[idx
], name
, data_type
, data
);
362 static WERROR
ldb_get_value(TALLOC_CTX
*mem_ctx
, struct hive_key
*k
,
363 const char *name
, uint32_t *data_type
,
366 struct ldb_key_data
*kd
= talloc_get_type(k
, struct ldb_key_data
);
367 struct ldb_context
*c
= kd
->ldb
;
368 struct ldb_result
*res
;
372 if ((name
== NULL
) || (name
[0] == '\0')) {
374 return ldb_get_default_value(mem_ctx
, k
, NULL
, data_type
, data
);
377 query
= talloc_asprintf(mem_ctx
, "(value=%s)", name
);
378 ret
= ldb_search(c
, mem_ctx
, &res
, kd
->dn
, LDB_SCOPE_ONELEVEL
, NULL
, "%s", query
);
381 if (ret
!= LDB_SUCCESS
) {
382 DEBUG(0, ("Error getting values for '%s': %s\n",
383 ldb_dn_get_linearized(kd
->dn
), ldb_errstring(c
)));
390 reg_ldb_unpack_value(mem_ctx
, res
->msgs
[0], NULL
, data_type
, data
);
398 static WERROR
ldb_open_key(TALLOC_CTX
*mem_ctx
, const struct hive_key
*h
,
399 const char *name
, struct hive_key
**key
)
401 struct ldb_result
*res
;
402 struct ldb_dn
*ldap_path
;
404 struct ldb_key_data
*newkd
;
405 struct ldb_key_data
*kd
= talloc_get_type(h
, struct ldb_key_data
);
406 struct ldb_context
*c
= kd
->ldb
;
408 ldap_path
= reg_path_to_ldb(mem_ctx
, h
, name
, NULL
);
410 ret
= ldb_search(c
, mem_ctx
, &res
, ldap_path
, LDB_SCOPE_BASE
, NULL
, "(key=*)");
412 if (ret
!= LDB_SUCCESS
) {
413 DEBUG(3, ("Error opening key '%s': %s\n",
414 ldb_dn_get_linearized(ldap_path
), ldb_errstring(c
)));
416 } else if (res
->count
== 0) {
417 DEBUG(3, ("Key '%s' not found\n",
418 ldb_dn_get_linearized(ldap_path
)));
423 newkd
= talloc_zero(mem_ctx
, struct ldb_key_data
);
424 newkd
->key
.ops
= ®_backend_ldb
;
425 newkd
->ldb
= talloc_reference(newkd
, kd
->ldb
);
426 newkd
->dn
= ldb_dn_copy(mem_ctx
, res
->msgs
[0]->dn
);
428 *key
= (struct hive_key
*)newkd
;
433 WERROR
reg_open_ldb_file(TALLOC_CTX
*parent_ctx
, const char *location
,
434 struct auth_session_info
*session_info
,
435 struct cli_credentials
*credentials
,
436 struct tevent_context
*ev_ctx
,
437 struct loadparm_context
*lp_ctx
,
440 struct ldb_key_data
*kd
;
441 struct ldb_context
*wrap
;
442 struct ldb_message
*attrs_msg
;
444 if (location
== NULL
)
445 return WERR_INVALID_PARAM
;
447 wrap
= ldb_wrap_connect(parent_ctx
, ev_ctx
, lp_ctx
,
448 location
, session_info
, credentials
, 0);
451 DEBUG(1, (__FILE__
": unable to connect\n"));
455 attrs_msg
= ldb_msg_new(wrap
);
456 W_ERROR_HAVE_NO_MEMORY(attrs_msg
);
457 attrs_msg
->dn
= ldb_dn_new(attrs_msg
, wrap
, "@ATTRIBUTES");
458 W_ERROR_HAVE_NO_MEMORY(attrs_msg
->dn
);
459 ldb_msg_add_string(attrs_msg
, "key", "CASE_INSENSITIVE");
460 ldb_msg_add_string(attrs_msg
, "value", "CASE_INSENSITIVE");
462 ldb_add(wrap
, attrs_msg
);
464 ldb_set_debug_stderr(wrap
);
466 kd
= talloc_zero(parent_ctx
, struct ldb_key_data
);
467 kd
->key
.ops
= ®_backend_ldb
;
468 kd
->ldb
= talloc_reference(kd
, wrap
);
469 talloc_set_destructor (kd
, reg_close_ldb_key
);
470 kd
->dn
= ldb_dn_new(kd
, wrap
, "hive=NONE");
472 *k
= (struct hive_key
*)kd
;
477 static WERROR
ldb_add_key(TALLOC_CTX
*mem_ctx
, const struct hive_key
*parent
,
478 const char *name
, const char *classname
,
479 struct security_descriptor
*sd
,
480 struct hive_key
**newkey
)
482 struct ldb_key_data
*parentkd
= discard_const_p(struct ldb_key_data
, parent
);
483 struct ldb_message
*msg
;
484 struct ldb_key_data
*newkd
;
487 msg
= ldb_msg_new(mem_ctx
);
489 msg
->dn
= reg_path_to_ldb(msg
, parent
, name
, NULL
);
491 ldb_msg_add_string(msg
, "key", talloc_strdup(mem_ctx
, name
));
492 if (classname
!= NULL
)
493 ldb_msg_add_string(msg
, "classname",
494 talloc_strdup(mem_ctx
, classname
));
496 ret
= ldb_add(parentkd
->ldb
, msg
);
497 if (ret
== LDB_ERR_ENTRY_ALREADY_EXISTS
) {
498 return WERR_ALREADY_EXISTS
;
501 if (ret
!= LDB_SUCCESS
) {
502 DEBUG(1, ("ldb_add: %s\n", ldb_errstring(parentkd
->ldb
)));
506 DEBUG(2, ("key added: %s\n", ldb_dn_get_linearized(msg
->dn
)));
508 newkd
= talloc_zero(mem_ctx
, struct ldb_key_data
);
509 newkd
->ldb
= talloc_reference(newkd
, parentkd
->ldb
);
510 newkd
->key
.ops
= ®_backend_ldb
;
511 newkd
->dn
= talloc_steal(newkd
, msg
->dn
);
513 *newkey
= (struct hive_key
*)newkd
;
516 talloc_free(parentkd
->subkeys
);
517 parentkd
->subkeys
= NULL
;
522 static WERROR
ldb_del_value (struct hive_key
*key
, const char *child
)
525 struct ldb_key_data
*kd
= talloc_get_type(key
, struct ldb_key_data
);
527 struct ldb_message
*msg
;
528 struct ldb_dn
*childdn
;
530 if ((child
== NULL
) || (child
[0] == '\0')) {
532 mem_ctx
= talloc_init("ldb_del_value");
534 msg
= talloc_zero(mem_ctx
, struct ldb_message
);
535 msg
->dn
= ldb_dn_copy(msg
, kd
->dn
);
536 ldb_msg_add_empty(msg
, "data", LDB_FLAG_MOD_DELETE
, NULL
);
537 ldb_msg_add_empty(msg
, "type", LDB_FLAG_MOD_DELETE
, NULL
);
539 ret
= ldb_modify(kd
->ldb
, msg
);
540 if (ret
!= LDB_SUCCESS
) {
541 DEBUG(1, ("ldb_del_value: %s\n", ldb_errstring(kd
->ldb
)));
542 talloc_free(mem_ctx
);
546 talloc_free(mem_ctx
);
549 childdn
= ldb_dn_copy(kd
->ldb
, kd
->dn
);
550 if (!ldb_dn_add_child_fmt(childdn
, "value=%s",
551 reg_ldb_escape(childdn
, child
)))
553 talloc_free(childdn
);
557 ret
= ldb_delete(kd
->ldb
, childdn
);
559 talloc_free(childdn
);
561 if (ret
== LDB_ERR_NO_SUCH_OBJECT
) {
563 } else if (ret
!= LDB_SUCCESS
) {
564 DEBUG(1, ("ldb_del_value: %s\n", ldb_errstring(kd
->ldb
)));
570 talloc_free(kd
->values
);
576 static WERROR
ldb_del_key(const struct hive_key
*key
, const char *name
)
580 struct ldb_key_data
*parentkd
= talloc_get_type(key
, struct ldb_key_data
);
581 struct ldb_dn
*ldap_path
;
582 TALLOC_CTX
*mem_ctx
= talloc_init("ldb_del_key");
583 struct ldb_context
*c
= parentkd
->ldb
;
584 struct ldb_result
*res_keys
;
585 struct ldb_result
*res_vals
;
589 /* Verify key exists by opening it */
590 werr
= ldb_open_key(mem_ctx
, key
, name
, &hk
);
591 if (!W_ERROR_IS_OK(werr
)) {
592 talloc_free(mem_ctx
);
596 ldap_path
= reg_path_to_ldb(mem_ctx
, key
, name
, NULL
);
598 talloc_free(mem_ctx
);
602 /* Search for subkeys */
603 ret
= ldb_search(c
, mem_ctx
, &res_keys
, ldap_path
, LDB_SCOPE_ONELEVEL
,
606 if (ret
!= LDB_SUCCESS
) {
607 DEBUG(0, ("Error getting subkeys for '%s': %s\n",
608 ldb_dn_get_linearized(ldap_path
), ldb_errstring(c
)));
609 talloc_free(mem_ctx
);
613 /* Search for values */
614 ret
= ldb_search(c
, mem_ctx
, &res_vals
, ldap_path
, LDB_SCOPE_ONELEVEL
,
617 if (ret
!= LDB_SUCCESS
) {
618 DEBUG(0, ("Error getting values for '%s': %s\n",
619 ldb_dn_get_linearized(ldap_path
), ldb_errstring(c
)));
620 talloc_free(mem_ctx
);
624 /* Start an explicit transaction */
625 ret
= ldb_transaction_start(c
);
627 if (ret
!= LDB_SUCCESS
) {
628 DEBUG(0, ("ldb_transaction_start: %s\n", ldb_errstring(c
)));
629 talloc_free(mem_ctx
);
633 if (res_keys
->count
|| res_vals
->count
)
635 /* Delete any subkeys */
636 for (i
= 0; i
< res_keys
->count
; i
++)
638 werr
= ldb_del_key(hk
, ldb_msg_find_attr_as_string(
641 if (!W_ERROR_IS_OK(werr
)) {
642 ret
= ldb_transaction_cancel(c
);
643 talloc_free(mem_ctx
);
648 /* Delete any values */
649 for (i
= 0; i
< res_vals
->count
; i
++)
651 werr
= ldb_del_value(hk
, ldb_msg_find_attr_as_string(
654 if (!W_ERROR_IS_OK(werr
)) {
655 ret
= ldb_transaction_cancel(c
);
656 talloc_free(mem_ctx
);
662 /* Delete the key itself */
663 ret
= ldb_delete(c
, ldap_path
);
665 if (ret
!= LDB_SUCCESS
)
667 DEBUG(1, ("ldb_del_key: %s\n", ldb_errstring(c
)));
668 ret
= ldb_transaction_cancel(c
);
669 talloc_free(mem_ctx
);
673 /* Commit the transaction */
674 ret
= ldb_transaction_commit(c
);
676 if (ret
!= LDB_SUCCESS
)
678 DEBUG(0, ("ldb_transaction_commit: %s\n", ldb_errstring(c
)));
679 ret
= ldb_transaction_cancel(c
);
680 talloc_free(mem_ctx
);
684 talloc_free(mem_ctx
);
687 talloc_free(parentkd
->subkeys
);
688 parentkd
->subkeys
= NULL
;
693 static WERROR
ldb_set_value(struct hive_key
*parent
,
694 const char *name
, uint32_t type
,
695 const DATA_BLOB data
)
697 struct ldb_message
*msg
;
698 struct ldb_key_data
*kd
= talloc_get_type(parent
, struct ldb_key_data
);
701 TALLOC_CTX
*mem_ctx
= talloc_init("ldb_set_value");
703 msg
= reg_ldb_pack_value(kd
->ldb
, mem_ctx
, name
, type
, data
);
704 msg
->dn
= ldb_dn_copy(msg
, kd
->dn
);
706 if ((name
!= NULL
) && (name
[0] != '\0')) {
707 /* For a default value, we add/overwrite the attributes to/of the hive.
708 For a normal value, we create a new child. */
709 if (!ldb_dn_add_child_fmt(msg
->dn
, "value=%s",
710 reg_ldb_escape(mem_ctx
, name
)))
712 talloc_free(mem_ctx
);
717 /* Try first a "modify" and if this doesn't work do try an "add" */
718 for (i
= 0; i
< msg
->num_elements
; i
++) {
719 if (msg
->elements
[i
].flags
!= LDB_FLAG_MOD_DELETE
) {
720 msg
->elements
[i
].flags
= LDB_FLAG_MOD_REPLACE
;
723 ret
= ldb_modify(kd
->ldb
, msg
);
724 if (ret
== LDB_ERR_NO_SUCH_OBJECT
) {
726 while (i
< msg
->num_elements
) {
727 if (msg
->elements
[i
].flags
== LDB_FLAG_MOD_DELETE
) {
728 ldb_msg_remove_element(msg
, &msg
->elements
[i
]);
733 ret
= ldb_add(kd
->ldb
, msg
);
735 if (ret
== LDB_ERR_NO_SUCH_ATTRIBUTE
) {
736 /* ignore this -> the value didn't exist and also now doesn't */
740 if (ret
!= LDB_SUCCESS
) {
741 DEBUG(1, ("ldb_set_value: %s\n", ldb_errstring(kd
->ldb
)));
742 talloc_free(mem_ctx
);
747 talloc_free(kd
->values
);
750 talloc_free(mem_ctx
);
754 static WERROR
ldb_get_key_info(TALLOC_CTX
*mem_ctx
,
755 const struct hive_key
*key
,
756 const char **classname
,
757 uint32_t *num_subkeys
,
758 uint32_t *num_values
,
759 NTTIME
*last_change_time
,
760 uint32_t *max_subkeynamelen
,
761 uint32_t *max_valnamelen
,
762 uint32_t *max_valbufsize
)
764 struct ldb_key_data
*kd
= talloc_get_type(key
, struct ldb_key_data
);
767 if (classname
!= NULL
)
769 if (num_subkeys
!= NULL
)
771 if (num_values
!= NULL
)
773 if (last_change_time
!= NULL
)
774 *last_change_time
= 0;
775 if (max_subkeynamelen
!= NULL
)
776 *max_subkeynamelen
= 0;
777 if (max_valnamelen
!= NULL
)
779 if (max_valbufsize
!= NULL
)
782 if (kd
->subkeys
== NULL
) {
783 W_ERROR_NOT_OK_RETURN(cache_subkeys(kd
));
786 if (kd
->values
== NULL
) {
787 W_ERROR_NOT_OK_RETURN(cache_values(kd
));
790 if (num_subkeys
!= NULL
) {
791 *num_subkeys
= kd
->subkey_count
;
793 if (num_values
!= NULL
) {
794 *num_values
= kd
->value_count
;
798 if (max_subkeynamelen
!= NULL
) {
800 struct ldb_message_element
*el
;
802 *max_subkeynamelen
= 0;
804 for (i
= 0; i
< kd
->subkey_count
; i
++) {
805 el
= ldb_msg_find_element(kd
->subkeys
[i
], "key");
806 *max_subkeynamelen
= MAX(*max_subkeynamelen
, el
->values
[0].length
);
810 if (max_valnamelen
!= NULL
|| max_valbufsize
!= NULL
) {
812 struct ldb_message_element
*el
;
813 W_ERROR_NOT_OK_RETURN(cache_values(kd
));
815 if (max_valbufsize
!= NULL
)
818 if (max_valnamelen
!= NULL
)
821 for (i
= 0; i
< kd
->value_count
; i
++) {
822 if (max_valnamelen
!= NULL
) {
823 el
= ldb_msg_find_element(kd
->values
[i
], "value");
824 *max_valnamelen
= MAX(*max_valnamelen
, el
->values
[0].length
);
827 if (max_valbufsize
!= NULL
) {
830 reg_ldb_unpack_value(mem_ctx
,
833 *max_valbufsize
= MAX(*max_valbufsize
, data
.length
);
834 talloc_free(data
.data
);
842 static struct hive_operations reg_backend_ldb
= {
844 .add_key
= ldb_add_key
,
845 .del_key
= ldb_del_key
,
846 .get_key_by_name
= ldb_open_key
,
847 .enum_value
= ldb_get_value_by_id
,
848 .enum_key
= ldb_get_subkey_by_id
,
849 .set_value
= ldb_set_value
,
850 .get_value_by_name
= ldb_get_value
,
851 .delete_value
= ldb_del_value
,
852 .get_key_info
= ldb_get_key_info
,