[SCM] SAMBA-CTDB repository - branch v3-6-ctdb updated - 3.6.0-ctdb-20-18-g40b9739

Michael Adam obnox at samba.org
Thu Aug 25 07:10:03 MDT 2011


The branch, v3-6-ctdb has been updated
       via  40b973957d7f5bc58fdf2545e7a5575a1950a7e4 (commit)
       via  3bfd83b7873db9f9231f4ecf3c376009cf066ccb (commit)
       via  67c14630d7fd3c96881a7496d69df7752d6e6774 (commit)
       via  caf90885b5fd30675789173b2302a000664766d5 (commit)
       via  90238567c992eaa2362069f409c7b8b8d842f380 (commit)
       via  8b128d569bdeae4ee2941686670f672d13aaf5b3 (commit)
       via  c4ec809f7536223df9a378e3be28a2cc6bf83702 (commit)
       via  52fa89b1aeca7e2cda264770c8351239dd3a0bc3 (commit)
       via  21b783ea0ededc4075e69bfe868db7541ea22231 (commit)
       via  67fcc13e646d47cb6541c9f46a34cd10cc3e0283 (commit)
       via  df69d253de02d40e01317e6022723cca8770036c (commit)
       via  c0ffb254f6f2df549f91aa70ae088892d7e37b86 (commit)
       via  e885e62cd60fb474ee6084dc72d26740f41b2213 (commit)
       via  3203c5b095ed6d4d5d210666c2372f360968345b (commit)
       via  bde97ec075f8d47d5af3db45566daebead752dac (commit)
       via  95877e7d41ccc70e2f05c55f20fde48a97e72d31 (commit)
       via  ada08e829057aef4553005c6d968f0bdf7f423c9 (commit)
       via  ab2fe321f4fa8dcc09bd0b8470201413a2e2f1b5 (commit)
      from  32f142a1a9689c8846d072d51e8f1c980c06b203 (commit)

http://gitweb.samba.org/?p=obnox/samba-ctdb.git;a=shortlog;h=v3-6-ctdb


- Log -----------------------------------------------------------------
commit 40b973957d7f5bc58fdf2545e7a5575a1950a7e4
Author: Michael Adam <obnox at samba.org>
Date:   Tue Aug 23 14:36:52 2011 +0200

    v3-6-ctdb: VERSION: Bump the ctdb vendor patch level to 21

commit 3bfd83b7873db9f9231f4ecf3c376009cf066ccb
Author: Gregor Beck <gbeck at sernet.de>
Date:   Thu Jun 30 12:08:16 2011 +0200

    s3:net add command "registry check"
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit 67c14630d7fd3c96881a7496d69df7752d6e6774
Author: Gregor Beck <gbeck at sernet.de>
Date:   Thu Aug 18 14:13:28 2011 +0200

    s3:net: factor out interact_edit()
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit caf90885b5fd30675789173b2302a000664766d5
Author: Gregor Beck <gbeck at sernet.de>
Date:   Thu Jul 7 14:50:47 2011 +0200

    s3:utils change data_blob_dup_talloc() to take a DATA_BLOB by value

