KEY_SMBCONF,
KEY_PERFLIB,
KEY_PERFLIB_009,
+ KEY_GROUP_POLICY,
+ KEY_SAMBA_GROUP_POLICY,
+ KEY_GP_MACHINE_POLICY,
+ KEY_GP_MACHINE_WIN_POLICY,
+ KEY_HKCU,
+ KEY_GP_USER_POLICY,
+ KEY_GP_USER_WIN_POLICY,
+ KEY_WINLOGON_GPEXT_PATH,
"HKLM\\SYSTEM\\CurrentControlSet\\Control\\Print\\Monitors",
KEY_PROD_OPTIONS,
"HKLM\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\DefaultUserConfiguration",
{ NULL, NULL, 0, { NULL } }
};
-/***********************************************************************
- Open the registry data in the tdb
- ***********************************************************************/
-
-static bool init_registry_data(void)
+/**
+ * Initialize a key in the registry:
+ * create each component key of the specified path.
+ */
+static bool init_registry_key_internal(const char *add_path)
{
+ bool ret = false;
+ TALLOC_CTX *frame = talloc_stackframe();
char *path = NULL;
char *base = NULL;
char *remaining = NULL;
- TALLOC_CTX *frame = NULL;
char *keyname;
char *subkeyname;
REGSUBKEY_CTR *subkeys;
- REGVAL_CTR *values;
- int i;
const char *p, *p2;
- UNISTR2 data;
- /*
- * There are potentially quite a few store operations which are all
- * indiviually wrapped in tdb transactions. Wrapping them in a single
- * transaction gives just a single transaction_commit() to actually do
- * its fsync()s. See tdb/common/transaction.c for info about nested
- * transaction behaviour.
- */
+ DEBUG(6, ("init_registry_key: Adding [%s]\n", add_path));
- if (regdb->transaction_start(regdb) == -1) {
- DEBUG(0, ("init_registry_data: tdb_transaction_start "
- "failed\n"));
- return false;
+ path = talloc_strdup(frame, add_path);
+ base = talloc_strdup(frame, "");
+ if (!path || !base) {
+ goto fail;
}
+ p = path;
- /* loop over all of the predefined paths and add each component */
-
- for (i=0; builtin_registry_paths[i] != NULL; i++) {
-
- frame = talloc_stackframe();
+ while (next_token_talloc(frame, &p, &keyname, "\\")) {
- DEBUG(6, ("init_registry_data: Adding [%s]\n",
- builtin_registry_paths[i]));
+ /* build up the registry path from the components */
- path = talloc_strdup(frame, builtin_registry_paths[i]);
- base = talloc_strdup(frame, "");
- if (!path || !base) {
- goto fail;
- }
- p = path;
-
- while (next_token_talloc(frame, &p, &keyname, "\\")) {
-
- /* build up the registry path from the components */
-
- if (*base) {
- base = talloc_asprintf(frame, "%s\\", base);
- if (!base) {
- goto fail;
- }
- }
- base = talloc_asprintf_append(base, "%s", keyname);
+ if (*base) {
+ base = talloc_asprintf(frame, "%s\\", base);
if (!base) {
goto fail;
}
+ }
+ base = talloc_asprintf_append(base, "%s", keyname);
+ if (!base) {
+ goto fail;
+ }
- /* get the immediate subkeyname (if we have one ) */
+ /* get the immediate subkeyname (if we have one ) */
- subkeyname = talloc_strdup(frame, "");
- if (!subkeyname) {
+ subkeyname = talloc_strdup(frame, "");
+ if (!subkeyname) {
+ goto fail;
+ }
+ if (*p) {
+ remaining = talloc_strdup(frame, p);
+ if (!remaining) {
goto fail;
}
- if (*p) {
- remaining = talloc_strdup(frame, p);
- if (!remaining) {
+ p2 = remaining;
+
+ if (!next_token_talloc(frame, &p2,
+ &subkeyname, "\\"))
+ {
+ subkeyname = talloc_strdup(frame,p2);
+ if (!subkeyname) {
goto fail;
}
- p2 = remaining;
-
- if (!next_token_talloc(frame, &p2,
- &subkeyname, "\\"))
- {
- subkeyname = talloc_strdup(frame,p2);
- if (!subkeyname) {
- goto fail;
- }
- }
}
+ }
- DEBUG(10,("init_registry_data: Storing key [%s] with "
- "subkey [%s]\n", base,
- *subkeyname ? subkeyname : "NULL"));
+ DEBUG(10,("init_registry_key: Storing key [%s] with "
+ "subkey [%s]\n", base,
+ *subkeyname ? subkeyname : "NULL"));
- /* we don't really care if the lookup succeeds or not
- * since we are about to update the record.
- * We just want any subkeys already present */
+ /* we don't really care if the lookup succeeds or not
+ * since we are about to update the record.
+ * We just want any subkeys already present */
- if (!(subkeys = TALLOC_ZERO_P(frame, REGSUBKEY_CTR))) {
- DEBUG(0,("talloc() failure!\n"));
- goto fail;
- }
+ if (!(subkeys = TALLOC_ZERO_P(frame, REGSUBKEY_CTR))) {
+ DEBUG(0,("talloc() failure!\n"));
+ goto fail;
+ }
- regdb_fetch_keys(base, subkeys);
- if (*subkeyname) {
- regsubkey_ctr_addkey( subkeys, subkeyname);
- }
- if (!regdb_store_keys( base, subkeys)) {
- goto fail;
- }
+ regdb_fetch_keys(base, subkeys);
+ if (*subkeyname) {
+ regsubkey_ctr_addkey( subkeys, subkeyname);
+ }
+ if (!regdb_store_keys( base, subkeys)) {
+ goto fail;
}
+ }
+
+ ret = true;
+fail:
+ TALLOC_FREE(frame);
+ return ret;
+}
+
+/**
+ * Initialize a key in the registry:
+ * create each component key of the specified path,
+ * wrapped in one db transaction.
+ */
+bool init_registry_key(const char *add_path)
+{
+ if (regdb->transaction_start(regdb) != 0) {
+ DEBUG(0, ("init_registry_key: transaction_start failed\n"));
+ return false;
+ }
- TALLOC_FREE(frame);
+ if (!init_registry_key_internal(add_path)) {
+ goto fail;
+ }
+
+ if (regdb->transaction_commit(regdb) != 0) {
+ DEBUG(0, ("init_registry_key: Could not commit transaction\n"));
+ return false;
+ }
+
+ return true;
+
+fail:
+ if (regdb->transaction_cancel(regdb) != 0) {
+ smb_panic("init_registry_key: transaction_cancel failed\n");
+ }
+
+ return false;
+}
+
+/***********************************************************************
+ Open the registry data in the tdb
+ ***********************************************************************/
+
+bool init_registry_data(void)
+{
+ TALLOC_CTX *frame = NULL;
+ REGVAL_CTR *values;
+ int i;
+ UNISTR2 data;
+
+ /*
+ * There are potentially quite a few store operations which are all
+ * indiviually wrapped in tdb transactions. Wrapping them in a single
+ * transaction gives just a single transaction_commit() to actually do
+ * its fsync()s. See tdb/common/transaction.c for info about nested
+ * transaction behaviour.
+ */
+
+ if (regdb->transaction_start(regdb) != 0) {
+ DEBUG(0, ("init_registry_data: tdb_transaction_start "
+ "failed\n"));
+ return false;
+ }
+
+ /* loop over all of the predefined paths and add each component */
+
+ for (i=0; builtin_registry_paths[i] != NULL; i++) {
+ if (!init_registry_key_internal(builtin_registry_paths[i])) {
+ goto fail;
+ }
}
/* loop over all of the predefined values and add each component */
for (i=0; builtin_registry_values[i].path != NULL; i++) {
- if (!(values = TALLOC_ZERO_P(frame, REGVAL_CTR))) {
+ values = TALLOC_ZERO_P(frame, REGVAL_CTR);
+ if (values == NULL) {
goto fail;
}
TALLOC_FREE(frame);
- if (regdb->transaction_commit(regdb) == -1) {
+ if (regdb->transaction_commit(regdb) != 0) {
DEBUG(0, ("init_registry_data: Could not commit "
"transaction\n"));
return false;
TALLOC_FREE(frame);
- if (regdb->transaction_cancel(regdb) == -1) {
+ if (regdb->transaction_cancel(regdb) != 0) {
smb_panic("init_registry_data: tdb_transaction_cancel "
"failed\n");
}
Open the registry database
***********************************************************************/
-bool regdb_init( void )
+bool regdb_init(void)
{
const char *vstring = "INFO/version";
uint32 vers_id;
- if ( regdb ) {
- DEBUG(10,("regdb_init: incrementing refcount (%d)\n", regdb_refcount));
+ if (regdb) {
+ DEBUG(10, ("regdb_init: incrementing refcount (%d)\n",
+ regdb_refcount));
regdb_refcount++;
return true;
}
- if ( !(regdb = db_open(NULL, state_path("registry.tdb"), 0, REG_TDB_FLAGS, O_RDWR, 0600)) )
- {
- regdb = db_open(NULL, state_path("registry.tdb"), 0, REG_TDB_FLAGS, O_RDWR|O_CREAT, 0600);
- if ( !regdb ) {
+ regdb = db_open_trans(NULL, state_path("registry.tdb"), 0,
+ REG_TDB_FLAGS, O_RDWR, 0600);
+ if (!regdb) {
+ regdb = db_open_trans(NULL, state_path("registry.tdb"), 0,
+ REG_TDB_FLAGS, O_RDWR|O_CREAT, 0600);
+ if (!regdb) {
DEBUG(0,("regdb_init: Failed to open registry %s (%s)\n",
state_path("registry.tdb"), strerror(errno) ));
return false;
vers_id = dbwrap_fetch_int32(regdb, vstring);
if ( vers_id != REGVER_V1 ) {
+ NTSTATUS status;
/* any upgrade code here if needed */
- DEBUG(10, ("regdb_init: got INFO/version = %d != %d\n",
+ DEBUG(10, ("regdb_init: got %s = %d != %d\n", vstring,
vers_id, REGVER_V1));
- }
-
- /* always setup the necessary keys and values */
-
- if ( !init_registry_data() ) {
- DEBUG(0,("regdb_init: Failed to initialize data in registry!\n"));
- return false;
+ status = dbwrap_trans_store_int32(regdb, vstring, REGVER_V1);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0, ("regdb_init: error storing %s = %d: %s\n",
+ vstring, REGVER_V1, nt_errstr(status)));
+ return false;
+ } else {
+ DEBUG(10, ("regdb_init: stored %s = %d\n",
+ vstring, REGVER_V1));
+ }
}
return true;
become_root();
- regdb = db_open(NULL, state_path("registry.tdb"), 0, REG_TDB_FLAGS, O_RDWR, 0600);
+ regdb = db_open_trans(NULL, state_path("registry.tdb"), 0,
+ REG_TDB_FLAGS, O_RDWR, 0600);
if ( !regdb ) {
result = ntstatus_to_werror( map_nt_error_from_unix( errno ) );
DEBUG(0,("regdb_open: Failed to open %s! (%s)\n",
TALLOC_FREE(old_subkeys);
- if (regdb->transaction_start(regdb) == -1) {
+ if (regdb->transaction_start(regdb) != 0) {
DEBUG(0, ("regdb_store_keys: transaction_start failed\n"));
goto fail;
}
TALLOC_FREE(path);
}
- if (regdb->transaction_commit(regdb) == -1) {
+ if (regdb->transaction_commit(regdb) != 0) {
DEBUG(0, ("regdb_store_keys: Could not commit transaction\n"));
goto fail;
}
return true;
cancel:
- if (regdb->transaction_cancel(regdb) == -1) {
+ if (regdb->transaction_cancel(regdb) != 0) {
smb_panic("regdb_store_keys: transaction_cancel failed\n");
}
int i;
fstring subkeyname;
int ret = -1;
+ int dbret = -1;
TALLOC_CTX *frame = talloc_stackframe();
- struct db_record *rec;
+ TDB_DATA value;
DEBUG(11,("regdb_fetch_keys: Enter key => [%s]\n", key ? key : "NULL"));
}
strupper_m(path);
- rec = regdb->fetch_locked(regdb, frame, string_term_tdb_data(path));
- if (rec == NULL) {
- ret = 0;
+ ctr->seqnum = regdb_get_seqnum();
+
+ dbret = regdb->fetch(regdb, frame, string_term_tdb_data(path), &value);
+ if (dbret != 0) {
goto fail;
}
- ctr->seqnum = regdb_get_seqnum();
-
- buf = rec->value.dptr;
- buflen = rec->value.dsize;
+ buf = value.dptr;
+ buflen = value.dsize;
if ( !buf ) {
DEBUG(5,("regdb_fetch_keys: tdb lookup failed to locate key [%s]\n", key));
{
char *keystr = NULL;
TALLOC_CTX *ctx = talloc_stackframe();
- struct db_record *rec;
int ret = 0;
+ int dbret = -1;
+ TDB_DATA value;
DEBUG(10,("regdb_fetch_values: Looking for value of key [%s] \n", key));
goto done;
}
- rec = regdb->fetch_locked(regdb, ctx, string_term_tdb_data(keystr));
- if (rec == NULL) {
+ values->seqnum = regdb_get_seqnum();
+
+ dbret = regdb->fetch(regdb, ctx, string_term_tdb_data(keystr), &value);
+ if (dbret != 0) {
goto done;
}
- values->seqnum = regdb_get_seqnum();
-
- if (!rec->value.dptr) {
+ if (!value.dptr) {
/* all keys have zero values by default */
goto done;
}
- regdb_unpack_values(values, rec->value.dptr, rec->value.dsize);
+ regdb_unpack_values(values, value.dptr, value.dsize);
ret = regval_ctr_numvals(values);
done:
TDB_DATA old_data, data;
char *keystr = NULL;
TALLOC_CTX *ctx = talloc_stackframe();
- int len, ret;
+ int len;
+ NTSTATUS status;
bool result = false;
DEBUG(10,("regdb_store_values: Looking for value of key [%s] \n", key));
goto done;
}
- ret = dbwrap_trans_store(regdb, string_term_tdb_data(keystr), data,
- TDB_REPLACE);
- result = (ret != -1);
+ status = dbwrap_trans_store(regdb, string_term_tdb_data(keystr), data,
+ TDB_REPLACE);
+
+ result = NT_STATUS_IS_OK(status);
done:
TALLOC_FREE(ctx);
{
TALLOC_CTX *mem_ctx = talloc_stackframe();
char *tdbkey;
+ NTSTATUS status;
WERROR err = WERR_NOMEM;
TDB_DATA tdbdata;
int tdb_ret;
/* assuming a delete */
tdb_ret = dbwrap_trans_delete(regdb,
string_term_tdb_data(tdbkey));
- if (tdb_ret == -1) {
- err = ntstatus_to_werror(map_nt_error_from_unix(errno));
- } else {
+ if (tdb_ret == 0) {
err = WERR_OK;
+ } else {
+ err = ntstatus_to_werror(map_nt_error_from_unix(errno));
}
goto done;
}
goto done;
}
- tdb_ret = dbwrap_trans_store(regdb, string_term_tdb_data(tdbkey),
- tdbdata, 0);
- if (tdb_ret == -1) {
- err = ntstatus_to_werror(map_nt_error_from_unix(errno));
+ status = dbwrap_trans_store(regdb, string_term_tdb_data(tdbkey),
+ tdbdata, 0);
+ if (!NT_STATUS_IS_OK(status)) {
+ err = ntstatus_to_werror(status);
goto done;
}
*/
REGISTRY_OPS regdb_ops = {
- regdb_fetch_keys,
- regdb_fetch_values,
- regdb_store_keys,
- regdb_store_values,
- NULL,
- regdb_get_secdesc,
- regdb_set_secdesc,
- regdb_subkeys_need_update,
- regdb_values_need_update
+ .fetch_subkeys = regdb_fetch_keys,
+ .fetch_values = regdb_fetch_values,
+ .store_subkeys = regdb_store_keys,
+ .store_values = regdb_store_values,
+ .get_secdesc = regdb_get_secdesc,
+ .set_secdesc = regdb_set_secdesc,
+ .subkeys_need_update = regdb_subkeys_need_update,
+ .values_need_update = regdb_values_need_update
};