bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / modules / generators / mod_suexec.c
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #define CORE_PRIVATE
18 #include "httpd.h"
19 #include "http_config.h"
20 #include "http_core.h"
21 #include "http_log.h"
22 #include "http_request.h"
23 #include "apr_strings.h"
24 #include "unixd.h"
25 #include "mpm_common.h"
26 #include "mod_suexec.h"
27
28 module AP_MODULE_DECLARE_DATA suexec_module;
29
30 /*
31  * Create a configuration specific to this module for a server or directory
32  * location, and fill it with the default settings.
33  */
34 static void *mkconfig(apr_pool_t *p)
35 {
36     suexec_config_t *cfg = apr_palloc(p, sizeof(suexec_config_t));
37
38     cfg->active = 0;
39     return cfg;
40 }
41
42 /*
43  * Respond to a callback to create configuration record for a server or
44  * vhost environment.
45  */
46 static void *create_mconfig_for_server(apr_pool_t *p, server_rec *s)
47 {
48     return mkconfig(p);
49 }
50
51 /*
52  * Respond to a callback to create a config record for a specific directory.
53  */
54 static void *create_mconfig_for_directory(apr_pool_t *p, char *dir)
55 {
56     return mkconfig(p);
57 }
58
59 static const char *set_suexec_ugid(cmd_parms *cmd, void *mconfig,
60                                    const char *uid, const char *gid)
61 {
62     suexec_config_t *cfg = (suexec_config_t *) mconfig;
63     const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
64
65     if (err != NULL) {
66         return err;
67     }
68     if (unixd_config.suexec_enabled) {
69         cfg->ugid.uid = ap_uname2id(uid);
70         cfg->ugid.gid = ap_gname2id(gid);
71         cfg->ugid.userdir = 0;
72         cfg->active = 1;
73     }
74     else {
75         fprintf(stderr,
76                 "Warning: SuexecUserGroup directive requires SUEXEC wrapper.\n");
77     }
78     return NULL;
79 }
80
81 static ap_unix_identity_t *get_suexec_id_doer(const request_rec *r)
82 {
83     suexec_config_t *cfg =
84     (suexec_config_t *) ap_get_module_config(r->per_dir_config, &suexec_module);
85
86     return cfg->active ? &cfg->ugid : NULL;
87 }
88
89 #define SUEXEC_POST_CONFIG_USERDATA "suexec_post_config_userdata"
90 static int suexec_post_config(apr_pool_t *p, apr_pool_t *plog,
91                               apr_pool_t *ptemp, server_rec *s)
92 {
93     void *reported;
94
95     apr_pool_userdata_get(&reported, SUEXEC_POST_CONFIG_USERDATA,
96                           s->process->pool);
97
98     if ((reported == NULL) && unixd_config.suexec_enabled) {
99         ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
100                      "suEXEC mechanism enabled (wrapper: %s)", SUEXEC_BIN);
101
102         apr_pool_userdata_set((void *)1, SUEXEC_POST_CONFIG_USERDATA,
103                               apr_pool_cleanup_null, s->process->pool);
104     }
105
106     return OK;
107 }
108 #undef SUEXEC_POST_CONFIG_USERDATA
109
110 /*
111  * Define the directives specific to this module.  This structure is referenced
112  * later by the 'module' structure.
113  */
114 static const command_rec suexec_cmds[] =
115 {
116     /* XXX - Another important reason not to allow this in .htaccess is that
117      * the ap_[ug]name2id() is not thread-safe */
118     AP_INIT_TAKE2("SuexecUserGroup", set_suexec_ugid, NULL, RSRC_CONF,
119       "User and group for spawned processes"),
120     { NULL }
121 };
122
123 static void suexec_hooks(apr_pool_t *p)
124 {
125     ap_hook_get_suexec_identity(get_suexec_id_doer,NULL,NULL,APR_HOOK_MIDDLE);
126     ap_hook_post_config(suexec_post_config,NULL,NULL,APR_HOOK_MIDDLE);
127 }
128
129 module AP_MODULE_DECLARE_DATA suexec_module =
130 {
131     STANDARD20_MODULE_STUFF,
132     create_mconfig_for_directory,   /* create per-dir config */
133     NULL,                       /* merge per-dir config */
134     create_mconfig_for_server,  /* server config */
135     NULL,                       /* merge server config */
136     suexec_cmds,                /* command table */
137     suexec_hooks                /* register hooks */
138 };