Lines 127-143
def getBaseDN(host='localhost', port=None, uri=None): # type: (str, Optional[in
|
Link Here
|
---|
|
127 |
:returns: The distinguished name of the LDAP root. |
127 |
:returns: The distinguished name of the LDAP root. |
128 |
:rtype: str |
128 |
:rtype: str |
129 |
""" |
129 |
""" |
|
|
130 |
try: |
131 |
client_retry_count = int(configRegistry.get('ldap/client/retry/count', 10)) |
132 |
except ValueError: |
133 |
univention.debug.debug(univention.debug.LDAP, univention.debug.ERROR, "Unable to read ldap/client/retry/count, please reset to an integer value") |
134 |
client_retry_count = 10 |
135 |
|
136 |
client_connection_attempt = client_retry_count + 1 |
137 |
|
130 |
if not uri: |
138 |
if not uri: |
131 |
if not port: |
139 |
if not port: |
132 |
port = int(configRegistry.get('ldap/server/port', 7389)) |
140 |
port = int(configRegistry.get('ldap/server/port', 7389)) |
133 |
uri = "ldap://%s:%s" % (host, port) |
141 |
uri = "ldap://%s:%s" % (host, port) |
134 |
try: |
142 |
try: |
135 |
lo = ldap.ldapobject.ReconnectLDAPObject(uri, trace_stack_limit=None) |
143 |
lo = ldap.ldapobject.ReconnectLDAPObject(uri, trace_stack_limit=None, retry_max=client_connection_attempt, retry_delay=1) |
136 |
result = lo.search_s('', ldap.SCOPE_BASE, 'objectClass=*', ['NamingContexts']) |
144 |
result = lo.search_s('', ldap.SCOPE_BASE, 'objectClass=*', ['NamingContexts']) |
137 |
return result[0][1]['namingContexts'][0] |
145 |
return result[0][1]['namingContexts'][0] |
138 |
except ldap.SERVER_DOWN: |
146 |
except ldap.SERVER_DOWN: |
139 |
time.sleep(60) |
147 |
time.sleep(60) |
140 |
lo = ldap.ldapobject.ReconnectLDAPObject(uri, trace_stack_limit=None) |
148 |
lo = ldap.ldapobject.ReconnectLDAPObject(uri, trace_stack_limit=None, retry_max=client_connection_attempt, retry_delay=1) |
141 |
result = lo.search_s('', ldap.SCOPE_BASE, 'objectClass=*', ['NamingContexts']) |
149 |
result = lo.search_s('', ldap.SCOPE_BASE, 'objectClass=*', ['NamingContexts']) |
142 |
return result[0][1]['namingContexts'][0] |
150 |
return result[0][1]['namingContexts'][0] |
143 |
|
151 |
|