commit 90238567c992eaa2362069f409c7b8b8d842f380
Author: Gregor Beck <gbeck at sernet.de>
Date:   Tue Jul 12 13:04:37 2011 +0200

    s3:registry add function srprs_hive()
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit 8b128d569bdeae4ee2941686670f672d13aaf5b3
Author: Gregor Beck <gbeck at sernet.de>
Date:   Wed Aug 17 11:44:12 2011 +0200

    s3:dbwrap: fix db_rbt_traverse() to return the record count on success
    
    this makes it consistent with documented behaviour of tdb_traverse()
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit c4ec809f7536223df9a378e3be28a2cc6bf83702
Author: Gregor Beck <gbeck at sernet.de>
Date:   Tue Aug 16 14:55:30 2011 +0200

    s3:dbwrap: add specific dbwrap_wipe() implementation to dbwrap_rbt
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit 52fa89b1aeca7e2cda264770c8351239dd3a0bc3
Author: Gregor Beck <gbeck at sernet.de>
Date:   Tue Aug 16 14:43:29 2011 +0200

    s3:dbwrap: add specific dbwrap_wipe() implementation to dbwrap_tdb
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit 21b783ea0ededc4075e69bfe868db7541ea22231
Author: Gregor Beck <gbeck at sernet.de>
Date:   Tue Aug 16 14:39:19 2011 +0200

    s3:dbwrap: add function dbwrap_wipe()
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit 67fcc13e646d47cb6541c9f46a34cd10cc3e0283
Author: Gregor Beck <gbeck at sernet.de>
Date:   Mon Jul 4 10:22:46 2011 +0200

    s3:dbwrap: add specific dbwrap_exists implementation to dbwrap_rbt
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit df69d253de02d40e01317e6022723cca8770036c
Author: Gregor Beck <gbeck at sernet.de>
Date:   Mon Jul 4 09:54:31 2011 +0200

    s3:dbwrap: factor out db_rpt_search_internal
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit c0ffb254f6f2df549f91aa70ae088892d7e37b86
Author: Gregor Beck <gbeck at sernet.de>
Date:   Mon Jul 4 10:27:17 2011 +0200

    s3:dbwrap: add specific dbwrap_exists implementation to dbwrap_tdb
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit e885e62cd60fb474ee6084dc72d26740f41b2213
Author: Gregor Beck <gbeck at sernet.de>
Date:   Mon Jul 4 10:15:44 2011 +0200

    s3:dbwrap: add function dbwrap_exists()
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit 3203c5b095ed6d4d5d210666c2372f360968345b
Author: Gregor Beck <gbeck at sernet.de>
Date:   Tue Jun 14 13:19:59 2011 +0200

    s3:smbcacls fix leaking talloc stackframce on tcon failure
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit bde97ec075f8d47d5af3db45566daebead752dac
Author: Gregor Beck <gbeck at sernet.de>
Date:   Tue Jun 14 13:56:22 2011 +0200

    s3:smbcacls fix possible SEGFAULT
    
    sddl_encode returns NULL on failure
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit 95877e7d41ccc70e2f05c55f20fde48a97e72d31
Author: Gregor Beck <gbeck at sernet.de>
Date:   Thu Jun 9 15:29:32 2011 +0200

    s3:smbcacls add option domain-sid
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit ada08e829057aef4553005c6d968f0bdf7f423c9
Author: Gregor Beck <gbeck at sernet.de>
Date:   Thu Jun 9 14:32:27 2011 +0200

    s3:smbcacls get_domain_sid for sddl parsing/formating from lsarpc
    
    get_global_sid panics if we are not root and may give the wrong answer anyway.
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit ab2fe321f4fa8dcc09bd0b8470201413a2e2f1b5
Author: Gregor Beck <gbeck at sernet.de>
Date:   Tue Jun 7 10:54:16 2011 +0200

    s3:smbcacls pretty print acl control field
    
    Signed-off-by: Michael Adam <obnox at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 lib/util/data_blob.h                               |    2 +-
 source3/Makefile.in                                |    5 +-
 source3/VERSION                                    |    2 +-
 source3/include/dbwrap.h                           |    4 +
 source3/lib/dbwrap.c                               |   52 +
 source3/lib/dbwrap_rbt.c                           |   60 +-
 source3/lib/dbwrap_tdb.c                           |   16 +
 source3/librpc/crypto/cli_spnego.c                 |    2 +-
 source3/registry/reg_format.c                      |    2 +-
 source3/registry/reg_parse_internal.c              |  110 ++-
 source3/registry/reg_parse_internal.h              |   17 +-
 source3/rpc_client/cli_pipe.c                      |    2 +-
 source3/utils/interact.c                           |  126 +++
 source3/utils/{net_idmap_check.h => interact.h}    |   32 +-
 source3/utils/net.c                                |    4 +
 source3/utils/net.h                                |    3 +
 source3/utils/net_idmap_check.c                    |   94 +--
 source3/utils/net_registry.c                       |   57 +
 source3/utils/net_registry_check.c                 | 1165 ++++++++++++++++++++
 .../{net_idmap_check.h => net_registry_check.h}    |   15 +-
 source3/utils/smbcacls.c                           |  157 +++-
 21 files changed, 1737 insertions(+), 190 deletions(-)
 create mode 100644 source3/utils/interact.c
 copy source3/utils/{net_idmap_check.h => interact.h} (61%)
 create mode 100644 source3/utils/net_registry_check.c
 copy source3/utils/{net_idmap_check.h => net_registry_check.h} (77%)


