mod_privileges.c revision cc677e4f655e70eae2d6a7e72db8a1d6341ec9d2
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering/* Licensed to the Apache Software Foundation (ASF) under one or more
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * contributor license agreements. See the NOTICE file distributed with
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * this work for additional information regarding copyright ownership.
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * The ASF licenses this file to You under the Apache License, Version 2.0
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * (the "License"); you may not use this file except in compliance with
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * the License. You may obtain a copy of the License at
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * http://www.apache.org/licenses/LICENSE-2.0
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * Unless required by applicable law or agreed to in writing, software
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * distributed under the License is distributed on an "AS IS" BASIS,
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * See the License for the specific language governing permissions and
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * limitations under the License.
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering/* TODO - get rid of unixd dependency */
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering#define CFG_CHECK(x) if (x == -1) return strerror(errno);
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering ap_log_error(APLOG_MARK, APLOG_CRIT,0,0, \
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering "Failed to initialise privileges: %s", strerror(errno))
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poetteringmodule AP_MODULE_DECLARE_DATA privileges_module;
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering/* #define BIG_SECURITY_HOLE 1 */
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poetteringtypedef struct {
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poetteringstatic apr_status_t priv_cfg_cleanup(void *CFG)
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poetteringstatic void *privileges_create_cfg(apr_pool_t *pool, server_rec *s)
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering priv_cfg *cfg = apr_palloc(pool, sizeof(priv_cfg));
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering /* Start at basic privileges all round. */
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering cfg->priv = priv_str_to_set("basic", ",", NULL);
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering cfg->child_priv = priv_str_to_set("basic", ",", NULL);
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering /* By default, run in secure mode.
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering * That means dropping basic privileges we don't usually need.
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering CR_CHECK(priv_delset(cfg->priv, PRIV_FILE_LINK_ANY));
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering CR_CHECK(priv_delset(cfg->priv, PRIV_PROC_INFO));
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering CR_CHECK(priv_delset(cfg->priv, PRIV_PROC_SESSION));
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering/* Hmmm, should CGI default to secure too ? */
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering CR_CHECK(priv_delset(cfg->child_priv, PRIV_FILE_LINK_ANY));
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering CR_CHECK(priv_delset(cfg->child_priv, PRIV_PROC_INFO));
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering CR_CHECK(priv_delset(cfg->child_priv, PRIV_PROC_SESSION));
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering CR_CHECK(priv_delset(cfg->child_priv, PRIV_PROC_FORK));
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering CR_CHECK(priv_delset(cfg->child_priv, PRIV_PROC_EXEC));
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering /* we´ll use 0 for unset */
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering apr_pool_cleanup_register(pool, cfg, priv_cfg_cleanup,
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poettering /* top-level default_priv wants the top-level cfg */
af3bccd6d87759f0b146bf5980bdd56144d70c7eLennart Poetteringstatic apr_status_t privileges_end_req(void *data)
return APR_SUCCESS;
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
return OK;
return !OK; \
return OK;
return OK;
return APR_SUCCESS;
if (dtrace_enabled) {
return !OK;
return OK;
int threaded;
if (threaded) {
return !OK;
return OK;
return NULL;
return NULL;
if (!arg) {
return NULL;
return NULL;
return err;
return NULL;
#ifdef BIG_SECURITY_HOLE
return NULL;
return NULL;
#ifdef BIG_SECURITY_HOLE
{NULL}
NULL,
NULL,
NULL,