You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by tr...@apache.org on 2003/06/07 21:50:01 UTC

cvs commit: httpd-2.0/os/unix unixd.c unixd.h

trawick     2003/06/07 12:50:01

  Modified:    .        CHANGES
               modules/mappers mod_rewrite.c
               modules/ssl mod_ssl.h ssl_engine_config.c ssl_engine_mutex.c
               os/unix  unixd.c unixd.h
  Log:
  Unix: Handle permissions settings for flock-based mutexes in
  unixd_set_global|proc_mutex_perms().  Allow the functions to be
  called for any type of mutex.
  
  This resolves a fatal problem with mod_rewrite on systems where
  APR uses flock-based mutex.
  
  It simplifies mod_ssl as well, which had special logic to perform
  the chown().  It fixed an init error with mod_ssl on systems where
  flock is used when the user had no SSLMutex directive.
  
  The Unix MPMs continue to call unixd_set_global|proc_mutex_perms()
  only for SysV sems.  There is no permission problem with flock-based
  accept mutexes since the child init logic for the MPMs is done
  prior to switching identity.
  
  PR:              20312
  
  Revision  Changes    Path
  1.1199    +4 -0      httpd-2.0/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/CHANGES,v
  retrieving revision 1.1198
  retrieving revision 1.1199
  diff -u -r1.1198 -r1.1199
  --- CHANGES	7 Jun 2003 13:09:09 -0000	1.1198
  +++ CHANGES	7 Jun 2003 19:50:00 -0000	1.1199
  @@ -2,6 +2,10 @@
   
     [Remove entries to the current 2.0 section below, when backported]
   
  +  *) Unix: Handle permissions settings for flock-based mutexes in 
  +     unixd_set_global|proc_mutex_perms().  Allow the functions to be
  +     called for any type of mutex.  PR 20312  [Jeff Trawick]
  +
     *) mod_rewrite: Perform child initialization on the rewrite log lock.
        This fixes a log corruption issue when flock-based serialization
        is used (e.g., FreeBSD).  [Jeff Trawick]
  
  
  
  1.153     +3 -2      httpd-2.0/modules/mappers/mod_rewrite.c
  
  Index: mod_rewrite.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/mappers/mod_rewrite.c,v
  retrieving revision 1.152
  retrieving revision 1.153
  diff -u -r1.152 -r1.153
  --- mod_rewrite.c	7 Jun 2003 13:09:10 -0000	1.152
  +++ mod_rewrite.c	7 Jun 2003 19:50:00 -0000	1.153
  @@ -118,6 +118,7 @@
   
   #if !defined(OS2) && !defined(WIN32) && !defined(BEOS)  && !defined(NETWARE)
   #include "unixd.h"
  +#define MOD_REWRITE_SET_MUTEX_PERMS /* XXX Apache should define something */
   #endif
   
   /*
  @@ -1017,7 +1018,7 @@
           return HTTP_INTERNAL_SERVER_ERROR;
       }
   
  -#if APR_USE_SYSVSEM_SERIALIZE
  +#ifdef MOD_REWRITE_SET_MUTEX_PERMS
       rv = unixd_set_global_mutex_perms(rewrite_log_lock);
       if (rv != APR_SUCCESS) {
           ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
  @@ -3585,7 +3586,7 @@
           return rc;
       }
   
  -#if APR_USE_SYSVSEM_SERIALIZE
  +#ifdef MOD_REWRITE_SET_MUTEX_PERMS
       rc = unixd_set_global_mutex_perms(rewrite_mapr_lock_acquire);
       if (rc != APR_SUCCESS) {
           ap_log_error(APLOG_MARK, APLOG_CRIT, rc, s,
  
  
  
  1.136     +0 -1      httpd-2.0/modules/ssl/mod_ssl.h
  
  Index: mod_ssl.h
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/ssl/mod_ssl.h,v
  retrieving revision 1.135
  retrieving revision 1.136
  diff -u -r1.135 -r1.136
  --- mod_ssl.h	19 May 2003 14:48:47 -0000	1.135
  +++ mod_ssl.h	7 Jun 2003 19:50:01 -0000	1.136
  @@ -394,7 +394,6 @@
       ssl_mutexmode_t nMutexMode;
       apr_lockmech_e  nMutexMech;
       const char     *szMutexFile;
  -    BOOL           ChownMutexFile;
       apr_global_mutex_t   *pMutex;
       apr_array_header_t   *aRandSeed;
       apr_hash_t     *tVHostKeys;
  
  
  
  1.81      +0 -3      httpd-2.0/modules/ssl/ssl_engine_config.c
  
  Index: ssl_engine_config.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/ssl/ssl_engine_config.c,v
  retrieving revision 1.80
  retrieving revision 1.81
  diff -u -r1.80 -r1.81
  --- ssl_engine_config.c	30 May 2003 21:01:57 -0000	1.80
  +++ ssl_engine_config.c	7 Jun 2003 19:50:01 -0000	1.81
  @@ -101,7 +101,6 @@
       mc->nMutexMode             = SSL_MUTEXMODE_UNSET;
       mc->nMutexMech             = APR_LOCK_DEFAULT;
       mc->szMutexFile            = NULL;
  -    mc->ChownMutexFile         = FALSE;
       mc->pMutex                 = NULL;
       mc->aRandSeed              = apr_array_make(pool, 4,
                                                   sizeof(ssl_randseed_t));
  @@ -401,7 +400,6 @@
        */
       mc->nMutexMode  = SSL_MUTEXMODE_USED;
       mc->szMutexFile = NULL;
  -    mc->ChownMutexFile = FALSE;
   
       /* NOTE: previously, 'yes' implied 'sem' */
       if (!strcasecmp(meth, "default") || !strcasecmp(meth, "yes")) {
  @@ -415,7 +413,6 @@
   #if APR_HAS_FLOCK_SERIALIZE
       else if ((!strcasecmp(meth, "flock") || !strcasecmp(meth, "file")) && file) {
           mc->nMutexMech = APR_LOCK_FLOCK;
  -        mc->ChownMutexFile = TRUE;
       }
   #endif
   #if APR_HAS_POSIXSEM_SERIALIZE
  
  
  
  1.26      +8 -18     httpd-2.0/modules/ssl/ssl_engine_mutex.c
  
  Index: ssl_engine_mutex.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/ssl/ssl_engine_mutex.c,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- ssl_engine_mutex.c	31 Mar 2003 14:38:51 -0000	1.25
  +++ ssl_engine_mutex.c	7 Jun 2003 19:50:01 -0000	1.26
  @@ -63,6 +63,7 @@
   #include "mod_ssl.h"
   #if !defined(OS2) && !defined(WIN32) && !defined(BEOS) && !defined(NETWARE)
   #include "unixd.h"
  +#define MOD_SSL_SET_MUTEX_PERMS /* XXX Apache should define something */
   #endif
   
   int ssl_mutex_init(server_rec *s, apr_pool_t *p)
  @@ -88,25 +89,14 @@
                            "Cannot create SSLMutex");
           return FALSE;
       }
  -#if !defined(OS2) && !defined(WIN32) && !defined(BEOS) && !defined(NETWARE)
  -    if (mc->szMutexFile && mc->ChownMutexFile == TRUE)
  -        chown(mc->szMutexFile, unixd_config.user_id, -1);
  -#endif
   
  -#if APR_HAS_SYSVSEM_SERIALIZE
  -#if APR_USE_SYSVSEM_SERIALIZE
  -    if (mc->nMutexMech == APR_LOCK_DEFAULT || 
  -        mc->nMutexMech == APR_LOCK_SYSVSEM) {
  -#else
  -    if (mc->nMutexMech == APR_LOCK_SYSVSEM) {
  -#endif
  -        rv = unixd_set_global_mutex_perms(mc->pMutex);
  -        if (rv != APR_SUCCESS) {
  -            ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
  -                         "Could not set permissions on ssl_mutex; check User "
  -                         "and Group directives");
  -            return FALSE;
  -        }
  +#ifdef MOD_SSL_SET_MUTEX_PERMS
  +    rv = unixd_set_global_mutex_perms(mc->pMutex);
  +    if (rv != APR_SUCCESS) {
  +        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
  +                     "Could not set permissions on ssl_mutex; check User "
  +                     "and Group directives");
  +        return FALSE;
       }
   #endif
       return TRUE;
  
  
  
  1.58      +56 -21    httpd-2.0/os/unix/unixd.c
  
  Index: unixd.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/os/unix/unixd.c,v
  retrieving revision 1.57
  retrieving revision 1.58
  diff -u -r1.57 -r1.58
  --- unixd.c	6 Mar 2003 21:48:58 -0000	1.57
  +++ unixd.c	7 Jun 2003 19:50:01 -0000	1.58
  @@ -417,35 +417,70 @@
                                                 attr, ugid, p);
   }
   
  +/* XXX move to APR and externalize (but implement differently :) ) */
  +static apr_lockmech_e proc_mutex_mech(apr_proc_mutex_t *pmutex)
  +{
  +    const char *mechname = apr_proc_mutex_name(pmutex);
  +
  +    if (!strcmp(mechname, "sysvsem")) {
  +        return APR_LOCK_SYSVSEM;
  +    }
  +    else if (!strcmp(mechname, "flock")) {
  +        return APR_LOCK_FLOCK;
  +    }
  +    return APR_LOCK_DEFAULT;
  +}
  +
   AP_DECLARE(apr_status_t) unixd_set_proc_mutex_perms(apr_proc_mutex_t *pmutex)
   {
  -/* MPM shouldn't call us unless we're actually using a SysV sem;
  - * this is just to avoid compile issues on systems without that
  - * feature
  - */
  +    if (!geteuid()) {
  +        apr_lockmech_e mech = proc_mutex_mech(pmutex);
  +
  +        switch(mech) {
   #if APR_HAS_SYSVSEM_SERIALIZE
  -    apr_os_proc_mutex_t ospmutex;
  +        case APR_LOCK_SYSVSEM:
  +        {
  +            apr_os_proc_mutex_t ospmutex;
   #if !APR_HAVE_UNION_SEMUN
  -    union semun {
  -        long val;
  -        struct semid_ds *buf;
  -        ushort *array;
  -    };
  +            union semun {
  +                long val;
  +                struct semid_ds *buf;
  +                ushort *array;
  +            };
   #endif
  -    union semun ick;
  -    struct semid_ds buf;
  +            union semun ick;
  +            struct semid_ds buf;
  +        
  +            apr_os_proc_mutex_get(&ospmutex, pmutex);
  +            buf.sem_perm.uid = unixd_config.user_id;
  +            buf.sem_perm.gid = unixd_config.group_id;
  +            buf.sem_perm.mode = 0600;
  +            ick.buf = &buf;
  +            if (semctl(ospmutex.crossproc, 0, IPC_SET, ick) < 0) {
  +                return errno;
  +            }
  +        }
  +        break;
  +#endif
  +#if APR_HAS_FLOCK_SERIALIZE
  +        case APR_LOCK_FLOCK:
  +        {
  +            const char *lockfile = apr_proc_mutex_lockfile(pmutex);
   
  -    if (!geteuid()) {
  -        apr_os_proc_mutex_get(&ospmutex, pmutex);
  -        buf.sem_perm.uid = unixd_config.user_id;
  -        buf.sem_perm.gid = unixd_config.group_id;
  -        buf.sem_perm.mode = 0600;
  -        ick.buf = &buf;
  -        if (semctl(ospmutex.crossproc, 0, IPC_SET, ick) < 0) {
  -            return errno;
  +            if (lockfile) {
  +                if (chown(lockfile, unixd_config.user_id,
  +                          -1 /* no gid change */) < 0) {
  +                    return errno;
  +                }
  +            }
           }
  -    }
  +        break;
   #endif
  +        default:
  +            /* do nothing */
  +            break;
  +        }
  +    }
       return APR_SUCCESS;
   }
   
  
  
  
  1.38      +10 -0     httpd-2.0/os/unix/unixd.h
  
  Index: unixd.h
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/os/unix/unixd.h,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- unixd.h	3 Feb 2003 17:53:17 -0000	1.37
  +++ unixd.h	7 Jun 2003 19:50:01 -0000	1.38
  @@ -120,6 +120,16 @@
   AP_DECLARE(void) unixd_set_rlimit(cmd_parms *cmd, struct rlimit **plimit,
                              const char *arg, const char * arg2, int type);
   #endif
  +
  +/**
  + * One of the functions to set mutex permissions should be called in
  + * the parent process on platforms that switch identity when the 
  + * server is started as root.
  + * If the child init logic is performed before switching identity
  + * (e.g., MPM setup for an accept mutex), it should only be called
  + * for SysV semaphores.  Otherwise, it is safe to call it for all
  + * mutex types.
  + */
   AP_DECLARE(apr_status_t) unixd_set_proc_mutex_perms(apr_proc_mutex_t *pmutex);
   AP_DECLARE(apr_status_t) unixd_set_global_mutex_perms(apr_global_mutex_t *gmutex);
   AP_DECLARE(apr_status_t) unixd_accept(void **accepted, ap_listen_rec *lr, apr_pool_t *ptrans);