Changeset truncated at 500 lines:

diff --git a/lib/util/data_blob.h b/lib/util/data_blob.h
index 558ade9..09a9292 100644
--- a/lib/util/data_blob.h
+++ b/lib/util/data_blob.h
@@ -50,7 +50,7 @@ struct data_blob_list_item {
 
 #define data_blob(ptr, size) data_blob_named(ptr, size, "DATA_BLOB: "__location__)
 #define data_blob_talloc(ctx, ptr, size) data_blob_talloc_named(ctx, ptr, size, "DATA_BLOB: "__location__)
-#define data_blob_dup_talloc(ctx, blob) data_blob_talloc_named(ctx, (blob)->data, (blob)->length, "DATA_BLOB: "__location__)
+#define data_blob_dup_talloc(ctx, blob) data_blob_talloc_named(ctx, (blob).data, (blob).length, "DATA_BLOB: "__location__)
 
 /**
  construct a data blob, must be freed with data_blob_free()
diff --git a/source3/Makefile.in b/source3/Makefile.in
index b350dd3..55f0141 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -1157,14 +1157,15 @@ LIBNET_SAMSYNC_OBJ = libnet/libnet_samsync.o \
 NET_OBJ1 = utils/net.o utils/net_ads.o utils/net_help.o \
 	   utils/net_rap.o utils/net_rpc.o utils/net_rpc_samsync.o \
 	   utils/net_rpc_join.o utils/net_time.o utils/net_lookup.o \
-	   utils/net_cache.o utils/net_groupmap.o utils/net_idmap.o utils/net_idmap_check.o\
+	   utils/net_cache.o utils/net_groupmap.o utils/net_idmap.o \
+	   utils/net_idmap_check.o utils/interact.o \
 	   utils/net_status.o utils/net_rpc_printer.o utils/net_rpc_rights.o \
 	   utils/net_rpc_service.o utils/net_rpc_registry.o utils/net_usershare.o \
 	   utils/netlookup.o utils/net_sam.o utils/net_rpc_shell.o \
 	   utils/net_util.o utils/net_rpc_sh_acct.o utils/net_rpc_audit.o \
 	   $(PASSWD_UTIL_OBJ) utils/net_dns.o utils/net_ads_gpo.o \
 	   utils/net_conf.o utils/net_join.o utils/net_user.o \
-	   utils/net_group.o utils/net_file.o utils/net_registry.o \
+	   utils/net_group.o utils/net_file.o utils/net_registry.o utils/net_registry_check.o\
 	   auth/token_util.o utils/net_dom.o utils/net_share.o \
 	   utils/net_g_lock.o \
 	   utils/net_serverid.o \
diff --git a/source3/VERSION b/source3/VERSION
index 2cb358a..c2d80e9 100644
--- a/source3/VERSION
+++ b/source3/VERSION
@@ -85,7 +85,7 @@ SAMBA_VERSION_IS_GIT_SNAPSHOT=no
 #                                                      #
 ########################################################
 SAMBA_VERSION_VENDOR_SUFFIX="ctdb"
-SAMBA_VERSION_VENDOR_PATCH=20
+SAMBA_VERSION_VENDOR_PATCH=21
 
 ########################################################
 # This can be set by vendors if they want..            #
diff --git a/source3/include/dbwrap.h b/source3/include/dbwrap.h
index d657ee7..e8493ed 100644
--- a/source3/include/dbwrap.h
+++ b/source3/include/dbwrap.h
@@ -52,6 +52,8 @@ struct db_context {
 			    int (*parser)(TDB_DATA key, TDB_DATA data,
 					  void *private_data),
 			    void *private_data);
+	int (*exists)(struct db_context *db,TDB_DATA key);
+	int (*wipe)(struct db_context *db);
 	void *private_data;
 	bool persistent;
 };
@@ -91,6 +93,8 @@ NTSTATUS dbwrap_store(struct db_context *db, TDB_DATA key,
 		      TDB_DATA data, int flags);
 TDB_DATA dbwrap_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
 		      TDB_DATA key);
+int dbwrap_wipe(struct db_context *db);
+bool dbwrap_exists(struct db_context *db, TDB_DATA key);
 NTSTATUS dbwrap_delete_bystring(struct db_context *db, const char *key);
 NTSTATUS dbwrap_store_bystring(struct db_context *db, const char *key,
 			       TDB_DATA data, int flags);
diff --git a/source3/lib/dbwrap.c b/source3/lib/dbwrap.c
index 9b3197f..1b5748e 100644
--- a/source3/lib/dbwrap.c
+++ b/source3/lib/dbwrap.c
@@ -45,6 +45,39 @@ static int dbwrap_fallback_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
 }
 
 /*
+ * Fall back using fetch if no genuine exists operation is provided
+ */
+
+static int dbwrap_fallback_exists(struct db_context *db, TDB_DATA key)
+{
+	TDB_DATA val;
+	if ( db->fetch(db, talloc_tos(), key, &val) != 0 ) {
+		return 0;
+	}
+	if (val.dptr == NULL ) {
+		return 0;
+	} else {
+		TALLOC_FREE(val.dptr);
+		return 1;
+	}
+}
+
+static int delete_record(struct db_record *rec, void *data)
+{
+	NTSTATUS status = rec->delete_rec(rec);
+	return NT_STATUS_IS_OK(status) ? 0 : -1;
+}
+
+/*
+ * Fall back using traverse and delete if no genuine wipe operation is provided
+ */
+static int dbwrap_fallback_wipe(struct db_context *db)
+{
+	NTSTATUS status = dbwrap_trans_traverse(db, &delete_record, NULL);
+	return NT_STATUS_IS_OK(status) ? 0 : -1;
+}
+
+/*
  * Fall back using fetch if no genuine parse operation is provided
  */
 
@@ -155,6 +188,10 @@ struct db_context *db_open(TALLOC_CTX *mem_ctx,
 		result->parse_record = dbwrap_fallback_parse_record;
 	}
 
+	if ((result != NULL) && (result->wipe == NULL)) {
+		result->wipe = dbwrap_fallback_wipe;
+	}
+
 	return result;
 }
 
