Return-Path: Delivered-To: apmail-apr-commits-archive@www.apache.org Received: (qmail 4094 invoked from network); 7 Feb 2009 09:06:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Feb 2009 09:06:22 -0000 Received: (qmail 16456 invoked by uid 500); 7 Feb 2009 09:06:22 -0000 Delivered-To: apmail-apr-commits-archive@apr.apache.org Received: (qmail 16422 invoked by uid 500); 7 Feb 2009 09:06:22 -0000 Mailing-List: contact commits-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: Reply-To: dev@apr.apache.org List-Id: Delivered-To: mailing list commits@apr.apache.org Received: (qmail 16413 invoked by uid 99); 7 Feb 2009 09:06:22 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Feb 2009 01:06:22 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Feb 2009 09:06:18 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7E199238887D; Sat, 7 Feb 2009 09:05:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r741862 - in /apr/apr/trunk: ./ 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/ threadproc/unix/... Date: Sat, 07 Feb 2009 09:05:55 -0000 To: commits@apr.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090207090556.7E199238887D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mturk Date: Sat Feb 7 09:05:54 2009 New Revision: 741862 URL: http://svn.apache.org/viewvc?rev=741862&view=rev Log: Add object perms set macros and implement them for shm and mutex Added: apr/apr/trunk/include/apr_perms_set.h (with props) Modified: apr/apr/trunk/CHANGES apr/apr/trunk/include/apr_global_mutex.h apr/apr/trunk/include/apr_proc_mutex.h apr/apr/trunk/include/apr_shm.h apr/apr/trunk/include/apr_thread_proc.h apr/apr/trunk/include/arch/unix/apr_arch_proc_mutex.h apr/apr/trunk/include/arch/unix/apr_arch_shm.h apr/apr/trunk/include/arch/unix/apr_arch_threadproc.h apr/apr/trunk/locks/beos/proc_mutex.c apr/apr/trunk/locks/netware/proc_mutex.c apr/apr/trunk/locks/os2/proc_mutex.c apr/apr/trunk/locks/unix/global_mutex.c apr/apr/trunk/locks/unix/proc_mutex.c apr/apr/trunk/locks/win32/proc_mutex.c apr/apr/trunk/shmem/beos/shm.c apr/apr/trunk/shmem/os2/shm.c apr/apr/trunk/shmem/unix/shm.c apr/apr/trunk/shmem/win32/shm.c apr/apr/trunk/threadproc/beos/proc.c apr/apr/trunk/threadproc/netware/proc.c apr/apr/trunk/threadproc/os2/proc.c apr/apr/trunk/threadproc/unix/proc.c apr/apr/trunk/threadproc/win32/proc.c Modified: apr/apr/trunk/CHANGES URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/CHANGES [utf-8] (original) +++ apr/apr/trunk/CHANGES [utf-8] Sat Feb 7 09:05:54 2009 @@ -1,6 +1,11 @@ -*- coding: utf-8 -*- Changes for APR 2.0.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] + Changes for APR 1.4.0 *) Win32: Do not error out on apr_pollset_poll() when there are no sockets. Modified: apr/apr/trunk/include/apr_global_mutex.h URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_global_mutex.h?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/include/apr_global_mutex.h (original) +++ apr/apr/trunk/include/apr_global_mutex.h Sat Feb 7 09:05:54 2009 @@ -121,6 +121,11 @@ APR_DECLARE(apr_status_t) apr_global_mutex_destroy(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 */ Added: apr/apr/trunk/include/apr_perms_set.h URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_perms_set.h?rev=741862&view=auto ============================================================================== --- apr/apr/trunk/include/apr_perms_set.h (added) +++ apr/apr/trunk/include/apr_perms_set.h Sat Feb 7 09:05:54 2009 @@ -0,0 +1,65 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef APR_PERMS_SET_H +#define APR_PERMS_SET_H + +/** + * @file apr_perms_set.h + * @brief APR Process Locking Routines + */ + +#include "apr.h" +#include "apr_pools.h" +#include "apr_errno.h" +#include "apr_user.h" +#include "apr_file_info.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @defgroup apr_perms_set Object permission set functions + * @ingroup APR + * @{ + */ + +/** Permission set callback function. */ +typedef apr_status_t (apr_perms_setfn_t)(void *object, apr_fileperms_t perms, + apr_uid_t uid, apr_gid_t gid); + +#define APR_PERMS_SET_IMPLEMENT(type) \ + APR_DECLARE(apr_status_t) apr_##type##_perms_set \ + (void *the##type, apr_fileperms_t perms, \ + apr_uid_t uid, apr_gid_t gid) + +#define APR_PERMS_SET_ENOTIMPL(type) \ + APR_DECLARE(apr_status_t) apr_##type##_perms_set \ + (void *the##type, apr_fileperms_t perms, \ + apr_uid_t uid, apr_gid_t gid) \ + { return APR_ENOTIMPL ; } + +#define APR_PERMS_SET_FN(type) apr_##type##_perms_set + + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* ! APR_PERMS_SET */ Propchange: apr/apr/trunk/include/apr_perms_set.h ------------------------------------------------------------------------------ svn:eol-style = native Modified: apr/apr/trunk/include/apr_proc_mutex.h URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_proc_mutex.h?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/include/apr_proc_mutex.h (original) +++ apr/apr/trunk/include/apr_proc_mutex.h Sat Feb 7 09:05:54 2009 @@ -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_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/trunk/include/apr_shm.h URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_shm.h?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/include/apr_shm.h (original) +++ apr/apr/trunk/include/apr_shm.h Sat Feb 7 09:05:54 2009 @@ -25,6 +25,7 @@ #include "apr.h" #include "apr_pools.h" #include "apr_errno.h" +#include "apr_perms_set.h" #ifdef __cplusplus extern "C" { @@ -133,6 +134,11 @@ 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/trunk/include/apr_thread_proc.h URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_thread_proc.h?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/include/apr_thread_proc.h (original) +++ apr/apr/trunk/include/apr_thread_proc.h Sat Feb 7 09:05:54 2009 @@ -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 @@ -577,6 +578,18 @@ 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/trunk/include/arch/unix/apr_arch_proc_mutex.h URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/arch/unix/apr_arch_proc_mutex.h?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/include/arch/unix/apr_arch_proc_mutex.h (original) +++ apr/apr/trunk/include/arch/unix/apr_arch_proc_mutex.h Sat Feb 7 09:05:54 2009 @@ -75,6 +75,7 @@ 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/trunk/include/arch/unix/apr_arch_shm.h URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/arch/unix/apr_arch_shm.h?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/include/arch/unix/apr_arch_shm.h (original) +++ apr/apr/trunk/include/arch/unix/apr_arch_shm.h Sat Feb 7 09:05:54 2009 @@ -67,6 +67,7 @@ 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/trunk/include/arch/unix/apr_arch_threadproc.h URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/arch/unix/apr_arch_threadproc.h?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/include/arch/unix/apr_arch_threadproc.h (original) +++ apr/apr/trunk/include/arch/unix/apr_arch_threadproc.h Sat Feb 7 09:05:54 2009 @@ -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 @@ #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 @@ 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/trunk/locks/beos/proc_mutex.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/beos/proc_mutex.c?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/locks/beos/proc_mutex.c (original) +++ apr/apr/trunk/locks/beos/proc_mutex.c Sat Feb 7 09:05:54 2009 @@ -140,6 +140,8 @@ 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/trunk/locks/netware/proc_mutex.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/netware/proc_mutex.c?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/locks/netware/proc_mutex.c (original) +++ apr/apr/trunk/locks/netware/proc_mutex.c Sat Feb 7 09:05:54 2009 @@ -97,6 +97,8 @@ 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/trunk/locks/os2/proc_mutex.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/os2/proc_mutex.c?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/locks/os2/proc_mutex.c (original) +++ apr/apr/trunk/locks/os2/proc_mutex.c Sat Feb 7 09:05:54 2009 @@ -199,7 +199,7 @@ return APR_FROM_OS_ERROR(rc); } - +APR_PERMS_SET_ENOTIMPL(proc_mutex) APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex) Modified: apr/apr/trunk/locks/unix/global_mutex.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/unix/global_mutex.c?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/locks/unix/global_mutex.c (original) +++ apr/apr/trunk/locks/unix/global_mutex.c Sat Feb 7 09:05:54 2009 @@ -175,4 +175,13 @@ return apr_pool_cleanup_run(mutex->pool, mutex, global_mutex_cleanup); } +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/trunk/locks/unix/proc_mutex.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/unix/proc_mutex.c?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/locks/unix/proc_mutex.c (original) +++ apr/apr/trunk/locks/unix/proc_mutex.c Sat Feb 7 09:05:54 2009 @@ -34,6 +34,17 @@ } #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 @@ -155,6 +166,7 @@ proc_mutex_posix_release, proc_mutex_posix_cleanup, proc_mutex_no_child_init, + proc_mutex_no_perms_set, "posixsem" }; @@ -263,6 +275,24 @@ 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) @@ -276,6 +306,7 @@ proc_mutex_sysv_release, proc_mutex_sysv_cleanup, proc_mutex_no_child_init, + proc_mutex_sysv_perms_set, "sysvsem" }; @@ -471,6 +502,7 @@ proc_mutex_proc_pthread_release, proc_mutex_proc_pthread_cleanup, proc_mutex_no_child_init, + proc_mutex_no_perms_set, "pthread" }; @@ -592,6 +624,22 @@ 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) @@ -605,6 +653,7 @@ proc_mutex_fcntl_release, proc_mutex_fcntl_cleanup, proc_mutex_no_child_init, + proc_mutex_fcntl_perms_set, "fcntl" }; @@ -730,6 +779,22 @@ 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) @@ -743,6 +808,7 @@ proc_mutex_flock_release, proc_mutex_flock_cleanup, proc_mutex_flock_child_init, + proc_mutex_flock_perms_set, "flock" }; @@ -915,6 +981,12 @@ 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/trunk/locks/win32/proc_mutex.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/win32/proc_mutex.c?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/locks/win32/proc_mutex.c (original) +++ apr/apr/trunk/locks/win32/proc_mutex.c Sat Feb 7 09:05:54 2009 @@ -199,6 +199,8 @@ 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/trunk/shmem/beos/shm.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/shmem/beos/shm.c?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/shmem/beos/shm.c (original) +++ apr/apr/trunk/shmem/beos/shm.c Sat Feb 7 09:05:54 2009 @@ -149,6 +149,8 @@ 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/trunk/shmem/os2/shm.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/shmem/os2/shm.c?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/shmem/os2/shm.c (original) +++ apr/apr/trunk/shmem/os2/shm.c Sat Feb 7 09:05:54 2009 @@ -113,6 +113,8 @@ 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/trunk/shmem/unix/shm.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/shmem/unix/shm.c?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/shmem/unix/shm.c (original) +++ apr/apr/trunk/shmem/unix/shm.c Sat Feb 7 09:05:54 2009 @@ -105,7 +105,6 @@ #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 @@ -180,8 +179,8 @@ 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; } @@ -318,12 +317,12 @@ /* ftok() (on solaris at least) requires that the file actually * exist before calling ftok(). */ - shmkey = ftok(filename, 1); - if (shmkey == (key_t)-1) { + new_m->shmkey = ftok(filename, 1); + if (new_m->shmkey == (key_t)-1) { 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) { return errno; } @@ -526,7 +525,6 @@ 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)); @@ -549,11 +547,11 @@ new_m->filename = apr_pstrdup(pool, filename); new_m->pool = pool; - shmkey = ftok(filename, 1); - if (shmkey == (key_t)-1) { + new_m->shmkey = ftok(filename, 1); + 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) { @@ -590,6 +588,28 @@ 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/trunk/shmem/win32/shm.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/shmem/win32/shm.c?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/shmem/win32/shm.c (original) +++ apr/apr/trunk/shmem/win32/shm.c Sat Feb 7 09:05:54 2009 @@ -281,6 +281,8 @@ 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/trunk/threadproc/beos/proc.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/threadproc/beos/proc.c?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/threadproc/beos/proc.c (original) +++ apr/apr/trunk/threadproc/beos/proc.c Sat Feb 7 09:05:54 2009 @@ -443,3 +443,11 @@ { 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/trunk/threadproc/netware/proc.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/threadproc/netware/proc.c?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/threadproc/netware/proc.c (original) +++ apr/apr/trunk/threadproc/netware/proc.c Sat Feb 7 09:05:54 2009 @@ -491,3 +491,11 @@ /* 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/trunk/threadproc/os2/proc.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/threadproc/os2/proc.c?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/threadproc/os2/proc.c (original) +++ apr/apr/trunk/threadproc/os2/proc.c Sat Feb 7 09:05:54 2009 @@ -662,3 +662,11 @@ { 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/trunk/threadproc/unix/proc.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/threadproc/unix/proc.c?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/threadproc/unix/proc.c (original) +++ apr/apr/trunk/threadproc/unix/proc.c Sat Feb 7 09:05:54 2009 @@ -463,7 +463,19 @@ _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 ((status = setgid(attr->gid))) { @@ -708,3 +720,20 @@ 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) +{ + 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/trunk/threadproc/win32/proc.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/threadproc/win32/proc.c?rev=741862&r1=741861&r2=741862&view=diff ============================================================================== --- apr/apr/trunk/threadproc/win32/proc.c (original) +++ apr/apr/trunk/threadproc/win32/proc.c Sat Feb 7 09:05:54 2009 @@ -1147,3 +1147,11 @@ { 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; +}