apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r1590617 - in /apr/apr/branches/1.6.x: ./ include/ include/arch/unix/ locks/beos/ locks/netware/ locks/os2/ locks/unix/ locks/win32/ shmem/beos/ shmem/os2/ shmem/unix/ shmem/win32/ threadproc/beos/ threadproc/netware/ threadproc/os2/ thread...
Date Mon, 28 Apr 2014 12:08:39 GMT
Author: jim
Date: Mon Apr 28 12:08:38 2014
New Revision: 1590617

URL: http://svn.apache.org/r1590617
Log:
Merge r741862, r741866 from trunk:

Add object perms set macros and implement them for shm and mutex
Submitted by: mturk, rpluem
Reviewed/backported by: jim

Added:
    apr/apr/branches/1.6.x/include/apr_perms_set.h
      - copied unchanged from r741862, apr/apr/trunk/include/apr_perms_set.h
Modified:
    apr/apr/branches/1.6.x/   (props changed)
    apr/apr/branches/1.6.x/CHANGES
    apr/apr/branches/1.6.x/include/apr_global_mutex.h
    apr/apr/branches/1.6.x/include/apr_proc_mutex.h
    apr/apr/branches/1.6.x/include/apr_shm.h
    apr/apr/branches/1.6.x/include/apr_thread_proc.h
    apr/apr/branches/1.6.x/include/arch/unix/apr_arch_proc_mutex.h
    apr/apr/branches/1.6.x/include/arch/unix/apr_arch_shm.h
    apr/apr/branches/1.6.x/include/arch/unix/apr_arch_threadproc.h
    apr/apr/branches/1.6.x/locks/beos/proc_mutex.c
    apr/apr/branches/1.6.x/locks/netware/proc_mutex.c
    apr/apr/branches/1.6.x/locks/os2/proc_mutex.c
    apr/apr/branches/1.6.x/locks/unix/global_mutex.c
    apr/apr/branches/1.6.x/locks/unix/proc_mutex.c
    apr/apr/branches/1.6.x/locks/win32/proc_mutex.c
    apr/apr/branches/1.6.x/shmem/beos/shm.c
    apr/apr/branches/1.6.x/shmem/os2/shm.c
    apr/apr/branches/1.6.x/shmem/unix/shm.c
    apr/apr/branches/1.6.x/shmem/win32/shm.c
    apr/apr/branches/1.6.x/threadproc/beos/proc.c
    apr/apr/branches/1.6.x/threadproc/netware/proc.c
    apr/apr/branches/1.6.x/threadproc/os2/proc.c
    apr/apr/branches/1.6.x/threadproc/unix/proc.c
    apr/apr/branches/1.6.x/threadproc/win32/proc.c

Propchange: apr/apr/branches/1.6.x/
------------------------------------------------------------------------------
  Merged /apr/apr/trunk:r741862,741866

Modified: apr/apr/branches/1.6.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/CHANGES?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/CHANGES [utf-8] (original)
+++ apr/apr/branches/1.6.x/CHANGES [utf-8] Mon Apr 28 12:08:38 2014
@@ -1,6 +1,11 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 1.6.0
 
+  *) Intruduce APR_PERMS_SET macros for setting the owner/group on
+     objects. Currently only implemented for shm, proc and global
+     mutexes on posix platforms.
+     [Mladen Turk]
+
   *) Add apr_escape_ldap() and apr_pescape_ldap(), escaping characters
      as described by RFC4514 and RFC4515 respectively. [Graham Leggett]
 

Modified: apr/apr/branches/1.6.x/include/apr_global_mutex.h
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/include/apr_global_mutex.h?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/include/apr_global_mutex.h (original)
+++ apr/apr/branches/1.6.x/include/apr_global_mutex.h Mon Apr 28 12:08:38 2014
@@ -135,6 +135,11 @@ APR_DECLARE(const char *) apr_global_mut
 APR_DECLARE(const char *) apr_global_mutex_name(apr_global_mutex_t *mutex);
 
 /**
+ * Set mutex permissions.
+ */
+APR_PERMS_SET_IMPLEMENT(global_mutex);
+
+/**
  * Get the pool used by this global_mutex.
  * @return apr_pool_t the pool
  */

