svn commit: samba r19448 - in branches/SAMBA_3_0/source: lib param rpc_server

vlendec at samba.org vlendec at samba.org
Sat Oct 21 17:00:47 GMT 2006


Author: vlendec
Date: 2006-10-21 17:00:47 +0000 (Sat, 21 Oct 2006)
New Revision: 19448

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

Log:
Convert delete_share_security to struct share_params plus some cleanups
Modified:
   branches/SAMBA_3_0/source/lib/sharesec.c
   branches/SAMBA_3_0/source/lib/util_tdb.c
   branches/SAMBA_3_0/source/param/loadparm.c
   branches/SAMBA_3_0/source/rpc_server/srv_srvsvc_nt.c


Changeset:
Modified: branches/SAMBA_3_0/source/lib/sharesec.c
===================================================================
--- branches/SAMBA_3_0/source/lib/sharesec.c	2006-10-21 16:52:25 UTC (rev 19447)
+++ branches/SAMBA_3_0/source/lib/sharesec.c	2006-10-21 17:00:47 UTC (rev 19448)
@@ -188,18 +188,19 @@
  Delete a security descriptor.
 ********************************************************************/
 
-BOOL delete_share_security(int snum)
+BOOL delete_share_security(const struct share_params *params)
 {
 	TDB_DATA kbuf;
 	fstring key;
 
-	slprintf(key, sizeof(key)-1, "SECDESC/%s", lp_servicename(snum));
+	slprintf(key, sizeof(key)-1, "SECDESC/%s",
+		 lp_servicename(params->service));
 	kbuf.dptr = key;
 	kbuf.dsize = strlen(key)+1;
 
-	if (tdb_delete(share_tdb, kbuf) != 0) {
+	if (tdb_trans_delete(share_tdb, kbuf) != 0) {
 		DEBUG(0,("delete_share_security: Failed to delete entry for share %s\n",
-				lp_servicename(snum) ));
+			 lp_servicename(params->service) ));
 		return False;
 	}
 

Modified: branches/SAMBA_3_0/source/lib/util_tdb.c
===================================================================
--- branches/SAMBA_3_0/source/lib/util_tdb.c	2006-10-21 16:52:25 UTC (rev 19447)
+++ branches/SAMBA_3_0/source/lib/util_tdb.c	2006-10-21 17:00:47 UTC (rev 19448)
@@ -809,3 +809,32 @@
 
 	return res;
 }
+
+/****************************************************************************
+ tdb_delete, wrapped in a transaction. This way we make sure that a process
+ that dies within deleting does not leave a corrupt tdb behind.
+****************************************************************************/
+
+int tdb_trans_delete(struct tdb_context *tdb, TDB_DATA key)
+{
+	int res;
+
+	if ((res = tdb_transaction_start(tdb)) != 0) {
+		DEBUG(5, ("tdb_transaction_start failed\n"));
+		return res;
+	}
+
+	if ((res = tdb_delete(tdb, key)) != 0) {
+		DEBUG(10, ("tdb_delete failed\n"));
+		if (tdb_transaction_cancel(tdb) != 0) {
+			smb_panic("Cancelling transaction failed\n");
+		}
+		return res;
+	}
+
+	if ((res = tdb_transaction_commit(tdb)) != 0) {
+		DEBUG(5, ("tdb_transaction_commit failed\n"));
+	}
+
+	return res;
+}

Modified: branches/SAMBA_3_0/source/param/loadparm.c
===================================================================
--- branches/SAMBA_3_0/source/param/loadparm.c	2006-10-21 16:52:25 UTC (rev 19447)
+++ branches/SAMBA_3_0/source/param/loadparm.c	2006-10-21 17:00:47 UTC (rev 19448)
@@ -4879,7 +4879,7 @@
 			/* Remove from the share ACL db. */
 			DEBUG(10,("load_usershare_shares: Removing deleted usershare %s\n",
 				lp_servicename(iService) ));
-			delete_share_security(iService);
+			delete_share_security(snum2params_static(iService));
 			free_service_byindex(iService);
 		}
 	}
