Rev 5325: add _key_exists function used in import function. in http://samba.sernet.de/ma/bzr/SAMBA_3_0-registry.bzr/

Michael Adam ma at sernet.de
Tue Apr 3 21:41:15 GMT 2007


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

------------------------------------------------------------
revno: 5325
revision-id: ma at sernet.de-20070403214112-fc711ae2210566e7
parent: ma at sernet.de-20070403212235-04bf8e8ea92fab7a
committer: Michael Adam <ma at sernet.de>
branch nick: SAMBA_3_0-registry.bzr
timestamp: Tue 2007-04-03 23:41:12 +0200
message:
  add _key_exists function used in import function. 
  add __open_path function: like _open_path without error output
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-04-03 21:22:35 +0000
+++ b/source/utils/net_conf.c	2007-04-03 21:41:12 +0000
@@ -190,8 +190,9 @@
 
 /* 
  * Open a subkey of KEY_SMBCONF (i.e a service)
+ * - variant without error output -
  */
-static WERROR _open_path(TALLOC_CTX *ctx, const char *subkeyname,
+static WERROR __open_path(TALLOC_CTX *ctx, const char *subkeyname,
 			 uint32 desired_access, struct registry_key **key)
 {
 	WERROR werr = WERR_OK;
@@ -206,16 +207,31 @@
 
 	werr = reg_open_path(ctx, path, desired_access,
 			     get_root_nt_token(), key);
-	if (!W_ERROR_IS_OK(werr)) {
-		d_fprintf(stderr, "Error opening registry path '%s': %s\n",
-			  path, dos_errstr(werr));
-		goto done;
-	}
-done:
+
 	TALLOC_FREE(path);
 	return werr;
 }
 
+/* 
+ * Open a subkey of KEY_SMBCONF (i.e a service)
+ * - variant with error output -
+ */
+static WERROR _open_path(TALLOC_CTX *ctx, const char *subkeyname,
+			 uint32 desired_access, struct registry_key **key)
+{
+	WERROR werr = WERR_OK;
+
+	werr = __open_path(ctx, subkeyname, desired_access, key);
+	if (!W_ERROR_IS_OK(werr)) {
+		d_fprintf(stderr, "Error opening registry path '%s\\%s': %s\n",
+			  KEY_SMBCONF, 
+			  (subkeyname == NULL) ? "" : subkeyname, 
+			  dos_errstr(werr));
+	}
+
+	return werr;
+}
+
 /*
  * open the base key KEY_SMBCONF
  */
@@ -290,6 +306,31 @@
 	return werr;
 }
 
+/*
+ * check if a subkey of KEY_SMBCONF of a given name exists
+ */
+static BOOL _key_exists(TALLOC_CTX *ctx, const char *subkeyname)
+{
+	BOOL ret = False;
+	WERROR werr = WERR_OK;
+	TALLOC_CTX *mem_ctx;
+	struct registry_key *key;
+
+	if (!(mem_ctx = talloc_new(ctx))) {
+		d_fprintf(stderr, "ERROR: Out of memory...!\n");
+		goto done;
+	}
+
+	werr = __open_path(mem_ctx, subkeyname, REG_KEY_READ, &key);
+	if (W_ERROR_IS_OK(werr)) {
+		ret = True;
+	}
+
+done:
+	TALLOC_FREE(mem_ctx);
+	return ret;
+}
+
 static WERROR delete_globals(TALLOC_CTX *ctx)
 {
 	WERROR werr = WERR_OK;
@@ -385,9 +426,11 @@
 			}
 		}
 		else {
-			werr = reg_delkey_internal(ctx, servicename);
-			if (!W_ERROR_IS_OK(werr)) {
-				goto done;
+			if (_key_exists(ctx, servicename)) {
+				werr = reg_delkey_internal(ctx, servicename);
+				if (!W_ERROR_IS_OK(werr)) {
+					goto done;
+				}
 			}
 			werr = reg_createkey_internal(ctx, servicename, &key);
 			if (!W_ERROR_IS_OK(werr)) {



More information about the samba-cvs mailing list