From 8f286450a223d002358f6dfe81b770fee86c3c85 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl@samba.org>
Date: Tue, 3 Dec 2013 13:20:17 +0100
Subject: [PATCH 1/3] PATCHSET15: smbd: Fix regression for the dropbox case.

We need to allow to save a file to a directory with perm -wx.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=10297

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
(cherry picked from commit 5b49fe24c906cbae12beff7a1b45de6809258cab)
---
 source3/smbd/filename.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c
index 8ef0c0a..ca19369 100644
--- a/source3/smbd/filename.c
+++ b/source3/smbd/filename.c
@@ -716,7 +716,10 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
 				 * here.
 				 */
 				if (errno == EACCES) {
-					if (ucf_flags & UCF_CREATING_FILE) {
+					if ((ucf_flags & UCF_CREATING_FILE) == 0) {
+						status = NT_STATUS_ACCESS_DENIED;
+						goto fail;
+					} else {
 						/*
 						 * This is the dropbox
 						 * behaviour. A dropbox is a
@@ -728,11 +731,8 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
 						 * nevertheless want to allow
 						 * users creating a file.
 						 */
-						status = NT_STATUS_OBJECT_PATH_NOT_FOUND;
-					} else {
-						status = NT_STATUS_ACCESS_DENIED;
+						errno = 0;
 					}
-					goto fail;
 				}
 
 				if ((errno != 0) && (errno != ENOENT)) {
-- 
1.9.3


From 38674e8f208a7e8f2ead72266292f30b7ea33c87 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra@samba.org>
Date: Tue, 3 Dec 2013 10:19:09 -0800
Subject: [PATCH 2/3] PATCHSET15: smbd: change flag name from UCF_CREATING_FILE
 to UCF_PREP_CREATEFILE

In preparation to using it for all open calls.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=10297

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
(cherry picked from commit 874318a97868e08837a1febb1be8e8a167b5ae0f)
---
 source3/include/smb.h      |  2 +-
 source3/smbd/filename.c    |  2 +-
 source3/smbd/nttrans.c     |  4 ++--
 source3/smbd/reply.c       | 10 +++++-----
 source3/smbd/smb2_create.c |  2 +-
 5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/source3/include/smb.h b/source3/include/smb.h
index 2d04373..559e061 100644
--- a/source3/include/smb.h
+++ b/source3/include/smb.h
@@ -1716,7 +1716,7 @@ struct smb_file_time {
 #define UCF_COND_ALLOW_WCARD_LCOMP	0x00000004
 #define UCF_POSIX_PATHNAMES		0x00000008
 #define UCF_UNIX_NAME_LOOKUP		0x00000010
-#define UCF_CREATING_FILE		0x00000020
+#define UCF_PREP_CREATEFILE		0x00000020
 
 /*
  * smb_filename
diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c
index ca19369..2e68e52 100644
--- a/source3/smbd/filename.c
+++ b/source3/smbd/filename.c
@@ -716,7 +716,7 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
 				 * here.
 				 */
 				if (errno == EACCES) {
-					if ((ucf_flags & UCF_CREATING_FILE) == 0) {
+					if ((ucf_flags & UCF_PREP_CREATEFILE) == 0) {
 						status = NT_STATUS_ACCESS_DENIED;
 						goto fail;
 					} else {
diff --git a/source3/smbd/nttrans.c b/source3/smbd/nttrans.c
index 4c145e0..f5da720 100644
--- a/source3/smbd/nttrans.c
+++ b/source3/smbd/nttrans.c
@@ -537,7 +537,7 @@ void reply_ntcreate_and_X(struct smb_request *req)
 				req->flags2 & FLAGS2_DFS_PATHNAMES,
 				fname,
 				(create_disposition == FILE_CREATE)
-					? UCF_CREATING_FILE : 0,
+				  ? UCF_PREP_CREATEFILE : 0,
 				NULL,
 				&smb_fname);
 
@@ -1167,7 +1167,7 @@ static void call_nt_transact_create(connection_struct *conn,
 				req->flags2 & FLAGS2_DFS_PATHNAMES,
 				fname,
 				(create_disposition == FILE_CREATE)
-					? UCF_CREATING_FILE : 0,
+				  ? UCF_PREP_CREATEFILE : 0,
 				NULL,
 				&smb_fname);
 
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 0585a6e..8478031 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -1761,7 +1761,7 @@ void reply_open(struct smb_request *req)
 				req->flags2 & FLAGS2_DFS_PATHNAMES,
 				fname,
 				(create_disposition == FILE_CREATE)
-					? UCF_CREATING_FILE : 0,
+				  ? UCF_PREP_CREATEFILE : 0,
 				NULL,
 				&smb_fname);
 	if (!NT_STATUS_IS_OK(status)) {
@@ -1939,7 +1939,7 @@ void reply_open_and_X(struct smb_request *req)
 				req->flags2 & FLAGS2_DFS_PATHNAMES,
 				fname,
 				(create_disposition == FILE_CREATE)
-					? UCF_CREATING_FILE : 0,
+				  ? UCF_PREP_CREATEFILE : 0,
 				NULL,
 				&smb_fname);
 	if (!NT_STATUS_IS_OK(status)) {
@@ -2147,7 +2147,7 @@ void reply_mknew(struct smb_request *req)
 				conn,
 				req->flags2 & FLAGS2_DFS_PATHNAMES,
 				fname,
-				UCF_CREATING_FILE,
+				UCF_PREP_CREATEFILE,
 				NULL,
 				&smb_fname);
 	if (!NT_STATUS_IS_OK(status)) {
@@ -2288,7 +2288,7 @@ void reply_ctemp(struct smb_request *req)
 		status = filename_convert(ctx, conn,
 				req->flags2 & FLAGS2_DFS_PATHNAMES,
 				fname,
-				UCF_CREATING_FILE,
+				UCF_PREP_CREATEFILE,
 				NULL,
 				&smb_fname);
 		if (!NT_STATUS_IS_OK(status)) {
@@ -5541,7 +5541,7 @@ void reply_mkdir(struct smb_request *req)
 	status = filename_convert(ctx, conn,
 				 req->flags2 & FLAGS2_DFS_PATHNAMES,
 				 directory,
-				 UCF_CREATING_FILE,
+				 UCF_PREP_CREATEFILE,
 				 NULL,
 				 &smb_dname);
 	if (!NT_STATUS_IS_OK(status)) {
diff --git a/source3/smbd/smb2_create.c b/source3/smbd/smb2_create.c
index 0862990..cd15852 100644
--- a/source3/smbd/smb2_create.c
+++ b/source3/smbd/smb2_create.c
@@ -695,7 +695,7 @@ static struct tevent_req *smbd_smb2_create_send(TALLOC_CTX *mem_ctx,
 					  smb1req->flags2 & FLAGS2_DFS_PATHNAMES,
 					  fname,
 					  (in_create_disposition == FILE_CREATE) ?
-						UCF_CREATING_FILE : 0,
+						  UCF_PREP_CREATEFILE : 0,
 					  NULL,
 					  &smb_fname);
 		if (!NT_STATUS_IS_OK(status)) {
-- 
1.9.3


From d3fb56a7239ef4173ff13f2fec2beb44402dee6b Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra@samba.org>
Date: Tue, 3 Dec 2013 10:21:16 -0800
Subject: [PATCH 3/3] PATCHSET15: smbd: Always use UCF_PREP_CREATEFILE for
 filename_convert calls to resolve a path for open.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=10297

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Mon Dec  9 21:02:21 CET 2013 on sn-devel-104

(cherry picked from commit f98d10af2a05f0261611f4cabdfe274cd9fe91c0)
---
 source3/smbd/nttrans.c     | 6 ++----
 source3/smbd/reply.c       | 6 ++----
 source3/smbd/smb2_create.c | 3 +--
 3 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/source3/smbd/nttrans.c b/source3/smbd/nttrans.c
index f5da720..f7d9b9d 100644
--- a/source3/smbd/nttrans.c
+++ b/source3/smbd/nttrans.c
@@ -536,8 +536,7 @@ void reply_ntcreate_and_X(struct smb_request *req)
 				conn,
 				req->flags2 & FLAGS2_DFS_PATHNAMES,
 				fname,
-				(create_disposition == FILE_CREATE)
-				  ? UCF_PREP_CREATEFILE : 0,
+				UCF_PREP_CREATEFILE,
 				NULL,
 				&smb_fname);
 
@@ -1166,8 +1165,7 @@ static void call_nt_transact_create(connection_struct *conn,
 				conn,
 				req->flags2 & FLAGS2_DFS_PATHNAMES,
 				fname,
-				(create_disposition == FILE_CREATE)
-				  ? UCF_PREP_CREATEFILE : 0,
+				UCF_PREP_CREATEFILE,
 				NULL,
 				&smb_fname);
 
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 8478031..1583c23 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -1760,8 +1760,7 @@ void reply_open(struct smb_request *req)
 				conn,
 				req->flags2 & FLAGS2_DFS_PATHNAMES,
 				fname,
-				(create_disposition == FILE_CREATE)
-				  ? UCF_PREP_CREATEFILE : 0,
+				UCF_PREP_CREATEFILE,
 				NULL,
 				&smb_fname);
 	if (!NT_STATUS_IS_OK(status)) {
@@ -1938,8 +1937,7 @@ void reply_open_and_X(struct smb_request *req)
 				conn,
 				req->flags2 & FLAGS2_DFS_PATHNAMES,
 				fname,
-				(create_disposition == FILE_CREATE)
-				  ? UCF_PREP_CREATEFILE : 0,
+				UCF_PREP_CREATEFILE,
 				NULL,
 				&smb_fname);
 	if (!NT_STATUS_IS_OK(status)) {
diff --git a/source3/smbd/smb2_create.c b/source3/smbd/smb2_create.c
index cd15852..d0cda33 100644
--- a/source3/smbd/smb2_create.c
+++ b/source3/smbd/smb2_create.c
@@ -694,8 +694,7 @@ static struct tevent_req *smbd_smb2_create_send(TALLOC_CTX *mem_ctx,
 					  smb1req->conn,
 					  smb1req->flags2 & FLAGS2_DFS_PATHNAMES,
 					  fname,
-					  (in_create_disposition == FILE_CREATE) ?
-						  UCF_PREP_CREATEFILE : 0,
+					  UCF_PREP_CREATEFILE,
 					  NULL,
 					  &smb_fname);
 		if (!NT_STATUS_IS_OK(status)) {
-- 
1.9.3

