summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2013-10-25 23:25:00 +0200
committerArthur de Jong <arthur@arthurdejong.org>2013-10-25 23:36:03 +0200
commit1d8db24de6fce25997b1e672c497daf9b60ac725 (patch)
tree177170530694d8b2eb3cb09340b5fea731dabd1c
parentee8737f1a1d048f5b06ce479337e72382e36bf8f (diff)
Also run invalidators on initial connect
This also invalidates the caches configured with reconnect_invalidate on the first successful search. This should handle the case more gracefully where caches were filled with negative hits before nslcd was running.
-rw-r--r--nslcd/myldap.c15
-rw-r--r--pynslcd/search.py8
2 files changed, 19 insertions, 4 deletions
diff --git a/nslcd/myldap.c b/nslcd/myldap.c
index 959669b..235c3c6 100644
--- a/nslcd/myldap.c
+++ b/nslcd/myldap.c
@@ -150,6 +150,9 @@ struct myldap_entry {
char **rangedattributevalues[MAX_RANGED_ATTRIBUTES_PER_ENTRY];
};
+/* Flag to record first search operation */
+int first_search = 1;
+
static void myldap_err(int pri, LDAP *ld, int rc, const char *format, ...)
{
char message[200];
@@ -1159,6 +1162,7 @@ static int do_retry_search(MYLDAP_SEARCH *search)
int rc = LDAP_UNAVAILABLE;
struct myldap_uri *current_uri;
int dotry[NSS_LDAP_CONFIG_MAX_URIS];
+ int do_invalidate = 0;
/* clear time stamps */
for (start_uri = 0; start_uri < NSS_LDAP_CONFIG_MAX_URIS; start_uri++)
dotry[start_uri] = 1;
@@ -1197,8 +1201,12 @@ static int do_retry_search(MYLDAP_SEARCH *search)
if ((current_uri->lastfail > 0) || (search->session->current_uri != start_uri))
{
log_log(LOG_INFO, "connected to LDAP server %s", current_uri->uri);
- /* signal external invalidation of configured caches */
- invalidator_do(LM_NONE);
+ do_invalidate = 1;
+ }
+ if (first_search)
+ {
+ do_invalidate = 1;
+ first_search = 0;
}
/* update ok time */
current_uri->firstfail = 0;
@@ -1206,6 +1214,9 @@ static int do_retry_search(MYLDAP_SEARCH *search)
pthread_mutex_unlock(&uris_mutex);
/* flag the search as valid */
search->valid = 1;
+ /* signal external invalidation of configured caches */
+ if (do_invalidate)
+ invalidator_do(LM_NONE);
return LDAP_SUCCESS;
}
/* close the current connection */
diff --git a/pynslcd/search.py b/pynslcd/search.py
index 4c6f243..4a57ab3 100644
--- a/pynslcd/search.py
+++ b/pynslcd/search.py
@@ -30,6 +30,9 @@ import cfg
# global indicator that there was some error connection to an LDAP server
server_error = False
+# global indicator of first search operation
+first_search = True
+
class Connection(ldap.ldapobject.ReconnectLDAPObject):
@@ -65,15 +68,16 @@ class Connection(ldap.ldapobject.ReconnectLDAPObject):
def search_s(self, *args, **kwargs):
# wrapper function to keep the global server_error state
- global server_error
+ global server_error, first_search
try:
res = ldap.ldapobject.ReconnectLDAPObject.search_s(self, *args, **kwargs)
except ldap.SERVER_DOWN:
server_error = True
raise
- if server_error:
+ if server_error or first_search:
self.reconnect_after_fail()
server_error = False
+ first_search = False
return res