Rev 11165: More simplifications for the registry subsystem: in file:///home/jelmer/bzr.samba/4.0-regwrite/

Jelmer Vernooij jelmer at samba.org
Thu Feb 8 17:19:41 GMT 2007


At file:///home/jelmer/bzr.samba/4.0-regwrite/

------------------------------------------------------------
revno: 11165
revision-id: jelmer at samba.org-20070208171835-589fvhzi1hilvnan
parent: jelmer at samba.org-20070208161920-v3bjwnhfqy4f6j6y
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 4.0-regwrite
timestamp: Thu 2007-02-08 18:18:35 +0100
message:
  More simplifications for the registry subsystem:
  
   * Shorten file names
   * Get rid of the registration mechanism. Instead, add reg_open_file() which 
     autodetects file formats.
   * Get rid of reg_hive struct
renamed:
  source/lib/registry/reg_backend_dir.c => source/lib/registry/dir.c svn-v2:4132 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fregistry%2freg_backend_dir.c
  source/lib/registry/reg_backend_ldb.c => source/lib/registry/ldb.c svn-v2:4132 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fregistry%2freg_backend_ldb.c
  source/lib/registry/reg_backend_regf.c => source/lib/registry/regf.c svn-v2:4132 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fregistry%2freg_backend_nt4.c
  source/lib/registry/reg_backend_w95.c => source/lib/registry/creg.c svn-v2:4132 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fregistry%2freg_backend_w95.c
  source/lib/registry/reg_backend_wine.c => source/lib/registry/wine.c svn-v2:4132 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fregistry%2freg_backend_wine.c
modified:
  source/lib/registry/config.mk  svn-v2:851 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fregistry%2fconfig.mk
  source/lib/registry/interface.c svn-v2:20 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fregistry%2fcommon%2freg_interface.c
  source/lib/registry/reg_samba.c svn-v2:4132 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fregistry%2freg_samba.c
  source/lib/registry/registry.h svn-v2:10026 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fregistry%2fregistry.h
  source/lib/registry/rpc.c      svn-v2:4132 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fregistry%2freg_backend_rpc.c
  source/lib/registry/dir.c      svn-v2:4132 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fregistry%2freg_backend_dir.c
  source/lib/registry/ldb.c      svn-v2:4132 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fregistry%2freg_backend_ldb.c
  source/lib/registry/regf.c     svn-v2:4132 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fregistry%2freg_backend_nt4.c
  source/lib/registry/creg.c     svn-v2:4132 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fregistry%2freg_backend_w95.c
  source/lib/registry/wine.c     svn-v2:4132 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fregistry%2freg_backend_wine.c
=== renamed file 'source/lib/registry/reg_backend_dir.c' => 'source/lib/registry/dir.c'
--- a/source/lib/registry/reg_backend_dir.c	2006-10-18 21:37:37 +0000
+++ b/source/lib/registry/dir.c	2007-02-08 17:18:35 +0000
@@ -118,25 +118,19 @@
 	return WERR_NO_MORE_ITEMS;
 }
 
-static WERROR reg_dir_open(struct registry_hive *h, struct registry_key **key)
+WERROR reg_open_directory(const char *location, struct registry_key **key)
 {
 	if(!h->location) return WERR_INVALID_PARAM;
 
 	*key = talloc(h, struct registry_key);
-	(*key)->backend_data = talloc_strdup(*key, h->location);
+	(*key)->backend_data = talloc_strdup(*key, location);
 	return WERR_OK;
 }
 
 static struct hive_operations reg_backend_dir = {
 	.name = "dir",
-	.open_hive = reg_dir_open,
 	.open_key = reg_dir_open_key,
 	.add_key = reg_dir_add_key,
 	.del_key = reg_dir_del_key,
 	.get_subkey_by_index = reg_dir_key_by_index
 };
-
-NTSTATUS registry_dir_init(void)
-{
-	return registry_register(&reg_backend_dir);
-}

=== renamed file 'source/lib/registry/reg_backend_ldb.c' => 'source/lib/registry/ldb.c'
--- a/source/lib/registry/reg_backend_ldb.c	2006-11-22 02:05:19 +0000
+++ b/source/lib/registry/ldb.c	2007-02-08 17:18:35 +0000
@@ -261,17 +261,21 @@
 	return WERR_OK;
 }
 
