|
@@ -17,7 +17,6 @@ def main():
|
|
if len(args) < 3:
|
|
if len(args) < 3:
|
|
print("Usage: script.py <LDAP_URI> <BIND_DN> <PASSWORD>")
|
|
print("Usage: script.py <LDAP_URI> <BIND_DN> <PASSWORD>")
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
-
|
|
|
|
ldap_uri = args[0]
|
|
ldap_uri = args[0]
|
|
binddn = args[1]
|
|
binddn = args[1]
|
|
pw = args[2]
|
|
pw = args[2]
|
|
@@ -25,7 +24,6 @@ def main():
|
|
searchFilter = "(objectClass=*)"
|
|
searchFilter = "(objectClass=*)"
|
|
searchAttribute = ["*"]
|
|
searchAttribute = ["*"]
|
|
searchScope = ldap.SCOPE_SUBTREE
|
|
searchScope = ldap.SCOPE_SUBTREE
|
|
-
|
|
|
|
try:
|
|
try:
|
|
# ignore TLS certificate checking
|
|
# ignore TLS certificate checking
|
|
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
|
|
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
|
|
@@ -36,7 +34,6 @@ def main():
|
|
except ldap.LDAPError as e:
|
|
except ldap.LDAPError as e:
|
|
print(f"Failed to initialize LDAP connection: {e}")
|
|
print(f"Failed to initialize LDAP connection: {e}")
|
|
sys.exit(f"Failed to initialize LDAP connection: {e}")
|
|
sys.exit(f"Failed to initialize LDAP connection: {e}")
|
|
-
|
|
|
|
try:
|
|
try:
|
|
# Attempt to bind with given credentials
|
|
# Attempt to bind with given credentials
|
|
l.simple_bind_s(binddn, pw)
|
|
l.simple_bind_s(binddn, pw)
|
|
@@ -46,18 +43,16 @@ def main():
|
|
except ldap.LDAPError as e:
|
|
except ldap.LDAPError as e:
|
|
print(f"LDAP error during bind: {e}")
|
|
print(f"LDAP error during bind: {e}")
|
|
sys.exit(f"LDAP error during bind: {e}")
|
|
sys.exit(f"LDAP error during bind: {e}")
|
|
-
|
|
|
|
try:
|
|
try:
|
|
ldap_result_id = l.search(basedn, searchScope, searchFilter, searchAttribute)
|
|
ldap_result_id = l.search(basedn, searchScope, searchFilter, searchAttribute)
|
|
result_set = []
|
|
result_set = []
|
|
|
|
|
|
while True:
|
|
while True:
|
|
- result_type, result_data = l.result(ldap_result_id, 0)
|
|
|
|
|
|
+ result_type, result_data = l.result(ldap_result_id, 0, timeout=40)
|
|
if (result_data == []):
|
|
if (result_data == []):
|
|
break
|
|
break
|
|
elif result_type == ldap.RES_SEARCH_ENTRY:
|
|
elif result_type == ldap.RES_SEARCH_ENTRY:
|
|
result_set.append(result_data)
|
|
result_set.append(result_data)
|
|
-
|
|
|
|
print('<<<edirectory_monitor_agent:sep(124)>>>')
|
|
print('<<<edirectory_monitor_agent:sep(124)>>>')
|
|
for i in range(len(result_set)):
|
|
for i in range(len(result_set)):
|
|
for val in result_set[i]:
|
|
for val in result_set[i]:
|
|
@@ -99,8 +94,9 @@ def main():
|
|
print(f"LDAP search failed: {e}")
|
|
print(f"LDAP search failed: {e}")
|
|
sys.exit(f"LDAP search failed: {e}")
|
|
sys.exit(f"LDAP search failed: {e}")
|
|
finally:
|
|
finally:
|
|
- l.unbind_s()
|
|
|
|
-
|
|
|
|
|
|
+ if l is not None:
|
|
|
|
+ l.unbind_s()
|
|
|
|
+
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
main()
|
|
main()
|
|
|
|
|