smbd: Use has_other_nonposix_opens in smb_posix_unlink
authorVolker Lendecke <vl@samba.org>
Sat, 8 Sep 2018 16:05:57 +0000 (18:05 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 11 Sep 2018 16:36:23 +0000 (18:36 +0200)
Almost the same code as in close.c. has_other_nonposix_opens() is a bit
more general, but the purpose is the same.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/trans2.c

index c0f984704d2f49fe0ee56c2627a2a132986dae38..0003c3682e3cce33866d30dbc94159ed130c755d 100644 (file)
@@ -32,7 +32,6 @@
 #include "../libcli/auth/libcli_auth.h"
 #include "../librpc/gen_ndr/xattr.h"
 #include "../librpc/gen_ndr/ndr_security.h"
-#include "../librpc/gen_ndr/open_files.h"
 #include "libcli/security/security.h"
 #include "trans2.h"
 #include "auth.h"
@@ -41,6 +40,7 @@
 #include "printing.h"
 #include "lib/util_ea.h"
 #include "lib/readdir_attr.h"
+#include "messages.h"
 
 #define DIR_ENTRY_SAFETY_MARGIN 4096
 
@@ -8309,14 +8309,15 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn,
                                int total_data,
                                struct smb_filename *smb_fname)
 {
+       struct server_id self = messaging_server_id(conn->sconn->msg_ctx);
        NTSTATUS status = NT_STATUS_OK;
        files_struct *fsp = NULL;
        uint16_t flags = 0;
        char del = 1;
        int info = 0;
        int create_options = 0;
-       int i;
        struct share_mode_lock *lck = NULL;
+       bool other_nonposix_opens;
 
        if (total_data < 2) {
                return NT_STATUS_INVALID_PARAMETER;
@@ -8379,25 +8380,12 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       /*
-        * See if others still have the file open. If this is the case, then
-        * don't delete. If all opens are POSIX delete we can set the delete
-        * on close disposition.
-        */
-       for (i=0; i<lck->data->num_share_modes; i++) {
-               struct share_mode_entry *e = &lck->data->share_modes[i];
-               if (is_valid_share_mode_entry(e)) {
-                       if (e->flags & SHARE_MODE_FLAG_POSIX_OPEN) {
-                               continue;
-                       }
-                       if (share_mode_stale_pid(lck->data, i)) {
-                               continue;
-                       }
-                       /* Fail with sharing violation. */
-                       TALLOC_FREE(lck);
-                       close_file(req, fsp, NORMAL_CLOSE);
-                       return NT_STATUS_SHARING_VIOLATION;
-               }
+       other_nonposix_opens = has_other_nonposix_opens(lck, fsp, self);
+       if (other_nonposix_opens) {
+               /* Fail with sharing violation. */
+               TALLOC_FREE(lck);
+               close_file(req, fsp, NORMAL_CLOSE);
+               return NT_STATUS_SHARING_VIOLATION;
        }
 
        /*