]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samba-tool: Move smb_connection to a common file
authorDavid Mulder <dmulder@samba.org>
Wed, 7 Dec 2022 18:32:30 +0000 (11:32 -0700)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 30 Jan 2023 09:00:39 +0000 (09:00 +0000)
This is in preparation for needing it here later.

Signed-off-by: David Mulder <dmulder@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/netcmd/gpcommon.py
python/samba/netcmd/gpo.py

index f578b945cbf59814e5ff8fc6e1e8588dfd8f6720..9ad1d4409c4503eb995d8fc2c149b7e06c036a9a 100644 (file)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
+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
index 55da664d04d70861f44cf3ee4c723a1fa7621069..6e64cc46a474dc6af4f3d577ffefef94a0b3baba 100644 (file)
@@ -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,