@@ -200,6 +237,21 @@ TDB_DATA dbwrap_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
 	return result;
 }
 
+int dbwrap_wipe(struct db_context *db) {
+	return db->wipe(db);
+}
+
+bool dbwrap_exists(struct db_context *db, TDB_DATA key)
+{
+	int result;
+	if (db->exists != NULL) {
+		result = db->exists(db, key);
+	} else {
+		result = dbwrap_fallback_exists(db,key);
+	}
+	return (result == 1);
+}
+
 NTSTATUS dbwrap_delete_bystring(struct db_context *db, const char *key)
 {
 	return dbwrap_delete(db, string_term_tdb_data(key));
diff --git a/source3/lib/dbwrap_rbt.c b/source3/lib/dbwrap_rbt.c
index af88c79..6ce934f 100644
--- a/source3/lib/dbwrap_rbt.c
+++ b/source3/lib/dbwrap_rbt.c
@@ -285,8 +285,20 @@ static struct db_record *db_rbt_fetch_locked(struct db_context *db_ctx,
 	return result;
 }
 
-static int db_rbt_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
-			TDB_DATA key, TDB_DATA *data)
+static int db_rbt_wipe(struct db_context *db)
+{
+	struct db_rbt_ctx *old_ctx = talloc_get_type_abort(
+		db->private_data, struct db_rbt_ctx);
+	struct db_rbt_ctx *new_ctx = TALLOC_ZERO_P(db, struct db_rbt_ctx);
+	if (new_ctx == NULL) {
+		return -1;
+	}
+	db->private_data = new_ctx;
+	talloc_free(old_ctx);
+	return 0;
+}
+
+static bool db_rbt_search_internal(struct db_context *db, TDB_DATA key, TDB_DATA *data)
 {
 	struct db_rbt_ctx *ctx = talloc_get_type_abort(
 		db->private_data, struct db_rbt_ctx);
@@ -295,7 +307,6 @@ static int db_rbt_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
 	bool found = false;
 	struct db_rbt_node *r = NULL;
 	TDB_DATA search_key, search_val;
-	uint8_t *result;
 
 	n = ctx->tree.rb_node;
 
@@ -320,26 +331,44 @@ static int db_rbt_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
 		}
 	}
 
