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

obnox at samba.org obnox at samba.org
Tue Jun 12 15:36:03 GMT 2007


Author: obnox
Date: 2007-06-12 15:36:02 +0000 (Tue, 12 Jun 2007)
New Revision: 23440

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

Log:
Merge r20016 from 3_0:

Add two utility functions for easy opening/creating registry keys.

Michael

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


Changeset:
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:33:47 UTC (rev 23439)
+++ branches/SAMBA_3_0_26/source/registry/reg_frontend.c	2007-06-12 15:36:02 UTC (rev 23440)
@@ -631,8 +631,8 @@
 			SAFE_FREE(path);
 			return err;
 		}
+		SAFE_FREE(path);
 		*pkey = hive;
-		SAFE_FREE(path);
 		return WERR_OK;
 	}
 
@@ -657,3 +657,97 @@
 	*pkey = key;
 	return WERR_OK;
 }
+
+/*
+ * Utility function to create a registry key without opening the hive
+ * before. Assumes the hive already exists.
+ */
+
+WERROR reg_create_path(TALLOC_CTX *mem_ctx, const char *orig_path,
+		       uint32 desired_access,
+		       const struct nt_user_token *token,
+		       enum winreg_CreateAction *paction,
+		       struct registry_key **pkey)
+{
+	struct registry_key *hive;
+	char *path, *p;
+	WERROR err;
+
+	if (!(path = SMB_STRDUP(orig_path))) {
+		return WERR_NOMEM;
+	}
+
+	p = strchr(path, '\\');
+
+	if ((p == NULL) || (p[1] == '\0')) {
+		/*
+		 * No key behind the hive, just return the hive
+		 */
+
+		err = reg_openhive(mem_ctx, path, desired_access, token,
+				   &hive);
+		if (!W_ERROR_IS_OK(err)) {
+			SAFE_FREE(path);
+			return err;
+		}
+		SAFE_FREE(path);
+		*pkey = hive;
+		*paction = REG_OPENED_EXISTING_KEY;
+		return WERR_OK;
+	}
+
+	*p = '\0';
+
+	err = reg_openhive(mem_ctx, path,
+			   (strchr(p+1, '\\') != NULL) ?
+			   SEC_RIGHTS_ENUM_SUBKEYS : SEC_RIGHTS_CREATE_SUBKEY,
+			   token, &hive);
+	if (!W_ERROR_IS_OK(err)) {
+		SAFE_FREE(path);
+		return err;
+	}
+
+	err = reg_createkey(mem_ctx, hive, p+1, desired_access, pkey, paction);
+	SAFE_FREE(path);
+	TALLOC_FREE(hive);
+	return err;
+}
+
+/*
+ * Utility function to create a registry key without opening the hive
+ * before. Will not delete a hive.
+ */
+
+WERROR reg_delete_path(const struct nt_user_token *token,
+		       const char *orig_path)
+{
+	struct registry_key *hive;
+	char *path, *p;
+	WERROR err;
+
+	if (!(path = SMB_STRDUP(orig_path))) {
+		return WERR_NOMEM;
+	}
+
+	p = strchr(path, '\\');
+
+	if ((p == NULL) || (p[1] == '\0')) {
+		return WERR_INVALID_PARAM;
+	}
+
+	*p = '\0';
+
+	err = reg_openhive(NULL, path,
+			   (strchr(p+1, '\\') != NULL) ?
+			   SEC_RIGHTS_ENUM_SUBKEYS : SEC_RIGHTS_CREATE_SUBKEY,
+			   token, &hive);
+	if (!W_ERROR_IS_OK(err)) {
+		SAFE_FREE(path);
+		return err;
+	}
+
+	err = reg_deletekey(hive, p+1);
+	SAFE_FREE(path);
+	TALLOC_FREE(hive);
+	return err;
+}



More information about the samba-cvs mailing list