Bug 12757 - mod_ldap cache tries to open an existing shared memory file
Summary: mod_ldap cache tries to open an existing shared memory file
Status: CLOSED FIXED
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: Other Modules (show other bugs)
Version: 2.0-HEAD
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-09-18 03:09 UTC by Shaun Kelly
Modified: 2004-11-16 19:05 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Shaun Kelly 2002-09-18 03:09:16 UTC
File: /modules/experimental/util_ldap_cach.c

apr_status_t util_ldap_cache_init(apr_pool_t *pool, apr_size_t reqsize)
{
#if APR_HAS_SHARED_MEMORY
    apr_status_t result;

    - result = apr_shm_create(&util_ldap_shm, reqsize, "/tmp/ldap_cache", pool);
    + result = apr_shm_create(&util_ldap_shm, reqsize, NULL, pool);
    if (result != APR_SUCCESS) {
        return result;
    }

pool);
#endif
....
}
The ldap cache used by mod_ldap and mod_auth_ldap tries to create a shared 
memory file for each process forked. The problem is that only the first process 
is able to create the file, all the other processes fail to create the file 
because it already exists. This disables caching on all processes other than 
the initial process. Caching LDAP authentication is essential as this is a slow 
task, especially with Microsoft Active Directory. One solution on linux is to 
use an anonymous shared memory file (fileName is NULL) but apparently anonymous 
shared memory is not supported on other platforms. I assume all processes 
should share a single cache. Would anonymous shared memory create a new file 
for each process? If this is not desired, only the first process should create 
the file and all the other processes should attach to in.
Comment 1 Michael Dean 2002-12-10 11:45:26 UTC
This also happens on a solaris 8 platform with the error

[debug] util_ldap.c(1066): (17)File exists: [4449] ldap cache init: File exists


i tried disabling the code in the #if APR_HAS_SHARED_MEMORY statements to at
least get the per server cache to work although it has the error

[debug] util_ldap.c(1066): [8329] ldap cache init: Error 0
Comment 2 Scooter Morris 2003-01-10 22:58:21 UTC
Actually, wouldn't it be better to just attach to the named file?  I implemented
something like this:

cvs diff -c util_ldap_cache.c 
Index: util_ldap_cache.c
===================================================================
RCS file:
/usr/src/cvs/cvsroot/contrib/Apache/modules/experimental/util_ldap_cache.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 util_ldap_cache.c
*** util_ldap_cache.c   8 Oct 2002 20:49:28 -0000       1.1.1.1
--- util_ldap_cache.c   10 Jan 2003 22:55:51 -0000
***************
*** 296,304 ****
      apr_status_t result;
  
      result = apr_shm_create(&util_ldap_shm, reqsize, "/tmp/ldap_cache", pool);
!     if (result != APR_SUCCESS) {
          return result;
-     }
  
      /* This will create a rmm "handler" to get into the shared memory area */
      apr_rmm_init(&util_ldap_rmm, NULL,
--- 296,310 ----
      apr_status_t result;
  
      result = apr_shm_create(&util_ldap_shm, reqsize, "/tmp/ldap_cache", pool);
!     if (result == EEXIST) {
!       /*
!        * The cache could have already been created (i.e. we may be a child
process).  See
!        * if we can attach to the existing shared memory
!        */
!       result = apr_shm_attach(&util_ldap_shm, "/tmp/ldap_cache", pool);
!     } 
!     if (result != APR_SUCCESS)
          return result;
  
      /* This will create a rmm "handler" to get into the shared memory area */
      apr_rmm_init(&util_ldap_rmm, NULL,

and it seems to work for me.
Comment 3 Graham Leggett 2003-01-21 10:57:58 UTC
Patch applied to v2.0.45-dev and v2.1.0-dev