[SCM] Samba Shared Repository - branch v3-2-test updated - release-3-2-0pre2-2482-g4b312d4

Jeremy Allison jra at samba.org
Tue May 27 18:26:15 GMT 2008


The branch, v3-2-test has been updated
       via  4b312d4e6fdd30ea754cf499fbe86ce932d1d9d2 (commit)
      from  bcf721770d2a76df85737596d6b73e9e6d982c32 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test


- Log -----------------------------------------------------------------
commit 4b312d4e6fdd30ea754cf499fbe86ce932d1d9d2
Author: Jeremy Allison <jra at samba.org>
Date:   Tue May 27 11:23:59 2008 -0700

    Allow server manager to close open files selected by id.
    Jeremy.

-----------------------------------------------------------------------

Summary of changes:
 source/include/messages.h         |    4 ++
 source/locking/locking.c          |    2 +-
 source/rpc_server/srv_srvsvc_nt.c |   57 +++++++++++++++++++++++++++++++++++-
 source/smbd/close.c               |   34 ++++++++++++++++++++++
 source/smbd/oplock.c              |    2 +-
 source/smbd/server.c              |    2 +
 6 files changed, 97 insertions(+), 4 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/include/messages.h b/source/include/messages.h
index 8f0112a..b3ac5e4 100644
--- a/source/include/messages.h
+++ b/source/include/messages.h
@@ -87,6 +87,10 @@
  */
 #define MSG_SMB_BRL_VALIDATE		0x0311
 #define MSG_SMB_RELEASE_IP		0x0312
+/*
+ * Close a specific file given a share entry.
+ */
+#define MSG_SMB_CLOSE_FILE		0x0313
 
 /* winbind messages */
 #define MSG_WINBIND_FINISHED		0x0401
diff --git a/source/locking/locking.c b/source/locking/locking.c
index 5faebef..84e5a17 100644
--- a/source/locking/locking.c
+++ b/source/locking/locking.c
@@ -443,7 +443,7 @@ static TDB_DATA locking_key(const struct file_id *id, struct file_id *tmp)
  Print out a share mode.
 ********************************************************************/
 
-char *share_mode_str(TALLOC_CTX *ctx, int num, struct share_mode_entry *e)
+char *share_mode_str(TALLOC_CTX *ctx, int num, const struct share_mode_entry *e)
 {
 	return talloc_asprintf(ctx, "share_mode_entry[%d]: %s "
 		 "pid = %s, share_access = 0x%x, private_options = 0x%x, "
diff --git a/source/rpc_server/srv_srvsvc_nt.c b/source/rpc_server/srv_srvsvc_nt.c
index 5348535..3672219 100644
--- a/source/rpc_server/srv_srvsvc_nt.c
+++ b/source/rpc_server/srv_srvsvc_nt.c
@@ -2363,14 +2363,67 @@ WERROR _srvsvc_NetNameValidate(pipes_struct *p,
 	return WERR_OK;
 }
 
+/*******************************************************************
+********************************************************************/
+
+static void enum_file_close_fn( const struct share_mode_entry *e,
+                          const char *sharepath, const char *fname,
+			  void *private_data )
+{
+	char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
+	struct srvsvc_NetFileClose *r =
+ 		(struct srvsvc_NetFileClose *)private_data;
+	uint32_t fid = (((uint32_t)(procid_to_pid(&e->pid))<<16) | e->share_file_id);
+
+	if (fid != r->in.fid) {
+		return; /* Not this file. */
+	}
+
+	if (!process_exists(e->pid) ) {
+		return;
+	}
+
+	/* Ok - send the close message. */
+	DEBUG(10,("enum_file_close_fn: request to close file %s, %s\n",
+		sharepath,
+		share_mode_str(talloc_tos(), 0, e) ));
+
+	share_mode_entry_to_message(msg, e);
+
+	r->out.result = ntstatus_to_werror(
+			messaging_send_buf(smbd_messaging_context(),
+				e->pid, MSG_SMB_CLOSE_FILE,
+				(uint8 *)msg,
+				MSG_SMB_SHARE_MODE_ENTRY_SIZE));
+}
+
 /********************************************************************
+ Close a file given a 32-bit file id.
 ********************************************************************/
 
 WERROR _srvsvc_NetFileClose(pipes_struct *p, struct srvsvc_NetFileClose *r)
 {
-	return WERR_ACCESS_DENIED;
-}
+	struct current_user user;
+	SE_PRIV se_diskop = SE_DISK_OPERATOR;
+	bool is_disk_op;
+
+	DEBUG(5,("_srvsvc_NetFileClose: %d\n", __LINE__));
+
+	get_current_user(&user,p);
 
+	is_disk_op = user_has_privileges( p->pipe_user.nt_user_token, &se_diskop );
+
+	if (user.ut.uid != sec_initial_uid() && !is_disk_op) {
+		return WERR_ACCESS_DENIED;
+	}
+
+	/* enum_file_close_fn sends the close message to
+	 * the relevent smbd process. */
+
+	r->out.result = WERR_BADFILE;
+	share_mode_forall( enum_file_close_fn, (void *)r);
+	return r->out.result;
+}
 
 /********************************************************************
 ********************************************************************/
diff --git a/source/smbd/close.c b/source/smbd/close.c
index 3afc037..3d3c4cf 100644
--- a/source/smbd/close.c
+++ b/source/smbd/close.c
@@ -752,3 +752,37 @@ NTSTATUS close_file(files_struct *fsp, enum file_close_type close_type)
 
 	return status;
 }
