From 84f1e4683e602954b0c259c81bee45926d1d5e3e Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 4 Jun 2020 11:19:53 +0200 Subject: [PATCH] auth:creds: Add python bindings for cli_credentials_set_conf() Signed-off-by: Andreas Schneider Reviewed-by: Stefan Metzmacher --- auth/credentials/pycredentials.c | 41 +++++++++++++++++++++++++++++++ python/samba/tests/credentials.py | 33 +++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/auth/credentials/pycredentials.c b/auth/credentials/pycredentials.c index 628aae6500b..17c90573f09 100644 --- a/auth/credentials/pycredentials.c +++ b/auth/credentials/pycredentials.c @@ -621,6 +621,42 @@ static PyObject *py_creds_set_forced_sasl_mech(PyObject *self, PyObject *args) Py_RETURN_NONE; } +static PyObject *py_creds_set_conf(PyObject *self, PyObject *args) +{ + PyObject *py_lp_ctx = Py_None; + struct loadparm_context *lp_ctx; + TALLOC_CTX *mem_ctx; + struct cli_credentials *creds; + + creds = PyCredentials_AsCliCredentials(self); + if (creds == NULL) { + PyErr_Format(PyExc_TypeError, "Credentials expected"); + return NULL; + } + + if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx)) { + return NULL; + } + + mem_ctx = talloc_new(NULL); + if (mem_ctx == NULL) { + PyErr_NoMemory(); + return NULL; + } + + lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx); + if (lp_ctx == NULL) { + talloc_free(mem_ctx); + return NULL; + } + + cli_credentials_set_conf(creds, lp_ctx); + + talloc_free(mem_ctx); + + Py_RETURN_NONE; +} + static PyObject *py_creds_guess(PyObject *self, PyObject *args) { PyObject *py_lp_ctx = Py_None; @@ -1279,6 +1315,11 @@ static PyMethodDef py_creds_methods[] = { .ml_meth = py_creds_set_krb_forwardable, .ml_flags = METH_VARARGS, }, + { + .ml_name = "set_conf", + .ml_meth = py_creds_set_conf, + .ml_flags = METH_VARARGS, + }, { .ml_name = "guess", .ml_meth = py_creds_guess, diff --git a/python/samba/tests/credentials.py b/python/samba/tests/credentials.py index fcd430f5ab4..bcd15b1130f 100644 --- a/python/samba/tests/credentials.py +++ b/python/samba/tests/credentials.py @@ -455,14 +455,47 @@ class CredentialsTests(samba.tests.TestCaseInTempDir): creds.set_smb_signing(credentials.SMB_SIGNING_REQUIRED) self.assertEqual(creds.get_smb_signing(), credentials.SMB_SIGNING_REQUIRED) + def test_smb_signing_set_conf(self): + lp = samba.tests.env_loadparm() + + creds = credentials.Credentials() + creds.set_conf(lp) + self.assertEqual(creds.get_smb_signing(), credentials.SMB_SIGNING_DEFAULT) + creds.set_smb_signing(credentials.SMB_SIGNING_OFF) + self.assertEqual(creds.get_smb_signing(), credentials.SMB_SIGNING_OFF) + creds.set_conf(lp) + self.assertEqual(creds.get_smb_signing(), credentials.SMB_SIGNING_OFF) + def test_smb_ipc_signing(self): creds = credentials.Credentials() self.assertEqual(creds.get_smb_ipc_signing(), credentials.SMB_SIGNING_REQUIRED) creds.set_smb_ipc_signing(credentials.SMB_SIGNING_OFF) self.assertEqual(creds.get_smb_ipc_signing(), credentials.SMB_SIGNING_OFF) + def test_smb_ipc_signing_set_conf(self): + lp = samba.tests.env_loadparm() + + creds = credentials.Credentials() + creds.set_conf(lp) + self.assertEqual(creds.get_smb_ipc_signing(), credentials.SMB_SIGNING_REQUIRED) + creds.set_smb_ipc_signing(credentials.SMB_SIGNING_OFF) + self.assertEqual(creds.get_smb_ipc_signing(), credentials.SMB_SIGNING_OFF) + creds.set_conf(lp) + self.assertEqual(creds.get_smb_ipc_signing(), credentials.SMB_SIGNING_OFF) + def test_smb_encryption(self): creds = credentials.Credentials() self.assertEqual(creds.get_smb_encryption(), credentials.SMB_ENCRYPTION_DEFAULT) creds.set_smb_encryption(credentials.SMB_ENCRYPTION_REQUIRED) self.assertEqual(creds.get_smb_encryption(), credentials.SMB_ENCRYPTION_REQUIRED) + + def test_smb_encryption_set_conf(self): + lp = samba.tests.env_loadparm() + + creds = credentials.Credentials() + creds.set_conf(lp) + self.assertEqual(creds.get_smb_encryption(), credentials.SMB_ENCRYPTION_DEFAULT) + creds.set_smb_encryption(credentials.SMB_ENCRYPTION_OFF) + self.assertEqual(creds.get_smb_encryption(), credentials.SMB_ENCRYPTION_OFF) + creds.set_conf(lp) + self.assertEqual(creds.get_smb_encryption(), credentials.SMB_ENCRYPTION_OFF) -- 2.34.1