svn commit: samba r19818 - in branches/SAMBA_3_0/source: rpc_client utils

vlendec at samba.org vlendec at samba.org
Tue Nov 21 10:48:12 GMT 2006


Author: vlendec
Date: 2006-11-21 10:48:11 +0000 (Tue, 21 Nov 2006)
New Revision: 19818

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

Log:
Remove reg_split_hive, make use of registry_openkey
Modified:
   branches/SAMBA_3_0/source/rpc_client/cli_reg.c
   branches/SAMBA_3_0/source/utils/net_rpc_registry.c


Changeset:
Modified: branches/SAMBA_3_0/source/rpc_client/cli_reg.c
===================================================================
--- branches/SAMBA_3_0/source/rpc_client/cli_reg.c	2006-11-21 10:32:08 UTC (rev 19817)
+++ branches/SAMBA_3_0/source/rpc_client/cli_reg.c	2006-11-21 10:48:11 UTC (rev 19818)
@@ -58,50 +58,6 @@
 	return NT_STATUS_INVALID_PARAMETER;
 }
 
-/*
- *
- * Utility functions
- * 
- */
-
-/*****************************************************************
- Splits out the start of the key (HKLM or HKU) and the rest of the key.
-*****************************************************************/  
-
-BOOL reg_split_hive(const char *full_keyname, uint32 *reg_type, pstring key_name)
-{
-	pstring tmp;
-
-	if (!next_token(&full_keyname, tmp, "\\", sizeof(tmp)))
-		return False;
-
-	(*reg_type) = 0;
-
-	DEBUG(10, ("reg_split_key: hive %s\n", tmp));
-
-	if (strequal(tmp, "HKLM") || strequal(tmp, "HKEY_LOCAL_MACHINE"))
-		(*reg_type) = HKEY_LOCAL_MACHINE;
-	else if (strequal(tmp, "HKCR") || strequal(tmp, "HKEY_CLASSES_ROOT"))
-		(*reg_type) = HKEY_CLASSES_ROOT;
-	else if (strequal(tmp, "HKU") || strequal(tmp, "HKEY_USERS"))
-		(*reg_type) = HKEY_USERS;
-	else if (strequal(tmp, "HKPD")||strequal(tmp, "HKEY_PERFORMANCE_DATA"))
-		(*reg_type) = HKEY_PERFORMANCE_DATA;
-	else {
-		DEBUG(10,("reg_split_key: unrecognised hive key %s\n", tmp));
-		return False;
-	}
-	
-	if (next_token(&full_keyname, tmp, "\n\r", sizeof(tmp)))
-		pstrcpy(key_name, tmp);
-	else
-		key_name[0] = 0;
-
-	DEBUG(10, ("reg_split_key: name %s\n", key_name));
-
-	return True;
-}
-
 /*******************************************************************
  Fill in a REGVAL_BUFFER for the data given a REGISTRY_VALUE
  *******************************************************************/

Modified: branches/SAMBA_3_0/source/utils/net_rpc_registry.c
===================================================================
--- branches/SAMBA_3_0/source/utils/net_rpc_registry.c	2006-11-21 10:32:08 UTC (rev 19817)
+++ branches/SAMBA_3_0/source/utils/net_rpc_registry.c	2006-11-21 10:48:11 UTC (rev 19818)
@@ -474,12 +474,6 @@
 	NTSTATUS status;
 	struct registry_value value;
 
-	if (argc < 4) {
-		d_fprintf(stderr, "usage: net rpc registry setvalue <key> "
-			  "<valuename> <type> [<val>]+\n");
-		return NT_STATUS_INVALID_PARAMETER;
-	}
-
 	status = registry_openkey(mem_ctx, pipe_hnd, argv[0], REG_KEY_WRITE,
 				  &hive_hnd, &key_hnd);
 	if (!NT_STATUS_IS_OK(status)) {
@@ -525,6 +519,12 @@
 
 static int rpc_registry_setvalue( int argc, const char **argv )
 {
+	if (argc < 4) {
+		d_fprintf(stderr, "usage: net rpc registry setvalue <key> "
+			  "<valuename> <type> [<val>]+\n");
+		return -1;
+	}
+
 	return run_rpc_command( NULL, PI_WINREG, 0, 
 		rpc_registry_setvalue_internal, argc, argv );
 }
@@ -540,12 +540,8 @@
 						int argc,
 						const char **argv )
 {
-	WERROR result = WERR_GENERAL_FAILURE;
-	uint32 hive;
-	pstring subpath;
 	POLICY_HND pol_hive, pol_key; 
 	NTSTATUS status;
-	struct winreg_String subkeyname;
 	uint32 num_subkeys;
 	uint32 num_values;
 	char **names, **classes;
@@ -558,29 +554,14 @@
 		d_printf("Example:  net rpc enumerate 'HKLM\\Software\\Samba'\n");
 		return NT_STATUS_OK;
 	}