Modified: apr/apr/branches/1.6.x/include/apr_proc_mutex.h
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/include/apr_proc_mutex.h?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/include/apr_proc_mutex.h (original)
+++ apr/apr/branches/1.6.x/include/apr_proc_mutex.h Mon Apr 28 12:08:38 2014
@@ -25,6 +25,7 @@
 #include "apr.h"
 #include "apr_pools.h"
 #include "apr_errno.h"
+#include "apr_perms_set.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -152,6 +153,11 @@ APR_DECLARE(const char *) apr_proc_mutex
 APR_DECLARE(const char *) apr_proc_mutex_defname(void);
 
 /**
+ * Set mutex permissions.
+ */
+APR_PERMS_SET_IMPLEMENT(proc_mutex);
+
+/**
  * Get the pool used by this proc_mutex.
  * @return apr_pool_t the pool
  */

Modified: apr/apr/branches/1.6.x/include/apr_shm.h
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/include/apr_shm.h?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/include/apr_shm.h (original)
+++ apr/apr/branches/1.6.x/include/apr_shm.h Mon Apr 28 12:08:38 2014
@@ -25,6 +25,7 @@
 #include "apr.h"
 #include "apr_pools.h"
 #include "apr_errno.h"
+#include "apr_perms_set.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -195,6 +196,11 @@ APR_DECLARE(void *) apr_shm_baseaddr_get
 APR_DECLARE(apr_size_t) apr_shm_size_get(const apr_shm_t *m);
 
 /**
+ * Set shared memory permissions.
+ */
+APR_PERMS_SET_IMPLEMENT(shm);
+
+/**
  * Get the pool used by this shared memory segment.
  */
 APR_POOL_DECLARE_ACCESSOR(shm);

Modified: apr/apr/branches/1.6.x/include/apr_thread_proc.h
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/include/apr_thread_proc.h?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/include/apr_thread_proc.h (original)
+++ apr/apr/branches/1.6.x/include/apr_thread_proc.h Mon Apr 28 12:08:38 2014
@@ -26,6 +26,7 @@
 #include "apr_file_io.h"
 #include "apr_pools.h"
 #include "apr_errno.h"
+#include "apr_perms_set.h"
 
 #if APR_HAVE_STRUCT_RLIMIT
 #include <sys/time.h>
@@ -579,6 +580,18 @@ APR_DECLARE(apr_status_t) apr_procattr_g
                                                  const char *groupname);
 
 
+/**
+ * Register permission set function
+ * @param attr The procattr we care about. 
+ * @param perms_set_fn Permission set callback
+ * @param data Data to pass to permission callback function
+ * @param perms Permissions to set
+ */
+APR_DECLARE(apr_status_t) apr_procattr_perms_set_register(apr_procattr_t *attr,
+                                                 apr_perms_setfn_t *perms_set_fn,
+                                                 void *data,
+                                                 apr_fileperms_t perms);
+
 #if APR_HAS_FORK
 /**
  * This is currently the only non-portable call in APR.  This executes 

Modified: apr/apr/branches/1.6.x/include/arch/unix/apr_arch_proc_mutex.h
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/include/arch/unix/apr_arch_proc_mutex.h?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/include/arch/unix/apr_arch_proc_mutex.h (original)
+++ apr/apr/branches/1.6.x/include/arch/unix/apr_arch_proc_mutex.h Mon Apr 28 12:08:38 2014
@@ -75,6 +75,7 @@ struct apr_proc_mutex_unix_lock_methods_
     apr_status_t (*release)(apr_proc_mutex_t *);
     apr_status_t (*cleanup)(void *);
     apr_status_t (*child_init)(apr_proc_mutex_t **, apr_pool_t *, const char *);
+    apr_status_t (*perms_set)(apr_proc_mutex_t *, apr_fileperms_t, apr_uid_t, apr_gid_t);
     const char *name;
 };
 typedef struct apr_proc_mutex_unix_lock_methods_t apr_proc_mutex_unix_lock_methods_t;

Modified: apr/apr/branches/1.6.x/include/arch/unix/apr_arch_shm.h
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/include/arch/unix/apr_arch_shm.h?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/include/arch/unix/apr_arch_shm.h (original)
+++ apr/apr/branches/1.6.x/include/arch/unix/apr_arch_shm.h Mon Apr 28 12:08:38 2014
@@ -67,6 +67,7 @@ struct apr_shm_t {
     const char *filename;      /* NULL if anonymous */
 #if APR_USE_SHMEM_SHMGET || APR_USE_SHMEM_SHMGET_ANON
     int shmid;          /* shmem ID returned from shmget() */
