svn commit: samba r23585 - in branches: SAMBA_3_0/source/utils SAMBA_3_0_26/source/utils

obnox at samba.org obnox at samba.org
Fri Jun 22 11:43:50 GMT 2007


Author: obnox
Date: 2007-06-22 11:43:50 +0000 (Fri, 22 Jun 2007)
New Revision: 23585

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

Log:
Add a "drop" function to "net conf" that clears the
whole configuration stored in registry.

Michael


Modified:
   branches/SAMBA_3_0/source/utils/net_conf.c
   branches/SAMBA_3_0_26/source/utils/net_conf.c


Changeset:
Modified: branches/SAMBA_3_0/source/utils/net_conf.c
===================================================================
--- branches/SAMBA_3_0/source/utils/net_conf.c	2007-06-22 11:42:17 UTC (rev 23584)
+++ branches/SAMBA_3_0/source/utils/net_conf.c	2007-06-22 11:43:50 UTC (rev 23585)
@@ -54,6 +54,12 @@
 	return -1;
 }
 
+static int net_conf_drop_usage(int argc, const char **argv)
+{
+	d_printf("USAGE: net conf drop\n");
+	return -1;
+}
+
 static int net_conf_showshare_usage(int argc, const char **argv)
 {
 	d_printf("USAGE: net conf showshare <sharename>\n");
@@ -368,6 +374,56 @@
 	return werr; 
 }
 
+static WERROR drop_smbconf_internal(TALLOC_CTX *ctx)
+{
+	char *path, *p;
+	WERROR werr = WERR_OK;
+	NT_USER_TOKEN *token;
+	struct registry_key *parent_key = NULL;
+	struct registry_key *new_key = NULL;
+	TALLOC_CTX* tmp_ctx = NULL;
+	enum winreg_CreateAction action;
+
+	tmp_ctx = talloc_new(ctx);
+	if (tmp_ctx == NULL) {
+		werr = WERR_NOMEM;
+		goto done;
+	}
+
+	if (!(token = registry_create_admin_token(tmp_ctx))) {
+		/* what is the appropriate error code here? */
+		werr = WERR_CAN_NOT_COMPLETE; 
+		goto done;
+	}
+
+	path = talloc_strdup(tmp_ctx, KEY_SMBCONF);
+	if (path == NULL) {
+		d_fprintf(stderr, "ERROR: out of memory!\n");
+		werr = WERR_NOMEM;
+		goto done;
+	}
+	p = strrchr(path, '\\');
+	*p = '\0';
+	werr = reg_open_path(tmp_ctx, path, REG_KEY_WRITE, token, &parent_key);
+
+	if (!W_ERROR_IS_OK(werr)) {
+		goto done;
+	}
+
+	werr = reg_deletekey_recursive(tmp_ctx, parent_key, p+1);
+
+	if (!W_ERROR_IS_OK(werr)) {
+		goto done;
+	}
+	
+	werr = reg_createkey(tmp_ctx, parent_key, p+1, REG_KEY_WRITE, 
+			     &new_key, &action);
+
+done:
+	TALLOC_FREE(tmp_ctx);
+	return werr;
+}
+
 static int import_process_service(TALLOC_CTX *ctx, 
 				  struct share_params *share)
 {
@@ -708,6 +764,29 @@
 	return ret;
 }
 
+int net_conf_drop(int argc, const char **argv)
+{
+	int ret = -1;
+	WERROR werr;
+
+	if (argc != 0) {
+		net_conf_drop_usage(argc, argv);
+		goto done;
+	}
+
+	werr = drop_smbconf_internal(NULL);
+	if (!W_ERROR_IS_OK(werr)) {
+		d_fprintf(stderr, "Error deleting configuration: %s\n",
+			  dos_errstr(werr));
+		goto done;
+	}
+
+	ret = 0;
+
+done:
+	return ret;
+}
+
 int net_conf_showshare(int argc, const char **argv)
 {
 	int ret = -1;
@@ -1067,6 +1146,8 @@
 		 "Import configuration from file in smb.conf format."},
 		{"listshares", net_conf_listshares, 
 		 "List the registry shares."},
