diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2013-12-21 21:18:39 +0100 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2013-12-21 21:34:01 +0100 |
commit | a0c90d244be26391b44931d8d74ed8b2ea07c11e (patch) | |
tree | bb6756d41a02a664a213206182177fdad7665411 /nslcd/passwd.c | |
parent | 99ad1b4b9b40db7ebddeabc9e6b754c58f97e913 (diff) |
Use dn2uid cache options
The configuration values are used in the cache to determine positive and
negative hit TTLs. This also allows completely disabling the cache.
Diffstat (limited to 'nslcd/passwd.c')
-rw-r--r-- | nslcd/passwd.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/nslcd/passwd.c b/nslcd/passwd.c index bdc2049..e9cf950 100644 --- a/nslcd/passwd.c +++ b/nslcd/passwd.c @@ -162,8 +162,6 @@ struct dn2uid_cache_entry { time_t timestamp; char *uid; }; -#define DN2UID_CACHE_POSITIVE_TIMEOUT (30 * 60) -#define DN2UID_CACHE_NEGATIVE_TIMEOUT (15 * 60) /* checks whether the entry has a valid uidNumber attribute (>= nss_min_uid) */ @@ -280,6 +278,9 @@ char *dn2uid(MYLDAP_SESSION *session, const char *dn, char *buf, size_t buflen) return NULL; return buf; } + /* if we don't use the cache, just lookup and return */ + if ((nslcd_cfg->cache_dn2uid_positive == 0) && (nslcd_cfg->cache_dn2uid_negative == 0)) + return lookup_dn2uid(session, dn, NULL, buf, buflen); /* see if we have a cached entry */ pthread_mutex_lock(&dn2uid_cache_mutex); if (dn2uid_cache == NULL) @@ -289,7 +290,8 @@ char *dn2uid(MYLDAP_SESSION *session, const char *dn, char *buf, size_t buflen) if ((cacheentry->uid != NULL) && (strlen(cacheentry->uid) < buflen)) { /* if the cached entry is still valid, return that */ - if (time(NULL) < (cacheentry->timestamp + DN2UID_CACHE_POSITIVE_TIMEOUT)) + if ((nslcd_cfg->cache_dn2uid_positive > 0) && + (time(NULL) < (cacheentry->timestamp + nslcd_cfg->cache_dn2uid_positive))) { strcpy(buf, cacheentry->uid); pthread_mutex_unlock(&dn2uid_cache_mutex); @@ -298,7 +300,8 @@ char *dn2uid(MYLDAP_SESSION *session, const char *dn, char *buf, size_t buflen) } else { - if (time(NULL) < (cacheentry->timestamp + DN2UID_CACHE_NEGATIVE_TIMEOUT)) + if ((nslcd_cfg->cache_dn2uid_negative > 0) && + (time(NULL) < (cacheentry->timestamp + nslcd_cfg->cache_dn2uid_negative))) /* if the cached entry is still valid, return that */ { pthread_mutex_unlock(&dn2uid_cache_mutex); |