2 * Unix SMB/CIFS implementation.
3 * Virtual Windows Registry Layer
4 * Copyright (C) Gerald Carter 2002-2005
5 * Copyright (C) Michael Adam 2007-2009
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/>.
21 /* Implementation of internal registry database functions. */
27 #include "reg_util_internal.h"
28 #include "reg_backend_db.h"
29 #include "reg_objects.h"
32 #define DBGC_CLASS DBGC_REGISTRY
34 static struct db_context
*regdb
= NULL
;
35 static int regdb_refcount
;
37 static bool regdb_key_exists(struct db_context
*db
, const char *key
);
38 static bool regdb_key_is_base_key(const char *key
);
39 static WERROR
regdb_fetch_keys_internal(struct db_context
*db
, const char *key
,
40 struct regsubkey_ctr
*ctr
);
41 static bool regdb_store_keys_internal(struct db_context
*db
, const char *key
,
42 struct regsubkey_ctr
*ctr
);
43 static int regdb_fetch_values_internal(struct db_context
*db
, const char* key
,
44 struct regval_ctr
*values
);
45 static bool regdb_store_values_internal(struct db_context
*db
, const char *key
,
46 struct regval_ctr
*values
);
48 /* List the deepest path into the registry. All part components will be created.*/
50 /* If you want to have a part of the path controlled by the tdb and part by
51 a virtual registry db (e.g. printing), then you have to list the deepest path.
52 For example,"HKLM/SOFTWARE/Microsoft/Windows NT/CurrentVersion/Print"
53 allows the reg_db backend to handle everything up to
54 "HKLM/SOFTWARE/Microsoft/Windows NT/CurrentVersion" and then we'll hook
55 the reg_printing backend onto the last component of the path (see
56 KEY_PRINTING_2K in include/rpc_reg.h) --jerry */
58 static const char *builtin_registry_paths
[] = {
62 KEY_PRINTING
"\\Forms",
63 KEY_PRINTING
"\\Printers",
64 KEY_PRINTING
"\\Environments\\Windows NT x86\\Print Processors\\winprint",
71 KEY_SAMBA_GROUP_POLICY
,
72 KEY_GP_MACHINE_POLICY
,
73 KEY_GP_MACHINE_WIN_POLICY
,
76 KEY_GP_USER_WIN_POLICY
,
77 "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\GPExtensions",
78 "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Print\\Monitors",
80 "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\DefaultUserConfiguration",
89 struct builtin_regkey_value
{
91 const char *valuename
;
99 static struct builtin_regkey_value builtin_registry_values
[] = {
100 { KEY_PRINTING_PORTS
,
101 SAMBA_PRINTER_PORT_NAME
, REG_SZ
, { "" } },
103 "DefaultSpoolDirectory", REG_SZ
, { "C:\\Windows\\System32\\Spool\\Printers" } },
105 "DisplayName", REG_SZ
, { "Event Log" } },
107 "ErrorControl", REG_DWORD
, { (char*)0x00000001 } },
108 { NULL
, NULL
, 0, { NULL
} }
112 * Initialize a key in the registry:
113 * create each component key of the specified path.
115 static WERROR
init_registry_key_internal(struct db_context
*db
,
116 const char *add_path
)
119 TALLOC_CTX
*frame
= talloc_stackframe();
122 char *remaining
= NULL
;
125 struct regsubkey_ctr
*subkeys
;
128 DEBUG(6, ("init_registry_key: Adding [%s]\n", add_path
));
130 path
= talloc_strdup(frame
, add_path
);
131 base
= talloc_strdup(frame
, "");
132 if (!path
|| !base
) {
138 while (next_token_talloc(frame
, &p
, &keyname
, "\\")) {
140 /* build up the registry path from the components */
143 base
= talloc_asprintf(frame
, "%s\\", base
);
149 base
= talloc_asprintf_append(base
, "%s", keyname
);
155 /* get the immediate subkeyname (if we have one ) */
157 subkeyname
= talloc_strdup(frame
, "");
163 remaining
= talloc_strdup(frame
, p
);
170 if (!next_token_talloc(frame
, &p2
,
173 subkeyname
= talloc_strdup(frame
,p2
);
181 DEBUG(10,("init_registry_key: Storing key [%s] with "
182 "subkey [%s]\n", base
,
183 *subkeyname
? subkeyname
: "NULL"));
185 /* we don't really care if the lookup succeeds or not
186 * since we are about to update the record.
187 * We just want any subkeys already present */
189 werr
= regsubkey_ctr_init(frame
, &subkeys
);
190 if (!W_ERROR_IS_OK(werr
)) {
191 DEBUG(0,("talloc() failure!\n"));
195 werr
= regdb_fetch_keys_internal(db
, base
, subkeys
);
196 if (!W_ERROR_IS_OK(werr
) &&
197 !W_ERROR_EQUAL(werr
, WERR_NOT_FOUND
))
203 werr
= regsubkey_ctr_addkey(subkeys
, subkeyname
);
204 if (!W_ERROR_IS_OK(werr
)) {
208 if (!regdb_store_keys_internal(db
, base
, subkeys
)) {
209 werr
= WERR_CAN_NOT_COMPLETE
;
221 struct init_registry_key_context
{
222 const char *add_path
;
225 static NTSTATUS
init_registry_key_action(struct db_context
*db
,
228 struct init_registry_key_context
*init_ctx
=
229 (struct init_registry_key_context
*)private_data
;
231 return werror_to_ntstatus(init_registry_key_internal(
232 db
, init_ctx
->add_path
));
236 * Initialize a key in the registry:
237 * create each component key of the specified path,
238 * wrapped in one db transaction.
240 WERROR
init_registry_key(const char *add_path
)
242 struct init_registry_key_context init_ctx
;
244 if (regdb_key_exists(regdb
, add_path
)) {
248 init_ctx
.add_path
= add_path
;
250 return ntstatus_to_werror(dbwrap_trans_do(regdb
,
251 init_registry_key_action
,
255 /***********************************************************************
256 Open the registry data in the tdb
257 ***********************************************************************/
259 static void regdb_ctr_add_value(struct regval_ctr
*ctr
,
260 struct builtin_regkey_value
*value
)
262 switch(value
->type
) {
264 regval_ctr_addvalue(ctr
, value
->valuename
, REG_DWORD
,
265 (uint8_t *)&value
->data
.dw_value
,
270 regval_ctr_addvalue_sz(ctr
, value
->valuename
,
275 DEBUG(0, ("regdb_ctr_add_value: invalid value type in "
276 "registry values [%d]\n", value
->type
));
280 static NTSTATUS
init_registry_data_action(struct db_context
*db
,
284 TALLOC_CTX
*frame
= talloc_stackframe();
285 struct regval_ctr
*values
;
288 /* loop over all of the predefined paths and add each component */
290 for (i
=0; builtin_registry_paths
[i
] != NULL
; i
++) {
291 if (regdb_key_exists(db
, builtin_registry_paths
[i
])) {
294 status
= werror_to_ntstatus(init_registry_key_internal(db
,
295 builtin_registry_paths
[i
]));
296 if (!NT_STATUS_IS_OK(status
)) {
301 /* loop over all of the predefined values and add each component */
303 for (i
=0; builtin_registry_values
[i
].path
!= NULL
; i
++) {
306 werr
= regval_ctr_init(frame
, &values
);
307 if (!W_ERROR_IS_OK(werr
)) {
308 status
= werror_to_ntstatus(werr
);
312 regdb_fetch_values_internal(db
,
313 builtin_registry_values
[i
].path
,
316 /* preserve existing values across restarts. Only add new ones */
318 if (!regval_ctr_key_exists(values
,
319 builtin_registry_values
[i
].valuename
))
321 regdb_ctr_add_value(values
,
322 &builtin_registry_values
[i
]);
323 regdb_store_values_internal(db
,
324 builtin_registry_values
[i
].path
,
330 status
= NT_STATUS_OK
;
338 WERROR
init_registry_data(void)
341 TALLOC_CTX
*frame
= talloc_stackframe();
342 struct regval_ctr
*values
;
346 * First, check for the existence of the needed keys and values.
347 * If all do already exist, we can save the writes.
349 for (i
=0; builtin_registry_paths
[i
] != NULL
; i
++) {
350 if (!regdb_key_exists(regdb
, builtin_registry_paths
[i
])) {
355 for (i
=0; builtin_registry_values
[i
].path
!= NULL
; i
++) {
356 werr
= regval_ctr_init(frame
, &values
);
357 W_ERROR_NOT_OK_GOTO_DONE(werr
);
359 regdb_fetch_values_internal(regdb
,
360 builtin_registry_values
[i
].path
,
362 if (!regval_ctr_key_exists(values
,
363 builtin_registry_values
[i
].valuename
))
378 * There are potentially quite a few store operations which are all
379 * indiviually wrapped in tdb transactions. Wrapping them in a single
380 * transaction gives just a single transaction_commit() to actually do
381 * its fsync()s. See tdb/common/transaction.c for info about nested
382 * transaction behaviour.
385 werr
= ntstatus_to_werror(dbwrap_trans_do(regdb
,
386 init_registry_data_action
,
394 static int regdb_normalize_keynames_fn(struct db_record
*rec
,
397 TALLOC_CTX
*mem_ctx
= talloc_tos();
401 if (rec
->key
.dptr
== NULL
|| rec
->key
.dsize
== 0) {
405 keyname
= strchr((const char *) rec
->key
.dptr
, '/');
407 struct db_record new_rec
;
409 keyname
= talloc_string_sub(mem_ctx
,
410 (const char *) rec
->key
.dptr
,
414 DEBUG(2, ("regdb_normalize_keynames_fn: Convert %s to %s\n",
415 (const char *) rec
->key
.dptr
,
418 new_rec
.value
.dptr
= rec
->value
.dptr
;
419 new_rec
.value
.dsize
= rec
->value
.dsize
;
420 new_rec
.key
.dptr
= (unsigned char *) keyname
;
421 new_rec
.key
.dsize
= strlen(keyname
);
422 new_rec
.private_data
= rec
->private_data
;
424 /* Delete the original record and store the normalized key */
425 status
= rec
->delete_rec(rec
);
426 if (!NT_STATUS_IS_OK(status
)) {
427 DEBUG(0,("regdb_normalize_keynames_fn: "
428 "tdb_delete for [%s] failed!\n",
433 status
= rec
->store(&new_rec
, new_rec
.value
, TDB_REPLACE
);
434 if (!NT_STATUS_IS_OK(status
)) {
435 DEBUG(0,("regdb_normalize_keynames_fn: "
436 "failed to store new record for [%s]!\n",
445 static WERROR
regdb_store_regdb_version(uint32_t version
)
448 const char *version_keyname
= "INFO/version";
451 return WERR_CAN_NOT_COMPLETE
;
454 status
= dbwrap_trans_store_int32(regdb
, version_keyname
, version
);
455 if (!NT_STATUS_IS_OK(status
)) {
456 DEBUG(1, ("regdb_init: error storing %s = %d: %s\n",
457 version_keyname
, version
, nt_errstr(status
)));
458 return ntstatus_to_werror(status
);
460 DEBUG(10, ("regdb_init: stored %s = %d\n",
461 version_keyname
, version
));
466 static WERROR
regdb_upgrade_v1_to_v2(void)
472 mem_ctx
= talloc_stackframe();
473 if (mem_ctx
== NULL
) {
477 rc
= regdb
->traverse(regdb
, regdb_normalize_keynames_fn
, mem_ctx
);
479 talloc_destroy(mem_ctx
);
482 return WERR_REG_IO_FAILURE
;
485 werr
= regdb_store_regdb_version(REGVER_V2
);
489 /***********************************************************************
490 Open the registry database
491 ***********************************************************************/
493 WERROR
regdb_init(void)
495 const char *vstring
= "INFO/version";
496 uint32 vers_id
, expected_version
;
500 DEBUG(10, ("regdb_init: incrementing refcount (%d)\n",
506 regdb
= db_open(NULL
, state_path("registry.tdb"), 0,
507 REG_TDB_FLAGS
, O_RDWR
, 0600);
509 regdb
= db_open(NULL
, state_path("registry.tdb"), 0,
510 REG_TDB_FLAGS
, O_RDWR
|O_CREAT
, 0600);
512 werr
= ntstatus_to_werror(map_nt_error_from_unix(errno
));
513 DEBUG(1,("regdb_init: Failed to open registry %s (%s)\n",
514 state_path("registry.tdb"), strerror(errno
) ));
518 DEBUG(10,("regdb_init: Successfully created registry tdb\n"));
523 expected_version
= REGVER_V2
;
525 vers_id
= dbwrap_fetch_int32(regdb
, vstring
);
527 DEBUG(10, ("regdb_init: registry version uninitialized "
528 "(got %d), initializing to version %d\n",
529 vers_id
, expected_version
));
531 werr
= regdb_store_regdb_version(expected_version
);
535 if (vers_id
> expected_version
|| vers_id
== 0) {
536 DEBUG(1, ("regdb_init: unknown registry version %d "
537 "(code version = %d), refusing initialization\n",
538 vers_id
, expected_version
));
539 return WERR_CAN_NOT_COMPLETE
;
542 if (vers_id
== REGVER_V1
) {
543 DEBUG(10, ("regdb_init: got registry db version %d, upgrading "
544 "to version %d\n", REGVER_V1
, REGVER_V2
));
546 if (regdb
->transaction_start(regdb
) != 0) {
547 return WERR_REG_IO_FAILURE
;
550 werr
= regdb_upgrade_v1_to_v2();
551 if (!W_ERROR_IS_OK(werr
)) {
552 regdb
->transaction_cancel(regdb
);
556 if (regdb
->transaction_commit(regdb
) != 0) {
557 return WERR_REG_IO_FAILURE
;
563 /* future upgrade code should go here */
568 /***********************************************************************
569 Open the registry. Must already have been initialized by regdb_init()
570 ***********************************************************************/
572 WERROR
regdb_open( void )
574 WERROR result
= WERR_OK
;
577 DEBUG(10,("regdb_open: incrementing refcount (%d)\n", regdb_refcount
));
584 regdb
= db_open(NULL
, state_path("registry.tdb"), 0,
585 REG_TDB_FLAGS
, O_RDWR
, 0600);
587 result
= ntstatus_to_werror( map_nt_error_from_unix( errno
) );
588 DEBUG(0,("regdb_open: Failed to open %s! (%s)\n",
589 state_path("registry.tdb"), strerror(errno
) ));
595 DEBUG(10,("regdb_open: refcount reset (%d)\n", regdb_refcount
));
600 /***********************************************************************
601 ***********************************************************************/
603 int regdb_close( void )
605 if (regdb_refcount
== 0) {
611 DEBUG(10,("regdb_close: decrementing refcount (%d)\n", regdb_refcount
));
613 if ( regdb_refcount
> 0 )
616 SMB_ASSERT( regdb_refcount
>= 0 );
622 WERROR
regdb_transaction_start(void)
624 return (regdb
->transaction_start(regdb
) == 0) ?
625 WERR_OK
: WERR_REG_IO_FAILURE
;
628 WERROR
regdb_transaction_commit(void)
630 return (regdb
->transaction_commit(regdb
) == 0) ?
631 WERR_OK
: WERR_REG_IO_FAILURE
;
634 WERROR
regdb_transaction_cancel(void)
636 return (regdb
->transaction_cancel(regdb
) == 0) ?
637 WERR_OK
: WERR_REG_IO_FAILURE
;
640 /***********************************************************************
641 return the tdb sequence number of the registry tdb.
642 this is an indicator for the content of the registry
643 having changed. it will change upon regdb_init, too, though.
644 ***********************************************************************/
645 int regdb_get_seqnum(void)
647 return regdb
->get_seqnum(regdb
);
651 static WERROR
regdb_delete_key_with_prefix(struct db_context
*db
,
656 WERROR werr
= WERR_NOMEM
;
657 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
659 if (keyname
== NULL
) {
660 werr
= WERR_INVALID_PARAM
;
664 if (prefix
== NULL
) {
665 path
= discard_const_p(char, keyname
);
667 path
= talloc_asprintf(mem_ctx
, "%s\\%s", prefix
, keyname
);
673 path
= normalize_reg_path(mem_ctx
, path
);
678 werr
= ntstatus_to_werror(dbwrap_delete_bystring(db
, path
));
680 /* treat "not" found" as ok */
681 if (W_ERROR_EQUAL(werr
, WERR_NOT_FOUND
)) {
686 talloc_free(mem_ctx
);
691 static WERROR
regdb_delete_values(struct db_context
*db
, const char *keyname
)
693 return regdb_delete_key_with_prefix(db
, keyname
, REG_VALUE_PREFIX
);
696 static WERROR
regdb_delete_secdesc(struct db_context
*db
, const char *keyname
)
698 return regdb_delete_key_with_prefix(db
, keyname
, REG_SECDESC_PREFIX
);
701 static WERROR
regdb_delete_subkeylist(struct db_context
*db
, const char *keyname
)
703 return regdb_delete_key_with_prefix(db
, keyname
, NULL
);
706 static WERROR
regdb_delete_key_lists(struct db_context
*db
, const char *keyname
)
710 werr
= regdb_delete_values(db
, keyname
);
711 if (!W_ERROR_IS_OK(werr
)) {
712 DEBUG(1, (__location__
" Deleting %s\\%s failed: %s\n",
713 REG_VALUE_PREFIX
, keyname
, win_errstr(werr
)));
717 werr
= regdb_delete_secdesc(db
, keyname
);
718 if (!W_ERROR_IS_OK(werr
)) {
719 DEBUG(1, (__location__
" Deleting %s\\%s failed: %s\n",
720 REG_SECDESC_PREFIX
, keyname
, win_errstr(werr
)));
724 werr
= regdb_delete_subkeylist(db
, keyname
);
725 if (!W_ERROR_IS_OK(werr
)) {
726 DEBUG(1, (__location__
" Deleting %s failed: %s\n",
727 keyname
, win_errstr(werr
)));
735 /***********************************************************************
736 Add subkey strings to the registry tdb under a defined key
737 fmt is the same format as tdb_pack except this function only supports
739 ***********************************************************************/
741 static WERROR
regdb_store_keys_internal2(struct db_context
*db
,
743 struct regsubkey_ctr
*ctr
)
746 uint8
*buffer
= NULL
;
749 uint32 num_subkeys
= regsubkey_ctr_numkeys(ctr
);
750 char *keyname
= NULL
;
751 TALLOC_CTX
*ctx
= talloc_stackframe();
755 werr
= WERR_INVALID_PARAM
;
759 keyname
= talloc_strdup(ctx
, key
);
765 keyname
= normalize_reg_path(ctx
, keyname
);
771 /* allocate some initial memory */
773 buffer
= (uint8
*)SMB_MALLOC(1024);
774 if (buffer
== NULL
) {
781 /* store the number of subkeys */
783 len
+= tdb_pack(buffer
+len
, buflen
-len
, "d", num_subkeys
);
785 /* pack all the strings */
787 for (i
=0; i
<num_subkeys
; i
++) {
790 thistime
= tdb_pack(buffer
+len
, buflen
-len
, "f",
791 regsubkey_ctr_specific_key(ctr
, i
));
792 if (len
+thistime
> buflen
) {
795 * tdb_pack hasn't done anything because of the short
796 * buffer, allocate extra space.
798 buffer
= SMB_REALLOC_ARRAY(buffer
, uint8_t,
801 DEBUG(0, ("regdb_store_keys: Failed to realloc "
802 "memory of size [%u]\n",
803 (unsigned int)(len
+thistime
)*2));
807 buflen
= (len
+thistime
)*2;
808 thistime2
= tdb_pack(
809 buffer
+len
, buflen
-len
, "f",
810 regsubkey_ctr_specific_key(ctr
, i
));
811 if (thistime2
!= thistime
) {
812 DEBUG(0, ("tdb_pack failed\n"));
813 werr
= WERR_CAN_NOT_COMPLETE
;
820 /* finally write out the data */
824 werr
= ntstatus_to_werror(dbwrap_store_bystring(db
, keyname
, dbuf
,
826 W_ERROR_NOT_OK_GOTO_DONE(werr
);
829 * Delete a sorted subkey cache for regdb_key_exists, will be
830 * recreated automatically
832 keyname
= talloc_asprintf(ctx
, "%s\\%s", REG_SORTED_SUBKEYS_PREFIX
,
834 if (keyname
== NULL
) {
839 werr
= ntstatus_to_werror(dbwrap_delete_bystring(db
, keyname
));
841 /* don't treat WERR_NOT_FOUND as an error here */
842 if (W_ERROR_EQUAL(werr
, WERR_NOT_FOUND
)) {
852 /***********************************************************************
853 Store the new subkey record and create any child key records that
854 do not currently exist
855 ***********************************************************************/
857 struct regdb_store_keys_context
{
859 struct regsubkey_ctr
*ctr
;
862 static NTSTATUS
regdb_store_keys_action(struct db_context
*db
,
865 struct regdb_store_keys_context
*store_ctx
;
869 struct regsubkey_ctr
*subkeys
= NULL
, *old_subkeys
= NULL
;
870 char *oldkeyname
= NULL
;
871 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
873 store_ctx
= (struct regdb_store_keys_context
*)private_data
;
876 * Re-fetch the old keys inside the transaction
879 werr
= regsubkey_ctr_init(mem_ctx
, &old_subkeys
);
880 W_ERROR_NOT_OK_GOTO_DONE(werr
);
882 werr
= regdb_fetch_keys_internal(db
, store_ctx
->key
, old_subkeys
);
883 if (!W_ERROR_IS_OK(werr
) &&
884 !W_ERROR_EQUAL(werr
, WERR_NOT_FOUND
))
890 * Make the store operation as safe as possible without transactions:
892 * (1) For each subkey removed from ctr compared with old_subkeys:
894 * (a) First delete the value db entry.
896 * (b) Next delete the secdesc db record.
898 * (c) Then delete the subkey list entry.
900 * (2) Now write the list of subkeys of the parent key,
901 * deleting removed entries and adding new ones.
903 * (3) Finally create the subkey list entries for the added keys.
905 * This way if we crash half-way in between deleting the subkeys
906 * and storing the parent's list of subkeys, no old data can pop up
907 * out of the blue when re-adding keys later on.
910 /* (1) delete removed keys' lists (values/secdesc/subkeys) */
912 num_subkeys
= regsubkey_ctr_numkeys(old_subkeys
);
913 for (i
=0; i
<num_subkeys
; i
++) {
914 oldkeyname
= regsubkey_ctr_specific_key(old_subkeys
, i
);
916 if (regsubkey_ctr_key_exists(store_ctx
->ctr
, oldkeyname
)) {
918 * It's still around, don't delete
923 path
= talloc_asprintf(mem_ctx
, "%s\\%s", store_ctx
->key
,
930 werr
= regdb_delete_key_lists(db
, path
);
931 W_ERROR_NOT_OK_GOTO_DONE(werr
);
936 TALLOC_FREE(old_subkeys
);
938 /* (2) store the subkey list for the parent */
940 werr
= regdb_store_keys_internal2(db
, store_ctx
->key
, store_ctx
->ctr
);
941 if (!W_ERROR_IS_OK(werr
)) {
942 DEBUG(0,("regdb_store_keys: Failed to store new subkey list "
943 "for parent [%s]: %s\n", store_ctx
->key
,
948 /* (3) now create records for any subkeys that don't already exist */
950 num_subkeys
= regsubkey_ctr_numkeys(store_ctx
->ctr
);
952 if (num_subkeys
== 0) {
953 werr
= regsubkey_ctr_init(mem_ctx
, &subkeys
);
954 W_ERROR_NOT_OK_GOTO_DONE(werr
);
956 werr
= regdb_store_keys_internal2(db
, store_ctx
->key
, subkeys
);
957 if (!W_ERROR_IS_OK(werr
)) {
958 DEBUG(0,("regdb_store_keys: Failed to store "
959 "new record for key [%s]: %s\n",
960 store_ctx
->key
, win_errstr(werr
)));
963 TALLOC_FREE(subkeys
);
966 for (i
=0; i
<num_subkeys
; i
++) {
967 path
= talloc_asprintf(mem_ctx
, "%s\\%s", store_ctx
->key
,
968 regsubkey_ctr_specific_key(store_ctx
->ctr
, i
));
973 werr
= regsubkey_ctr_init(mem_ctx
, &subkeys
);
974 W_ERROR_NOT_OK_GOTO_DONE(werr
);
976 werr
= regdb_fetch_keys_internal(db
, path
, subkeys
);
977 if (!W_ERROR_IS_OK(werr
)) {
978 /* create a record with 0 subkeys */
979 werr
= regdb_store_keys_internal2(db
, path
, subkeys
);
980 if (!W_ERROR_IS_OK(werr
)) {
981 DEBUG(0,("regdb_store_keys: Failed to store "
982 "new record for key [%s]: %s\n", path
,
988 TALLOC_FREE(subkeys
);
995 talloc_free(mem_ctx
);
996 return werror_to_ntstatus(werr
);
999 static bool regdb_store_keys_internal(struct db_context
*db
, const char *key
,
1000 struct regsubkey_ctr
*ctr
)
1002 int num_subkeys
, old_num_subkeys
, i
;
1003 struct regsubkey_ctr
*old_subkeys
= NULL
;
1004 TALLOC_CTX
*ctx
= talloc_stackframe();
1007 struct regdb_store_keys_context store_ctx
;
1009 if (!regdb_key_is_base_key(key
) && !regdb_key_exists(db
, key
)) {
1014 * fetch a list of the old subkeys so we can determine if anything has
1018 werr
= regsubkey_ctr_init(ctx
, &old_subkeys
);
1019 if (!W_ERROR_IS_OK(werr
)) {
1020 DEBUG(0,("regdb_store_keys: talloc() failure!\n"));
1024 werr
= regdb_fetch_keys_internal(db
, key
, old_subkeys
);
1025 if (!W_ERROR_IS_OK(werr
) &&
1026 !W_ERROR_EQUAL(werr
, WERR_NOT_FOUND
))
1031 num_subkeys
= regsubkey_ctr_numkeys(ctr
);
1032 old_num_subkeys
= regsubkey_ctr_numkeys(old_subkeys
);
1033 if ((num_subkeys
&& old_num_subkeys
) &&
1034 (num_subkeys
== old_num_subkeys
)) {
1036 for (i
= 0; i
< num_subkeys
; i
++) {
1037 if (strcmp(regsubkey_ctr_specific_key(ctr
, i
),
1038 regsubkey_ctr_specific_key(old_subkeys
, i
))
1044 if (i
== num_subkeys
) {
1046 * Nothing changed, no point to even start a tdb
1055 TALLOC_FREE(old_subkeys
);
1057 store_ctx
.key
= key
;
1058 store_ctx
.ctr
= ctr
;
1060 werr
= ntstatus_to_werror(dbwrap_trans_do(db
,
1061 regdb_store_keys_action
,
1064 ret
= W_ERROR_IS_OK(werr
);
1072 bool regdb_store_keys(const char *key
, struct regsubkey_ctr
*ctr
)
1074 return regdb_store_keys_internal(regdb
, key
, ctr
);
1078 * create a subkey of a given key
1081 struct regdb_create_subkey_context
{
1086 static NTSTATUS
regdb_create_subkey_action(struct db_context
*db
,
1090 struct regdb_create_subkey_context
*create_ctx
;
1091 struct regsubkey_ctr
*subkeys
;
1092 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1094 create_ctx
= (struct regdb_create_subkey_context
*)private_data
;
1096 werr
= regsubkey_ctr_init(mem_ctx
, &subkeys
);
1097 W_ERROR_NOT_OK_GOTO_DONE(werr
);
1099 werr
= regdb_fetch_keys_internal(db
, create_ctx
->key
, subkeys
);
1100 W_ERROR_NOT_OK_GOTO_DONE(werr
);
1102 werr
= regsubkey_ctr_addkey(subkeys
, create_ctx
->subkey
);
1103 W_ERROR_NOT_OK_GOTO_DONE(werr
);
1105 werr
= regdb_store_keys_internal2(db
, create_ctx
->key
, subkeys
);
1106 if (!W_ERROR_IS_OK(werr
)) {
1107 DEBUG(0, (__location__
" failed to store new subkey list for "
1108 "parent key %s: %s\n", create_ctx
->key
,
1113 talloc_free(mem_ctx
);
1114 return werror_to_ntstatus(werr
);
1117 static WERROR
regdb_create_subkey(const char *key
, const char *subkey
)
1120 struct regsubkey_ctr
*subkeys
;
1121 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1122 struct regdb_create_subkey_context create_ctx
;
1124 if (!regdb_key_is_base_key(key
) && !regdb_key_exists(regdb
, key
)) {
1125 werr
= WERR_NOT_FOUND
;
1129 werr
= regsubkey_ctr_init(mem_ctx
, &subkeys
);
1130 W_ERROR_NOT_OK_GOTO_DONE(werr
);
1132 werr
= regdb_fetch_keys_internal(regdb
, key
, subkeys
);
1133 W_ERROR_NOT_OK_GOTO_DONE(werr
);
1135 if (regsubkey_ctr_key_exists(subkeys
, subkey
)) {
1140 talloc_free(subkeys
);
1142 create_ctx
.key
= key
;
1143 create_ctx
.subkey
= subkey
;
1145 werr
= ntstatus_to_werror(dbwrap_trans_do(regdb
,
1146 regdb_create_subkey_action
,
1150 talloc_free(mem_ctx
);
1155 * create a subkey of a given key
1158 struct regdb_delete_subkey_context
{
1164 static NTSTATUS
regdb_delete_subkey_action(struct db_context
*db
,
1168 struct regdb_delete_subkey_context
*delete_ctx
;
1169 struct regsubkey_ctr
*subkeys
;
1170 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1172 delete_ctx
= (struct regdb_delete_subkey_context
*)private_data
;
1174 werr
= regdb_delete_key_lists(db
, delete_ctx
->path
);
1175 W_ERROR_NOT_OK_GOTO_DONE(werr
);
1177 werr
= regsubkey_ctr_init(mem_ctx
, &subkeys
);
1178 W_ERROR_NOT_OK_GOTO_DONE(werr
);
1180 werr
= regdb_fetch_keys_internal(db
, delete_ctx
->key
, subkeys
);
1181 W_ERROR_NOT_OK_GOTO_DONE(werr
);
1183 werr
= regsubkey_ctr_delkey(subkeys
, delete_ctx
->subkey
);
1184 W_ERROR_NOT_OK_GOTO_DONE(werr
);
1186 werr
= regdb_store_keys_internal2(db
, delete_ctx
->key
, subkeys
);
1187 if (!W_ERROR_IS_OK(werr
)) {
1188 DEBUG(0, (__location__
" failed to store new subkey_list for "
1189 "parent key %s: %s\n", delete_ctx
->key
,
1194 talloc_free(mem_ctx
);
1195 return werror_to_ntstatus(werr
);
1198 static WERROR
regdb_delete_subkey(const char *key
, const char *subkey
)
1202 struct regdb_delete_subkey_context delete_ctx
;
1203 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1205 if (!regdb_key_is_base_key(key
) && !regdb_key_exists(regdb
, key
)) {
1206 werr
= WERR_NOT_FOUND
;
1210 path
= talloc_asprintf(mem_ctx
, "%s\\%s", key
, subkey
);
1216 if (!regdb_key_exists(regdb
, path
)) {
1221 delete_ctx
.key
= key
;
1222 delete_ctx
.subkey
= subkey
;
1223 delete_ctx
.path
= path
;
1225 werr
= ntstatus_to_werror(dbwrap_trans_do(regdb
,
1226 regdb_delete_subkey_action
,
1230 talloc_free(mem_ctx
);
1234 static TDB_DATA
regdb_fetch_key_internal(struct db_context
*db
,
1235 TALLOC_CTX
*mem_ctx
, const char *key
)
1240 path
= normalize_reg_path(mem_ctx
, key
);
1242 return make_tdb_data(NULL
, 0);
1245 data
= dbwrap_fetch_bystring(db
, mem_ctx
, path
);
1253 * check whether a given key name represents a base key,
1254 * i.e one without a subkey separator ('\').
1256 static bool regdb_key_is_base_key(const char *key
)
1258 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1266 path
= normalize_reg_path(mem_ctx
, key
);
1268 DEBUG(0, ("out of memory! (talloc failed)\n"));
1272 if (*path
== '\0') {
1276 ret
= (strrchr(path
, '\\') == NULL
);
1279 TALLOC_FREE(mem_ctx
);
1284 * regdb_key_exists() is a very frequent operation. It can be quite
1285 * time-consuming to fully fetch the parent's subkey list, talloc_strdup all
1286 * subkeys and then compare the keyname linearly to all the parent's subkeys.
1288 * The following code tries to make this operation as efficient as possible:
1289 * Per registry key we create a list of subkeys that is very efficient to
1290 * search for existence of a subkey. Its format is:
1292 * 4 bytes num_subkeys
1293 * 4*num_subkey bytes offset into the string array
1294 * then follows a sorted list of subkeys in uppercase
1296 * This record is created by create_sorted_subkeys() on demand if it does not
1297 * exist. scan_parent_subkeys() uses regdb->parse_record to search the sorted
1298 * list, the parsing code and the binary search can be found in
1299 * parent_subkey_scanner. The code uses parse_record() to avoid a memcpy of
1300 * the potentially large subkey record.
1302 * The sorted subkey record is deleted in regdb_store_keys_internal2 and
1303 * recreated on demand.
1306 static int cmp_keynames(char **p1
, char **p2
)
1308 return StrCaseCmp(*p1
, *p2
);
1311 struct create_sorted_subkeys_context
{
1313 const char *sorted_keyname
;
1316 static NTSTATUS
create_sorted_subkeys_action(struct db_context
*db
,
1319 char **sorted_subkeys
;
1320 struct regsubkey_ctr
*ctr
;
1327 struct create_sorted_subkeys_context
*sorted_ctx
;
1329 sorted_ctx
= (struct create_sorted_subkeys_context
*)private_data
;
1332 * In this function, we only treat failing of the actual write to
1333 * the db as a real error. All preliminary errors, at a stage when
1334 * nothing has been written to the DB yet are treated as success
1335 * to be committed (as an empty transaction).
1337 * The reason is that this (disposable) call might be nested in other
1338 * transactions. Doing a cancel here would destroy the possibility of
1339 * a transaction_commit for transactions that we might be wrapped in.
1342 status
= werror_to_ntstatus(regsubkey_ctr_init(talloc_tos(), &ctr
));
1343 if (!NT_STATUS_IS_OK(status
)) {
1344 /* don't treat this as an error */
1345 status
= NT_STATUS_OK
;
1349 status
= werror_to_ntstatus(regdb_fetch_keys_internal(db
,
1352 if (!NT_STATUS_IS_OK(status
)) {
1353 /* don't treat this as an error */
1354 status
= NT_STATUS_OK
;
1358 num_subkeys
= regsubkey_ctr_numkeys(ctr
);
1359 sorted_subkeys
= talloc_array(ctr
, char *, num_subkeys
);
1360 if (sorted_subkeys
== NULL
) {
1361 /* don't treat this as an error */
1365 len
= 4 + 4*num_subkeys
;
1367 for (i
= 0; i
< num_subkeys
; i
++) {
1368 sorted_subkeys
[i
] = talloc_strdup_upper(sorted_subkeys
,
1369 regsubkey_ctr_specific_key(ctr
, i
));
1370 if (sorted_subkeys
[i
] == NULL
) {
1371 /* don't treat this as an error */
1374 len
+= strlen(sorted_subkeys
[i
])+1;
1377 TYPESAFE_QSORT(sorted_subkeys
, num_subkeys
, cmp_keynames
);
1379 buf
= talloc_array(ctr
, char, len
);
1381 /* don't treat this as an error */
1384 p
= buf
+ 4 + 4*num_subkeys
;
1386 SIVAL(buf
, 0, num_subkeys
);
1388 for (i
=0; i
< num_subkeys
; i
++) {
1389 ptrdiff_t offset
= p
- buf
;
1390 SIVAL(buf
, 4 + 4*i
, offset
);
1391 strlcpy(p
, sorted_subkeys
[i
], len
-offset
);
1392 p
+= strlen(sorted_subkeys
[i
]) + 1;
1395 status
= dbwrap_store_bystring(
1396 db
, sorted_ctx
->sorted_keyname
, make_tdb_data((uint8_t *)buf
,
1405 static bool create_sorted_subkeys(const char *key
, const char *sorted_keyname
)
1408 struct create_sorted_subkeys_context sorted_ctx
;
1410 sorted_ctx
.key
= key
;
1411 sorted_ctx
.sorted_keyname
= sorted_keyname
;
1413 status
= dbwrap_trans_do(regdb
,
1414 create_sorted_subkeys_action
,
1417 return NT_STATUS_IS_OK(status
);
1420 struct scan_subkey_state
{
1426 static int parent_subkey_scanner(TDB_DATA key
, TDB_DATA data
,
1429 struct scan_subkey_state
*state
=
1430 (struct scan_subkey_state
*)private_data
;
1431 uint32_t num_subkeys
;
1434 if (data
.dsize
< sizeof(uint32_t)) {
1438 state
->scanned
= true;
1439 state
->found
= false;
1441 tdb_unpack(data
.dptr
, data
.dsize
, "d", &num_subkeys
);
1447 uint32_t idx
= (l
+u
)/2;
1448 char *s
= (char *)data
.dptr
+ IVAL(data
.dptr
, 4 + 4*idx
);
1449 int comparison
= strcmp(state
->name
, s
);
1451 if (comparison
< 0) {
1453 } else if (comparison
> 0) {
1456 state
->found
= true;
1463 static bool scan_parent_subkeys(struct db_context
*db
, const char *parent
,
1468 struct scan_subkey_state state
= { 0, };
1469 bool result
= false;
1474 path
= normalize_reg_path(talloc_tos(), parent
);
1479 key
= talloc_asprintf(talloc_tos(), "%s\\%s",
1480 REG_SORTED_SUBKEYS_PREFIX
, path
);
1485 state
.name
= talloc_strdup_upper(talloc_tos(), name
);
1486 if (state
.name
== NULL
) {
1489 state
.scanned
= false;
1491 res
= db
->parse_record(db
, string_term_tdb_data(key
),
1492 parent_subkey_scanner
, &state
);
1494 if (state
.scanned
) {
1495 result
= state
.found
;
1497 res
= db
->transaction_start(db
);
1499 DEBUG(0, ("error starting transacion\n"));
1503 if (!create_sorted_subkeys(path
, key
)) {
1504 res
= db
->transaction_cancel(db
);
1506 smb_panic("Failed to cancel transaction.");
1511 res
= db
->parse_record(db
, string_term_tdb_data(key
),
1512 parent_subkey_scanner
, &state
);
1513 if ((res
== 0) && (state
.scanned
)) {
1514 result
= state
.found
;
1517 res
= db
->transaction_commit(db
);
1519 DEBUG(0, ("error committing transaction\n"));
1526 TALLOC_FREE(state
.name
);
1531 * Check for the existence of a key.
1533 * Existence of a key is authoritatively defined by its
1534 * existence in the list of subkeys of its parent key.
1535 * The exeption of this are keys without a parent key,
1536 * i.e. the "base" keys (HKLM, HKCU, ...).
1538 static bool regdb_key_exists(struct db_context
*db
, const char *key
)
1540 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1549 path
= normalize_reg_path(mem_ctx
, key
);
1551 DEBUG(0, ("out of memory! (talloc failed)\n"));
1555 if (*path
== '\0') {
1559 p
= strrchr(path
, '\\');
1561 /* this is a base key */
1562 value
= regdb_fetch_key_internal(db
, mem_ctx
, path
);
1563 ret
= (value
.dptr
!= NULL
);
1566 ret
= scan_parent_subkeys(db
, path
, p
+1);
1570 TALLOC_FREE(mem_ctx
);
1575 /***********************************************************************
1576 Retrieve an array of strings containing subkeys. Memory should be
1577 released by the caller.
1578 ***********************************************************************/
1580 static WERROR
regdb_fetch_keys_internal(struct db_context
*db
, const char *key
,
1581 struct regsubkey_ctr
*ctr
)
1589 TALLOC_CTX
*frame
= talloc_stackframe();
1592 DEBUG(11,("regdb_fetch_keys: Enter key => [%s]\n", key
? key
: "NULL"));
1594 frame
= talloc_stackframe();
1596 if (!regdb_key_exists(db
, key
)) {
1597 DEBUG(10, ("key [%s] not found\n", key
));
1598 werr
= WERR_NOT_FOUND
;
1602 werr
= regsubkey_ctr_set_seqnum(ctr
, db
->get_seqnum(db
));
1603 W_ERROR_NOT_OK_GOTO_DONE(werr
);
1605 value
= regdb_fetch_key_internal(db
, frame
, key
);
1607 if (value
.dsize
== 0 || value
.dptr
== NULL
) {
1608 DEBUG(10, ("regdb_fetch_keys: no subkeys found for key [%s]\n",
1614 buflen
= value
.dsize
;
1615 len
= tdb_unpack( buf
, buflen
, "d", &num_items
);
1616 if (len
== (uint32_t)-1) {
1617 werr
= WERR_NOT_FOUND
;
1621 werr
= regsubkey_ctr_reinit(ctr
);
1622 W_ERROR_NOT_OK_GOTO_DONE(werr
);
1624 for (i
=0; i
<num_items
; i
++) {
1625 len
+= tdb_unpack(buf
+len
, buflen
-len
, "f", subkeyname
);
1626 werr
= regsubkey_ctr_addkey(ctr
, subkeyname
);
1627 if (!W_ERROR_IS_OK(werr
)) {
1628 DEBUG(5, ("regdb_fetch_keys: regsubkey_ctr_addkey "
1629 "failed: %s\n", win_errstr(werr
)));
1635 DEBUG(11,("regdb_fetch_keys: Exit [%d] items\n", num_items
));
1642 int regdb_fetch_keys(const char *key
, struct regsubkey_ctr
*ctr
)
1646 werr
= regdb_fetch_keys_internal(regdb
, key
, ctr
);
1647 if (!W_ERROR_IS_OK(werr
)) {
1651 return regsubkey_ctr_numkeys(ctr
);
1654 /****************************************************************************
1655 Unpack a list of registry values frem the TDB
1656 ***************************************************************************/
1658 static int regdb_unpack_values(struct regval_ctr
*values
, uint8
*buf
, int buflen
)
1665 uint32 num_values
= 0;
1668 /* loop and unpack the rest of the registry values */
1670 len
+= tdb_unpack(buf
+len
, buflen
-len
, "d", &num_values
);
1672 for ( i
=0; i
<num_values
; i
++ ) {
1673 /* unpack the next regval */
1678 valuename
[0] = '\0';
1679 len
+= tdb_unpack(buf
+len
, buflen
-len
, "fdB",
1685 regval_ctr_addvalue(values
, valuename
, type
,
1686 (uint8_t *)data_p
, size
);
1687 SAFE_FREE(data_p
); /* 'B' option to tdb_unpack does a malloc() */
1689 DEBUG(8,("specific: [%s], len: %d\n", valuename
, size
));
1695 /****************************************************************************
1696 Pack all values in all printer keys
1697 ***************************************************************************/
1699 static int regdb_pack_values(struct regval_ctr
*values
, uint8
*buf
, int buflen
)
1703 struct regval_blob
*val
;
1709 num_values
= regval_ctr_numvals( values
);
1711 /* pack the number of values first */
1713 len
+= tdb_pack( buf
+len
, buflen
-len
, "d", num_values
);
1715 /* loop over all values */
1717 for ( i
=0; i
<num_values
; i
++ ) {
1718 val
= regval_ctr_specific_value( values
, i
);
1719 len
+= tdb_pack(buf
+len
, buflen
-len
, "fdB",
1723 regval_data_p(val
) );
1729 /***********************************************************************
1730 Retrieve an array of strings containing subkeys. Memory should be
1731 released by the caller.
1732 ***********************************************************************/
1734 static int regdb_fetch_values_internal(struct db_context
*db
, const char* key
,
1735 struct regval_ctr
*values
)
1737 char *keystr
= NULL
;
1738 TALLOC_CTX
*ctx
= talloc_stackframe();
1743 DEBUG(10,("regdb_fetch_values: Looking for value of key [%s] \n", key
));
1745 if (!regdb_key_exists(db
, key
)) {
1749 keystr
= talloc_asprintf(ctx
, "%s\\%s", REG_VALUE_PREFIX
, key
);
1754 werr
= regval_ctr_set_seqnum(values
, db
->get_seqnum(db
));
1755 W_ERROR_NOT_OK_GOTO_DONE(werr
);
1757 value
= regdb_fetch_key_internal(db
, ctx
, keystr
);
1760 /* all keys have zero values by default */
1764 regdb_unpack_values(values
, value
.dptr
, value
.dsize
);
1765 ret
= regval_ctr_numvals(values
);
1772 int regdb_fetch_values(const char* key
, struct regval_ctr
*values
)
1774 return regdb_fetch_values_internal(regdb
, key
, values
);
1777 static bool regdb_store_values_internal(struct db_context
*db
, const char *key
,
1778 struct regval_ctr
*values
)
1780 TDB_DATA old_data
, data
;
1781 char *keystr
= NULL
;
1782 TALLOC_CTX
*ctx
= talloc_stackframe();
1785 bool result
= false;
1787 DEBUG(10,("regdb_store_values: Looking for value of key [%s] \n", key
));
1789 if (!regdb_key_exists(db
, key
)) {
1795 len
= regdb_pack_values(values
, data
.dptr
, data
.dsize
);
1797 DEBUG(0,("regdb_store_values: unable to pack values. len <= 0\n"));
1801 data
.dptr
= TALLOC_ARRAY(ctx
, uint8
, len
);
1804 len
= regdb_pack_values(values
, data
.dptr
, data
.dsize
);
1806 SMB_ASSERT( len
== data
.dsize
);
1808 keystr
= talloc_asprintf(ctx
, "%s\\%s", REG_VALUE_PREFIX
, key
);
1812 keystr
= normalize_reg_path(ctx
, keystr
);
1817 old_data
= dbwrap_fetch_bystring(db
, ctx
, keystr
);
1819 if ((old_data
.dptr
!= NULL
)
1820 && (old_data
.dsize
== data
.dsize
)
1821 && (memcmp(old_data
.dptr
, data
.dptr
, data
.dsize
) == 0))
1827 status
= dbwrap_trans_store_bystring(db
, keystr
, data
, TDB_REPLACE
);
1829 result
= NT_STATUS_IS_OK(status
);
1836 bool regdb_store_values(const char *key
, struct regval_ctr
*values
)
1838 return regdb_store_values_internal(regdb
, key
, values
);
1841 static WERROR
regdb_get_secdesc(TALLOC_CTX
*mem_ctx
, const char *key
,
1842 struct security_descriptor
**psecdesc
)
1847 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1848 WERROR err
= WERR_OK
;
1850 DEBUG(10, ("regdb_get_secdesc: Getting secdesc of key [%s]\n", key
));
1852 if (!regdb_key_exists(regdb
, key
)) {
1857 tdbkey
= talloc_asprintf(tmp_ctx
, "%s\\%s", REG_SECDESC_PREFIX
, key
);
1858 if (tdbkey
== NULL
) {
1863 tdbkey
= normalize_reg_path(tmp_ctx
, tdbkey
);
1864 if (tdbkey
== NULL
) {
1869 data
= dbwrap_fetch_bystring(regdb
, tmp_ctx
, tdbkey
);
1870 if (data
.dptr
== NULL
) {
1875 status
= unmarshall_sec_desc(mem_ctx
, (uint8
*)data
.dptr
, data
.dsize
,
1878 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_MEMORY
)) {
1880 } else if (!NT_STATUS_IS_OK(status
)) {
1881 err
= WERR_REG_CORRUPT
;
1885 TALLOC_FREE(tmp_ctx
);
1889 static WERROR
regdb_set_secdesc(const char *key
,
1890 struct security_descriptor
*secdesc
)
1892 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1894 WERROR err
= WERR_NOMEM
;
1897 if (!regdb_key_exists(regdb
, key
)) {
1902 tdbkey
= talloc_asprintf(mem_ctx
, "%s\\%s", REG_SECDESC_PREFIX
, key
);
1903 if (tdbkey
== NULL
) {
1907 tdbkey
= normalize_reg_path(mem_ctx
, tdbkey
);
1908 if (tdbkey
== NULL
) {
1913 if (secdesc
== NULL
) {
1914 /* assuming a delete */
1915 err
= ntstatus_to_werror(dbwrap_trans_delete_bystring(regdb
,
1920 err
= ntstatus_to_werror(marshall_sec_desc(mem_ctx
, secdesc
,
1923 W_ERROR_NOT_OK_GOTO_DONE(err
);
1925 err
= ntstatus_to_werror(dbwrap_trans_store_bystring(regdb
, tdbkey
,
1929 TALLOC_FREE(mem_ctx
);
1933 bool regdb_subkeys_need_update(struct regsubkey_ctr
*subkeys
)
1935 return (regdb_get_seqnum() != regsubkey_ctr_get_seqnum(subkeys
));
1938 bool regdb_values_need_update(struct regval_ctr
*values
)
1940 return (regdb_get_seqnum() != regval_ctr_get_seqnum(values
));
1944 * Table of function pointers for default access
1947 struct registry_ops regdb_ops
= {
1948 .fetch_subkeys
= regdb_fetch_keys
,
1949 .fetch_values
= regdb_fetch_values
,
1950 .store_subkeys
= regdb_store_keys
,
1951 .store_values
= regdb_store_values
,
1952 .create_subkey
= regdb_create_subkey
,
1953 .delete_subkey
= regdb_delete_subkey
,
1954 .get_secdesc
= regdb_get_secdesc
,
1955 .set_secdesc
= regdb_set_secdesc
,
1956 .subkeys_need_update
= regdb_subkeys_need_update
,
1957 .values_need_update
= regdb_values_need_update