-static WERROR ldb_open_hive(struct registry_hive *hive, struct registry_key **k)
+WERROR reg_open_ldb_file(const char *location, 
+								struct auth_session_info *session_info,
+								struct cli_credentials *credentials,
+								struct registry_key **k)
 {
 	struct ldb_key_data *kd;
 	struct ldb_context *wrap;
 
-	if (!hive->location) return WERR_INVALID_PARAM;
+	if (!location) 
+		return WERR_INVALID_PARAM;
 
-	wrap = ldb_wrap_connect(hive, hive->location, hive->session_info, hive->credentials, 0, NULL);
+	wrap = ldb_wrap_connect(hive, location, session_info, credentials, 0, NULL);
 
 	if(!wrap) {
-		DEBUG(1, ("ldb_open_hive: unable to connect\n"));
+		DEBUG(1, (__FILE__": unable to connect\n"));
 		return WERR_FOOBAR;
 	}
 
@@ -284,7 +288,6 @@
 	(*k)->name = talloc_strdup(*k, "");
 	(*k)->backend_data = kd = talloc_zero(*k, struct ldb_key_data);
 	kd->dn = ldb_dn_new(*k, wrap, "hive=NONE");
-	
 
 	return WERR_OK;
 }
@@ -392,15 +395,9 @@
 	.name = "ldb",
 	.add_key = ldb_add_key,
 	.del_key = ldb_del_key,
-	.open_hive = ldb_open_hive,
 	.open_key = ldb_open_key,
 	.get_value_by_index = ldb_get_value_by_id,
 	.get_subkey_by_index = ldb_get_subkey_by_id,
 	.set_value = ldb_set_value,
 	.del_value = ldb_del_value,
 };
-
-NTSTATUS registry_ldb_init(void)
-{
-	return registry_register(&reg_backend_ldb);
-}

=== renamed file 'source/lib/registry/reg_backend_regf.c' => 'source/lib/registry/regf.c'
--- a/source/lib/registry/reg_backend_regf.c	2007-01-24 13:19:46 +0000
+++ b/source/lib/registry/regf.c	2007-02-08 17:18:35 +0000
@@ -31,7 +31,6 @@
  *  - Locking
  */
 
-static WERROR regf_save_hbin(struct registry_hive *hive);
 /*
  * Read HBIN blocks into memory
  */
@@ -42,9 +41,12 @@
 	struct regf_hdr *header;
 };
 
+static WERROR regf_save_hbin(struct regf_data *data);
+
 struct regf_key_data {
 	uint32_t offset;
 	struct nk_block *nk;
+	struct regf_data *hive;
 };
 
 static struct hbin_block *hbin_by_offset (const struct regf_data *data, uint32_t offset, uint32_t *rel_offset)
@@ -412,6 +414,7 @@
 
 	ret = talloc_zero(ctx, struct registry_key);
 	private_data = talloc_zero(ret, struct regf_key_data);
+	private_data->hive = talloc_reference(private_data, regf);
 	private_data->offset = offset;
 	nk = talloc(ret, struct nk_block);
 	private_data->nk = nk;
