LDAP caching refactored, code duplication removed

2-stage LDAP cache lookup to reduce unneeded INSERTs that cause the MySQL
binary log to grow rapidly.
1st stage: only the SELECT is performed. If it is a valid cache row, no
more locks/inserts occur.
2nd stage: we try to lock the existing/new cache row and validate it again.
If it fails, LDAP query is performed.

authenticated_via_ldap_cache: 2-stage cache lookup introduced, refactored.
fetchLDAPCacheRow: simple fetching function. The query was in acquireLDAPCache before
acquireLDAPCache: now it only makes lock on cache row (existing or new)
isLDAPCacheValid: check if cache row matches complex validity condition
replaceLDAPCacheRecord: does real replace, not update (resets refresh timeout)
touchLDAPCacheRecord: form_username argument renamed to username
deleteLDAPCacheRecord: idem