+    key_t shmkey;       /* shmem key IPC_ANON or returned from ftok() */
 #endif
 };
 

Modified: apr/apr/branches/1.6.x/include/arch/unix/apr_arch_threadproc.h
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/include/arch/unix/apr_arch_threadproc.h?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/include/arch/unix/apr_arch_threadproc.h (original)
+++ apr/apr/branches/1.6.x/include/arch/unix/apr_arch_threadproc.h Mon Apr 28 12:08:38 2014
@@ -19,6 +19,7 @@
 #include "apr_thread_proc.h"
 #include "apr_file_io.h"
 #include "apr_arch_file_io.h"
+#include "apr_perms_set.h"
 
 /* System headers required for thread/process library */
 #if APR_HAVE_PTHREAD_H
@@ -76,6 +77,14 @@ struct apr_thread_once_t {
 
 #endif
 
+typedef struct apr_procattr_pscb_t apr_procattr_pscb_t;
+struct apr_procattr_pscb_t {
+    struct apr_procattr_pscb_t *next;
+    apr_perms_setfn_t *perms_set_fn;
+    apr_fileperms_t perms;
+    const void *data;
+};
+
 struct apr_procattr_t {
     apr_pool_t *pool;
     apr_file_t *parent_in;
@@ -103,6 +112,7 @@ struct apr_procattr_t {
     apr_int32_t errchk;
     apr_uid_t   uid;
     apr_gid_t   gid;
+    apr_procattr_pscb_t *perms_set_callbacks;
 };
 
 #endif  /* ! THREAD_PROC_H */

Modified: apr/apr/branches/1.6.x/locks/beos/proc_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/locks/beos/proc_mutex.c?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/locks/beos/proc_mutex.c (original)
+++ apr/apr/branches/1.6.x/locks/beos/proc_mutex.c Mon Apr 28 12:08:38 2014
@@ -140,6 +140,8 @@ APR_DECLARE(const char *) apr_proc_mutex
     return "beossem";
 }
 
+APR_PERMS_SET_ENOTIMPL(proc_mutex)
+
 APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex)
 
 /* Implement OS-specific accessors defined in apr_portable.h */

Modified: apr/apr/branches/1.6.x/locks/netware/proc_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/locks/netware/proc_mutex.c?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/locks/netware/proc_mutex.c (original)
+++ apr/apr/branches/1.6.x/locks/netware/proc_mutex.c Mon Apr 28 12:08:38 2014
@@ -97,6 +97,8 @@ APR_DECLARE(const char *) apr_proc_mutex
     return "netwarethread";
 }
 
+APR_PERMS_SET_ENOTIMPL(proc_mutex)
+
 APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex)
 
 /* Implement OS-specific accessors defined in apr_portable.h */

Modified: apr/apr/branches/1.6.x/locks/os2/proc_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/locks/os2/proc_mutex.c?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/locks/os2/proc_mutex.c (original)
+++ apr/apr/branches/1.6.x/locks/os2/proc_mutex.c Mon Apr 28 12:08:38 2014
@@ -199,7 +199,7 @@ APR_DECLARE(apr_status_t) apr_proc_mutex
     return APR_FROM_OS_ERROR(rc);
 }
 
-
+APR_PERMS_SET_ENOTIMPL(proc_mutex)
 
 APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex)
 

Modified: apr/apr/branches/1.6.x/locks/unix/global_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/locks/unix/global_mutex.c?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/locks/unix/global_mutex.c (original)
+++ apr/apr/branches/1.6.x/locks/unix/global_mutex.c Mon Apr 28 12:08:38 2014
@@ -185,4 +185,13 @@ APR_DECLARE(const char *) apr_global_mut
     return apr_proc_mutex_name(mutex->proc_mutex);
 }
 
+APR_PERMS_SET_IMPLEMENT(global_mutex)
+{
+    apr_status_t rv;
+    apr_global_mutex_t *mutex = (apr_global_mutex_t *)theglobal_mutex;
+
+    rv = apr_proc_mutex_set_perms(mutex->proc_mutex, perms, uid, gid);
+    return rv;
+}
+
 APR_POOL_IMPLEMENT_ACCESSOR(global_mutex)

