Rev 5300: refactoring: put creation of a subkey (aka regshare) into a static in http://samba.sernet.de/ma/bzr/SAMBA_3_0-registry.bzr/

Michael Adam ma at sernet.de
Thu Mar 22 14:42:24 GMT 2007


At http://samba.sernet.de/ma/bzr/SAMBA_3_0-registry.bzr/

------------------------------------------------------------
revno: 5300
revision-id: ma at sernet.de-20070322144222-a56026b171ee1a35
parent: ma at sernet.de-20070322134752-496c2a22c1a3ca5d
committer: Michael Adam <ma at sernet.de>
branch nick: SAMBA_3_0-registry.bzr
timestamp: Thu 2007-03-22 15:42:22 +0100
message:
  refactoring: put creation of a subkey (aka regshare) into a static 
  function to be able to use it in other places (e.g. net conf import).
modified:
  source/utils/net_conf.c        net_conf.c-20070228210606-uywdn1acd043wgvt-1
=== modified file 'source/utils/net_conf.c'
--- a/source/utils/net_conf.c	2007-03-22 13:47:52 +0000
+++ b/source/utils/net_conf.c	2007-03-22 14:42:22 +0000
@@ -185,7 +185,7 @@
 }
 
 /*
- * delete a subkey of smbconf
+ * delete a subkey of KEY_SMBCONF
  */
 static WERROR reg_delkey_internal(TALLOC_CTX *ctx, const char *keyname)
 {
@@ -211,6 +211,51 @@
 	return werr;
 }
 
+/*
+ * create a subkey of KEY_SMBCONF
+ */
+static WERROR reg_createkey_internal(TALLOC_CTX *ctx,
+				     const char * subkeyname,
+				     struct registry_key **newkey)
+						
+{
+	WERROR werr = WERR_OK;
+	struct registry_key *create_parent = NULL;
+	TALLOC_CTX *create_ctx;
+	enum winreg_CreateAction action = REG_ACTION_NONE;
+
+	/* create a new talloc ctx for creation. it will hold
+	 * the intermediate parent key (SMBCONF) for creation
+	 * and will be destroyed when leaving this function... */
+	if (!(create_ctx = talloc_new(ctx))) {
+		werr = WERR_NOMEM;
+		goto done;
+	}
+
+	werr = reg_open_path(create_ctx, KEY_SMBCONF, REG_KEY_WRITE,
+			     get_root_nt_token(), &create_parent);
+	if (!W_ERROR_IS_OK(werr)) {
+		d_fprintf(stderr, "Error opening registry path '%s': %s\n",
+			  KEY_SMBCONF, dos_errstr(werr));
+		goto done;
+	}
+
+	werr = reg_createkey(ctx, create_parent, subkeyname, 
+			     REG_KEY_WRITE, newkey, &action);
+	if (W_ERROR_IS_OK(werr) && (action != REG_CREATED_NEW_KEY)) {
+		d_fprintf(stderr, "Key '%s' already exists.\n", subkeyname);
+		werr = WERR_ALREADY_EXISTS;
+	}
+	if (!W_ERROR_IS_OK(werr)) {
+		d_fprintf(stderr, "Error creating key %s: %s\n",
+			 subkeyname, dos_errstr(werr));
+	}
+
+done:
+	TALLOC_FREE(create_ctx);
+	return werr;
+}
+
 static WERROR list_values(TALLOC_CTX *ctx, struct registry_key *key)
 {
 	WERROR werr = WERR_OK;
@@ -513,9 +558,7 @@
 {
 	int ret = -1;
 	WERROR werr = WERR_OK;
-	struct registry_key *key = NULL;
 	struct registry_key *newkey = NULL;
-	enum winreg_CreateAction action = REG_ACTION_NONE;
 	char *sharename = NULL;
 	const char *path = NULL;
 	const char *comment = NULL;
@@ -630,23 +673,8 @@
 	 * create the share 
 	 */
 
-	werr = reg_open_path(NULL, KEY_SMBCONF, REG_KEY_WRITE,
-			       get_root_nt_token(), &key);
-	if (!W_ERROR_IS_OK(werr)) {
-		d_fprintf(stderr, "Error opening registry path '%s': %s\n",
-			  KEY_SMBCONF, dos_errstr(werr));
-		goto done;
-	}
-
-	werr = reg_createkey(key, key, argv[0], REG_KEY_WRITE, &newkey, 
-			       &action);
-	if (W_ERROR_IS_OK(werr) && (action != REG_CREATED_NEW_KEY)) {
-		d_fprintf(stderr, "Share '%s' already exists.\n", argv[0]);
-		werr = WERR_ALREADY_EXISTS;
-	}
-	if (!W_ERROR_IS_OK(werr)) {
-		d_fprintf(stderr, "Error creating share %s: %s\n",
-			 argv[0], dos_errstr(werr));
+	werr = reg_createkey_internal(NULL, argv[0], &newkey);
+	if (!W_ERROR_IS_OK(werr)) {
 		goto done;
 	}
 
@@ -673,7 +701,7 @@
 	ret = 0;
 
 done:
-	TALLOC_FREE(key);
+	TALLOC_FREE(newkey);
 	SAFE_FREE(sharename);
 	return ret;
 }



More information about the samba-cvs mailing list