s3:pylibsmb: .get_oplock_break API is dependent on multi_threaded=True
authorTim Beale <timbeale@catalyst.net.nz>
Mon, 3 Dec 2018 23:32:58 +0000 (12:32 +1300)
committerStefan Metzmacher <metze@samba.org>
Thu, 13 Dec 2018 07:52:23 +0000 (08:52 +0100)
The .get_oplock_break is dependent on the pthread code, which is only
used when creating a SMB connection with multi_threaded=True.

Add an explicit error to the .get_oplock_break() if someone tries to use
it in non-multithreaded mode.

Initializing self->oplock_waiter in non-multithreaded mode is similarly
redundant if the API can never be used.

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

BUG: https://bugzilla.samba.org/show_bug.cgi?id=7113
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11892
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source3/libsmb/pylibsmb.c

index e4552a2d68a24b07c7f754fa5b0f4499ecdab010..19587a8f07419fd1ae179c57f054a8996e4e7b89 100644 (file)
@@ -526,6 +526,13 @@ static int py_cli_state_init(struct py_cli_state *self, PyObject *args,
                self->is_smb1 = true;
        }
 
+       /*
+        * Oplocks require a multi threaded connection
+        */
+       if (self->thread_state == NULL) {
+               return 0;
+       }
+
        self->oplock_waiter = cli_smb_oplock_break_waiter_send(
                self->ev, self->ev, self->cli);
        if (self->oplock_waiter == NULL) {
@@ -585,6 +592,13 @@ static PyObject *py_cli_get_oplock_break(struct py_cli_state *self,
                return NULL;
        }
 
+       if (self->thread_state == NULL) {
+               PyErr_SetString(PyExc_RuntimeError,
+                               "get_oplock_break() only possible on "
+                               "a multi_threaded connection");
+               return NULL;
+       }
+
        if (self->oplock_cond != NULL) {
                errno = EBUSY;
                PyErr_SetFromErrno(PyExc_RuntimeError);