Modified: apr/apr/branches/1.6.x/locks/unix/proc_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/locks/unix/proc_mutex.c?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/locks/unix/proc_mutex.c (original)
+++ apr/apr/branches/1.6.x/locks/unix/proc_mutex.c Mon Apr 28 12:08:38 2014
@@ -35,6 +35,17 @@ static apr_status_t proc_mutex_no_child_
 }
 #endif    
 
+#if APR_HAS_POSIXSEM_SERIALIZE || APR_HAS_PROC_PTHREAD_SERIALIZE
+static apr_status_t proc_mutex_no_perms_set(apr_proc_mutex_t *mutex,
+                                            apr_fileperms_t perms,
+                                            apr_uid_t uid,
+                                            apr_gid_t gid)
+{
+    return APR_ENOTIMPL;
+}
+#endif    
+
+
 #if APR_HAS_POSIXSEM_SERIALIZE
 
 #ifndef SEM_FAILED
@@ -183,6 +194,7 @@ static const apr_proc_mutex_unix_lock_me
     proc_mutex_posix_release,
     proc_mutex_posix_cleanup,
     proc_mutex_no_child_init,
+    proc_mutex_no_perms_set,
     "posixsem"
 };
 
@@ -291,6 +303,24 @@ static apr_status_t proc_mutex_sysv_rele
     return APR_SUCCESS;
 }
 
+static apr_status_t proc_mutex_sysv_perms_set(apr_proc_mutex_t *mutex,
+                                              apr_fileperms_t perms,
+                                              apr_uid_t uid,
+                                              apr_gid_t gid)
+{
+
+    union semun ick;
+    struct semid_ds buf;
+    buf.sem_perm.uid = uid;
+    buf.sem_perm.gid = gid;
+    buf.sem_perm.mode = apr_unix_perms2mode(perms);
+    ick.buf = &buf;
+    if (semctl(mutex->interproc->filedes, 0, IPC_SET, ick) < 0) {
+        return errno;
+    }
+    return APR_SUCCESS;
+}
+
 static const apr_proc_mutex_unix_lock_methods_t mutex_sysv_methods =
 {
 #if APR_PROCESS_LOCK_IS_GLOBAL || !APR_HAS_THREADS || defined(SYSVSEM_IS_GLOBAL)
@@ -304,6 +334,7 @@ static const apr_proc_mutex_unix_lock_me
     proc_mutex_sysv_release,
     proc_mutex_sysv_cleanup,
     proc_mutex_no_child_init,
+    proc_mutex_sysv_perms_set,
     "sysvsem"
 };
 
@@ -499,6 +530,7 @@ static const apr_proc_mutex_unix_lock_me
     proc_mutex_proc_pthread_release,
     proc_mutex_proc_pthread_cleanup,
     proc_mutex_no_child_init,
+    proc_mutex_no_perms_set,
     "pthread"
 };
 
@@ -620,6 +652,22 @@ static apr_status_t proc_mutex_fcntl_rel
     return APR_SUCCESS;
 }
 
+static apr_status_t proc_mutex_fcntl_perms_set(apr_proc_mutex_t *mutex,
+                                               apr_fileperms_t perms,
+                                               apr_uid_t uid,
+                                               apr_gid_t gid)
+{
+
+    if (mutex->fname) {
+        if (!(perms & APR_FPROT_GSETID))
+            gid = -1;
+        if (fchown(mutex->interproc->filedes, uid, gid) < 0) {
+            return errno;
+        }
+    }
+    return APR_SUCCESS;
+}
+
 static const apr_proc_mutex_unix_lock_methods_t mutex_fcntl_methods =
 {
 #if APR_PROCESS_LOCK_IS_GLOBAL || !APR_HAS_THREADS || defined(FCNTL_IS_GLOBAL)
@@ -633,6 +681,7 @@ static const apr_proc_mutex_unix_lock_me
     proc_mutex_fcntl_release,
     proc_mutex_fcntl_cleanup,
     proc_mutex_no_child_init,
+    proc_mutex_fcntl_perms_set,
     "fcntl"
 };
 
@@ -758,6 +807,22 @@ static apr_status_t proc_mutex_flock_chi
     return APR_SUCCESS;
 }
 
