svn commit: samba r23441 - in branches/SAMBA_3_0_26/source/registry: .

obnox at samba.org obnox at samba.org
Tue Jun 12 15:55:02 GMT 2007


Author: obnox
Date: 2007-06-12 15:55:00 +0000 (Tue, 12 Jun 2007)
New Revision: 23441

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=23441

Log:
Merge r20037 from 3_0:

"Reduce code size slightly by shuffling stuff around."

Michael


Modified:
   branches/SAMBA_3_0_26/source/registry/reg_api.c
   branches/SAMBA_3_0_26/source/registry/reg_frontend.c


Changeset:
Modified: branches/SAMBA_3_0_26/source/registry/reg_api.c
===================================================================
--- branches/SAMBA_3_0_26/source/registry/reg_api.c	2007-06-12 15:36:02 UTC (rev 23440)
+++ branches/SAMBA_3_0_26/source/registry/reg_api.c	2007-06-12 15:55:00 UTC (rev 23441)
@@ -62,81 +62,67 @@
 		    const struct nt_user_token *token,
 		    struct registry_key **pkey)
 {
-	struct registry_key *key;
-	WERROR err;
-
+	SMB_ASSERT(hive != NULL);
 	SMB_ASSERT(hive[0] != '\0');
 	SMB_ASSERT(strchr(hive, '\\') == NULL);
 
-	if (!(key = TALLOC_ZERO_P(mem_ctx, struct registry_key))) {
-		return WERR_NOMEM;
-	}
-
-	if (!(key->token = dup_nt_token(key, token))) {
-		TALLOC_FREE(key);
-		return WERR_NOMEM;
-	}
-
-	err = regkey_open_internal(key, &key->key, hive, token,
-				   desired_access);
-
-	if (!W_ERROR_IS_OK(err)) {
-		TALLOC_FREE(key);
-		return err;
-	}
-
-	*pkey = key;
-	return WERR_OK;
-
+	return regkey_open_onelevel(mem_ctx, NULL, hive, token, desired_access,
+				    pkey);
 }
 
 WERROR reg_openkey(TALLOC_CTX *mem_ctx, struct registry_key *parent,
 		   const char *name, uint32 desired_access,
 		   struct registry_key **pkey)
 {
-	struct registry_key *key;
+	struct registry_key *direct_parent = parent;
 	WERROR err;
-	char *path;
+	char *p, *path, *to_free;
+	size_t len;
 
-	if (!(key = TALLOC_ZERO_P(mem_ctx, struct registry_key))) {
+	if (!(path = SMB_STRDUP(name))) {
 		return WERR_NOMEM;
 	}
+	to_free = path;
 
-	if (!(key->token = dup_nt_token(key, parent->token))) {
-		TALLOC_FREE(key);
-		return WERR_NOMEM;
-	}
+	len = strlen(path);
 
-	if (name[0] == '\0') {
-		/*
-		 * Make a copy of the parent
-		 */ 
-		path = talloc_strdup(key, parent->key->name);
+	if ((len > 0) && (path[len-1] == '\\')) {
+		path[len-1] = '\0';
 	}
-	else {
-		/*
-		 * Normal subpath open
-		 */
-		path = talloc_asprintf(key, "%s\\%s", parent->key->name,
-				       name);
-	}
 
-	if (!path) {
-		TALLOC_FREE(key);
-		return WERR_NOMEM;
-	}
+	while ((p = strchr(path, '\\')) != NULL) {
+		char *name_component;
+		struct registry_key *tmp;
 
-	err = regkey_open_internal(key, &key->key, path, parent->token,
-				   desired_access);
-	TALLOC_FREE(path);
+		if (!(name_component = SMB_STRNDUP(path, (p - path)))) {
+			err = WERR_NOMEM;
+			goto error;
+		}
 
-	if (!W_ERROR_IS_OK(err)) {
-		TALLOC_FREE(key);
-		return err;
+		err = regkey_open_onelevel(mem_ctx, direct_parent,
+					   name_component, parent->token,
+					   SEC_RIGHTS_ENUM_SUBKEYS, &tmp);
+		SAFE_FREE(name_component);
+
+		if (!W_ERROR_IS_OK(err)) {
+			goto error;
+		}
+		if (direct_parent != parent) {
+			TALLOC_FREE(direct_parent);
+		}
+
+		direct_parent = tmp;
+		path = p+1;
 	}
 
-	*pkey = key;
-	return WERR_OK;
+	err = regkey_open_onelevel(mem_ctx, direct_parent, path, parent->token,
+				   desired_access, pkey);
+ error:
+	if (direct_parent != parent) {
+		TALLOC_FREE(direct_parent);
+	}
+	SAFE_FREE(to_free);
+	return err;
 }
 
 WERROR reg_enumkey(TALLOC_CTX *mem_ctx, struct registry_key *key,

Modified: branches/SAMBA_3_0_26/source/registry/reg_frontend.c
===================================================================
--- branches/SAMBA_3_0_26/source/registry/reg_frontend.c	2007-06-12 15:36:02 UTC (rev 23440)
+++ branches/SAMBA_3_0_26/source/registry/reg_frontend.c	2007-06-12 15:55:00 UTC (rev 23441)
@@ -412,29 +412,33 @@
 	return regdb_close();
 }
 
-WERROR regkey_open_onelevel( TALLOC_CTX *mem_ctx, REGISTRY_KEY *parent,
-			     REGISTRY_KEY **regkey, const char *name,
-                             const struct nt_user_token *token,
-			     uint32 access_desired )
+WERROR regkey_open_onelevel( TALLOC_CTX *mem_ctx, struct registry_key *parent,
+			     const char *name,
+			     const struct nt_user_token *token,
+			     uint32 access_desired,
+			     struct registry_key **pregkey)
 {
 	WERROR     	result = WERR_OK;
-	REGISTRY_KEY    *key;
+	struct registry_key *regkey;
+	REGISTRY_KEY *key;
 	REGSUBKEY_CTR	*subkeys = NULL;
 
 	DEBUG(7,("regkey_open_onelevel: name = [%s]\n", name));
 
-	if ((parent != NULL) &&
-	    ((parent->access_granted & SEC_RIGHTS_ENUM_SUBKEYS) == 0)) {
-		return WERR_ACCESS_DENIED;
+	SMB_ASSERT(strchr(name, '\\') == NULL);
+
+	if (!(regkey = TALLOC_ZERO_P(mem_ctx, struct registry_key)) ||
+	    !(regkey->token = dup_nt_token(regkey, token)) ||
+	    !(regkey->key = TALLOC_ZERO_P(regkey, REGISTRY_KEY))) {
+		result = WERR_NOMEM;
+		goto done;
 	}
 
-	if ( !(key = TALLOC_ZERO_P(mem_ctx, REGISTRY_KEY)) ) {
-		return WERR_NOMEM;
+	if ( !(W_ERROR_IS_OK(result = regdb_open())) ) {
+		goto done;
 	}
 
-	if ( !(W_ERROR_IS_OK(result = regdb_open()) ) )
-		return result;
-
+	key = regkey->key;
 	talloc_set_destructor(key, regkey_destructor);
 		
 	/* initialization */
@@ -449,14 +453,14 @@
 			result = WERR_BADFILE;
 			goto done;
 		}
-		key->name = talloc_strdup(key, parent->name);
+		key->name = talloc_strdup(key, parent->key->name);
 	}
 	else {
 		/*
-		 * Normal open, concat parent and new keynames
+		 * Normal subkey open
 		 */
 		key->name = talloc_asprintf(key, "%s%s%s",
-					    parent ? parent->name : "",
+					    parent ? parent->key->name : "",
 					    parent ? "\\": "",
 					    name);
 	}
@@ -501,12 +505,12 @@
 		goto done;
 	}
 
-	*regkey = key;
+	*pregkey = regkey;
 	result = WERR_OK;
 	
 done:
 	if ( !W_ERROR_IS_OK(result) ) {
-		TALLOC_FREE(key);
+		TALLOC_FREE(regkey);
 	}
 
 	return result;
@@ -517,53 +521,17 @@
                              const struct nt_user_token *token,
 			     uint32 access_desired )
 {
-	TALLOC_CTX *mem_ctx;
-	const char *p;
-	REGISTRY_KEY *parent = NULL;
+	struct registry_key *key;
 	WERROR err;
-	size_t len;
 
-	if (!(mem_ctx = talloc_new(ctx))) {
-		return WERR_NOMEM;
+	err = reg_open_path(NULL, path, access_desired, token, &key);
+	if (!W_ERROR_IS_OK(err)) {
+		return err;
 	}
 
-	len = strlen(path);
-	if ((len > 0) && (path[len-1] == '\\')) {
-		if (!(path = talloc_strndup(mem_ctx, path, len-1))) {
-			TALLOC_FREE(mem_ctx);
-			return WERR_NOMEM;
-		}
-	}
-
-	while ((p = strchr(path, '\\')) != NULL) {
-		char *name_component;
-		REGISTRY_KEY *intermediate;
-
-		if (!(name_component = talloc_strndup(
-			      mem_ctx, path, (p - path)))) {
-			TALLOC_FREE(mem_ctx);
-			return WERR_NOMEM;
-		}
-
-		err = regkey_open_onelevel(mem_ctx, parent, &intermediate,
-					   name_component, token,
-					   SEC_RIGHTS_ENUM_SUBKEYS);
-		TALLOC_FREE(name_component);
-
-		if (!W_ERROR_IS_OK(err)) {
-			TALLOC_FREE(mem_ctx);
-			return WERR_NOMEM;
-		}
-
-		TALLOC_FREE(parent);
-		parent = intermediate;
-		path = p+1;
-	}
-
-	err = regkey_open_onelevel(ctx, parent, regkey, path, token,
-				   access_desired);
-	TALLOC_FREE(mem_ctx);
-	return err;
+	*regkey = talloc_move(ctx, &key->key);
+	TALLOC_FREE(key);
+	return WERR_OK;
 }
 
 WERROR regkey_get_secdesc(TALLOC_CTX *mem_ctx, REGISTRY_KEY *key,



More information about the samba-cvs mailing list