2 * Unix SMB/CIFS implementation.
3 * Virtual Windows Registry Layer
4 * Copyright (C) Gerald Carter 2002-2005
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 /* Implementation of internal registry database functions. */
25 #define DBGC_CLASS DBGC_REGISTRY
27 static struct db_context
*regdb
= NULL
;
28 static int regdb_refcount
;
30 static bool regdb_key_exists(const char *key
);
32 /* List the deepest path into the registry. All part components will be created.*/
34 /* If you want to have a part of the path controlled by the tdb and part by
35 a virtual registry db (e.g. printing), then you have to list the deepest path.
36 For example,"HKLM/SOFTWARE/Microsoft/Windows NT/CurrentVersion/Print"
37 allows the reg_db backend to handle everything up to
38 "HKLM/SOFTWARE/Microsoft/Windows NT/CurrentVersion" and then we'll hook
39 the reg_printing backend onto the last component of the path (see
40 KEY_PRINTING_2K in include/rpc_reg.h) --jerry */
42 static const char *builtin_registry_paths
[] = {
52 KEY_SAMBA_GROUP_POLICY
,
53 KEY_GP_MACHINE_POLICY
,
54 KEY_GP_MACHINE_WIN_POLICY
,
57 KEY_GP_USER_WIN_POLICY
,
58 KEY_WINLOGON_GPEXT_PATH
,
59 "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Print\\Monitors",
61 "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\DefaultUserConfiguration",
70 struct builtin_regkey_value
{
72 const char *valuename
;
80 static struct builtin_regkey_value builtin_registry_values
[] = {
82 SAMBA_PRINTER_PORT_NAME
, REG_SZ
, { "" } },
84 "DefaultSpoolDirectory", REG_SZ
, { "C:\\Windows\\System32\\Spool\\Printers" } },
86 "DisplayName", REG_SZ
, { "Event Log" } },
88 "ErrorControl", REG_DWORD
, { (char*)0x00000001 } },
89 { NULL
, NULL
, 0, { NULL
} }
93 * Initialize a key in the registry:
94 * create each component key of the specified path.
96 static WERROR
init_registry_key_internal(const char *add_path
)
99 TALLOC_CTX
*frame
= talloc_stackframe();
102 char *remaining
= NULL
;
105 REGSUBKEY_CTR
*subkeys
;
108 DEBUG(6, ("init_registry_key: Adding [%s]\n", add_path
));
110 path
= talloc_strdup(frame
, add_path
);
111 base
= talloc_strdup(frame
, "");
112 if (!path
|| !base
) {
118 while (next_token_talloc(frame
, &p
, &keyname
, "\\")) {
120 /* build up the registry path from the components */
123 base
= talloc_asprintf(frame
, "%s\\", base
);
129 base
= talloc_asprintf_append(base
, "%s", keyname
);
135 /* get the immediate subkeyname (if we have one ) */
137 subkeyname
= talloc_strdup(frame
, "");
143 remaining
= talloc_strdup(frame
, p
);
150 if (!next_token_talloc(frame
, &p2
,
153 subkeyname
= talloc_strdup(frame
,p2
);
161 DEBUG(10,("init_registry_key: Storing key [%s] with "
162 "subkey [%s]\n", base
,
163 *subkeyname
? subkeyname
: "NULL"));
165 /* we don't really care if the lookup succeeds or not
166 * since we are about to update the record.
167 * We just want any subkeys already present */
169 if (!(subkeys
= TALLOC_ZERO_P(frame
, REGSUBKEY_CTR
))) {
170 DEBUG(0,("talloc() failure!\n"));
175 regdb_fetch_keys(base
, subkeys
);
177 werr
= regsubkey_ctr_addkey(subkeys
, subkeyname
);
178 if (!W_ERROR_IS_OK(werr
)) {
182 if (!regdb_store_keys( base
, subkeys
)) {
183 werr
= WERR_CAN_NOT_COMPLETE
;
196 * Initialize a key in the registry:
197 * create each component key of the specified path,
198 * wrapped in one db transaction.
200 WERROR
init_registry_key(const char *add_path
)
204 if (regdb_key_exists(add_path
)) {
208 if (regdb
->transaction_start(regdb
) != 0) {
209 DEBUG(0, ("init_registry_key: transaction_start failed\n"));
210 return WERR_REG_IO_FAILURE
;
213 werr
= init_registry_key_internal(add_path
);
214 if (!W_ERROR_IS_OK(werr
)) {
218 if (regdb
->transaction_commit(regdb
) != 0) {
219 DEBUG(0, ("init_registry_key: Could not commit transaction\n"));
220 return WERR_REG_IO_FAILURE
;
226 if (regdb
->transaction_cancel(regdb
) != 0) {
227 smb_panic("init_registry_key: transaction_cancel failed\n");
233 /***********************************************************************
234 Open the registry data in the tdb
235 ***********************************************************************/
237 WERROR
init_registry_data(void)
240 TALLOC_CTX
*frame
= talloc_stackframe();
246 * First, check for the existence of the needed keys and values.
247 * If all do already exist, we can save the writes.
249 for (i
=0; builtin_registry_paths
[i
] != NULL
; i
++) {
250 if (!regdb_key_exists(builtin_registry_paths
[i
])) {
255 for (i
=0; builtin_registry_values
[i
].path
!= NULL
; i
++) {
256 values
= TALLOC_ZERO_P(frame
, REGVAL_CTR
);
257 if (values
== NULL
) {
262 regdb_fetch_values(builtin_registry_values
[i
].path
, values
);
263 if (!regval_ctr_key_exists(values
,
264 builtin_registry_values
[i
].valuename
))
279 * There are potentially quite a few store operations which are all
280 * indiviually wrapped in tdb transactions. Wrapping them in a single
281 * transaction gives just a single transaction_commit() to actually do
282 * its fsync()s. See tdb/common/transaction.c for info about nested
283 * transaction behaviour.
286 if (regdb
->transaction_start(regdb
) != 0) {
287 DEBUG(0, ("init_registry_data: tdb_transaction_start "
289 werr
= WERR_REG_IO_FAILURE
;
293 /* loop over all of the predefined paths and add each component */
295 for (i
=0; builtin_registry_paths
[i
] != NULL
; i
++) {
296 if (regdb_key_exists(builtin_registry_paths
[i
])) {
299 werr
= init_registry_key_internal(builtin_registry_paths
[i
]);
300 if (!W_ERROR_IS_OK(werr
)) {
305 /* loop over all of the predefined values and add each component */
307 for (i
=0; builtin_registry_values
[i
].path
!= NULL
; i
++) {
309 values
= TALLOC_ZERO_P(frame
, REGVAL_CTR
);
310 if (values
== NULL
) {
315 regdb_fetch_values(builtin_registry_values
[i
].path
, values
);
317 /* preserve existing values across restarts. Only add new ones */
319 if (!regval_ctr_key_exists(values
,
320 builtin_registry_values
[i
].valuename
))
322 switch(builtin_registry_values
[i
].type
) {
324 regval_ctr_addvalue(values
,
325 builtin_registry_values
[i
].valuename
,
327 (char*)&builtin_registry_values
[i
].data
.dw_value
,
333 builtin_registry_values
[i
].data
.string
,
335 regval_ctr_addvalue(values
,
336 builtin_registry_values
[i
].valuename
,
339 data
.uni_str_len
*sizeof(uint16
));
343 DEBUG(0, ("init_registry_data: invalid value "
344 "type in builtin_registry_values "
346 builtin_registry_values
[i
].type
));
348 regdb_store_values(builtin_registry_values
[i
].path
,
354 if (regdb
->transaction_commit(regdb
) != 0) {
355 DEBUG(0, ("init_registry_data: Could not commit "
357 werr
= WERR_REG_IO_FAILURE
;
365 if (regdb
->transaction_cancel(regdb
) != 0) {
366 smb_panic("init_registry_data: tdb_transaction_cancel "
375 /***********************************************************************
376 Open the registry database
377 ***********************************************************************/
379 WERROR
regdb_init(void)
381 const char *vstring
= "INFO/version";
386 DEBUG(10, ("regdb_init: incrementing refcount (%d)\n",
392 regdb
= db_open_trans(NULL
, state_path("registry.tdb"), 0,
393 REG_TDB_FLAGS
, O_RDWR
, 0600);
395 regdb
= db_open_trans(NULL
, state_path("registry.tdb"), 0,
396 REG_TDB_FLAGS
, O_RDWR
|O_CREAT
, 0600);
398 werr
= ntstatus_to_werror(map_nt_error_from_unix(errno
));
399 DEBUG(0,("regdb_init: Failed to open registry %s (%s)\n",
400 state_path("registry.tdb"), strerror(errno
) ));
404 DEBUG(10,("regdb_init: Successfully created registry tdb\n"));
409 vers_id
= dbwrap_fetch_int32(regdb
, vstring
);
411 if ( vers_id
!= REGVER_V1
) {
413 /* any upgrade code here if needed */
414 DEBUG(10, ("regdb_init: got %s = %d != %d\n", vstring
,
415 vers_id
, REGVER_V1
));
416 status
= dbwrap_trans_store_int32(regdb
, vstring
, REGVER_V1
);
417 if (!NT_STATUS_IS_OK(status
)) {
418 DEBUG(0, ("regdb_init: error storing %s = %d: %s\n",
419 vstring
, REGVER_V1
, nt_errstr(status
)));
420 return ntstatus_to_werror(status
);
422 DEBUG(10, ("regdb_init: stored %s = %d\n",
423 vstring
, REGVER_V1
));
430 /***********************************************************************
431 Open the registry. Must already have been initialized by regdb_init()
432 ***********************************************************************/
434 WERROR
regdb_open( void )
436 WERROR result
= WERR_OK
;
439 DEBUG(10,("regdb_open: incrementing refcount (%d)\n", regdb_refcount
));
446 regdb
= db_open_trans(NULL
, state_path("registry.tdb"), 0,
447 REG_TDB_FLAGS
, O_RDWR
, 0600);
449 result
= ntstatus_to_werror( map_nt_error_from_unix( errno
) );
450 DEBUG(0,("regdb_open: Failed to open %s! (%s)\n",
451 state_path("registry.tdb"), strerror(errno
) ));
457 DEBUG(10,("regdb_open: refcount reset (%d)\n", regdb_refcount
));
462 /***********************************************************************
463 ***********************************************************************/
465 int regdb_close( void )
467 if (regdb_refcount
== 0) {
473 DEBUG(10,("regdb_close: decrementing refcount (%d)\n", regdb_refcount
));
475 if ( regdb_refcount
> 0 )
478 SMB_ASSERT( regdb_refcount
>= 0 );
484 /***********************************************************************
485 return the tdb sequence number of the registry tdb.
486 this is an indicator for the content of the registry
487 having changed. it will change upon regdb_init, too, though.
488 ***********************************************************************/
489 int regdb_get_seqnum(void)
491 return regdb
->get_seqnum(regdb
);
494 /***********************************************************************
495 Add subkey strings to the registry tdb under a defined key
496 fmt is the same format as tdb_pack except this function only supports
498 ***********************************************************************/
500 static bool regdb_store_keys_internal(const char *key
, REGSUBKEY_CTR
*ctr
)
503 uint8
*buffer
= NULL
;
507 uint32 num_subkeys
= regsubkey_ctr_numkeys(ctr
);
508 char *keyname
= NULL
;
509 TALLOC_CTX
*ctx
= talloc_stackframe();
516 keyname
= talloc_strdup(ctx
, key
);
520 keyname
= normalize_reg_path(ctx
, keyname
);
522 /* allocate some initial memory */
524 buffer
= (uint8
*)SMB_MALLOC(1024);
525 if (buffer
== NULL
) {
531 /* store the number of subkeys */
533 len
+= tdb_pack(buffer
+len
, buflen
-len
, "d", num_subkeys
);
535 /* pack all the strings */
537 for (i
=0; i
<num_subkeys
; i
++) {
538 len
+= tdb_pack(buffer
+len
, buflen
-len
, "f",
539 regsubkey_ctr_specific_key(ctr
, i
));
541 /* allocate some extra space */
542 buffer
= (uint8
*)SMB_REALLOC(buffer
, len
*2);
544 DEBUG(0, ("regdb_store_keys: Failed to realloc "
545 "memory of size [%d]\n", len
*2));
550 len
= tdb_pack(buffer
+len
, buflen
-len
, "f",
551 regsubkey_ctr_specific_key(ctr
, i
));
555 /* finally write out the data */
559 status
= dbwrap_store_bystring(regdb
, keyname
, dbuf
, TDB_REPLACE
);
560 if (!NT_STATUS_IS_OK(status
)) {
571 /***********************************************************************
572 Store the new subkey record and create any child key records that
573 do not currently exist
574 ***********************************************************************/
576 bool regdb_store_keys(const char *key
, REGSUBKEY_CTR
*ctr
)
580 REGSUBKEY_CTR
*subkeys
= NULL
, *old_subkeys
= NULL
;
581 char *oldkeyname
= NULL
;
582 TALLOC_CTX
*ctx
= talloc_stackframe();
586 * fetch a list of the old subkeys so we can determine if anything has
590 if (!(old_subkeys
= TALLOC_ZERO_P(ctx
, REGSUBKEY_CTR
))) {
591 DEBUG(0,("regdb_store_keys: talloc() failure!\n"));
595 regdb_fetch_keys(key
, old_subkeys
);
597 if ((ctr
->num_subkeys
&& old_subkeys
->num_subkeys
) &&
598 (ctr
->num_subkeys
== old_subkeys
->num_subkeys
)) {
600 for (i
= 0; i
<ctr
->num_subkeys
; i
++) {
601 if (strcmp(ctr
->subkeys
[i
],
602 old_subkeys
->subkeys
[i
]) != 0) {
606 if (i
== ctr
->num_subkeys
) {
608 * Nothing changed, no point to even start a tdb
611 TALLOC_FREE(old_subkeys
);
616 TALLOC_FREE(old_subkeys
);
618 if (regdb
->transaction_start(regdb
) != 0) {
619 DEBUG(0, ("regdb_store_keys: transaction_start failed\n"));
624 * Re-fetch the old keys inside the transaction
627 if (!(old_subkeys
= TALLOC_ZERO_P(ctx
, REGSUBKEY_CTR
))) {
628 DEBUG(0,("regdb_store_keys: talloc() failure!\n"));
632 regdb_fetch_keys(key
, old_subkeys
);
634 /* store the subkey list for the parent */
636 if (!regdb_store_keys_internal(key
, ctr
) ) {
637 DEBUG(0,("regdb_store_keys: Failed to store new subkey list "
638 "for parent [%s]\n", key
));
642 /* now delete removed keys */
644 num_subkeys
= regsubkey_ctr_numkeys(old_subkeys
);
645 for (i
=0; i
<num_subkeys
; i
++) {
646 oldkeyname
= regsubkey_ctr_specific_key(old_subkeys
, i
);
648 if (regsubkey_ctr_key_exists(ctr
, oldkeyname
)) {
650 * It's still around, don't delete
656 path
= talloc_asprintf(ctx
, "%s/%s", key
, oldkeyname
);
660 path
= normalize_reg_path(ctx
, path
);
664 status
= dbwrap_delete_bystring(regdb
, path
);
665 if (!NT_STATUS_IS_OK(status
)) {
666 DEBUG(1, ("Deleting %s failed\n", path
));
671 path
= talloc_asprintf(ctx
, "%s/%s/%s",
678 path
= normalize_reg_path(ctx
, path
);
684 * Ignore errors here, we might have no values around
686 dbwrap_delete_bystring(regdb
, path
);
690 TALLOC_FREE(old_subkeys
);
692 /* now create records for any subkeys that don't already exist */
694 num_subkeys
= regsubkey_ctr_numkeys(ctr
);
696 if (num_subkeys
== 0) {
697 if (!(subkeys
= TALLOC_ZERO_P(ctx
, REGSUBKEY_CTR
)) ) {
698 DEBUG(0,("regdb_store_keys: talloc() failure!\n"));
702 if (!regdb_store_keys_internal(key
, subkeys
)) {
703 DEBUG(0,("regdb_store_keys: Failed to store "
704 "new record for key [%s]\n", key
));
707 TALLOC_FREE(subkeys
);
711 for (i
=0; i
<num_subkeys
; i
++) {
712 path
= talloc_asprintf(ctx
, "%s/%s",
714 regsubkey_ctr_specific_key(ctr
, i
));
718 if (!(subkeys
= TALLOC_ZERO_P(ctx
, REGSUBKEY_CTR
)) ) {
719 DEBUG(0,("regdb_store_keys: talloc() failure!\n"));
723 if (regdb_fetch_keys( path
, subkeys
) == -1) {
724 /* create a record with 0 subkeys */
725 if (!regdb_store_keys_internal(path
, subkeys
)) {
726 DEBUG(0,("regdb_store_keys: Failed to store "
727 "new record for key [%s]\n", path
));
732 TALLOC_FREE(subkeys
);
736 if (regdb
->transaction_commit(regdb
) != 0) {
737 DEBUG(0, ("regdb_store_keys: Could not commit transaction\n"));
745 if (regdb
->transaction_cancel(regdb
) != 0) {
746 smb_panic("regdb_store_keys: transaction_cancel failed\n");
756 static TDB_DATA
regdb_fetch_key_internal(TALLOC_CTX
*mem_ctx
, const char *key
)
761 path
= normalize_reg_path(mem_ctx
, key
);
763 return make_tdb_data(NULL
, 0);
766 data
= dbwrap_fetch_bystring(regdb
, mem_ctx
, path
);
774 * Check for the existence of a key.
776 * Existence of a key is authoritatively defined by its
777 * existence in the list of subkeys of its parent key.
778 * The exeption of this are keys without a parent key,
779 * i.e. the "base" keys (HKLM, HKCU, ...).
781 static bool regdb_key_exists(const char *key
)
783 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
792 path
= normalize_reg_path(mem_ctx
, key
);
794 DEBUG(0, ("out of memory! (talloc failed)\n"));
802 p
= strrchr(path
, '/');
804 /* this is a base key */
805 value
= regdb_fetch_key_internal(mem_ctx
, path
);
806 ret
= (value
.dptr
!= NULL
);
808 /* get the list of subkeys of the parent key */
809 uint32 num_items
, len
, i
;
814 value
= regdb_fetch_key_internal(mem_ctx
, path
);
815 if (value
.dptr
== NULL
) {
819 len
= tdb_unpack(value
.dptr
, value
.dsize
, "d", &num_items
);
820 for (i
= 0; i
< num_items
; i
++) {
821 len
+= tdb_unpack(value
.dptr
+len
, value
.dsize
-len
,
823 if (strequal(subkeyname
, p
)) {
831 TALLOC_FREE(mem_ctx
);
836 /***********************************************************************
837 Retrieve an array of strings containing subkeys. Memory should be
838 released by the caller.
839 ***********************************************************************/
841 int regdb_fetch_keys(const char *key
, REGSUBKEY_CTR
*ctr
)
850 TALLOC_CTX
*frame
= talloc_stackframe();
853 DEBUG(11,("regdb_fetch_keys: Enter key => [%s]\n", key
? key
: "NULL"));
855 if (!regdb_key_exists(key
)) {
859 ctr
->seqnum
= regdb_get_seqnum();
861 value
= regdb_fetch_key_internal(frame
, key
);
864 buflen
= value
.dsize
;
867 DEBUG(5,("regdb_fetch_keys: tdb lookup failed to locate key [%s]\n", key
));
871 len
= tdb_unpack( buf
, buflen
, "d", &num_items
);
873 for (i
=0; i
<num_items
; i
++) {
874 len
+= tdb_unpack(buf
+len
, buflen
-len
, "f", subkeyname
);
875 werr
= regsubkey_ctr_addkey(ctr
, subkeyname
);
876 if (!W_ERROR_IS_OK(werr
)) {
877 DEBUG(5, ("regdb_fetch_keys: regsubkey_ctr_addkey "
878 "failed: %s\n", dos_errstr(werr
)));
883 DEBUG(11,("regdb_fetch_keys: Exit [%d] items\n", num_items
));
891 /****************************************************************************
892 Unpack a list of registry values frem the TDB
893 ***************************************************************************/
895 static int regdb_unpack_values(REGVAL_CTR
*values
, uint8
*buf
, int buflen
)
902 uint32 num_values
= 0;
905 /* loop and unpack the rest of the registry values */
907 len
+= tdb_unpack(buf
+len
, buflen
-len
, "d", &num_values
);
909 for ( i
=0; i
<num_values
; i
++ ) {
910 /* unpack the next regval */
916 len
+= tdb_unpack(buf
+len
, buflen
-len
, "fdB",
922 /* add the new value. Paranoid protective code -- make sure data_p is valid */
924 if (*valuename
&& size
&& data_p
) {
925 regval_ctr_addvalue(values
, valuename
, type
,
926 (const char *)data_p
, size
);
928 SAFE_FREE(data_p
); /* 'B' option to tdb_unpack does a malloc() */
930 DEBUG(8,("specific: [%s], len: %d\n", valuename
, size
));
936 /****************************************************************************
937 Pack all values in all printer keys
938 ***************************************************************************/
940 static int regdb_pack_values(REGVAL_CTR
*values
, uint8
*buf
, int buflen
)
950 num_values
= regval_ctr_numvals( values
);
952 /* pack the number of values first */
954 len
+= tdb_pack( buf
+len
, buflen
-len
, "d", num_values
);
956 /* loop over all values */
958 for ( i
=0; i
<num_values
; i
++ ) {
959 val
= regval_ctr_specific_value( values
, i
);
960 len
+= tdb_pack(buf
+len
, buflen
-len
, "fdB",
964 regval_data_p(val
) );
970 /***********************************************************************
971 Retrieve an array of strings containing subkeys. Memory should be
972 released by the caller.
973 ***********************************************************************/
975 int regdb_fetch_values( const char* key
, REGVAL_CTR
*values
)
978 TALLOC_CTX
*ctx
= talloc_stackframe();
982 DEBUG(10,("regdb_fetch_values: Looking for value of key [%s] \n", key
));
984 if (!regdb_key_exists(key
)) {
988 keystr
= talloc_asprintf(ctx
, "%s/%s", REG_VALUE_PREFIX
, key
);
993 values
->seqnum
= regdb_get_seqnum();
995 value
= regdb_fetch_key_internal(ctx
, keystr
);
998 /* all keys have zero values by default */
1002 regdb_unpack_values(values
, value
.dptr
, value
.dsize
);
1003 ret
= regval_ctr_numvals(values
);
1010 bool regdb_store_values( const char *key
, REGVAL_CTR
*values
)
1012 TDB_DATA old_data
, data
;
1013 char *keystr
= NULL
;
1014 TALLOC_CTX
*ctx
= talloc_stackframe();
1017 bool result
= false;
1019 DEBUG(10,("regdb_store_values: Looking for value of key [%s] \n", key
));
1021 if (!regdb_key_exists(key
)) {
1027 len
= regdb_pack_values(values
, data
.dptr
, data
.dsize
);
1029 DEBUG(0,("regdb_store_values: unable to pack values. len <= 0\n"));
1033 data
.dptr
= TALLOC_ARRAY(ctx
, uint8
, len
);
1036 len
= regdb_pack_values(values
, data
.dptr
, data
.dsize
);
1038 SMB_ASSERT( len
== data
.dsize
);
1040 keystr
= talloc_asprintf(ctx
, "%s/%s", REG_VALUE_PREFIX
, key
);
1044 keystr
= normalize_reg_path(ctx
, keystr
);
1049 old_data
= dbwrap_fetch_bystring(regdb
, ctx
, keystr
);
1051 if ((old_data
.dptr
!= NULL
)
1052 && (old_data
.dsize
== data
.dsize
)
1053 && (memcmp(old_data
.dptr
, data
.dptr
, data
.dsize
) == 0))
1059 status
= dbwrap_trans_store(regdb
, string_term_tdb_data(keystr
), data
,
1062 result
= NT_STATUS_IS_OK(status
);
1069 static WERROR
regdb_get_secdesc(TALLOC_CTX
*mem_ctx
, const char *key
,
1070 struct security_descriptor
**psecdesc
)
1075 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1076 WERROR err
= WERR_OK
;
1078 DEBUG(10, ("regdb_get_secdesc: Getting secdesc of key [%s]\n", key
));
1080 tdbkey
= talloc_asprintf(tmp_ctx
, "%s/%s", REG_SECDESC_PREFIX
, key
);
1081 if (tdbkey
== NULL
) {
1085 normalize_dbkey(tdbkey
);
1087 data
= dbwrap_fetch_bystring(regdb
, tmp_ctx
, tdbkey
);
1088 if (data
.dptr
== NULL
) {
1093 status
= unmarshall_sec_desc(mem_ctx
, (uint8
*)data
.dptr
, data
.dsize
,
1096 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_MEMORY
)) {
1098 } else if (!NT_STATUS_IS_OK(status
)) {
1099 err
= WERR_REG_CORRUPT
;
1103 TALLOC_FREE(tmp_ctx
);
1107 static WERROR
regdb_set_secdesc(const char *key
,
1108 struct security_descriptor
*secdesc
)
1110 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
1113 WERROR err
= WERR_NOMEM
;
1116 tdbkey
= talloc_asprintf(mem_ctx
, "%s/%s", REG_SECDESC_PREFIX
, key
);
1117 if (tdbkey
== NULL
) {
1120 normalize_dbkey(tdbkey
);
1122 if (secdesc
== NULL
) {
1123 /* assuming a delete */
1124 status
= dbwrap_trans_delete(regdb
,
1125 string_term_tdb_data(tdbkey
));
1126 if (NT_STATUS_IS_OK(status
)) {
1129 err
= ntstatus_to_werror(status
);
1134 err
= ntstatus_to_werror(marshall_sec_desc(mem_ctx
, secdesc
,
1137 if (!W_ERROR_IS_OK(err
)) {
1141 status
= dbwrap_trans_store(regdb
, string_term_tdb_data(tdbkey
),
1143 if (!NT_STATUS_IS_OK(status
)) {
1144 err
= ntstatus_to_werror(status
);
1149 TALLOC_FREE(mem_ctx
);
1153 bool regdb_subkeys_need_update(REGSUBKEY_CTR
*subkeys
)
1155 return (regdb_get_seqnum() != subkeys
->seqnum
);
1158 bool regdb_values_need_update(REGVAL_CTR
*values
)
1160 return (regdb_get_seqnum() != values
->seqnum
);
1164 * Table of function pointers for default access
1167 REGISTRY_OPS regdb_ops
= {
1168 .fetch_subkeys
= regdb_fetch_keys
,
1169 .fetch_values
= regdb_fetch_values
,
1170 .store_subkeys
= regdb_store_keys
,
1171 .store_values
= regdb_store_values
,
1172 .get_secdesc
= regdb_get_secdesc
,
1173 .set_secdesc
= regdb_set_secdesc
,
1174 .subkeys_need_update
= regdb_subkeys_need_update
,
1175 .values_need_update
= regdb_values_need_update