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