+
+/****************************************************************************
+ Deal with an (authorized) message to close a file given the share mode
+ entry.
+****************************************************************************/
+
+void msg_close_file(struct messaging_context *msg_ctx,
+			void *private_data,
+			uint32_t msg_type,
+			struct server_id server_id,
+			DATA_BLOB *data)
+{
+	files_struct *fsp = NULL;
+	struct share_mode_entry e;
+
+	message_to_share_mode_entry(&e, (char *)data->data);
+
+	if(DEBUGLVL(10)) {
+		char *sm_str = share_mode_str(NULL, 0, &e);
+		if (!sm_str) {
+			smb_panic("talloc failed");
+		}
+		DEBUG(10,("msg_close_file: got request to close share mode "
+			"entry %s\n", sm_str));
+		TALLOC_FREE(sm_str);
+	}
+
+	fsp = file_find_dif(e.id, e.share_file_id);
+	if (!fsp) {
+		DEBUG(10,("msg_close_file: failed to find file.\n"));
+		return;
+	}
+	close_file(fsp, NORMAL_CLOSE);
+}
diff --git a/source/smbd/oplock.c b/source/smbd/oplock.c
index c340954..2341129 100644
--- a/source/smbd/oplock.c
+++ b/source/smbd/oplock.c
@@ -824,7 +824,7 @@ void release_level_2_oplocks_on_change(files_struct *fsp)
  Linearize a share mode entry struct to an internal oplock break message.
 ****************************************************************************/
 
-void share_mode_entry_to_message(char *msg, struct share_mode_entry *e)
+void share_mode_entry_to_message(char *msg, const struct share_mode_entry *e)
 {
 	SIVAL(msg,0,(uint32)e->pid.pid);
 	SSVAL(msg,4,e->op_mid);
diff --git a/source/smbd/server.c b/source/smbd/server.c
index cf02589..035469c 100644
--- a/source/smbd/server.c
+++ b/source/smbd/server.c
@@ -1392,6 +1392,8 @@ extern void build_options(bool screen);
 			   MSG_SMB_FORCE_TDIS, msg_force_tdis);
 	messaging_register(smbd_messaging_context(), NULL,
 			   MSG_SMB_RELEASE_IP, msg_release_ip);
+	messaging_register(smbd_messaging_context(), NULL,
+			   MSG_SMB_CLOSE_FILE, msg_close_file);
 
 	if ((lp_keepalive() != 0)
 	    && !(event_add_idle(smbd_event_context(), NULL,


-- 
Samba Shared Repository


More information about the samba-cvs mailing list