def __init__(self, dc_fqdn=None): smbopts.__init__(self, 'GPO Applier') self.credopts = options.CredentialsOptions(self.parser) self.creds = self.credopts.get_credentials(self.lp, fallback_machine=True) self.selected_dc = self.set_dc(dc_fqdn)
from samba.auth import AuthContext from samba.ndr import ndr_unpack from samba import gensec from samba.credentials import Credentials, DONT_USE_KERBEROS from samba.dsdb import GTYPE_SECURITY_GLOBAL_GROUP, GTYPE_SECURITY_UNIVERSAL_GROUP import samba.tests from samba.tests import delete_force from samba.dcerpc import samr, security from samba.auth import AUTH_SESSION_INFO_DEFAULT_GROUPS, AUTH_SESSION_INFO_AUTHENTICATED, AUTH_SESSION_INFO_SIMPLE_PRIVILEGES, AUTH_SESSION_INFO_NTLM parser = optparse.OptionParser("token_group.py [options] <host>") sambaopts = options.SambaOptions(parser) parser.add_option_group(sambaopts) parser.add_option_group(options.VersionOptions(parser)) # use command line creds if available credopts = options.CredentialsOptions(parser) parser.add_option_group(credopts) subunitopts = SubunitOptions(parser) parser.add_option_group(subunitopts) opts, args = parser.parse_args() if len(args) < 1: parser.print_usage() sys.exit(1) url = args[0] lp = sambaopts.get_loadparm() creds = credopts.get_credentials(lp) creds.set_gensec_features(creds.get_gensec_features() | gensec.FEATURE_SEAL)
download_files(conn, win_path_join(remote_path, f['name']), os.path.join(local_path, f['name'])) else: # Download the file fname = os.path.join(local_path, f['name']) rname = win_path_join(remote_path, f['name']) open(fname, 'w').write(conn.loadfile(rname)) os.utime(fname, (time(), f['mtime'])) if __name__ == '__main__': parse = argparse.ArgumentParser(description='Sysvol replication tool') parse.add_argument('server', help='FQDN of server to replicate sysvol from') args = parse.parse_args() parser = optparse.OptionParser() lp = getopt.SambaOptions(parser).get_loadparm() creds = getopt.CredentialsOptions(parser).get_credentials(lp, fallback_machine=True) conn = smb.SMB(args.server, 'sysvol', lp=lp, creds=creds) gpo_versions = '%s/%s' % (lp.get('path', 'sysvol'), 'versions.tdb') if os.path.isfile(gpo_versions): vers_f = tdb.open(gpo_versions) else: vers_f = tdb.Tdb(gpo_versions, 0, tdb.DEFAULT, os.O_CREAT|os.O_RDWR) gpo_path = win_path_join(lp.get('realm').lower(), 'Policies') gpos = [x['name'] for x in conn.list(gpo_path)] for gpo in gpos: s_gpo_path = win_path_join(gpo_path, gpo) # Check if the version has changed fname = win_path_join(s_gpo_path, 'GPT.INI') data = conn.loadfile(fname)