def setUp(self): super(NtaclsBackupRestoreTests, self).setUp() self.server = os.environ["SERVER"] # addc samdb_url = 'ldap://' + self.server self.service = 'test1' # service/share to test # root path for service self.service_root = os.path.join(os.environ["LOCAL_PATH"], self.service) self.smb_conf_path = os.environ['SMB_CONF_PATH'] self.dom_sid = security.dom_sid(os.environ['DOMSID']) self.creds = self.insta_creds(template=self.get_credentials()) # helper will load conf into lp, that's how smbd can find services. self.ntacls_helper = ntacls.NtaclsHelper(self.service, self.smb_conf_path, self.dom_sid) self.lp = self.ntacls_helper.lp self.samdb_conn = samdb.SamDB(url=samdb_url, session_info=system_session(), credentials=self.creds, lp=self.lp) self.smb_conn = smb.SMB(self.server, self.service, lp=self.lp, creds=self.creds) self.smb_helper = ntacls.SMBHelper(self.smb_conn, self.dom_sid) self.tarfile_path = os.path.join(self.tempdir, 'ntacls-backup.tar.gz') # an example file tree self.tree = { 'file0.txt': b'test file0', 'dir1': { 'file1.txt': b'test file1', 'dir2': {} # an empty dir in dir }, } self._delete_tarfile() self.smb_helper.delete_tree() self.smb_helper.create_tree(self.tree) self._check_tree() # keep a copy of ntacls after tree just created self.original_ntacls = self.smb_helper.get_ntacls()
if opts.__dict__['name'] is None: parser.error('Parameter --sAMAccountName is required') lp = sambaopts.get_loadparm() creds = credopts.get_credentials(lp) realm = lp.get('realm') net = Net(creds) cldap_ret = net.finddc(domain=realm, flags=(nbt.NBT_SERVER_LDAP | nbt.NBT_SERVER_DS | nbt.NBT_SERVER_WRITABLE)) host = cldap_ret.pdc_dns_name ldb = samdb.SamDB(url='ldap://%s' % host, lp=lp, credentials=creds, session_info=system_session()) domain_sid = security.dom_sid(ldb.get_domain_sid()) s = samr.samr("ncacn_ip_tcp:%s[seal]" % host, lp, creds) samr_handle = s.Connect2(None, security.SEC_FLAG_MAXIMUM_ALLOWED) samr_domain = s.OpenDomain(samr_handle, security.SEC_FLAG_MAXIMUM_ALLOWED, domain_sid) try: (rids, _) = s.LookupNames(samr_domain, [lsa.String(opts.name)]) except NTSTATUSError: print('%s not found!' % opts.name) exit(1) samr_user = s.OpenUser(samr_domain, security.SEC_FLAG_MAXIMUM_ALLOWED, rids.ids[0])