+static apr_status_t proc_mutex_flock_perms_set(apr_proc_mutex_t *mutex,
+                                               apr_fileperms_t perms,
+                                               apr_uid_t uid,
+                                               apr_gid_t gid)
+{
+
+    if (mutex->fname) {
+        if (!(perms & APR_FPROT_GSETID))
+            gid = -1;
+        if (fchown(mutex->interproc->filedes, uid, gid) < 0) {
+            return errno;
+        }
+    }
+    return APR_SUCCESS;
+}
+
 static const apr_proc_mutex_unix_lock_methods_t mutex_flock_methods =
 {
 #if APR_PROCESS_LOCK_IS_GLOBAL || !APR_HAS_THREADS || defined(FLOCK_IS_GLOBAL)
@@ -771,6 +836,7 @@ static const apr_proc_mutex_unix_lock_me
     proc_mutex_flock_release,
     proc_mutex_flock_cleanup,
     proc_mutex_flock_child_init,
+    proc_mutex_flock_perms_set,
     "flock"
 };
 
@@ -943,6 +1009,12 @@ APR_DECLARE(const char *) apr_proc_mutex
     return NULL;
 }
 
+APR_PERMS_SET_IMPLEMENT(proc_mutex)
+{
+    apr_proc_mutex_t *mutex = (apr_proc_mutex_t *)theproc_mutex;
+    return mutex->meth->perms_set(mutex, perms, uid, gid);
+}
+
 APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex)
 
 /* Implement OS-specific accessors defined in apr_portable.h */

Modified: apr/apr/branches/1.6.x/locks/win32/proc_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/locks/win32/proc_mutex.c?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/locks/win32/proc_mutex.c (original)
+++ apr/apr/branches/1.6.x/locks/win32/proc_mutex.c Mon Apr 28 12:08:38 2014
@@ -199,6 +199,8 @@ APR_DECLARE(const char *) apr_proc_mutex
     return "win32mutex";
 }
 
+APR_PERMS_SET_ENOTIMPL(proc_mutex)
+
 APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex)
 
 /* Implement OS-specific accessors defined in apr_portable.h */

Modified: apr/apr/branches/1.6.x/shmem/beos/shm.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/shmem/beos/shm.c?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/shmem/beos/shm.c (original)
+++ apr/apr/branches/1.6.x/shmem/beos/shm.c Mon Apr 28 12:08:38 2014
@@ -166,6 +166,8 @@ APR_DECLARE(apr_size_t) apr_shm_size_get
     return m->reqsize;
 }
 
+APR_PERMS_SET_ENOTIMPL(shm)
+
 APR_POOL_IMPLEMENT_ACCESSOR(shm)
 
 APR_DECLARE(apr_status_t) apr_os_shm_get(apr_os_shm_t *osshm,

Modified: apr/apr/branches/1.6.x/shmem/os2/shm.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/shmem/os2/shm.c?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/shmem/os2/shm.c (original)
+++ apr/apr/branches/1.6.x/shmem/os2/shm.c Mon Apr 28 12:08:38 2014
@@ -130,6 +130,8 @@ APR_DECLARE(apr_size_t) apr_shm_size_get
     return size;
 }
 
