|
25 | 25 | import uuid |
26 | 26 | import getpass |
27 | 27 | import tempfile |
| 28 | +import optparse |
28 | 29 |
|
29 | 30 | from functools import wraps |
30 | 31 |
|
|
35 | 36 | import ldap.modlist |
36 | 37 |
|
37 | 38 | import samba |
38 | | -from samba import param, smb |
| 39 | +import samba.getopt as options |
39 | 40 | from samba.credentials import Credentials, MUST_USE_KERBEROS |
40 | 41 | from samba.ndr import ndr_unpack, ndr_pack |
41 | 42 | from samba.dcerpc import security |
42 | 43 | from samba.ntacls import dsacl2fsacl |
| 44 | +from samba.samba3 import param as s3param |
| 45 | + |
| 46 | +try: |
| 47 | + from samba.samba3 import libsmb |
| 48 | + logging.debug('Using SAMBA 3 SMB connection') |
| 49 | +except ImportError: |
| 50 | + from samba.samba3 import libsmb_samba_internal as libsmb |
| 51 | + logging.debug('Using SAMBA 3 SMB connection (Internal)') |
43 | 52 |
|
44 | 53 |
|
45 | 54 | GPO_SMB_PATH = '\\\\%s\\SysVol\\%s\\Policies\\%s' |
@@ -144,13 +153,32 @@ def _get_server_name(self): |
144 | 153 | def _generate_gpo_uuid(self): |
145 | 154 | return '{%s}' % str(uuid.uuid4()).upper() |
146 | 155 |
|
| 156 | + # def _get_smb_connection(self, service='SysVol'): |
| 157 | + # # Connect to SMB using kerberos |
| 158 | + # parm = param.LoadParm() |
| 159 | + # creds = Credentials() |
| 160 | + # creds.set_kerberos_state(MUST_USE_KERBEROS) |
| 161 | + # creds.guess(parm) |
| 162 | + # conn = SMBConn(self._get_server_name(), service, lp=parm, creds=creds) |
| 163 | + # return conn |
| 164 | + |
147 | 165 | def _get_smb_connection(self, service='SysVol'): |
148 | | - # Connect to SMB using kerberos |
149 | | - parm = param.LoadParm() |
| 166 | + # Create options like if we were using command line |
| 167 | + parser = optparse.OptionParser() |
| 168 | + sambaopts = options.SambaOptions(parser) |
| 169 | + # Samba options |
| 170 | + parm = sambaopts.get_loadparm() |
| 171 | + s3_lp = s3param.get_context() |
| 172 | + s3_lp.load(parm.configfile) |
| 173 | + # Build credentials from credential options |
150 | 174 | creds = Credentials() |
| 175 | + # Credentials need username and realm to be not empty strings to work |
| 176 | + creds.set_username('NOTEMPTY') |
| 177 | + creds.set_realm('NOTEMPTY') |
| 178 | + # Connect to SMB using kerberos |
151 | 179 | creds.set_kerberos_state(MUST_USE_KERBEROS) |
152 | | - creds.guess(parm) |
153 | | - conn = smb.SMB(self._get_server_name(), service, lp=parm, creds=creds) |
| 180 | + # Create connection |
| 181 | + conn = libsmb.Conn(self._get_server_name(), service, lp=parm, creds=creds, sign=False) |
154 | 182 | return conn |
155 | 183 |
|
156 | 184 | def _load_smb_data(self, gpo_uuid): |
|
0 commit comments