mod_suexec.c revision 04891cf70e0bfc38bfb027541dc821f04c754ff7
44N/A/* Copyright 2000-2004 Apache Software Foundation
44N/A *
44N/A * Licensed under the Apache License, Version 2.0 (the "License");
44N/A * you may not use this file except in compliance with the License.
44N/A * You may obtain a copy of the License at
44N/A *
44N/A * http://www.apache.org/licenses/LICENSE-2.0
44N/A *
44N/A * Unless required by applicable law or agreed to in writing, software
44N/A * distributed under the License is distributed on an "AS IS" BASIS,
44N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
44N/A * See the License for the specific language governing permissions and
44N/A * limitations under the License.
44N/A */
44N/A
44N/A#define CORE_PRIVATE
44N/A#include "httpd.h"
44N/A#include "http_config.h"
44N/A#include "http_core.h"
44N/A#include "http_log.h"
58N/A#include "http_request.h"
44N/A#include "apr_strings.h"
44N/A#include "unixd.h"
44N/A#include "mpm_common.h"
44N/A#include "mod_suexec.h"
44N/A
44N/Amodule AP_MODULE_DECLARE_DATA suexec_module;
44N/A
44N/A/*
44N/A * Create a configuration specific to this module for a server or directory
44N/A * location, and fill it with the default settings.
44N/A */
44N/Astatic void *mkconfig(apr_pool_t *p)
44N/A{
44N/A suexec_config_t *cfg = apr_palloc(p, sizeof(suexec_config_t));
44N/A
44N/A cfg->active = 0;
44N/A return cfg;
44N/A}
44N/A
44N/A/*
44N/A * Respond to a callback to create configuration record for a server or
58N/A * vhost environment.
44N/A */
44N/Astatic void *create_mconfig_for_server(apr_pool_t *p, server_rec *s)
44N/A{
44N/A return mkconfig(p);
44N/A}
44N/A
44N/A/*
44N/A * Respond to a callback to create a config record for a specific directory.
44N/A */
44N/Astatic void *create_mconfig_for_directory(apr_pool_t *p, char *dir)
44N/A{
44N/A return mkconfig(p);
44N/A}
44N/A
44N/Astatic const char *set_suexec_ugid(cmd_parms *cmd, void *mconfig,
44N/A const char *uid, const char *gid)
44N/A{
44N/A suexec_config_t *cfg = (suexec_config_t *) mconfig;
44N/A const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
44N/A
44N/A if (err != NULL) {
44N/A return err;
44N/A }
44N/A if (unixd_config.suexec_enabled) {
44N/A cfg->ugid.uid = ap_uname2id(uid);
44N/A cfg->ugid.gid = ap_gname2id(gid);
44N/A cfg->ugid.userdir = 0;
44N/A cfg->active = 1;
44N/A }
44N/A else {
44N/A fprintf(stderr,
44N/A "Warning: SuexecUserGroup directive requires SUEXEC wrapper.\n");
44N/A }
44N/A return NULL;
44N/A}
44N/A
44N/Astatic ap_unix_identity_t *get_suexec_id_doer(const request_rec *r)
44N/A{
44N/A suexec_config_t *cfg =
44N/A (suexec_config_t *) ap_get_module_config(r->per_dir_config, &suexec_module);
44N/A
44N/A return cfg->active ? &cfg->ugid : NULL;
44N/A}
44N/A
44N/A#define SUEXEC_POST_CONFIG_USERDATA "suexec_post_config_userdata"
44N/Astatic int suexec_post_config(apr_pool_t *p, apr_pool_t *plog,
44N/A apr_pool_t *ptemp, server_rec *s)
44N/A{
44N/A void *reported;
44N/A
44N/A apr_pool_userdata_get(&reported, SUEXEC_POST_CONFIG_USERDATA,
44N/A s->process->pool);
44N/A
44N/A if ((reported == NULL) && unixd_config.suexec_enabled) {
44N/A ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
44N/A "suEXEC mechanism enabled (wrapper: %s)", SUEXEC_BIN);
44N/A
44N/A apr_pool_userdata_set((void *)1, SUEXEC_POST_CONFIG_USERDATA,
44N/A apr_pool_cleanup_null, s->process->pool);
44N/A }
44N/A
44N/A return OK;
44N/A}
44N/A#undef SUEXEC_POST_CONFIG_USERDATA
44N/A
44N/A/*
44N/A * Define the directives specific to this module. This structure is referenced
44N/A * later by the 'module' structure.
44N/A */
44N/Astatic const command_rec suexec_cmds[] =
44N/A{
44N/A /* XXX - Another important reason not to allow this in .htaccess is that
44N/A * the ap_[ug]name2id() is not thread-safe */
44N/A AP_INIT_TAKE2("SuexecUserGroup", set_suexec_ugid, NULL, RSRC_CONF,
44N/A "User and group for spawned processes"),
44N/A { NULL }
44N/A};
44N/A
44N/Astatic void suexec_hooks(apr_pool_t *p)
44N/A{
44N/A ap_hook_get_suexec_identity(get_suexec_id_doer,NULL,NULL,APR_HOOK_MIDDLE);
44N/A ap_hook_post_config(suexec_post_config,NULL,NULL,APR_HOOK_MIDDLE);
44N/A}
44N/A
44N/Amodule AP_MODULE_DECLARE_DATA suexec_module =
44N/A{
44N/A STANDARD20_MODULE_STUFF,
44N/A create_mconfig_for_directory, /* create per-dir config */
44N/A NULL, /* merge per-dir config */
44N/A create_mconfig_for_server, /* server config */
44N/A NULL, /* merge server config */
44N/A suexec_cmds, /* command table */
44N/A suexec_hooks /* register hooks */
44N/A};
44N/A