python: wrap 'import dckeytab' in an explanatory function
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Sat, 4 Jul 2020 04:20:47 +0000 (16:20 +1200)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 17 Jul 2020 07:17:40 +0000 (07:17 +0000)
The samba.dckeytab module has magic effects on samba.net, but never
appears to be used. That can be confusing, both to people and to
linters. Here we wrap that confusion up into a well-commented
function, so we never again have to wonder why the unused import is
there.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: David Mulder <dmulder@samba.org>
python/samba/__init__.py
python/samba/netcmd/domain.py
python/samba/tests/dckeytab.py

index d851bf3606c593de8d66a77c0c7964285f100608..6272b3fb390b270274c32d81f240f949d6aeccba 100644 (file)
@@ -386,6 +386,23 @@ def arcfour_encrypt(key, data):
     return arcfour_crypt_blob(data, key)
 
 
+def enable_net_export_keytab():
+    """This function modifies the samba.net.Net class to contain
+    an export_keytab() method."""
+    # This looks very strange because it is.
+    #
+    # The dckeytab modules contains nothing, but the act of importing
+    # it pushes a method into samba.net.Net. It ended up this way
+    # because Net.export_keytab() only works on Heimdal builds, and
+    # people sometimes want to compile Samba without Heimdal while
+    # still having a working samba-tool.
+    #
+    # There is probably a better way to do this than a magic module
+    # import (yes, that's a FIXME if you can be bothered).
+    from samba import net
+    from samba import dckeytab
+
+
 version = _glue.version
 interface_ips = _glue.interface_ips
 fault_setup = _glue.fault_setup
index 4cb873fd6348b4c3b14b8dfe640785afd992f79c..8561188511e872be35144f4d3a95899b1b9e67c8 100644 (file)
@@ -40,6 +40,7 @@ from samba import NTSTATUSError
 from samba import werror
 from getpass import getpass
 from samba.net import Net, LIBNET_JOIN_AUTOMATIC
+from samba import enable_net_export_keytab
 import samba.ntacls
 from samba.join import join_RODC, join_DC
 from samba.auth import system_session
@@ -162,7 +163,7 @@ def get_testparm_var(testparm, smbconf, varname):
 
 
 try:
-    import samba.dckeytab
+    enable_net_export_keytab()
 except ImportError:
     cmd_domain_export_keytab = None
 else:
index cdb8c5151e7327ebbf590275c646edd0a4d9fa53..5d975f53500ada3a4d4e9985e0837f043581b380 100644 (file)
@@ -20,11 +20,15 @@ import os
 import sys
 import string
 from samba.net import Net
-import samba.dckeytab
+from samba import enable_net_export_keytab
+
 from samba import tests
 from samba.param import LoadParm
 
 
+enable_net_export_keytab()
+
+
 def open_bytes(filename):
     if sys.version_info[0] == 3:
         return open(filename, errors='ignore')