@@ -442,7 +445,7 @@
 {
 	struct regf_key_data *private_data = key->backend_data;
 	struct vk_block *vk;
-	struct regf_data *regf = key->hive->backend_data;
+	struct regf_data *regf = private_data->hive;
 	uint32_t vk_offset;
 	DATA_BLOB data;
 
@@ -501,7 +504,7 @@
 	if (idx >= nk->num_subkeys)
 		return WERR_NO_MORE_ITEMS;
 
-	data = hbin_get(key->hive->backend_data, nk->subkeys_offset);
+	data = hbin_get(private_data->hive, nk->subkeys_offset);
 	if (!data.data) {
 		DEBUG(0, ("Unable to find subkey list\n"));
 		return WERR_GENERAL_FAILURE;
@@ -586,7 +589,7 @@
 			DATA_BLOB list_data;
 			
 			/* Get sublist data blob */
-			list_data = hbin_get(key->hive->backend_data, ri.offset[i]);
+			list_data = hbin_get(private_data->hive, ri.offset[i]);
 			if (!list_data.data) {
 				DEBUG(0, ("Error getting RI list."));
 				return WERR_GENERAL_FAILURE;
@@ -650,7 +653,7 @@
 		return WERR_GENERAL_FAILURE;
 	}
 
-	*ret = regf_get_key (ctx, key->hive->backend_data, key_off);
+	*ret = regf_get_key (ctx, private_data->hive, key_off);
 
 	return WERR_OK;
 }
@@ -660,8 +663,9 @@
 	DATA_BLOB subkey_data;
 	struct nk_block subkey;
 	struct tdr_pull pull;
+	struct regf_key_data *private_data = key->backend_data;
 	
-	subkey_data = hbin_get(key->hive->backend_data, offset);
+	subkey_data = hbin_get(private_data->hive, offset);
 	if (!subkey_data.data) {
 		DEBUG(0, ("Unable to retrieve subkey HBIN\n"));
 		return WERR_GENERAL_FAILURE;
@@ -693,7 +697,7 @@
 	struct nk_block *nk = private_data->nk;
 	uint32_t key_off = 0;
 
-	data = hbin_get(key->hive->backend_data, nk->subkeys_offset);
+	data = hbin_get(private_data->hive, nk->subkeys_offset);
 	if (!data.data) {
 		DEBUG(0, ("Unable to find subkey list\n"));
 		return WERR_GENERAL_FAILURE;
@@ -814,7 +818,7 @@
 			DATA_BLOB list_data;
 			
 			/* Get sublist data blob */
-			list_data = hbin_get(key->hive->backend_data, ri.offset[i]);
+			list_data = hbin_get(private_data->hive, ri.offset[i]);
 			if (!list_data.data) {
 				DEBUG(0, ("Error getting RI list."));
 				return WERR_GENERAL_FAILURE;
@@ -874,7 +878,7 @@
 		return WERR_GENERAL_FAILURE;
 	}
 
-	*ret = regf_get_key (ctx, key->hive->backend_data, key_off);
+	*ret = regf_get_key (ctx, private_data->hive, key_off);
 	return WERR_OK;
 }
 
@@ -882,7 +886,7 @@
 {
 	struct regf_key_data *private_data = key->backend_data;
 	struct sk_block cur_sk, sk, new_sk;
-	struct regf_data *regf = key->hive->backend_data;
+	struct regf_data *regf = private_data->hive;
 	struct nk_block root;
 	DATA_BLOB data;
 	uint32_t sk_offset, cur_sk_offset;
@@ -999,7 +1003,7 @@
 {
 	struct regf_key_data *private_data = key->backend_data;
 	struct sk_block sk;
-	struct regf_data *regf = key->hive->backend_data;
+	struct regf_data *regf = private_data->hive;
 	DATA_BLOB data;
 
 	if (!hbin_get_tdr(regf, private_data->nk->sk_offset, ctx, (tdr_pull_fn_t) tdr_pull_sk_block, &sk)) {
@@ -1308,7 +1312,7 @@
 static WERROR regf_del_value (const struct registry_key *key, const char *name)
 {
 	struct regf_key_data *private_data = key->backend_data;
-	struct regf_data *regf = key->hive->backend_data;
+	struct regf_data *regf = private_data->hive;
 	struct nk_block *nk = private_data->nk;
 	struct vk_block vk;
 	uint32_t vk_offset;
@@ -1353,7 +1357,7 @@
 	}
 	hbin_store_tdr_resize(regf, (tdr_push_fn_t) tdr_push_nk_block, private_data->offset, nk);
 
-	return regf_save_hbin(key->hive);
+	return regf_save_hbin(private_data->hive);
 }
 
 
@@ -1386,7 +1390,7 @@
 	}
 	
 	/* Delete it from the subkey list. */
-	error = regf_sl_del_entry(parent->hive->backend_data, parent_nk->subkeys_offset, key_data->offset, &parent_nk->subkeys_offset);
+	error = regf_sl_del_entry(private_data->hive, parent_nk->subkeys_offset, key_data->offset, &parent_nk->subkeys_offset);
 	if (!W_ERROR_IS_OK(error)) {
 		DEBUG(0, ("Can't store new subkey list for parent key. Won't delete.\n"));
 		return error;
@@ -1394,14 +1398,14 @@
 
 	/* Re-store parent key */
 	parent_nk->num_subkeys--;
-	hbin_store_tdr_resize(parent->hive->backend_data, (tdr_push_fn_t) tdr_push_nk_block, private_data->offset, parent_nk);
+	hbin_store_tdr_resize(private_data->hive, (tdr_push_fn_t) tdr_push_nk_block, private_data->offset, parent_nk);
 
 	if (key_data->nk->clsname_offset != -1) {
-		hbin_free((struct regf_data *)parent->hive->backend_data, key_data->nk->clsname_offset);
+		hbin_free(private_data->hive, key_data->nk->clsname_offset);
 	}
-	hbin_free((struct regf_data *)parent->hive->backend_data, key_data->offset);
+	hbin_free(private_data->hive, key_data->offset);
 
-	return regf_save_hbin(parent->hive);
+	return regf_save_hbin(private_data->hive);
 }
 
 static WERROR regf_add_key (TALLOC_CTX *ctx, const struct registry_key *parent, const char *name, 
@@ -1410,7 +1414,7 @@
 	struct regf_key_data *private_data = parent->backend_data;
 	struct nk_block *parent_nk = private_data->nk, nk;
 	struct nk_block *root;
-	struct regf_data *regf = parent->hive->backend_data;
+	struct regf_data *regf = private_data->hive;
 	uint32_t offset;
 	WERROR error;
 
@@ -1456,13 +1460,13 @@
 
 	*ret = regf_get_key(ctx, regf, offset);
 
-	return regf_save_hbin(parent->hive);
+	return regf_save_hbin(private_data->hive);
 }
 
 static WERROR regf_set_value (const struct registry_key *key, const char *name, uint32_t type, const DATA_BLOB data)
 {
 	struct regf_key_data *private_data = key->backend_data;
-	struct regf_data *regf = key->hive->backend_data;
+	struct regf_data *regf = private_data->hive;
 	struct nk_block *nk = private_data->nk;
 	struct vk_block vk;
 	uint32_t i;
@@ -1550,13 +1554,12 @@
 		
 	}
 	hbin_store_tdr_resize(regf, (tdr_push_fn_t) tdr_push_nk_block, private_data->offset, nk);
-	return regf_save_hbin(key->hive);
+	return regf_save_hbin(private_data->hive);
 }
 
-static WERROR regf_save_hbin(struct registry_hive *hive)
+static WERROR regf_save_hbin(struct regf_data *regf)
 {
-	struct regf_data *regf = hive->backend_data;
-	struct tdr_push *push = talloc_zero(hive, struct tdr_push);
+	struct tdr_push *push = talloc_zero(regf, struct tdr_push);
 	int i;
 
 	if (lseek(regf->fd, 0, SEEK_SET) == -1) {
@@ -1590,24 +1593,25 @@
 	return WERR_OK;
 }
 
-static WERROR nt_open_hive (struct registry_hive *h, struct registry_key **key)
+WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx, 
+						  const char *location, struct registry_key **key)
 {
 	struct regf_data *regf;
 	struct regf_hdr *regf_hdr;
 	struct tdr_pull pull;
 	int i;
 
-	regf = (struct regf_data *)talloc_zero(h, struct regf_data);
-	h->backend_data = regf;
+	regf = (struct regf_data *)talloc_zero(NULL, struct regf_data);
 
 	DEBUG(5, ("Attempting to load registry file\n"));
 
 	/* Get the header */
-	regf->fd = open(h->location, O_RDWR);
+	regf->fd = open(location, O_RDWR);
 
 	if (regf->fd == -1) {
-		DEBUG(0,("Could not load file: %s, %s\n", h->location,
+		DEBUG(0,("Could not load file: %s, %s\n", location,
 				 strerror(errno)));
+		talloc_free(regf);
 		return WERR_GENERAL_FAILURE;
 	}
 
@@ -1616,11 +1620,13 @@
 
 	if (pull.data.data == NULL) {
 		DEBUG(0, ("Error reading data\n"));
+		talloc_free(regf);
 		return WERR_GENERAL_FAILURE;
 	}
 
 	regf_hdr = talloc(regf, struct regf_hdr);
 	if (NT_STATUS_IS_ERR(tdr_pull_regf_hdr(&pull, regf_hdr, regf_hdr))) {
+		talloc_free(regf);
 		return WERR_GENERAL_FAILURE;
 	}
 
@@ -1628,7 +1634,9 @@
 
 	if (strcmp(regf_hdr->REGF_ID, "regf") != 0) {
 		DEBUG(0, ("Unrecognized NT registry header id: %s, %s\n",
-				  regf_hdr->REGF_ID, h->location));
+				  regf_hdr->REGF_ID, location));
+		talloc_free(regf);
+		return WERR_GENERAL_FAILURE;
 	}
 
 	DEBUG(1, ("Registry '%s' read. Version %d.%d.%d.%d\n", 
@@ -1641,7 +1649,8 @@
 	 */
 	if (regf_hdr_checksum(pull.data.data) != regf_hdr->chksum) {
 		DEBUG(0, ("Registry file checksum error: %s: %d,%d\n",
-				  h->location, regf_hdr->chksum, regf_hdr_checksum(pull.data.data)));
+				  location, regf_hdr->chksum, regf_hdr_checksum(pull.data.data)));
+		talloc_free(regf);
 		return WERR_GENERAL_FAILURE;
 	}
 
@@ -1657,11 +1666,13 @@
 
 		if (NT_STATUS_IS_ERR(tdr_pull_hbin_block(&pull, hbin, hbin))) {
 			DEBUG(0, ("[%d] Error parsing HBIN block\n", i));
+			talloc_free(regf);
 			return WERR_FOOBAR;
 		}
 
 		if (strcmp(hbin->HBIN_ID, "hbin") != 0) {
 			DEBUG(0, ("[%d] Expected 'hbin', got '%s'\n", i, hbin->HBIN_ID));
+			talloc_free(regf);
 			return WERR_FOOBAR;
 		}
 
@@ -1673,14 +1684,16 @@
 
 	DEBUG(1, ("%d HBIN blocks read\n", i));
 
-	*key = regf_get_key(h, regf, regf->header->data_offset);
+	*key = regf_get_key(parent_ctx, regf, regf->header->data_offset);
+
+	/* We can drop our own reference now that *key will have created one */
+	talloc_free(regf);
 
 	return WERR_OK;
 }
 
 static struct hive_operations reg_backend_regf = {
 	.name = "regf",
-	.open_hive = nt_open_hive,
 	.num_subkeys = regf_num_subkeys,
 	.num_values = regf_num_values,
 	.get_subkey_by_index = regf_get_subkey_by_index,
@@ -1693,8 +1706,3 @@
 	.del_key = regf_del_key,
 	.del_value = regf_del_value,
 };
-
-NTSTATUS registry_regf_init(void)
-{
-	return registry_register(&reg_backend_regf);
-}

=== renamed file 'source/lib/registry/reg_backend_w95.c' => 'source/lib/registry/creg.c'
--- a/source/lib/registry/reg_backend_w95.c	2006-09-09 09:20:26 +0000
+++ b/source/lib/registry/creg.c	2007-02-08 17:18:35 +0000
@@ -183,7 +183,7 @@
 	}
 }
 
