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;
38 const char *classname;
41 static void reg_ldb_unpack_value(TALLOC_CTX *mem_ctx,
42 struct ldb_message *msg,
43 const char **name, uint32_t *type,
46 const struct ldb_val *val;
50 *name = talloc_strdup(mem_ctx,
51 ldb_msg_find_attr_as_string(msg, "value",
55 value_type = ldb_msg_find_attr_as_uint(msg, "type", 0);
58 val = ldb_msg_find_ldb_val(msg, "data");
65 /* The data should be provided as UTF16 string */
66 convert_string_talloc(mem_ctx, CH_UTF8, CH_UTF16,
67 val->data, val->length,
68 (void **)&data->data, &data->length, false);
76 case REG_DWORD_BIG_ENDIAN:
78 /* The data is a plain DWORD */
79 uint32_t tmp = strtoul((char *)val->data, NULL, 0);
80 data->data = talloc_size(mem_ctx, sizeof(uint32_t));
81 if (data->data != NULL) {
82 SIVAL(data->data, 0, tmp);
84 data->length = sizeof(uint32_t);
93 /* The data is a plain QWORD */
94 uint64_t tmp = strtoull((char *)val->data, NULL, 0);
95 data->data = talloc_size(mem_ctx, sizeof(uint64_t));
96 if (data->data != NULL) {
97 SBVAL(data->data, 0, tmp);
99 data->length = sizeof(uint64_t);
109 data->data = talloc_memdup(mem_ctx, val->data,
111 data->length = val->length;
120 static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx,
123 uint32_t type, DATA_BLOB data)
125 struct ldb_message *msg;
126 char *name_dup, *type_str;
129 msg = talloc_zero(mem_ctx, struct ldb_message);
134 name_dup = talloc_strdup(msg, name);
135 if (name_dup == NULL) {
140 ret = ldb_msg_add_string(msg, "value", name_dup);
141 if (ret != LDB_SUCCESS) {
149 if ((data.length > 0) && (data.data != NULL)) {
153 val = talloc_zero(msg, struct ldb_val);
159 /* The data is provided as UTF16 string */
160 ret2 = convert_string_talloc(mem_ctx, CH_UTF16, CH_UTF8,
161 (void *)data.data, data.length,
162 (void **)&val->data, &val->length,
165 ret = ldb_msg_add_value(msg, "data", val, NULL);
167 /* workaround for non-standard data */
168 ret = ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL);
171 ret = ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL);
176 case REG_DWORD_BIG_ENDIAN:
177 if ((data.length > 0) && (data.data != NULL)) {
178 if (data.length == sizeof(uint32_t)) {
181 conv_str = talloc_asprintf(msg, "0x%8.8x",
183 if (conv_str == NULL) {
187 ret = ldb_msg_add_string(msg, "data", conv_str);
189 /* workaround for non-standard data */
194 ret = ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL);
199 if ((data.length > 0) && (data.data != NULL)) {
200 if (data.length == sizeof(uint64_t)) {
203 conv_str = talloc_asprintf(msg, "0x%16.16llx",
205 if (conv_str == NULL) {
209 ret = ldb_msg_add_string(msg, "data", conv_str);
211 /* workaround for non-standard data */
217 ret = ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL);
223 if ((data.length > 0) && (data.data != NULL)) {
224 ret = ldb_msg_add_value(msg, "data", &data, NULL);
226 ret = ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL);
231 if (ret != LDB_SUCCESS) {
236 type_str = talloc_asprintf(mem_ctx, "%u", type);
237 if (type_str == NULL) {
242 ret = ldb_msg_add_string(msg, "type", type_str);
243 if (ret != LDB_SUCCESS) {
251 static char *reg_ldb_escape(TALLOC_CTX *mem_ctx, const char *value)
255 val.data = discard_const_p(uint8_t, value);
256 val.length = strlen(value);
258 return ldb_dn_escape_value(mem_ctx, val);
261 static int reg_close_ldb_key(struct ldb_key_data *key)
263 if (key->subkeys != NULL) {
264 talloc_free(key->subkeys);
268 if (key->values != NULL) {
269 talloc_free(key->values);
275 static struct ldb_dn *reg_path_to_ldb(TALLOC_CTX *mem_ctx,
276 const struct hive_key *from,
277 const char *path, const char *add)
282 struct ldb_key_data *kd = talloc_get_type(from, struct ldb_key_data);
283 struct ldb_context *ldb = kd->ldb;
285 mypath = talloc_strdup(mem_ctx, path);
286 if (mypath == NULL) {
290 ret = ldb_dn_new(mem_ctx, ldb, add);
291 if (!ldb_dn_validate(ret)) {
296 if (!ldb_dn_add_base(ret, kd->dn)) {
301 while (mypath[0] != '\0') {
302 begin = strchr(mypath, '\\');
307 if (!ldb_dn_add_child_fmt(ret, "key=%s",
308 reg_ldb_escape(mem_ctx, mypath))) {
323 static WERROR cache_subkeys(struct ldb_key_data *kd)
325 struct ldb_context *c = kd->ldb;
326 struct ldb_result *res;
329 ret = ldb_search(c, c, &res, kd->dn, LDB_SCOPE_ONELEVEL,
331 if (ret != LDB_SUCCESS) {
332 DEBUG(0, ("Error getting subkeys for '%s': %s\n",
333 ldb_dn_get_linearized(kd->dn), ldb_errstring(c)));
337 kd->subkey_count = res->count;
338 kd->subkeys = talloc_steal(kd, res->msgs);
344 static WERROR cache_values(struct ldb_key_data *kd)
346 struct ldb_context *c = kd->ldb;
347 struct ldb_result *res;
350 ret = ldb_search(c, c, &res, kd->dn, LDB_SCOPE_ONELEVEL,
352 if (ret != LDB_SUCCESS) {
353 DEBUG(0, ("Error getting values for '%s': %s\n",
354 ldb_dn_get_linearized(kd->dn), ldb_errstring(c)));
358 kd->value_count = res->count;
359 kd->values = talloc_steal(kd, res->msgs);
366 static WERROR ldb_get_subkey_by_id(TALLOC_CTX *mem_ctx,
367 const struct hive_key *k, uint32_t idx,
369 const char **classname,
370 NTTIME *last_mod_time)
372 struct ldb_key_data *kd = talloc_get_type(k, struct ldb_key_data);
377 if (classname != NULL)
379 if (last_mod_time != NULL)
380 *last_mod_time = 0; /* TODO: we need to add this to the
381 ldb backend properly */
383 /* Do a search if necessary */
384 if (kd->subkeys == NULL) {
385 W_ERROR_NOT_OK_RETURN(cache_subkeys(kd));
388 if (idx >= kd->subkey_count)
389 return WERR_NO_MORE_ITEMS;
392 *name = talloc_strdup(mem_ctx,
393 ldb_msg_find_attr_as_string(kd->subkeys[idx], "key", NULL));
394 if (classname != NULL)
395 *classname = talloc_strdup(mem_ctx,
396 ldb_msg_find_attr_as_string(kd->subkeys[idx], "classname", NULL));
401 static WERROR ldb_get_default_value(TALLOC_CTX *mem_ctx,
402 const struct hive_key *k,
403 const char **name, uint32_t *data_type,
406 struct ldb_key_data *kd = talloc_get_type(k, struct ldb_key_data);
407 struct ldb_context *c = kd->ldb;
408 const char* attrs[] = { "data", "type", NULL };
409 struct ldb_result *res;
412 ret = ldb_search(c, mem_ctx, &res, kd->dn, LDB_SCOPE_BASE, attrs, "(dn=*)");
414 if (ret != LDB_SUCCESS) {
415 DEBUG(0, ("Error getting default value for '%s': %s\n",
416 ldb_dn_get_linearized(kd->dn), ldb_errstring(c)));
420 if (res->count == 0 || res->msgs[0]->num_elements == 0)
423 if ((data_type != NULL) && (data != NULL)) {
424 reg_ldb_unpack_value(mem_ctx, res->msgs[0], name, data_type,
433 static WERROR ldb_get_value_by_id(TALLOC_CTX *mem_ctx, struct hive_key *k,
434 uint32_t idx, const char **name,
435 uint32_t *data_type, DATA_BLOB *data)
437 struct ldb_key_data *kd = talloc_get_type(k, struct ldb_key_data);
439 /* if the default value exists, give it back */
440 if (W_ERROR_IS_OK(ldb_get_default_value(mem_ctx, k, name, data_type,
448 /* Do the search if necessary */
449 if (kd->values == NULL) {
450 W_ERROR_NOT_OK_RETURN(cache_values(kd));
453 if (idx >= kd->value_count)
454 return WERR_NO_MORE_ITEMS;
456 reg_ldb_unpack_value(mem_ctx, kd->values[idx], name, data_type, data);
461 static WERROR ldb_get_value(TALLOC_CTX *mem_ctx, struct hive_key *k,
462 const char *name, uint32_t *data_type,
465 struct ldb_key_data *kd = talloc_get_type(k, struct ldb_key_data);
466 const char *res_name;
469 /* the default value was requested, give it back */
470 if (name[0] == '\0') {
471 return ldb_get_default_value(mem_ctx, k, NULL, data_type, data);
474 /* Do the search if necessary */
475 if (kd->values == NULL) {
476 W_ERROR_NOT_OK_RETURN(cache_values(kd));
479 for (idx = 0; idx < kd->value_count; idx++) {
480 res_name = ldb_msg_find_attr_as_string(kd->values[idx], "value",
482 if (ldb_attr_cmp(name, res_name) == 0) {
483 reg_ldb_unpack_value(mem_ctx, kd->values[idx], NULL,
492 static WERROR ldb_open_key(TALLOC_CTX *mem_ctx, const struct hive_key *h,
493 const char *name, struct hive_key **key)
495 struct ldb_result *res;
496 struct ldb_dn *ldb_path;
498 struct ldb_key_data *newkd;
499 struct ldb_key_data *kd = talloc_get_type(h, struct ldb_key_data);
500 struct ldb_context *c = kd->ldb;
502 ldb_path = reg_path_to_ldb(mem_ctx, h, name, NULL);
503 W_ERROR_HAVE_NO_MEMORY(ldb_path);
505 ret = ldb_search(c, mem_ctx, &res, ldb_path, LDB_SCOPE_BASE, NULL, "(key=*)");
507 if (ret != LDB_SUCCESS) {
508 DEBUG(3, ("Error opening key '%s': %s\n",
509 ldb_dn_get_linearized(ldb_path), ldb_errstring(c)));
511 } else if (res->count == 0) {
512 DEBUG(3, ("Key '%s' not found\n",
513 ldb_dn_get_linearized(ldb_path)));
518 newkd = talloc_zero(mem_ctx, struct ldb_key_data);
519 W_ERROR_HAVE_NO_MEMORY(newkd);
520 newkd->key.ops = ®_backend_ldb;
521 newkd->ldb = talloc_reference(newkd, kd->ldb);
522 newkd->dn = ldb_dn_copy(newkd, res->msgs[0]->dn);
523 newkd->classname = talloc_steal(newkd,
524 ldb_msg_find_attr_as_string(res->msgs[0], "classname", NULL));
528 *key = (struct hive_key *)newkd;
533 WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location,
534 struct auth_session_info *session_info,
535 struct cli_credentials *credentials,
536 struct tevent_context *ev_ctx,
537 struct loadparm_context *lp_ctx,
540 struct ldb_key_data *kd;
541 struct ldb_context *wrap;
542 struct ldb_message *attrs_msg;
544 if (location == NULL)
545 return WERR_INVALID_PARAM;
547 wrap = ldb_wrap_connect(parent_ctx, ev_ctx, lp_ctx,
548 location, session_info, credentials, 0);
551 DEBUG(1, (__FILE__": unable to connect\n"));
555 attrs_msg = ldb_msg_new(wrap);
556 W_ERROR_HAVE_NO_MEMORY(attrs_msg);
557 attrs_msg->dn = ldb_dn_new(attrs_msg, wrap, "@ATTRIBUTES");
558 W_ERROR_HAVE_NO_MEMORY(attrs_msg->dn);
559 ldb_msg_add_string(attrs_msg, "key", "CASE_INSENSITIVE");
560 ldb_msg_add_string(attrs_msg, "value", "CASE_INSENSITIVE");
562 ldb_add(wrap, attrs_msg);
564 ldb_set_debug_stderr(wrap);
566 kd = talloc_zero(parent_ctx, struct ldb_key_data);
567 kd->key.ops = ®_backend_ldb;
568 kd->ldb = talloc_reference(kd, wrap);
569 talloc_set_destructor (kd, reg_close_ldb_key);
570 kd->dn = ldb_dn_new(kd, wrap, "hive=NONE");
572 *k = (struct hive_key *)kd;
577 static WERROR ldb_add_key(TALLOC_CTX *mem_ctx, const struct hive_key *parent,
578 const char *name, const char *classname,
579 struct security_descriptor *sd,
580 struct hive_key **newkey)
582 struct ldb_key_data *parentkd = discard_const_p(struct ldb_key_data, parent);
583 struct ldb_dn *ldb_path;
584 struct ldb_message *msg;
585 struct ldb_key_data *newkd;
588 ldb_path = reg_path_to_ldb(mem_ctx, parent, name, NULL);
589 W_ERROR_HAVE_NO_MEMORY(ldb_path);
591 msg = ldb_msg_new(mem_ctx);
592 W_ERROR_HAVE_NO_MEMORY(msg);
596 ldb_msg_add_string(msg, "key", name);
597 if (classname != NULL) {
598 ldb_msg_add_string(msg, "classname", classname);
601 ret = ldb_add(parentkd->ldb, msg);
605 if (ret == LDB_ERR_ENTRY_ALREADY_EXISTS) {
606 return WERR_ALREADY_EXISTS;
609 if (ret != LDB_SUCCESS) {
610 DEBUG(1, ("ldb_add: %s\n", ldb_errstring(parentkd->ldb)));
614 DEBUG(2, ("key added: %s\n", ldb_dn_get_linearized(ldb_path)));
616 newkd = talloc_zero(mem_ctx, struct ldb_key_data);
617 W_ERROR_HAVE_NO_MEMORY(newkd);
618 newkd->ldb = talloc_reference(newkd, parentkd->ldb);
619 newkd->key.ops = ®_backend_ldb;
620 newkd->dn = talloc_steal(newkd, ldb_path);
621 newkd->classname = talloc_steal(newkd, classname);
623 *newkey = (struct hive_key *)newkd;
626 talloc_free(parentkd->subkeys);
627 parentkd->subkeys = NULL;
632 static WERROR ldb_del_value(TALLOC_CTX *mem_ctx, struct hive_key *key,
636 struct ldb_key_data *kd = talloc_get_type(key, struct ldb_key_data);
637 struct ldb_message *msg;
638 struct ldb_dn *childdn;
640 if (child[0] == '\0') {
642 msg = talloc_zero(mem_ctx, struct ldb_message);
643 W_ERROR_HAVE_NO_MEMORY(msg);
644 msg->dn = ldb_dn_copy(msg, kd->dn);
645 W_ERROR_HAVE_NO_MEMORY(msg->dn);
646 ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL);
647 ldb_msg_add_empty(msg, "type", LDB_FLAG_MOD_DELETE, NULL);
649 ret = ldb_modify(kd->ldb, msg);
650 if (ret != LDB_SUCCESS) {
651 DEBUG(1, ("ldb_del_value: %s\n", ldb_errstring(kd->ldb)));
656 childdn = ldb_dn_copy(kd->ldb, kd->dn);
657 if (!ldb_dn_add_child_fmt(childdn, "value=%s",
658 reg_ldb_escape(childdn, child)))
660 talloc_free(childdn);
664 ret = ldb_delete(kd->ldb, childdn);
666 talloc_free(childdn);
668 if (ret == LDB_ERR_NO_SUCH_OBJECT) {
670 } else if (ret != LDB_SUCCESS) {
671 DEBUG(1, ("ldb_del_value: %s\n", ldb_errstring(kd->ldb)));
677 talloc_free(kd->values);
683 static WERROR ldb_del_key(TALLOC_CTX *mem_ctx, const struct hive_key *key,
688 struct ldb_key_data *parentkd = talloc_get_type(key, struct ldb_key_data);
689 struct ldb_dn *ldb_path;
690 struct ldb_context *c = parentkd->ldb;
691 struct ldb_result *res_keys;
692 struct ldb_result *res_vals;
696 /* Verify key exists by opening it */
697 werr = ldb_open_key(mem_ctx, key, name, &hk);
698 if (!W_ERROR_IS_OK(werr)) {
702 ldb_path = reg_path_to_ldb(mem_ctx, key, name, NULL);
703 W_ERROR_HAVE_NO_MEMORY(ldb_path);
705 /* Search for subkeys */
706 ret = ldb_search(c, mem_ctx, &res_keys, ldb_path, LDB_SCOPE_ONELEVEL,
709 if (ret != LDB_SUCCESS) {
710 DEBUG(0, ("Error getting subkeys for '%s': %s\n",
711 ldb_dn_get_linearized(ldb_path), ldb_errstring(c)));
715 /* Search for values */
716 ret = ldb_search(c, mem_ctx, &res_vals, ldb_path, LDB_SCOPE_ONELEVEL,
719 if (ret != LDB_SUCCESS) {
720 DEBUG(0, ("Error getting values for '%s': %s\n",
721 ldb_dn_get_linearized(ldb_path), ldb_errstring(c)));
725 /* Start an explicit transaction */
726 ret = ldb_transaction_start(c);
728 if (ret != LDB_SUCCESS) {
729 DEBUG(0, ("ldb_transaction_start: %s\n", ldb_errstring(c)));
733 if (res_keys->count || res_vals->count)
735 /* Delete any subkeys */
736 for (i = 0; i < res_keys->count; i++)
738 werr = ldb_del_key(mem_ctx, hk,
739 ldb_msg_find_attr_as_string(
742 if (!W_ERROR_IS_OK(werr)) {
743 ret = ldb_transaction_cancel(c);
748 /* Delete any values */
749 for (i = 0; i < res_vals->count; i++)
751 werr = ldb_del_value(mem_ctx, hk,
752 ldb_msg_find_attr_as_string(
755 if (!W_ERROR_IS_OK(werr)) {
756 ret = ldb_transaction_cancel(c);
762 /* Delete the key itself */
763 ret = ldb_delete(c, ldb_path);
765 if (ret != LDB_SUCCESS)
767 DEBUG(1, ("ldb_del_key: %s\n", ldb_errstring(c)));
768 ret = ldb_transaction_cancel(c);
772 /* Commit the transaction */
773 ret = ldb_transaction_commit(c);
775 if (ret != LDB_SUCCESS)
777 DEBUG(0, ("ldb_transaction_commit: %s\n", ldb_errstring(c)));
778 ret = ldb_transaction_cancel(c);
783 talloc_free(parentkd->subkeys);
784 parentkd->subkeys = NULL;
789 static WERROR ldb_set_value(struct hive_key *parent,
790 const char *name, uint32_t type,
791 const DATA_BLOB data)
793 struct ldb_message *msg;
794 struct ldb_key_data *kd = talloc_get_type(parent, struct ldb_key_data);
797 TALLOC_CTX *mem_ctx = talloc_init("ldb_set_value");
799 msg = reg_ldb_pack_value(kd->ldb, mem_ctx, name, type, data);
800 W_ERROR_HAVE_NO_MEMORY(msg);
802 msg->dn = ldb_dn_copy(msg, kd->dn);
803 W_ERROR_HAVE_NO_MEMORY(msg->dn);
805 if (name[0] != '\0') {
806 /* For a default value, we add/overwrite the attributes to/of the hive.
807 For a normal value, we create a new child. */
808 if (!ldb_dn_add_child_fmt(msg->dn, "value=%s",
809 reg_ldb_escape(mem_ctx, name)))
811 talloc_free(mem_ctx);
816 /* Try first a "modify" and if this doesn't work do try an "add" */
817 for (i = 0; i < msg->num_elements; i++) {
818 if (msg->elements[i].flags != LDB_FLAG_MOD_DELETE) {
819 msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
822 ret = ldb_modify(kd->ldb, msg);
823 if (ret == LDB_ERR_NO_SUCH_OBJECT) {
825 while (i < msg->num_elements) {
826 if (msg->elements[i].flags == LDB_FLAG_MOD_DELETE) {
827 ldb_msg_remove_element(msg, &msg->elements[i]);
832 ret = ldb_add(kd->ldb, msg);
834 if (ret == LDB_ERR_NO_SUCH_ATTRIBUTE) {
835 /* ignore this -> the value didn't exist and also now doesn't */
839 if (ret != LDB_SUCCESS) {
840 DEBUG(1, ("ldb_set_value: %s\n", ldb_errstring(kd->ldb)));
841 talloc_free(mem_ctx);
846 talloc_free(kd->values);
849 talloc_free(mem_ctx);
853 static WERROR ldb_get_key_info(TALLOC_CTX *mem_ctx,
854 const struct hive_key *key,
855 const char **classname,
856 uint32_t *num_subkeys,
857 uint32_t *num_values,
858 NTTIME *last_change_time,
859 uint32_t *max_subkeynamelen,
860 uint32_t *max_valnamelen,
861 uint32_t *max_valbufsize)
863 struct ldb_key_data *kd = talloc_get_type(key, struct ldb_key_data);
864 uint32_t default_value_type = REG_NONE;
865 DATA_BLOB default_value = { NULL, 0 };
869 if (classname != NULL)
871 if (num_subkeys != NULL)
873 if (num_values != NULL)
875 if (last_change_time != NULL)
876 *last_change_time = 0;
877 if (max_subkeynamelen != NULL)
878 *max_subkeynamelen = 0;
879 if (max_valnamelen != NULL)
881 if (max_valbufsize != NULL)
884 /* We need this to get the default value (if it exists) for counting
885 * the values under the key and for finding out the longest value buffer
886 * size. If no default value exists the DATA_BLOB "default_value" will
887 * remain { NULL, 0 }. */
888 werr = ldb_get_default_value(mem_ctx, key, NULL, &default_value_type,
890 if ((!W_ERROR_IS_OK(werr)) && (!W_ERROR_EQUAL(werr, WERR_BADFILE))) {
894 if (kd->subkeys == NULL) {
895 W_ERROR_NOT_OK_RETURN(cache_subkeys(kd));
897 if (kd->values == NULL) {
898 W_ERROR_NOT_OK_RETURN(cache_values(kd));
901 if (classname != NULL) {
902 *classname = kd->classname;
905 if (num_subkeys != NULL) {
906 *num_subkeys = kd->subkey_count;
908 if (num_values != NULL) {
909 *num_values = kd->value_count;
910 /* also consider the default value if it exists */
911 if (default_value.data != NULL) {
917 if (max_subkeynamelen != NULL) {
919 struct ldb_message_element *el;
921 for (i = 0; i < kd->subkey_count; i++) {
922 el = ldb_msg_find_element(kd->subkeys[i], "key");
923 *max_subkeynamelen = MAX(*max_subkeynamelen, el->values[0].length);
927 if (max_valnamelen != NULL || max_valbufsize != NULL) {
929 struct ldb_message_element *el;
930 W_ERROR_NOT_OK_RETURN(cache_values(kd));
932 /* also consider the default value if it exists */
933 if ((max_valbufsize != NULL) && (default_value.data != NULL)) {
934 *max_valbufsize = MAX(*max_valbufsize,
935 default_value.length);
938 for (i = 0; i < kd->value_count; i++) {
939 if (max_valnamelen != NULL) {
940 el = ldb_msg_find_element(kd->values[i], "value");
941 *max_valnamelen = MAX(*max_valnamelen, el->values[0].length);
944 if (max_valbufsize != NULL) {
947 reg_ldb_unpack_value(mem_ctx,
950 *max_valbufsize = MAX(*max_valbufsize, data.length);
951 talloc_free(data.data);
956 talloc_free(default_value.data);
961 static struct hive_operations reg_backend_ldb = {
963 .add_key = ldb_add_key,
964 .del_key = ldb_del_key,
965 .get_key_by_name = ldb_open_key,
966 .enum_value = ldb_get_value_by_id,
967 .enum_key = ldb_get_subkey_by_id,
968 .set_value = ldb_set_value,
969 .get_value_by_name = ldb_get_value,
970 .delete_value = ldb_del_value,
971 .get_key_info = ldb_get_key_info,