+	if (data != NULL && found) {
+		*data = search_val;
+	}
+	return found;
+}
+
+static int db_rbt_exists(struct db_context *db, TDB_DATA key)
+{
+	return db_rbt_search_internal(db, key, NULL);
+}
+
+static int db_rbt_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
+			TDB_DATA key, TDB_DATA *data)
+{
+	TDB_DATA val;
+	uint8_t *result;
+
+	bool found = db_rbt_search_internal(db, key, &val);
+
 	if (!found) {
 		*data = tdb_null;
 		return 0;
 	}
 
-	result = (uint8 *)talloc_memdup(mem_ctx, search_val.dptr,
-					search_val.dsize);
+	result = (uint8_t*)talloc_memdup(mem_ctx, val.dptr, val.dsize);
 	if (result == NULL) {
 		return -1;
 	}
 
 	data->dptr = result;
-	data->dsize = search_val.dsize;
+	data->dsize = val.dsize;
 	return 0;
 }
 
 static int db_rbt_traverse_internal(struct rb_node *n,
 				    int (*f)(struct db_record *db,
 					     void *private_data),
-				    void *private_data)
+				    void *private_data, uint32_t* count)
 {
 	struct db_rbt_node *r;
 	struct db_record rec;
@@ -349,7 +378,7 @@ static int db_rbt_traverse_internal(struct rb_node *n,
 		return 0;
 	}
 
-	ret = db_rbt_traverse_internal(n->rb_left, f, private_data);
+	ret = db_rbt_traverse_internal(n->rb_left, f, private_data, count);
 	if (ret != 0) {
 		return ret;
 	}
@@ -359,11 +388,12 @@ static int db_rbt_traverse_internal(struct rb_node *n,
 	db_rbt_parse_node(r, &rec.key, &rec.value);
 
 	ret = f(&rec, private_data);
+	(*count) ++;
 	if (ret != 0) {
 		return ret;
 	}
 
-	return db_rbt_traverse_internal(n->rb_right, f, private_data);
+	return db_rbt_traverse_internal(n->rb_right, f, private_data, count);
 }
 
 static int db_rbt_traverse(struct db_context *db,
@@ -373,8 +403,16 @@ static int db_rbt_traverse(struct db_context *db,
 {
 	struct db_rbt_ctx *ctx = talloc_get_type_abort(
 		db->private_data, struct db_rbt_ctx);
+	uint32_t count = 0;
 
-	return db_rbt_traverse_internal(ctx->tree.rb_node, f, private_data);
+	int ret =  db_rbt_traverse_internal(ctx->tree.rb_node, f, private_data, &count);
+	if (ret != 0) {
+		return -1;
+	}
+	if (count > INT_MAX) {
+		return -1;
+	}
+	return count;
 }
 
 static int db_rbt_get_seqnum(struct db_context *db)
@@ -415,6 +453,8 @@ struct db_context *db_open_rbt(TALLOC_CTX *mem_ctx)
 	result->transaction_start = db_rbt_trans_dummy;
 	result->transaction_commit = db_rbt_trans_dummy;
 	result->transaction_cancel = db_rbt_trans_dummy;
+	result->exists = db_rbt_exists;
+	result->wipe = db_rbt_wipe;
 
 	return result;
 }
diff --git a/source3/lib/dbwrap_tdb.c b/source3/lib/dbwrap_tdb.c
index 98fd255..a9c69be 100644
--- a/source3/lib/dbwrap_tdb.c
+++ b/source3/lib/dbwrap_tdb.c
@@ -178,6 +178,20 @@ static int db_tdb_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
 	return 0;
 }
 
+static int db_tdb_exists(struct db_context *db, TDB_DATA key)
+{
+	struct db_tdb_ctx *ctx = talloc_get_type_abort(
+		db->private_data, struct db_tdb_ctx);
+	return tdb_exists(ctx->wtdb->tdb, key);
+}
+
+static int db_tdb_wipe(struct db_context *db)
+{
+	struct db_tdb_ctx *ctx = talloc_get_type_abort(
+		db->private_data, struct db_tdb_ctx);
+	return tdb_wipe_all(ctx->wtdb->tdb);
+}
+
 static int db_tdb_parse(struct db_context *db, TDB_DATA key,
 			int (*parser)(TDB_DATA key, TDB_DATA data,
 				      void *private_data),
@@ -371,6 +385,8 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx,
 	result->transaction_start = db_tdb_transaction_start;
 	result->transaction_commit = db_tdb_transaction_commit;
 	result->transaction_cancel = db_tdb_transaction_cancel;
+	result->exists = db_tdb_exists;
+	result->wipe = db_tdb_wipe;
 	return result;
 
  fail:
diff --git a/source3/librpc/crypto/cli_spnego.c b/source3/librpc/crypto/cli_spnego.c
index bf58e25..98f2a17 100644
--- a/source3/librpc/crypto/cli_spnego.c
+++ b/source3/librpc/crypto/cli_spnego.c
@@ -342,7 +342,7 @@ DATA_BLOB spnego_get_session_key(TALLOC_CTX *mem_ctx,
 	case SPNEGO_NTLMSSP:
 		sk = auth_ntlmssp_get_session_key(
 					sp_ctx->mech_ctx.ntlmssp_state);
-		return data_blob_dup_talloc(mem_ctx, &sk);
+		return data_blob_dup_talloc(mem_ctx, sk);
 	default:
 		DEBUG(0, ("Unsupported type in request!\n"));
 		return data_blob_null;
diff --git a/source3/registry/reg_format.c b/source3/registry/reg_format.c
index f2b0846..2d1b273 100644
--- a/source3/registry/reg_format.c
+++ b/source3/registry/reg_format.c
@@ -92,7 +92,7 @@ static int
 cbuf_print_hive(cbuf* ost, const char* hive, int len, const struct fmt_key* fmt)
 {
 	if (fmt->hive_fmt != FMT_HIVE_PRESERVE) {
-		const struct hive_info* hinfo = hive_info(hive, len);
+		const struct hive_info* hinfo = hive_info(hive);
 		if (hinfo == NULL) {
 			DEBUG(0, ("Unknown hive %*s", len, hive));
 		} else {
diff --git a/source3/registry/reg_parse_internal.c b/source3/registry/reg_parse_internal.c
index 79e9a32..c39f214 100644
--- a/source3/registry/reg_parse_internal.c
+++ b/source3/registry/reg_parse_internal.c
@@ -114,13 +114,13 @@ convert:
 #define HKEY_PERFORMANCE_NLSTEXT	0x80000060
 #endif
 
-#define HIVE_INFO_ENTRY(SHORT,LONG)			\
-static const struct hive_info HIVE_INFO_##SHORT = {	\
-	.handle = LONG,					\
-	.short_name = #SHORT,				\
-	.short_name_len = sizeof(#SHORT)-1,		\
-	.long_name = #LONG,				\
-	.long_name_len = sizeof(#LONG)-1,		\
+#define HIVE_INFO_ENTRY(SHORT,LONG)		\
+const struct hive_info HIVE_INFO_##SHORT = {	\
+	.handle = LONG,				\
+	.short_name = #SHORT,			\
+	.short_name_len = sizeof(#SHORT)-1,	\
+	.long_name = #LONG,			\
+	.long_name_len = sizeof(#LONG)-1,	\
 }
 
 HIVE_INFO_ENTRY(HKLM, HKEY_LOCAL_MACHINE);
@@ -134,49 +134,85 @@ HIVE_INFO_ENTRY(HKPT, HKEY_PERFORMANCE_TEXT);
 HIVE_INFO_ENTRY(HKPN, HKEY_PERFORMANCE_NLSTEXT);
 #undef HIVE_INFO_ENTRY
 
-static const struct hive_info* HIVE_INFO[] = {
+const struct hive_info* HIVE_INFO[] = {
 	&HIVE_INFO_HKLM, &HIVE_INFO_HKCU, &HIVE_INFO_HKCR, &HIVE_INFO_HKU,
 	&HIVE_INFO_HKCC, &HIVE_INFO_HKDD, &HIVE_INFO_HKPD, &HIVE_INFO_HKPT,
 	&HIVE_INFO_HKPN, NULL
 };
 
-const struct hive_info* hive_info(const char* name, int nlen)
-{
-	const struct hive_info** info;
-	char buf[32];
-	int s;
+#define TOINT(A,B) ((int)(A) << 8) + (int)(B)
 
-	if (nlen >= sizeof(buf)) {
-		return NULL;
-	}
-	for (s=0; s<nlen; s++) {
-		buf[s] = toupper(name[s]);
-	}
-	buf[s] = '\0';
+bool srprs_hive(const char** ptr, const struct hive_info** result)
+{
+	const char* str = *ptr;
+	const struct hive_info* info = NULL;
+	bool long_hive = false;
 
-	if ((s < 3) || (strncmp(buf, "HK", 2) != 0)) {
-		return NULL;
+	if ((toupper(str[0]) != 'H') || (toupper(str[1]) != 'K')
+	    || (str[2] == '\0') )
+	{
+		return false;
 	}
 
-	if (s <= 4) {
-		for(info = HIVE_INFO; *info; info++) {
-			if (strcmp(buf+2, (*info)->short_name+2) == 0) {
-				return *info;
+	switch ( TOINT(toupper(str[2]), toupper(str[3])) ) {
+	case TOINT('E', 'Y'):
+		if (str[4] == '_') {
+			int i;
+			for (i=0; (info = HIVE_INFO[i]); i++) {
+				if (strncmp(&str[5], &info->long_name[5],
+					    info->long_name_len-5) == 0)
+				{
+					long_hive = true;
+					break;
+				}
 			}
 		}
-		return NULL;
-	}
-
-	if ((s < 10) || (strncmp(buf, "HKEY_", 5)) != 0) {
-		return NULL;
+		break;
+	case TOINT('L', 'M'):
+		info = &HIVE_INFO_HKLM;
+		break;
+	case TOINT('C', 'U'):
+		info = &HIVE_INFO_HKCU;
+		break;
+	case TOINT('C', 'R'):
+		info = &HIVE_INFO_HKCR;
+		break;
+	case TOINT('C', 'C'):
+		info = &HIVE_INFO_HKCC;
+		break;
+	case TOINT('D', 'D'):
+		info = &HIVE_INFO_HKDD;
+		break;
+	case TOINT('P', 'D'):
+		info = &HIVE_INFO_HKPD;
+		break;
+	case TOINT('P', 'T'):
+		info = &HIVE_INFO_HKPT;
+		break;
+	case TOINT('P', 'N'):
+		info = &HIVE_INFO_HKPN;
+		break;
+	default:
+		if (toupper(str[2]) == 'U') {
+			info = &HIVE_INFO_HKU;
+		}
+		break;
 	}
-
-	for(info = HIVE_INFO; *info; info++) {
-		if (strcmp(buf+5, (*info)->long_name+5) == 0) {
-			return *info;
+	if (info != NULL) {
+		if (result != NULL) {
+			*result = info;
 		}
+		*ptr += long_hive ? info->long_name_len : info->short_name_len;
+		return true;
 	}
-	return NULL;
+	return false;
+}
+
+const struct hive_info* hive_info(const char* name)
+{
+	const struct hive_info* info = NULL;
+	srprs_hive(&name, &info);
+	return info;
 }
 
 const char* get_charset(const char* c)
diff --git a/source3/registry/reg_parse_internal.h b/source3/registry/reg_parse_internal.h
index 14fed89..dfa7c9f 100644
--- a/source3/registry/reg_parse_internal.h
+++ b/source3/registry/reg_parse_internal.h
@@ -56,7 +56,22 @@ struct hive_info {
 	size_t long_name_len;
 };
 
-const struct hive_info* hive_info(const char* name, int nlen);
+const struct hive_info HIVE_INFO_HKLM;
+const struct hive_info HIVE_INFO_HKCU;
+const struct hive_info HIVE_INFO_HKCR;
+const struct hive_info HIVE_INFO_HKU;
+const struct hive_info HIVE_INFO_HKCC;
+const struct hive_info HIVE_INFO_HKDD;
+const struct hive_info HIVE_INFO_HKPD;
+const struct hive_info HIVE_INFO_HKPT;
+const struct hive_info HIVE_INFO_HKPN;
+


-- 
SAMBA-CTDB repository


More information about the samba-cvs mailing list