-	
-	if ( !reg_split_hive( argv[0], &hive, subpath ) ) {
-		d_fprintf(stderr, "invalid registry path\n");
-		return NT_STATUS_OK;
-	}
-	
-	/* open the top level hive and then the registry key */
-	
-	status = rpccli_winreg_Connect(pipe_hnd, mem_ctx, hive, MAXIMUM_ALLOWED_ACCESS, &pol_hive );
-	if ( !NT_STATUS_IS_OK(status) ) {
-		d_fprintf(stderr, "Unable to connect to remote registry: "
-			  "%s\n", nt_errstr(status));
+
+	status = registry_openkey(mem_ctx, pipe_hnd, argv[0], REG_KEY_READ,
+				  &pol_hive, &pol_key);
+	if (!NT_STATUS_IS_OK(status)) {
+		d_fprintf(stderr, "registry_openkey failed: %s\n",
+			  nt_errstr(status));
 		return status;
 	}
-	
-	subkeyname.name = subpath;
-	status = rpccli_winreg_OpenKey(pipe_hnd, mem_ctx, &pol_hive, subkeyname,
-				       0, MAXIMUM_ALLOWED_ACCESS, &pol_key );
-	if ( !NT_STATUS_IS_OK(status) ) {
-		d_fprintf(stderr, "Unable to open [%s]: %s\n", argv[0],
-			  nt_errstr(status));
-		return werror_to_ntstatus(result);
-	}
 
 	status = registry_enumkeys(mem_ctx, pipe_hnd, &pol_key, &num_subkeys,
 				   &names, &classes, &modtimes);
@@ -639,8 +620,7 @@
 		d_printf("\n");
 	}
 
-	if ( strlen( subpath ) != 0 )
-		rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &pol_key );
+	rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &pol_key );
 	rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &pol_hive );
 
 	return status;
@@ -667,11 +647,8 @@
 					const char **argv )
 {
 	WERROR result = WERR_GENERAL_FAILURE;
-	uint32 hive;
-	pstring subpath;
 	POLICY_HND pol_hive, pol_key; 
 	NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
-	struct winreg_String subkeyname;
 	struct winreg_String filename;
 	
 	if (argc != 2 ) {
@@ -679,27 +656,14 @@
 		return NT_STATUS_OK;
 	}
 	
-	if ( !reg_split_hive( argv[0], &hive, subpath ) ) {
-		d_fprintf(stderr, "invalid registry path\n");
-		return NT_STATUS_OK;
-	}
-	
-	/* open the top level hive and then the registry key */
-	
-	status = rpccli_winreg_Connect(pipe_hnd, mem_ctx, hive, MAXIMUM_ALLOWED_ACCESS, &pol_hive );
-	if ( !NT_STATUS_IS_OK(status) ) {
-		d_fprintf(stderr, "Unable to connect to remote registry\n");
+	status = registry_openkey(mem_ctx, pipe_hnd, argv[0], REG_KEY_ALL,
+				  &pol_hive, &pol_key);
+	if (!NT_STATUS_IS_OK(status)) {
+		d_fprintf(stderr, "registry_openkey failed: %s\n",
+			  nt_errstr(status));
 		return status;
 	}
-	
-	subkeyname.name = subpath;
-	status = rpccli_winreg_OpenKey(pipe_hnd, mem_ctx, &pol_hive, subkeyname,
-			0, MAXIMUM_ALLOWED_ACCESS, &pol_key );
-	if ( !NT_STATUS_IS_OK(status) ) {
-		d_fprintf(stderr, "Unable to open [%s]\n", argv[0]);
-		return werror_to_ntstatus(result);
-	}
-	
+
 	filename.name = argv[1];
 	status = rpccli_winreg_SaveKey( pipe_hnd, mem_ctx, &pol_key, &filename, NULL  );
 	if ( !W_ERROR_IS_OK(result) ) {



More information about the samba-cvs mailing list