def open_object(moniker, username=None, password=None, extra_flags=0, interface=adsi.IID_IADs): flags = adsicon.ADS_SECURE_AUTHENTICATION | adsicon.ADS_FAST_BIND flags |= extra_flags return adsi.ADsOpenObject(moniker, username, password, flags, interface)
def AD(server=None, username=None, password=None): """Return an AD Object representing the root of the domain. """ default_naming_context = _root(server).Get("defaultNamingContext") flags = adsicon.ADS_SECURE_AUTHENTICATION | adsicon.ADS_FAST_BIND if server: moniker = "LDAP://%s/%s" % (server, default_naming_context) flags |= adsicon.ADS_SERVER_BIND else: moniker = "LDAP://%s" % default_naming_context obj = adsi.ADsOpenObject(moniker, username, password, flags, adsi.IID_IADs) return AD_object(obj, username=username, password=password)