+APR_PERMS_SET_ENOTIMPL(shm)
+
 APR_POOL_IMPLEMENT_ACCESSOR(shm)
 
 APR_DECLARE(apr_status_t) apr_os_shm_get(apr_os_shm_t *osshm,

Modified: apr/apr/branches/1.6.x/shmem/unix/shm.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/shmem/unix/shm.c?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/shmem/unix/shm.c (original)
+++ apr/apr/branches/1.6.x/shmem/unix/shm.c Mon Apr 28 12:08:38 2014
@@ -158,7 +158,6 @@ APR_DECLARE(apr_status_t) apr_shm_create
 #endif
 #if APR_USE_SHMEM_SHMGET
     apr_size_t nbytes;
-    key_t shmkey;
 #endif
 #if APR_USE_SHMEM_MMAP_ZERO || APR_USE_SHMEM_SHMGET || \
     APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM
@@ -231,8 +230,8 @@ APR_DECLARE(apr_status_t) apr_shm_create
         new_m->reqsize = reqsize;
         new_m->realsize = reqsize;
         new_m->filename = NULL;
-
-        if ((new_m->shmid = shmget(IPC_PRIVATE, new_m->realsize,
+        new_m->shmkey = IPC_PRIVATE;
+        if ((new_m->shmid = shmget(new_m->shmkey, new_m->realsize,
                                    SHM_R | SHM_W | IPC_CREAT)) < 0) {
             return errno;
         }
@@ -371,13 +370,13 @@ APR_DECLARE(apr_status_t) apr_shm_create
 
         /* ftok() (on solaris at least) requires that the file actually
          * exist before calling ftok(). */
-        shmkey = our_ftok(filename);
-        if (shmkey == (key_t)-1) {
+        new_m->shmkey = our_ftok(filename);
+        if (new_m->shmkey == (key_t)-1) {
             apr_file_close(file);
             return errno;
         }
 
-        if ((new_m->shmid = shmget(shmkey, new_m->realsize,
+        if ((new_m->shmid = shmget(new_m->shmkey, new_m->realsize,
                                    SHM_R | SHM_W | IPC_CREAT | IPC_EXCL)) < 0) {
             apr_file_close(file);
             return errno;
@@ -611,7 +610,6 @@ APR_DECLARE(apr_status_t) apr_shm_attach
         apr_status_t status;
         apr_file_t *file;   /* file where metadata is stored */
         apr_size_t nbytes;
-        key_t shmkey;
 
         new_m = apr_palloc(pool, sizeof(apr_shm_t));
 
@@ -634,11 +632,11 @@ APR_DECLARE(apr_status_t) apr_shm_attach
 
         new_m->filename = apr_pstrdup(pool, filename);
         new_m->pool = pool;
-        shmkey = our_ftok(filename);
-        if (shmkey == (key_t)-1) {
+        new_m->shmkey = our_ftok(filename);
+        if (new_m->shmkey == (key_t)-1) {
             return errno;
         }
-        if ((new_m->shmid = shmget(shmkey, 0, SHM_R | SHM_W)) == -1) {
+        if ((new_m->shmid = shmget(new_m->shmkey, 0, SHM_R | SHM_W)) == -1) {
             return errno;
         }
         if ((new_m->base = shmat(new_m->shmid, NULL, 0)) == (void *)-1) {
@@ -683,6 +681,28 @@ APR_DECLARE(apr_size_t) apr_shm_size_get
     return m->reqsize;
 }
 
+APR_PERMS_SET_IMPLEMENT(shm)
+{
+#if APR_USE_SHMEM_SHMGET || APR_USE_SHMEM_SHMGET_ANON
+    struct shmid_ds shmbuf;
+    int shmid;
+    apr_shm_t *m = (apr_shm_t *)theshm;
+
+    if ((shmid = shmget(m->shmkey, 0, SHM_R | SHM_W)) == -1) {
+        return errno;
+    }
+    shmbuf.shm_perm.uid  = uid;
+    shmbuf.shm_perm.gid  = gid;
+    shmbuf.shm_perm.mode = apr_unix_perms2mode(perms);
+    if (shmctl(shmid, IPC_SET, &shmbuf) == -1) {
+        return errno;
+    }
+    return APR_SUCCESS;
+#else
+    return APR_ENOTIMPL;
+#endif
+}
+
 APR_POOL_IMPLEMENT_ACCESSOR(shm)
 
 APR_DECLARE(apr_status_t) apr_os_shm_get(apr_os_shm_t *osshm,

Modified: apr/apr/branches/1.6.x/shmem/win32/shm.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/shmem/win32/shm.c?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/shmem/win32/shm.c (original)
+++ apr/apr/branches/1.6.x/shmem/win32/shm.c Mon Apr 28 12:08:38 2014
@@ -404,6 +404,8 @@ APR_DECLARE(apr_size_t) apr_shm_size_get
     return m->length;
 }
 
+APR_PERMS_SET_ENOTIMPL(shm)
+
 APR_POOL_IMPLEMENT_ACCESSOR(shm)
 
 APR_DECLARE(apr_status_t) apr_os_shm_get(apr_os_shm_t *osshm,

Modified: apr/apr/branches/1.6.x/threadproc/beos/proc.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/threadproc/beos/proc.c?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/threadproc/beos/proc.c (original)
+++ apr/apr/branches/1.6.x/threadproc/beos/proc.c Mon Apr 28 12:08:38 2014
@@ -444,3 +444,11 @@ APR_DECLARE(apr_status_t) apr_procattr_g
 {
     return APR_ENOTIMPL;
 }
+
+APR_DECLARE(apr_status_t) apr_procattr_perms_set_register(apr_procattr_t *attr,
+                                                 apr_perms_setfn_t *perms_set_fn,
+                                                 void *data,
+                                                 apr_fileperms_t perms)
+{
+    return APR_ENOTIMPL;
+}

Modified: apr/apr/branches/1.6.x/threadproc/netware/proc.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/threadproc/netware/proc.c?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/threadproc/netware/proc.c (original)
+++ apr/apr/branches/1.6.x/threadproc/netware/proc.c Mon Apr 28 12:08:38 2014
@@ -505,3 +505,11 @@ APR_DECLARE(apr_status_t) apr_procattr_g
     /* Always return SUCCESS because NetWare threads don't run within a group */
     return APR_SUCCESS;
 }
+
+APR_DECLARE(apr_status_t) apr_procattr_perms_set_register(apr_procattr_t *attr,
+                                                 apr_perms_setfn_t *perms_set_fn,
+                                                 void *data,
+                                                 apr_fileperms_t perms)
+{
+    return APR_ENOTIMPL;
+}

Modified: apr/apr/branches/1.6.x/threadproc/os2/proc.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/threadproc/os2/proc.c?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/threadproc/os2/proc.c (original)
+++ apr/apr/branches/1.6.x/threadproc/os2/proc.c Mon Apr 28 12:08:38 2014
@@ -662,3 +662,11 @@ APR_DECLARE(apr_status_t) apr_procattr_g
 {
     return APR_ENOTIMPL;
 }
+
+APR_DECLARE(apr_status_t) apr_procattr_perms_set_register(apr_procattr_t *attr,
+                                                 apr_perms_setfn_t *perms_set_fn,
+                                                 void *data,
+                                                 apr_fileperms_t perms)
+{
+    return APR_ENOTIMPL;
+}

Modified: apr/apr/branches/1.6.x/threadproc/unix/proc.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/threadproc/unix/proc.c?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/threadproc/unix/proc.c (original)
+++ apr/apr/branches/1.6.x/threadproc/unix/proc.c Mon Apr 28 12:08:38 2014
@@ -461,7 +461,19 @@ APR_DECLARE(apr_status_t) apr_proc_creat
                 _exit(-1);   /* We have big problems, the child should exit. */
             }
         }
+        if (!geteuid()) {
+            apr_procattr_pscb_t *c = attr->perms_set_callbacks;
 
+            while (c) {
+                apr_status_t r;
+                r = (*c->perms_set_fn)((void *)c->data, c->perms,
+                                       attr->uid, attr->gid);
+                if (r != APR_SUCCESS || r != APR_ENOTIMPL) {
+                    _exit(-1);
+                }
+                c = c->next;
+            }
+        }
         /* Only try to switch if we are running as root */
         if (attr->gid != -1 && !geteuid()) {
             if (setgid(attr->gid)) {
@@ -709,3 +721,19 @@ APR_DECLARE(apr_status_t) apr_procattr_l
 }
 #endif /* APR_HAVE_STRUCT_RLIMIT */
 
+APR_DECLARE(apr_status_t) apr_procattr_perms_set_register(apr_procattr_t *attr,
+                                                 apr_perms_setfn_t *perms_set_fn,
+                                                 void *data,
+                                                 apr_fileperms_t perms)
+{
+    apr_procattr_pscb_t *c;
+
+    c = apr_palloc(attr->pool, sizeof(apr_procattr_pscb_t));
+    c->data = data;
+    c->perms = perms;
+    c->perms_set_fn = perms_set_fn;
+    c->next = attr->perms_set_callbacks;
+    attr->perms_set_callbacks = c;
+
+    return APR_SUCCESS;
+}

Modified: apr/apr/branches/1.6.x/threadproc/win32/proc.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/threadproc/win32/proc.c?rev=1590617&r1=1590616&r2=1590617&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/threadproc/win32/proc.c (original)
+++ apr/apr/branches/1.6.x/threadproc/win32/proc.c Mon Apr 28 12:08:38 2014
@@ -1148,3 +1148,11 @@ APR_DECLARE(apr_status_t) apr_proc_detac
 {
     return APR_ENOTIMPL;
 }
+
+APR_DECLARE(apr_status_t) apr_procattr_perms_set_register(apr_procattr_t *attr,
+                                                 apr_perms_setfn_t *perms_set_fn,
+                                                 void *data,
+                                                 apr_fileperms_t perms)
+{
+    return APR_ENOTIMPL;
+}



Mime
View raw message