diff --git a/python/samba/netcmd/gpcommon.py b/python/samba/netcmd/gpcommon.py index f578b945cbf..9ad1d4409c4 100644 --- a/python/samba/netcmd/gpcommon.py +++ b/python/samba/netcmd/gpcommon.py @@ -16,6 +16,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # +from samba.credentials import SMB_SIGNING_REQUIRED +from samba.samba3 import param as s3param +from samba.samba3 import libsmb_samba_internal as libsmb +from samba.netcmd import CommandError def create_directory_hier(conn, remotedir): elems = remotedir.replace('/', '\\').split('\\') @@ -24,3 +28,19 @@ def create_directory_hier(conn, remotedir): path = path + '\\' + e if not conn.chkpath(path): conn.mkdir(path) + +def smb_connection(dc_hostname, service, lp, creds): + # SMB connect to DC + # Force signing for the smb connection + saved_signing_state = creds.get_smb_signing() + creds.set_smb_signing(SMB_SIGNING_REQUIRED) + try: + # the SMB bindings rely on having a s3 loadparm + s3_lp = s3param.get_context() + s3_lp.load(lp.configfile) + conn = libsmb.Conn(dc_hostname, service, lp=s3_lp, creds=creds) + except Exception: + raise CommandError("Error connecting to '%s' using SMB" % dc_hostname) + # Reset signing state + creds.set_smb_signing(saved_signing_state) + return conn diff --git a/python/samba/netcmd/gpo.py b/python/samba/netcmd/gpo.py index 55da664d04d..6e64cc46a47 100644 --- a/python/samba/netcmd/gpo.py +++ b/python/samba/netcmd/gpo.py @@ -43,7 +43,6 @@ import samba.auth from samba.auth import AUTH_SESSION_INFO_DEFAULT_GROUPS, AUTH_SESSION_INFO_AUTHENTICATED, AUTH_SESSION_INFO_SIMPLE_PRIVILEGES from samba.netcmd.common import netcmd_finddc from samba import policy -from samba.samba3 import param as s3param from samba.samba3 import libsmb_samba_internal as libsmb from samba import NTSTATUSError import uuid @@ -62,7 +61,6 @@ from samba.gp_parse.gp_csv import GPAuditCsvParser from samba.gp_parse.gp_inf import GptTmplInfParser from samba.gp_parse.gp_aas import GPAasParser from samba import param -from samba.credentials import SMB_SIGNING_REQUIRED from samba.netcmd.common import attr_default from samba.common import get_bytes, get_string from configparser import ConfigParser @@ -77,7 +75,7 @@ from samba.ntstatus import ( NT_STATUS_OBJECT_PATH_NOT_FOUND, NT_STATUS_ACCESS_DENIED ) -from samba.netcmd.gpcommon import create_directory_hier +from samba.netcmd.gpcommon import create_directory_hier, smb_connection def gpo_flags_string(value): @@ -383,23 +381,6 @@ def copy_directory_local_to_remote(conn, localdir, remotedir, conn.savefile(r_name, data) -def smb_connection(dc_hostname, service, lp, creds): - # SMB connect to DC - # Force signing for the smb connection - saved_signing_state = creds.get_smb_signing() - creds.set_smb_signing(SMB_SIGNING_REQUIRED) - try: - # the SMB bindings rely on having a s3 loadparm - s3_lp = s3param.get_context() - s3_lp.load(lp.configfile) - conn = libsmb.Conn(dc_hostname, service, lp=s3_lp, creds=creds) - except Exception: - raise CommandError("Error connecting to '%s' using SMB" % dc_hostname) - # Reset signing state - creds.set_smb_signing(saved_signing_state) - return conn - - class GPOCommand(Command): def construct_tmpdir(self, tmpdir, gpo): """Ensure that the temporary directory structure used in fetch,