From 790dab571c426abc1004d1c338e0b94382a2a2c0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 4 Dec 2018 10:40:18 +0100 Subject: [PATCH] s3:pylibsmb: add force_smb1=True in order to control forcing of SMB1 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: Stefan Metzmacher Reviewed-by: Tim Beale Reviewed-by: Andrew Bartlett --- python/samba/tests/libsmb_samba_internal.py | 3 +- source3/libsmb/pylibsmb.c | 35 +++++++++++++++------ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/python/samba/tests/libsmb_samba_internal.py b/python/samba/tests/libsmb_samba_internal.py index db99c0bfb2b..8918d848ea8 100644 --- a/python/samba/tests/libsmb_samba_internal.py +++ b/python/samba/tests/libsmb_samba_internal.py @@ -60,7 +60,8 @@ class LibsmbTestCase(samba.tests.TestCase): creds.set_password(os.getenv("PASSWORD")) c = libsmb_samba_internal.Conn(os.getenv("SERVER_IP"), "tmp", - creds, multi_threaded=True) + creds, multi_threaded=True, + force_smb1=True) mythreads = [] diff --git a/source3/libsmb/pylibsmb.c b/source3/libsmb/pylibsmb.c index 8e63cbf8568..ed3c041d4ff 100644 --- a/source3/libsmb/pylibsmb.c +++ b/source3/libsmb/pylibsmb.c @@ -425,19 +425,16 @@ static int py_cli_state_init(struct py_cli_state *self, PyObject *args, PyObject *py_sign = Py_False; bool sign = false; int signing_state = SMB_SIGNING_DEFAULT; + PyObject *py_force_smb1 = Py_False; + bool force_smb1 = false; struct tevent_req *req; bool ret; - /* - * For now we only support SMB1, - * as most of the cli_*_send() function - * don't support SMB2, it's only plugged - * into the sync wrapper functions currently. - */ - int flags = CLI_FULL_CONNECTION_FORCE_SMB1; + int flags = 0; static const char *kwlist[] = { "host", "share", "credentials", - "multi_threaded", "sign", NULL + "multi_threaded", "sign", "force_smb1", + NULL }; PyTypeObject *py_type_Credentials = get_pytype( @@ -447,11 +444,12 @@ static int py_cli_state_init(struct py_cli_state *self, PyObject *args, } ret = ParseTupleAndKeywords( - args, kwds, "ss|O!OO", kwlist, + args, kwds, "ss|O!OOO", kwlist, &host, &share, py_type_Credentials, &creds, &py_multi_threaded, - &py_sign); + &py_sign, + &py_force_smb1); Py_DECREF(py_type_Credentials); @@ -461,11 +459,22 @@ static int py_cli_state_init(struct py_cli_state *self, PyObject *args, multi_threaded = PyObject_IsTrue(py_multi_threaded); sign = PyObject_IsTrue(py_sign); + force_smb1 = PyObject_IsTrue(py_force_smb1); if (sign) { signing_state = SMB_SIGNING_REQUIRED; } + if (force_smb1) { + /* + * As most of the cli_*_send() function + * don't support SMB2 (it's only plugged + * into the sync wrapper functions currently) + * we have a way to force SMB1. + */ + flags = CLI_FULL_CONNECTION_FORCE_SMB1; + } + if (multi_threaded) { #ifdef HAVE_PTHREAD ret = py_cli_state_setup_mt_ev(self); @@ -477,6 +486,12 @@ static int py_cli_state_init(struct py_cli_state *self, PyObject *args, "No PTHREAD support available"); return -1; #endif + if (!force_smb1) { + PyErr_SetString(PyExc_RuntimeError, + "multi_threaded is only possible on " + "SMB1 connections"); + return -1; + } } else { ret = py_cli_state_setup_ev(self); if (!ret) { -- 2.34.1