@@ -5113,7 +5113,7 @@
 
 		if (!usershare_exists(iService, &last_mod)) {
 			/* Remove the share security tdb entry for it. */
-			delete_share_security(iService);
+			delete_share_security(snum2params_static(iService));
 			/* Remove it from the array. */
 			free_service_byindex(iService);
 			/* Doesn't exist anymore. */
@@ -5146,12 +5146,16 @@
 				      const char *sharename)
 {
 	struct share_params *result;
-	fstring sname;
+	char *sname;
 	int snum;
 
-	fstrcpy(sname, sharename);
+	if (!(sname = SMB_STRDUP(sharename))) {
+		return NULL;
+	}
 
 	snum = find_service(sname);
+	SAFE_FREE(sname);
+
 	if (snum < 0) {
 		return NULL;
 	}
@@ -5213,6 +5217,18 @@
 	return result;
 }
 
+/*
+ * This is a hack for a transition period until we transformed all code from
+ * service numbers to struct share_params.
+ */
+
+struct share_params *snum2params_static(int snum)
+{
+	static struct share_params result;
+	result.service = snum;
+	return &result;
+}
+
 /*******************************************************************
  A useful volume label function. 
 ********************************************************************/

Modified: branches/SAMBA_3_0/source/rpc_server/srv_srvsvc_nt.c
===================================================================
--- branches/SAMBA_3_0/source/rpc_server/srv_srvsvc_nt.c	2006-10-21 16:52:25 UTC (rev 19447)
+++ branches/SAMBA_3_0/source/rpc_server/srv_srvsvc_nt.c	2006-10-21 17:00:47 UTC (rev 19448)
@@ -1680,12 +1680,11 @@
 
 WERROR _srvsvc_NetShareDel(pipes_struct *p, const char *server_unc, const char *share_name, uint32_t reserved)
 {
-	pstring command;
+	char *command;
 	int ret;
-	int snum;
+	struct share_params *params;
 	SE_PRIV se_diskop = SE_DISK_OPERATOR;
 	BOOL is_disk_op;
-	fstring tmp_share_name;
 
 	DEBUG(5,("_srv_net_share_del: %d\n", __LINE__));
 
@@ -1696,14 +1695,12 @@
 		return WERR_ACCESS_DENIED;
 	}
 
-	fstrcpy(tmp_share_name, share_name);
-	snum = find_service(tmp_share_name);
-
-	if (snum < 0)
+	if (!(params = get_share_params(p->mem_ctx, share_name))) {
 		return WERR_NO_SUCH_SHARE;
+	}
 
 	/* No change to printer shares. */
-	if (lp_print_ok(snum))
+	if (lp_print_ok(params->service))
 		return WERR_ACCESS_DENIED;
 
 	is_disk_op = user_has_privileges( p->pipe_user.nt_user_token, &se_diskop );
@@ -1715,10 +1712,13 @@
 		DEBUG(10,("_srv_net_share_del: No delete share command\n"));
 		return WERR_ACCESS_DENIED;
 	}
-		
-	slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\"",
-			lp_delete_share_cmd(), dyn_CONFIGFILE, lp_servicename(snum));
 
+	if (asprintf(&command, "%s \"%s\" \"%s\"",
+		     lp_delete_share_cmd(), dyn_CONFIGFILE,
+		     lp_servicename(params->service)) == -1) {
+		return WERR_NOMEM;
+	}
+
 	DEBUG(10,("_srv_net_share_del: Running [%s]\n", command ));
 
 	/********* BEGIN SeDiskOperatorPrivilege BLOCK *********/
@@ -1733,6 +1733,8 @@
 
 	if ( is_disk_op )
 		unbecome_root();
+
+	SAFE_FREE(command);
 		
 	/********* END SeDiskOperatorPrivilege BLOCK *********/
 
@@ -1742,9 +1744,9 @@
 		return WERR_ACCESS_DENIED;
 
 	/* Delete the SD in the database. */
-	delete_share_security(snum);
+	delete_share_security(params);
 
-	lp_killservice(snum);
+	lp_killservice(params->service);
 
 	return WERR_OK;
 }



More information about the samba-cvs mailing list