]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Add defer_sharing_violation_smb1
authorVolker Lendecke <vl@samba.org>
Tue, 30 Jul 2019 12:54:18 +0000 (14:54 +0200)
committerJeremy Allison <jra@samba.org>
Wed, 7 Aug 2019 23:45:50 +0000 (23:45 +0000)
This is close to what Windows SMB1 does: Instead of waiting for the
share entry causing the SHARING_VIOLATION to disappear, retry every
200msec up to one second. Windows does it a little differently: Retry
up to 5 times. But up to one second should be close enough.

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

index b8b7ed025cca9948f4cb14269b3a04e81cc58863..f54c8cf63134f1ea6d538702ab4b2af507a32a7a 100644 (file)
@@ -2567,6 +2567,36 @@ static bool setup_poll_open(
        return true;
 }
 
+bool defer_smb1_sharing_violation(struct smb_request *req)
+{
+       bool ok;
+       int timeout_usecs;
+
+       if (!lp_defer_sharing_violations()) {
+               return false;
+       }
+
+       /*
+        * Try every 200msec up to (by default) one second. To be
+        * precise, according to behaviour note <247> in [MS-CIFS],
+        * the server tries 5 times. But up to one second should be
+        * close enough.
+        */
+
+       timeout_usecs = lp_parm_int(
+               SNUM(req->conn),
+               "smbd",
+               "sharedelay",
+               SHARING_VIOLATION_USEC_WAIT);
+
+       ok = setup_poll_open(
+               req,
+               (struct file_id) {0},
+               (struct timeval) { .tv_usec = timeout_usecs },
+               (struct timeval) { .tv_usec = 200000 });
+       return ok;
+}
+
 /****************************************************************************
  On overwrite open ensure that the attributes match.
 ****************************************************************************/
index 6d3a10f9d7500e6fbaeeedddcd65df05743f4675..0fde9b78fb085fb6e23045f30711408addd7d5bf 100644 (file)
@@ -680,6 +680,7 @@ NTSTATUS send_break_message(struct messaging_context *msg_ctx,
                            uint16_t break_to);
 struct deferred_open_record;
 bool is_deferred_open_async(const struct deferred_open_record *rec);
+bool defer_smb1_sharing_violation(struct smb_request *req);
 NTSTATUS create_directory(connection_struct *conn, struct smb_request *req,
                          struct smb_filename *smb_dname);
 void msg_file_was_renamed(struct messaging_context *msg,