Utilities¶
- pyad.pyad.from_cn(common_name, search_base=None, options={}) pyad.adobject.ADObject [source]¶
Generates ADObject based on common name
- pyad.pyad.from_dn(distinguished_name, options={}) pyad.adobject.ADObject [source]¶
Generates ADObject based on distinguished name
- pyad.pyad.from_guid(guid, options={}) pyad.adobject.ADObject [source]¶
Generates ADObject based on GUID
- pyad.pyadutils.convert_bigint(obj) int [source]¶
Converts a ADSI time object to an integer.
based on http://www.selfadsi.org/ads-attributes/user-usnChanged.htm
- Parameters
obj – the AD bigint object
- Raises
AttributeError – invalid object type
- Returns
the decimal value of the object
- Return type
int
- pyad.pyadutils.convert_datetime(adsi_time_com_obj)[source]¶
Converts 64-bit integer COM object representing time into a python datetime object.
Credit goes to John Nielsen who documented this at http://docs.activestate.com/activepython/2.6/pywin32/html/com/help/active_directory.html.
- pyad.pyadutils.convert_error_code(error_code: int) int [source]¶
Convert error code from the format returned by pywin32 to the format that Microsoft documents everything in.
- Parameters
error_code (int) – error code
- Returns
The error code in the format Microsoft documents it
- Return type
int
- pyad.pyadutils.convert_timespan(obj) datetime.timedelta [source]¶
Converts COM object representing time span to a python time span object.
- Parameters
obj – ADSI time span object
- Returns
the python timedelta object
- Return type
datetime.timedelta
- pyad.pyadutils.escape_path(path: str) str [source]¶
escapes a path for use in ADSI.
- Parameters
path (str) – the raw path to escape
- Returns
the escaped path
- Return type
str
- pyad.pyadutils.generate_ads_path(distinguished_name: str, type: str, server: Optional[str] = None, port: Optional[int] = None) str [source]¶
Generates a proper ADsPath to be used when connecting to an active directory object or when searching active directory.
- Parameters
distinguished_name (str) – DN of object or search base such as ‘cn=John Smith,cn=users,dc=example,dc=com’
type (str) – the connection type, either ‘LDAP’, ‘LDAPS’, or ‘GC’
server (str, optional) – FQDN of domain controller if necessary to connect to a particular server, defaults to the global catalog server
port (int, optional) – port number for directory service if not default port. If port is specified, server must be specified.
- Raises
TypeError – Invalid type for type
- Returns
the ADsPath to be used when connecting to Active Directory
- Return type
str
- pyad.pyadutils.generate_list(input) list [source]¶
converts a set or tuple to a list or returns the input in a list if it is not a list.
- Parameters
input (list, set, tuple, Any) – a list like object or any
- Returns
a list
- Return type
list
- pyad.pyadutils.interpret_com_exception(excp: pywintype.com_error, additional_info: dict = {}) dict [source]¶
Convert a pywin32 com_error exception into a dictionary of error information.
- Parameters
excp (pywintype.com_error) – pywin32 com_error exception
additional_info (dict, optional) – any additional information with the error, defaults to {}
- Returns
a dictionary of error information
- Return type
dict
- pyad.pyadutils.pass_up_com_exception(excp: pywintype.com_error, additional_info: dict = {})[source]¶
reparse the com_error into a sane exception and raise it.
- Parameters
excp (pywintype.com_error) – the com_error exception
additional_info (dict, optional) – Additional exception details, defaults to {}
- Raises
excp – if we don’t know how to handle the exception raise the original exception
- pyad.pyadutils.validate_credentials(username: str, password: str, domain: str = None) win32.PyHandle [source]¶
Validates credentials; returns a PyHANDLE object with a bool value of True if the credentials are valid, else returns None. Note that if the user would not be able to log on; for example, due to the account being expired; None will be returned.
- Parameters
username (str) – username
password (str) – password
domain (str, optional) – domain name, defaults to None
- Returns
PyHandle Object with a bool of true. or None
- Return type
win32.PyHandle