unixd.c revision e8096947315bbea272fb0e37e89c723dbb1d422f
842ae4bd224140319ae7feec1872b93dfd491143fielding/* Copyright 1999-2004 The Apache Software Foundation
842ae4bd224140319ae7feec1872b93dfd491143fielding * Licensed under the Apache License, Version 2.0 (the "License");
842ae4bd224140319ae7feec1872b93dfd491143fielding * you may not use this file except in compliance with the License.
842ae4bd224140319ae7feec1872b93dfd491143fielding * You may obtain a copy of the License at
dc9d4f49d36e64c0157d930cb22ca82a6291c0cbdgaudet * Unless required by applicable law or agreed to in writing, software
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * distributed under the License is distributed on an "AS IS" BASIS,
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * See the License for the specific language governing permissions and
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * limitations under the License.
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm/* Set group privileges.
28ce4a9baa76e678af814ec56aecaeeff7665f35trawick * Note that we use the username as set in the config files, rather than
28ce4a9baa76e678af814ec56aecaeeff7665f35trawick * the lookup of to uid --- the same uid may have multiple passwd entries,
28ce4a9baa76e678af814ec56aecaeeff7665f35trawick * with different sets of groups for each.
6e954603b02f2b7d4ad80af17d9b3cc6f0bacf69rbbstatic int set_group_privs(void)
742318b93e89c311f66b55f426c4d9cf2c14628bjim const char *name;
283cab4ec4c440fe33ce47778d85b1208e169a87manoj /* Get username if passed as a uid */
dc9d4f49d36e64c0157d930cb22ca82a6291c0cbdgaudet "getpwuid: couldn't determine user name from uid %u, "
8a944f317ca393b84b03922a1eee0910cbd55aa3rbb "you probably need to modify the User directive",
8a944f317ca393b84b03922a1eee0910cbd55aa3rbb (unsigned)uid);
8a944f317ca393b84b03922a1eee0910cbd55aa3rbb return -1;
43f284aaf6c7a7753395bbe4f846bee9cd6a7cd2pquerna /* OS/2 and TPF don't support groups. */
8a944f317ca393b84b03922a1eee0910cbd55aa3rbb * Set the GID before initgroups(), since on some platforms
8a944f317ca393b84b03922a1eee0910cbd55aa3rbb * setgid() is known to zap the group list.
e8fcc872d5caeea36adb6511f9d1ab6ce3fbb5c0jerenkrantz ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
8a944f317ca393b84b03922a1eee0910cbd55aa3rbb "setgid: unable to set group id to Group %u",
3c990331fc6702119e4f5b8ba9eae3021aea5265jim /* Reset `groups' attributes. */
a742cbb3e85669473b3233f30e3978bb6a20083cylavic "initgroups: unable to set groups for User %s "
a742cbb3e85669473b3233f30e3978bb6a20083cylavic "and Group %u", name, (unsigned)unixd_config.group_id);
a742cbb3e85669473b3233f30e3978bb6a20083cylavic#endif /* !defined(OS2) && !defined(TPF) */
a742cbb3e85669473b3233f30e3978bb6a20083cylavic /* Only try to switch if we're running as MANAGER.SYS */
d540257904755584099edb7c66387a25c3503ccftrawick "setuid: unable to change to uid: %ld",
8a944f317ca393b84b03922a1eee0910cbd55aa3rbb /* Only try to switch if we're running as root */
8a944f317ca393b84b03922a1eee0910cbd55aa3rbb if (!geteuid() && (
4b9d04712f3c887072645f9a628888998908467bjerenkrantz os_init_job_environment(NULL, unixd_config.user_name, ap_exists_config_define("DEBUG")) != 0 ||
4b9d04712f3c887072645f9a628888998908467bjerenkrantz "setuid: unable to change to uid: %ld",
275419d6395e6f072962fb701b89accaff1f3690jerenkrantz#if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)
dc9d4f49d36e64c0157d930cb22ca82a6291c0cbdgaudet /* this applies to Linux 2.4+ */
a742cbb3e85669473b3233f30e3978bb6a20083cylavic "set dumpable failed - this child will not coredump"
89211a3153be8b03353c3bfbca45fed67cb80f0bpquerna " after software errors");
1075efe007e7af339bde09cbb175d4f4d676eeb5rpluemAP_DECLARE(const char *) unixd_set_user(cmd_parms *cmd, void *dummy,
dc9d4f49d36e64c0157d930cb22ca82a6291c0cbdgaudet const char *arg)
return err;
"\tdirective in your httpd.conf file to list a non-root\n"
return NULL;
const char *arg)
return err;
return NULL;
#if (defined(RLIMIT_CPU) || defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined(RLIMIT_NPROC) || defined(RLIMIT_AS)) && APR_HAVE_STRUCT_RLIMIT && APR_HAVE_GETRLIMIT
char *str;
/* If your platform doesn't define rlim_t then typedef it in ap_config.h */
if (geteuid()) {
if (max) {
if (cur) {
if (max) {
const char * const *args,
const char * const *env,
apr_pool_t *p)
const char **newargs;
char *newprogname;
const char *argv0;
argv0++;
return APR_ENOMEM;
if (args) {
while (args[i]) {
return APR_EGENERAL;
} while (args[i++]);
const request_rec *r,
const char * const *args,
const char * const *env,
return APR_LOCK_SYSVSEM;
return APR_LOCK_FLOCK;
return APR_LOCK_DEFAULT;
if (!geteuid()) {
switch(mech) {
case APR_LOCK_SYSVSEM:
#if !APR_HAVE_UNION_SEMUN
union semun {
long val;
unsigned short *array;
return errno;
case APR_LOCK_FLOCK:
if (lockfile) {
return errno;
return APR_SUCCESS;
return APR_SUCCESS;
return status;
switch (status) {
case ENOBUFS:
#ifdef EPROTO
case EPROTO:
#ifdef ECONNABORTED
case ECONNABORTED:
#ifdef ECONNRESET
case ECONNRESET:
#ifdef ETIMEDOUT
case ETIMEDOUT:
#ifdef EHOSTUNREACH
case EHOSTUNREACH:
#ifdef ENETUNREACH
case ENETUNREACH:
#ifdef ENETDOWN
case ENETDOWN:
return APR_EGENERAL;
#ifdef TPF
case EINACT:
return APR_EGENERAL;
return APR_EGENERAL;
return APR_EGENERAL;
return status;