s3:smb2_lock: split smbd_smb2_lock_retry() into _try() and _retry()
authorStefan Metzmacher <metze@samba.org>
Tue, 13 Aug 2019 14:39:41 +0000 (16:39 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 9 Sep 2019 14:23:40 +0000 (14:23 +0000)
This makes it possible to reuse _try() in the _send() function in the
next commits.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
source3/smbd/smb2_lock.c

index 4cf735ff48d079723eac13d9e828e85aad0ff333..c2b4603f3e10645c7b22aa3c746c1c3c4d6671d4 100644 (file)
@@ -189,6 +189,7 @@ static void smbd_smb2_request_lock_done(struct tevent_req *subreq)
        }
 }
 
+static void smbd_smb2_lock_try(struct tevent_req *req);
 static void smbd_smb2_lock_retry(struct tevent_req *subreq);
 static bool smbd_smb2_lock_cancel(struct tevent_req *req);
 
@@ -410,10 +411,8 @@ static struct tevent_req *smbd_smb2_lock_send(TALLOC_CTX *mem_ctx,
        return tevent_req_post(req, ev);
 }
 
-static void smbd_smb2_lock_retry(struct tevent_req *subreq)
+static void smbd_smb2_lock_try(struct tevent_req *req)
 {
-       struct tevent_req *req = tevent_req_callback_data(
-               subreq, struct tevent_req);
        struct smbd_smb2_lock_state *state = tevent_req_data(
                req, struct smbd_smb2_lock_state);
        struct share_mode_lock *lck = NULL;
@@ -421,22 +420,7 @@ static void smbd_smb2_lock_retry(struct tevent_req *subreq)
        struct server_id blocking_pid = { 0 };
        uint64_t blocking_smblctx;
        NTSTATUS status;
-       bool ok;
-
-       /*
-        * Make sure we run as the user again
-        */
-       ok = change_to_user_by_fsp(state->fsp);
-       if (!ok) {
-               tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
-               return;
-       }
-
-       status = dbwrap_watched_watch_recv(subreq, NULL, NULL);
-       TALLOC_FREE(subreq);
-       if (tevent_req_nterror(req, status)) {
-               return;
-       }
+       struct tevent_req *subreq = NULL;
 
        lck = get_existing_share_mode_lock(
                talloc_tos(), state->fsp->file_id);
@@ -467,6 +451,33 @@ static void smbd_smb2_lock_retry(struct tevent_req *subreq)
        tevent_req_set_callback(subreq, smbd_smb2_lock_retry, req);
 }
 
+static void smbd_smb2_lock_retry(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct smbd_smb2_lock_state *state = tevent_req_data(
+               req, struct smbd_smb2_lock_state);
+       NTSTATUS status;
+       bool ok;
+
+       /*
+        * Make sure we run as the user again
+        */
+       ok = change_to_user_by_fsp(state->fsp);
+       if (!ok) {
+               tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
+               return;
+       }
+
+       status = dbwrap_watched_watch_recv(subreq, NULL, NULL);
+       TALLOC_FREE(subreq);
+       if (tevent_req_nterror(req, status)) {
+               return;
+       }
+
+       smbd_smb2_lock_try(req);
+}
+
 static NTSTATUS smbd_smb2_lock_recv(struct tevent_req *req)
 {
        return tevent_req_simple_recv_ntstatus(req);