[PATCH] Two small cleanups for our python code
Volker Lendecke
Volker.Lendecke at SerNet.DE
Tue Jan 9 12:59:54 UTC 2018
Hi!
Review appreciated!
Thanks, Volker
--
Besuchen Sie die verinice.XP 2018 in Berlin,
Anwenderkonferenz für Informationssicherheit
vom 21.-23.03.2018 im Sofitel Kurfürstendamm
Info & Anmeldung hier: http://veriniceXP.org
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From 55f622ca3717ca8774d2cf21ab8292b2dc5e0a84 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 9 Jan 2018 10:23:35 +0100
Subject: [PATCH 1/2] libnet: Add NULL checks to py_net_finddc
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/libnet/py_net.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/source4/libnet/py_net.c b/source4/libnet/py_net.c
index 7ddee2df92c..0567dbd6353 100644
--- a/source4/libnet/py_net.c
+++ b/source4/libnet/py_net.c
@@ -697,8 +697,18 @@ static PyObject *py_net_finddc(py_net_Object *self, PyObject *args, PyObject *kw
}
mem_ctx = talloc_new(self->mem_ctx);
+ if (mem_ctx == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
io = talloc_zero(mem_ctx, struct finddcs);
+ if (io == NULL) {
+ TALLOC_FREE(mem_ctx);
+ PyErr_NoMemory();
+ return NULL;
+ }
+
if (domain != NULL) {
io->in.domain_name = domain;
}
--
2.11.0
From 876aa12ae4fa3664afb057ed9c50a6c191a48dc5 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 9 Jan 2018 12:41:01 +0100
Subject: [PATCH 2/2] python: Print the finddcs error message
Signed-off-by: Volker Lendecke <vl at samba.org>
---
python/samba/join.py | 3 +++
python/samba/netcmd/domain.py | 3 +++
2 files changed, 6 insertions(+)
diff --git a/python/samba/join.py b/python/samba/join.py
index 63e9b9010ed..9782f536dce 100644
--- a/python/samba/join.py
+++ b/python/samba/join.py
@@ -336,6 +336,9 @@ class dc_join(object):
"""find a writeable DC for the given domain"""
try:
ctx.cldap_ret = ctx.net.finddc(domain=domain, flags=nbt.NBT_SERVER_LDAP | nbt.NBT_SERVER_DS | nbt.NBT_SERVER_WRITABLE)
+ except NTSTATUSError as error:
+ raise Exception("Failed to find a writeable DC for domain '%s': %s" %
+ (domain, error[1]))
except Exception:
raise Exception("Failed to find a writeable DC for domain '%s'" % domain)
if ctx.cldap_ret.client_site is not None and ctx.cldap_ret.client_site != "":
diff --git a/python/samba/netcmd/domain.py b/python/samba/netcmd/domain.py
index ada7d6b5f36..2cb14f150ec 100644
--- a/python/samba/netcmd/domain.py
+++ b/python/samba/netcmd/domain.py
@@ -1771,6 +1771,9 @@ class DomainTrustCommand(Command):
if require_pdc:
remote_flags |= nbt.NBT_SERVER_PDC
remote_info = remote_net.finddc(flags=remote_flags, domain=domain, address=remote_server)
+ except NTSTATUSError as error:
+ raise CommandError("Failed to find a writeable DC for domain '%s': %s" %
+ (domain, error[1]))
except Exception:
raise CommandError("Failed to find a writeable DC for domain '%s'" % domain)
flag_map = {
--
2.11.0
More information about the samba-technical
mailing list