smbd: Fix a profile problem
authorVolker Lendecke <Volker.Lendecke@SerNet.DE>
Tue, 9 Jul 2013 18:02:39 +0000 (11:02 -0700)
committerKarolin Seeger <kseeger@samba.org>
Fri, 30 Aug 2013 08:04:01 +0000 (10:04 +0200)
When trying to read a profile, under certain circumstances Windows tries
to read with its machine account first. The profile previously written
was stored with an ACL that only allows access for the user and not
the machine. Windows should get an NT_STATUS_ACCESS_DENIED when using
the machine account, making it retry with the user account (which would
then succeed).

Samba under these circumstances erroneously gives
NT_STATUS_OBJECT_PATH_NOT_FOUND, which makes Windows give up and not
retry. The reasons is the "dropbox" patch in unix_convert, turning EACCESS
on the last path component to OBJECT_PATH_NOT_FOUND. This patch makes
the dropbox behaviour only kick in when we are creating a file. I think
this is an abstraction violation. unix_convert() should not have to know
about the create_disposition, but given that we have pathname resolution
separated from the core open code right now this is the best we can do.

Signed-off-by: Volker Lendecke <Volker.Lendecke@SerNet.DE>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/filename.c
source3/smbd/nttrans.c
source3/smbd/reply.c
source3/smbd/smb2_create.c
source3/smbd/smbd.h

index 9b05de368c15bc9a69ef7152770a6009e48f12d7..76227e9f212e2c94cf4f4a0bb635b73d1e23ed01 100644 (file)
@@ -723,7 +723,8 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
                                 * can only put stuff with permission -wx.
                                 */
                                if ((errno != 0) && (errno != ENOENT)
-                                   && (errno != EACCES)) {
+                                   && ((ucf_flags & UCF_CREATING_FILE) &&
+                                       (errno != EACCES))) {
                                        /*
                                         * ENOTDIR and ELOOP both map to
                                         * NT_STATUS_OBJECT_PATH_NOT_FOUND
index ee0deb8cbeb08ffce250ab4cd30a96747d1b2fcd..b7dfa8c8186dc9cbce7f2abecd47af2f4cd10754 100644 (file)
@@ -538,7 +538,8 @@ void reply_ntcreate_and_X(struct smb_request *req)
                                conn,
                                req->flags2 & FLAGS2_DFS_PATHNAMES,
                                fname,
-                               0,
+                               (create_disposition == FILE_CREATE)
+                                 ? UCF_CREATING_FILE : 0,
                                NULL,
                                &smb_fname);
 
@@ -1117,7 +1118,8 @@ static void call_nt_transact_create(connection_struct *conn,
                                conn,
                                req->flags2 & FLAGS2_DFS_PATHNAMES,
                                fname,
-                               0,
+                               (create_disposition == FILE_CREATE)
+                                 ? UCF_CREATING_FILE : 0,
                                NULL,
                                &smb_fname);
 
index 3b2a4930b39a61e312b7e43d742a55836f21055a..2d729ece3b12ebb217b286746027b21f618665fb 100644 (file)
@@ -1905,11 +1905,20 @@ void reply_open(struct smb_request *req)
                goto out;
        }
 
+       if (!map_open_params_to_ntcreate(fname, deny_mode,
+                                        OPENX_FILE_EXISTS_OPEN, &access_mask,
+                                        &share_mode, &create_disposition,
+                                        &create_options, &private_flags)) {
+               reply_force_doserror(req, ERRDOS, ERRbadaccess);
+               goto out;
+       }
+
        status = filename_convert(ctx,
                                conn,
                                req->flags2 & FLAGS2_DFS_PATHNAMES,
                                fname,
-                               0,
+                               (create_disposition == FILE_CREATE)
+                                 ? UCF_CREATING_FILE : 0,
                                NULL,
                                &smb_fname);
        if (!NT_STATUS_IS_OK(status)) {
@@ -1923,14 +1932,6 @@ void reply_open(struct smb_request *req)
                goto out;
        }
 
-       if (!map_open_params_to_ntcreate(smb_fname->base_name, deny_mode,
-                                        OPENX_FILE_EXISTS_OPEN, &access_mask,
-                                        &share_mode, &create_disposition,
-                                        &create_options, &private_flags)) {
-               reply_force_doserror(req, ERRDOS, ERRbadaccess);
-               goto out;
-       }
-
        status = SMB_VFS_CREATE_FILE(
                conn,                                   /* conn */
                req,                                    /* req */
@@ -2080,11 +2081,22 @@ void reply_open_and_X(struct smb_request *req)
                goto out;
        }
 