+		{"drop", net_conf_drop,
+		 "Delete the complete configuration from registry."},
 		{"showshare", net_conf_showshare, 
 		 "Show the definition of a registry share."},
 		{"addshare", net_conf_addshare, 

Modified: branches/SAMBA_3_0_26/source/utils/net_conf.c
===================================================================
--- branches/SAMBA_3_0_26/source/utils/net_conf.c	2007-06-22 11:42:17 UTC (rev 23584)
+++ branches/SAMBA_3_0_26/source/utils/net_conf.c	2007-06-22 11:43:50 UTC (rev 23585)
@@ -54,6 +54,12 @@
 	return -1;
 }
 
+static int net_conf_drop_usage(int argc, const char **argv)
+{
+	d_printf("USAGE: net conf drop\n");
+	return -1;
+}
+
 static int net_conf_showshare_usage(int argc, const char **argv)
 {
 	d_printf("USAGE: net conf showshare <sharename>\n");
@@ -368,6 +374,56 @@
 	return werr; 
 }
 
+static WERROR drop_smbconf_internal(TALLOC_CTX *ctx)
+{
+	char *path, *p;
+	WERROR werr = WERR_OK;
+	NT_USER_TOKEN *token;
+	struct registry_key *parent_key = NULL;
+	struct registry_key *new_key = NULL;
+	TALLOC_CTX* tmp_ctx = NULL;
+	enum winreg_CreateAction action;
+
+	tmp_ctx = talloc_new(ctx);
+	if (tmp_ctx == NULL) {
+		werr = WERR_NOMEM;
+		goto done;
+	}
+
+	if (!(token = registry_create_admin_token(tmp_ctx))) {
+		/* what is the appropriate error code here? */
+		werr = WERR_CAN_NOT_COMPLETE; 
+		goto done;
+	}
+
+	path = talloc_strdup(tmp_ctx, KEY_SMBCONF);
+	if (path == NULL) {
+		d_fprintf(stderr, "ERROR: out of memory!\n");
+		werr = WERR_NOMEM;
+		goto done;
+	}
+	p = strrchr(path, '\\');
+	*p = '\0';
+	werr = reg_open_path(tmp_ctx, path, REG_KEY_WRITE, token, &parent_key);
+
+	if (!W_ERROR_IS_OK(werr)) {
+		goto done;
+	}
+
+	werr = reg_deletekey_recursive(tmp_ctx, parent_key, p+1);
+
+	if (!W_ERROR_IS_OK(werr)) {
+		goto done;
+	}
+	
+	werr = reg_createkey(tmp_ctx, parent_key, p+1, REG_KEY_WRITE, 
+			     &new_key, &action);
+
+done:
+	TALLOC_FREE(tmp_ctx);
+	return werr;
+}
+
 static int import_process_service(TALLOC_CTX *ctx, 
 				  struct share_params *share)
 {
@@ -708,6 +764,29 @@
 	return ret;
 }
 
+int net_conf_drop(int argc, const char **argv)
+{
+	int ret = -1;
+	WERROR werr;
+
+	if (argc != 0) {
+		net_conf_drop_usage(argc, argv);
+		goto done;
+	}
+
+	werr = drop_smbconf_internal(NULL);
+	if (!W_ERROR_IS_OK(werr)) {
+		d_fprintf(stderr, "Error deleting configuration: %s\n",
+			  dos_errstr(werr));
+		goto done;
+	}
+
+	ret = 0;
+
+done:
+	return ret;
+}
+
 int net_conf_showshare(int argc, const char **argv)
 {
 	int ret = -1;
@@ -1067,6 +1146,8 @@
 		 "Import configuration from file in smb.conf format."},
 		{"listshares", net_conf_listshares, 
 		 "List the registry shares."},
+		{"drop", net_conf_drop,
+		 "Delete the complete configuration from registry."},
 		{"showshare", net_conf_showshare, 
 		 "Show the definition of a registry share."},
 		{"addshare", net_conf_addshare, 



More information about the samba-cvs mailing list