[PATCH] Deny file rename if file has open streams

Jeremy Allison jra at samba.org
Wed May 30 00:00:09 UTC 2018


On Tue, May 29, 2018 at 02:12:40PM -0700, Jeremy Allison via samba-technical wrote:
> On Sun, May 27, 2018 at 04:57:54PM +0200, Ralph Böhme via samba-technical wrote:
> > Hi!
> > 
> > Just stumpled across this one: Windows denies renaming a file that has open
> > streams with NT_STATUS_ACCESS_DENIED.
> > 
> > Please review & push if happy.
> 
> Only one comment, you've dupicated:
> 
> +#define NTCREATEX_OPTIONS_PRIVATE_STREAM_BASEOPEN 0x0008
> 
> with the existing:
> 
>  /* Private options for printer support */
>  #define NTCREATEX_OPTIONS_PRIVATE_DELETE_ON_CLOSE 0x0008
> 
> Was this intentional ? They shouldn't conflict as
> NTCREATEX_OPTIONS_PRIVATE_DELETE_ON_CLOSE is only used for
> printer handles, but I'm thinking it'd be safer to set
> NTCREATEX_OPTIONS_PRIVATE_STREAM_BASEOPEN to be 0x0010 instead.

Ah. Some code got dropped going from Samba 3.0.x to 3.5.x,
- when we moved from print_fsp_end() -> print_spool_end().

This means setting "delete on close" on a print file
handle to cancel the job hasn't worked for a *long* time :-).

Here's the raw fix - now I just need to work out how
to test this, log a bug and submit it as a real fix
to samba-technical :-).

Jeremy.
-------------- next part --------------
diff --git a/source3/printing/printspoolss.c b/source3/printing/printspoolss.c
index 60002020351..7a9b1af8708 100644
--- a/source3/printing/printspoolss.c
+++ b/source3/printing/printspoolss.c
@@ -309,6 +309,18 @@ void print_spool_end(files_struct *fsp, enum file_close_type close_type)
 	WERROR werr;
 	struct dcerpc_binding_handle *b = NULL;
 
+	if (fsp->fh->private_options &
+			NTCREATEX_OPTIONS_PRIVATE_DELETE_ON_CLOSE) {
+		/*
+		 * Job was requested to be cancelled by setting
+		 * delete on close so truncate the job file.
+		 * print_job_end() which is called from
+		 * _spoolss_EndDocPrinter() will take
+		 * care of deleting it for us.
+		 */
+		ftruncate(fsp->fh->fd, 0);
+	}
+
 	b = fsp->conn->spoolss_pipe->binding_handle;
 
 	switch (close_type) {


More information about the samba-technical mailing list