+       if (!map_open_params_to_ntcreate(fname, deny_mode,
+                                        smb_ofun,
+                                        &access_mask, &share_mode,
+                                        &create_disposition,
+                                        &create_options,
+                                        &private_flags)) {
+               reply_force_doserror(req, ERRDOS, ERRbadaccess);
+               goto out;
+       }
+
        status = filename_convert(ctx,
                                conn,
                                req->flags2 & FLAGS2_DFS_PATHNAMES,
                                fname,
-                               0,
+                               (create_disposition == FILE_CREATE)
+                                 ? UCF_CREATING_FILE : 0,
                                NULL,
                                &smb_fname);
        if (!NT_STATUS_IS_OK(status)) {
@@ -2098,16 +2110,6 @@ void reply_open_and_X(struct smb_request *req)
                goto out;
        }
 
-       if (!map_open_params_to_ntcreate(smb_fname->base_name, deny_mode,
-                                        smb_ofun,
-                                        &access_mask, &share_mode,
-                                        &create_disposition,
-                                        &create_options,
-                                        &private_flags)) {
-               reply_force_doserror(req, ERRDOS, ERRbadaccess);
-               goto out;
-       }
-
        status = SMB_VFS_CREATE_FILE(
                conn,                                   /* conn */
                req,                                    /* req */
@@ -2327,7 +2329,7 @@ void reply_mknew(struct smb_request *req)
                                conn,
                                req->flags2 & FLAGS2_DFS_PATHNAMES,
                                fname,
-                               0,
+                               UCF_CREATING_FILE,
                                NULL,
                                &smb_fname);
        if (!NT_STATUS_IS_OK(status)) {
@@ -2468,7 +2470,7 @@ void reply_ctemp(struct smb_request *req)
                status = filename_convert(ctx, conn,
                                req->flags2 & FLAGS2_DFS_PATHNAMES,
                                fname,
-                               0,
+                               UCF_CREATING_FILE,
                                NULL,
                                &smb_fname);
                if (!NT_STATUS_IS_OK(status)) {
@@ -5827,7 +5829,7 @@ void reply_mkdir(struct smb_request *req)
        status = filename_convert(ctx, conn,
                                 req->flags2 & FLAGS2_DFS_PATHNAMES,
                                 directory,
-                                0,
+                                UCF_CREATING_FILE,
                                 NULL,
                                 &smb_dname);
        if (!NT_STATUS_IS_OK(status)) {
index edbd50fd9045bd690a5f59ec3a6a4a585ee324bd..c4d49913a7b1b444d52240fb3a07a860eb3830f4 100644 (file)
@@ -871,7 +871,8 @@ static struct tevent_req *smbd_smb2_create_send(TALLOC_CTX *mem_ctx,
                                                  smb1req->conn,
                                                  smb1req->flags2 & FLAGS2_DFS_PATHNAMES,
                                                  fname,
-                                                 0,    /* unix_convert flags */
+                                                 (in_create_disposition == FILE_CREATE) ?
+                                                 UCF_CREATING_FILE : 0,
                                                  NULL, /* ppath_contains_wcards */
                                                  &smb_fname);
                        if (!NT_STATUS_IS_OK(status)) {
index a5b211a678d93f3f95ff1bf634a3d378dafc7505..e76915730d4018f90afbf0b7c90743e8d7af82cd 100644 (file)
@@ -73,5 +73,6 @@ struct trans_state {
 #define UCF_COND_ALLOW_WCARD_LCOMP     0x00000004
 #define UCF_POSIX_PATHNAMES            0x00000008
 #define UCF_UNIX_NAME_LOOKUP           0x00000010
+#define UCF_CREATING_FILE              0x00000020
 
 #endif /* _SMBD_SMBD_H */