-static WERROR w95_open_reg (struct registry_hive *h, struct registry_key **root)
+WERROR reg_open_creg_file(const char *location, struct registry_key **root)
 {
 	CREG *creg;
 	DWORD creg_id, rgkn_id;
@@ -194,7 +194,7 @@
 	memset(creg, 0, sizeof(CREG));
 	h->backend_data = creg;
 
-	if((creg->fd = open(h->location, O_RDONLY, 0000)) < 0) {
+	if((creg->fd = open(location, O_RDONLY, 0000)) < 0) {
 		return WERR_FOOBAR;
 	}
 
@@ -269,7 +269,7 @@
 	return WERR_OK;
 }
 
-static WERROR w95_get_subkey_by_index (TALLOC_CTX *mem_ctx, const struct registry_key *parent, int n, struct registry_key **key)
+static WERROR creg_get_subkey_by_index (TALLOC_CTX *mem_ctx, const struct registry_key *parent, int n, struct registry_key **key)
 {
 	CREG *creg = parent->hive->backend_data;
 	RGKN_KEY *rgkn_key = parent->backend_data;
@@ -305,7 +305,7 @@
 	return WERR_NO_MORE_ITEMS;
 }
 
-static WERROR w95_num_values(const struct registry_key *k, uint32_t *count)
+static WERROR creg_num_values(const struct registry_key *k, uint32_t *count)
 {
 	RGKN_KEY *rgkn_key = k->backend_data;
 	RGDB_KEY *rgdb_key = LOCN_RGDB_KEY((CREG *)k->hive->backend_data, rgkn_key->id.rgdb, rgkn_key->id.id);
@@ -317,7 +317,7 @@
 	return WERR_OK;
 }
 
-static WERROR w95_get_value_by_id(TALLOC_CTX *mem_ctx, const struct registry_key *k, int idx, struct registry_value **value)
+static WERROR creg_get_value_by_id(TALLOC_CTX *mem_ctx, const struct registry_key *k, int idx, struct registry_value **value)
 {
 	RGKN_KEY *rgkn_key = k->backend_data;
 	DWORD i;
@@ -343,15 +343,9 @@
 	return WERR_OK;
 }
 
-static struct hive_operations reg_backend_w95 = {
-	.name = "w95",
-	.open_hive = w95_open_reg,
-	.get_value_by_index = w95_get_value_by_id,
-	.num_values = w95_num_values,
-	.get_subkey_by_index = w95_get_subkey_by_index,
+static struct hive_operations reg_backend_creg = {
+	.name = "creg",
+	.get_value_by_index = creg_get_value_by_id,
+	.num_values = creg_num_values,
+	.get_subkey_by_index = creg_get_subkey_by_index,
 };
-
-NTSTATUS registry_w95_init(void)
-{
-	return registry_register(&reg_backend_w95);
-}

=== renamed file 'source/lib/registry/reg_backend_wine.c' => 'source/lib/registry/wine.c'
--- a/source/lib/registry/reg_backend_wine.c	2004-12-10 20:07:04 +0000
+++ b/source/lib/registry/wine.c	2007-02-08 17:18:35 +0000
@@ -27,8 +27,6 @@
 	/* FIXME: Open h->location and mmap it */
 }
 
-
-
 static REG_OPS reg_backend_wine = {
 	.name = "wine",
 	.open_hive = wine_open_reg,

=== modified file 'source/lib/registry/config.mk'
--- a/source/lib/registry/config.mk	2007-02-08 16:19:20 +0000
+++ b/source/lib/registry/config.mk	2007-02-08 17:18:35 +0000
@@ -15,19 +15,6 @@
 	@-rm -f lib/registry/regf.h lib/registry/tdr_regf*
 
 ################################################
-# Start MODULE registry_rpc
-[MODULE::registry_rpc]
-INIT_FUNCTION = registry_rpc_init
-PRIVATE_PROTO_HEADER = reg_backend_rpc.h
-OUTPUT_TYPE = INTEGRATED
-SUBSYSTEM = registry
-OBJ_FILES = \
-		rpc.o
-PUBLIC_DEPENDENCIES = RPC_NDR_WINREG
-# End MODULE registry_rpc
-################################################
-
-################################################
 # Start SUBSYSTEM registry
 [LIBRARY::registry]
 VERSION = 0.0.1
@@ -40,12 +27,14 @@
 		patchfile_dotreg.o \
 		patchfile_preg.o \
 		patchfile.o \
-		reg_backend_regf.o \
-		reg_backend_w95.o \
-		reg_backend_ldb.o \
-		reg_backend_dir.o
+		regf.o \
+		creg.o \
+		ldb.o \
+		dir.o \
+		rpc.o
 PUBLIC_DEPENDENCIES = \
-		LIBSAMBA-UTIL CHARSET TDR_REGF ldb
+		LIBSAMBA-UTIL CHARSET TDR_REGF ldb \
+		RPC_NDR_WINREG
 PRIVATE_PROTO_HEADER = registry_proto.h
 PUBLIC_HEADERS = registry.h
 # End MODULE registry_ldb

=== modified file 'source/lib/registry/interface.c'
--- a/source/lib/registry/interface.c	2007-02-08 15:59:04 +0000
+++ b/source/lib/registry/interface.c	2007-02-08 17:18:35 +0000
@@ -21,6 +21,7 @@
 #include "includes.h"
 #include "lib/util/dlinklist.h"
 #include "lib/registry/registry.h"
+#include "system/filesys.h"
 #include "build.h"
 
 /**
@@ -28,68 +29,6 @@
  * @brief Main registry functions
  */
 
-/* List of available backends */
-static struct reg_init_function_entry *backends = NULL;
-
-static struct reg_init_function_entry *reg_find_backend_entry(const char *name);
-
-/** Register a new backend. */
-_PUBLIC_ NTSTATUS registry_register(const void *_hive_ops)
-{
-	const struct hive_operations *hive_ops = _hive_ops;
-	struct reg_init_function_entry *entry = backends;
-
-	DEBUG(5,("Attempting to register registry backend %s\n", hive_ops->name));
-
-	/* Check for duplicates */
-	if (reg_find_backend_entry(hive_ops->name)) {
-		DEBUG(0,("There already is a registry backend registered with the name %s!\n", hive_ops->name));
-		return NT_STATUS_OBJECT_NAME_COLLISION;
-	}
-
-	entry = talloc(talloc_autofree_context(), struct reg_init_function_entry);
-	entry->hive_functions = hive_ops;
-
-	DLIST_ADD(backends, entry);
-	DEBUG(5,("Successfully added registry backend '%s'\n", hive_ops->name));
-	return NT_STATUS_OK;
-}
-
-/** Find a backend in the list of available backends */
-static struct reg_init_function_entry *reg_find_backend_entry(const char *name)
-{
-	struct reg_init_function_entry *entry;
-
-	entry = backends;
-
-	while(entry) {
-		if (strcmp(entry->hive_functions->name, name) == 0) return entry;
-		entry = entry->next;
-	}
-
-	return NULL;
-}
-
-/** Initialize the registry subsystem */
-_PUBLIC_ NTSTATUS registry_init(void)
-{
-	init_module_fn static_init[] = STATIC_registry_MODULES;
-	init_module_fn *shared_init = load_samba_modules(NULL, "registry");
-
-	run_init_functions(static_init);
-	run_init_functions(shared_init);
-
-	talloc_free(shared_init);
-	
-	return NT_STATUS_OK;
-}
-
-/** Check whether a certain backend is present. */
-_PUBLIC_ BOOL reg_has_backend(const char *backend)
-{
-	return reg_find_backend_entry(backend) != NULL?True:False;
-}
-
 const struct reg_predefined_key reg_predefined_keys[] = {
 	{HKEY_CLASSES_ROOT,"HKEY_CLASSES_ROOT" },
 	{HKEY_CURRENT_USER,"HKEY_CURRENT_USER" },
@@ -157,8 +96,7 @@
 }
 
 /** Open a registry file/host/etc */
-_PUBLIC_ WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *backend, 
-							  const char *location, 
+_PUBLIC_ WERROR reg_open_file(TALLOC_CTX *parent_ctx, const char *location, 
 							  struct auth_session_info *session_info, 
 							  struct cli_credentials *credentials, 
 							  struct registry_key **root)
@@ -167,45 +105,36 @@
 	struct registry_key *retkey = NULL;
 	struct reg_init_function_entry *entry;
 	WERROR werr;
-
-	entry = reg_find_backend_entry(backend);
-	
-	if (!entry) {
-		DEBUG(0, ("No such registry backend '%s' loaded!\n", backend));
-		return WERR_GENERAL_FAILURE;
-	}
-
-	if(!entry->hive_functions || !entry->hive_functions->open_hive) {
-		return WERR_NOT_SUPPORTED;
-	}
-	
-	rethive = talloc(parent_ctx, struct registry_hive);
-	rethive->location = location?talloc_strdup(rethive, location):NULL;
-	rethive->session_info = talloc_reference(rethive, session_info);
-	rethive->credentials = talloc_reference(rethive, credentials);
-	rethive->functions = entry->hive_functions;
-	rethive->backend_data = NULL;
-
-	werr = entry->hive_functions->open_hive(rethive, &retkey);
-
-	if(!W_ERROR_IS_OK(werr)) {
-		return werr;
-	}
-
-	if(!retkey) {
-		DEBUG(0, ("Backend %s didn't provide root key!\n", backend));
-		return WERR_GENERAL_FAILURE;
-	}
-
-	rethive->root = retkey;
-
-	retkey->hive = rethive;
-	retkey->name = NULL;
-	retkey->path = talloc_strdup(retkey, "");
-	
-	*root = retkey;
-
-	return WERR_OK;
+	int fd, num;
+	char peek[20];
+
+	/* Check for directory */
+	if (directory_exist(location)) {
+		return reg_open_directory(location, root);
+	}
+
+	fd = open(location, O_RDWR);
+	if (fd == -1) {
+		return WERR_BADFILE;
+	}
+
+	num = read(fd, peek, 20);
+	if (num == -1) {
+		return WERR_BADFILE;
+	}
+
+	if (!strncmp(peek, "CREG", 4)) {
+		close(fd);
+		return reg_open_creg_file(location, root);
+	} else if (!strncmp(peek, "REGF", 4)) {
+		close(fd);
+		return reg_open_regf_file(location, root);
+	} else if (!strncmp(peek, "TDB file", 8)) {
+		close(fd);
+		return reg_open_ldb_file(location, session_info, credentials, root);
+	}
+
+	return WERR_BADFILE;
 }
 
 /**

=== modified file 'source/lib/registry/reg_samba.c'
--- a/source/lib/registry/reg_samba.c	2006-09-16 16:59:37 +0000
+++ b/source/lib/registry/reg_samba.c	2007-02-08 17:18:35 +0000
@@ -28,28 +28,18 @@
 static WERROR reg_samba_get_predef (struct registry_context *ctx, uint32_t hkey, struct registry_key **k)
 {
 	WERROR error;
-	const char *conf;
 	char *backend;
 	const char *location;
 	const char *hivename = reg_get_predef_name(hkey);
 
 	*k = NULL;
 
-	conf = lp_parm_string(-1, "registry", hivename);
+	location = lp_parm_string(-1, "registry", hivename);
 	
-	if (!conf) {
+	if (!location) {
 		return WERR_NOT_SUPPORTED;
 	}
 
-	location = strchr(conf, ':');
-	if (location) {
-		backend = talloc_strndup(ctx, conf, (int)(location - conf));
-		location++;
-	} else {
-		backend = talloc_strdup(ctx, "ldb");
-		location = conf;
-	}
-
 	/* FIXME: Different hive backend for HKEY_CLASSES_ROOT: merged view of HKEY_LOCAL_MACHINE\Software\Classes
 	 * and HKEY_CURRENT_USER\Software\Classes */
 
@@ -61,7 +51,7 @@
 
 	/* FIXME: HKEY_LOCAL_MACHINE\Security\SAM is an alias for HKEY_LOCAL_MACHINE\SAM */
 
-	error = reg_open_hive(ctx, backend, location, ctx->session_info, ctx->credentials, k);
+	error = reg_open_file(ctx, location, ctx->session_info, ctx->credentials, k);
 
 	talloc_free(backend);
 

=== modified file 'source/lib/registry/registry.h'
--- a/source/lib/registry/registry.h	2007-02-08 16:19:20 +0000
+++ b/source/lib/registry/registry.h	2007-02-08 17:18:35 +0000
@@ -55,6 +55,8 @@
 
 #define REGISTRY_INTERFACE_VERSION 1
 
+struct reg_key_operations;
+
 /* structure to store the registry handles */
 struct registry_key 
 {
@@ -62,8 +64,9 @@
   const char *path;	
   const char *class_name; 
   NTTIME last_mod; 
-  struct registry_hive *hive;
   void *backend_data;
+
+  struct reg_key_operations *ops;
 };
 
 struct registry_value 
@@ -81,9 +84,7 @@
  * Container for function pointers to enumeration routines
  * for virtual registry view 
  *
- * Backends can provide :
- *  - just one hive (example: regf, w95)
- *  - several hives (example: rpc).
+ * Backends provide just one hive (example: regf, w95)
  * 
  * Backends should always do case-insensitive compares 
  * (everything is case-insensitive but case-preserving, 
@@ -93,11 +94,9 @@
  * be atomic.
  */ 
 
-struct hive_operations {
+struct reg_key_operations {
 	const char *name;
 
-	WERROR (*open_hive) (struct registry_hive *, struct registry_key **);
-
 	/* Or this function or get_subkey_by_name() */
 	WERROR (*open_key) (TALLOC_CTX *, const struct registry_key *, const char *name, struct registry_key **);
 
@@ -132,16 +131,6 @@
 
 struct cli_credentials;
 
-struct registry_hive
-{
-	const struct hive_operations *functions;
-	struct registry_key *root;
-	struct auth_session_info *session_info;
-	struct cli_credentials *credentials;
-	void *backend_data;
-	const char *location;
-};
-
 /* Handle to a full registry
  * contains zero or more hives */
 struct registry_context {
@@ -151,11 +140,6 @@
 	WERROR (*get_predefined_key) (struct registry_context *, uint32_t hkey, struct registry_key **);
 };
 
-struct reg_init_function_entry {
-	const struct hive_operations *hive_functions;
-	struct reg_init_function_entry *prev, *next;
-};
-
 /* Representing differences between registry files */
 enum reg_diff_format {
 	REG_DIFF_DOTREG,

=== modified file 'source/lib/registry/rpc.c'
--- a/source/lib/registry/rpc.c	2007-02-08 16:19:20 +0000
+++ b/source/lib/registry/rpc.c	2007-02-08 17:18:35 +0000
@@ -363,6 +363,8 @@
 	NTSTATUS status;
 	struct dcerpc_pipe *p;
 
+	dcerpc_init();
+
 	*ctx = talloc(NULL, struct registry_context);
 
 	/* Default to local smbd if no connection is specified */
@@ -387,9 +389,3 @@
 
 	return WERR_OK;
 }
-
-NTSTATUS registry_rpc_init(void)
-{
-	dcerpc_init();
-	return registry_register(&reg_backend_rpc);
-}



More information about the samba-cvs mailing list