summaryrefslogtreecommitdiffhomepage
path: root/apache/options.patch
blob: faad2f2200ac7e31ee50a18bc56a82d18c04bebe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
https://bz.apache.org/bugzilla/show_bug.cgi?id=62061
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=888824

Index: libapache2-mod-fcgid-2.3.9/modules/fcgid/fcgid_conf.c
===================================================================
--- libapache2-mod-fcgid-2.3.9.orig/modules/fcgid/fcgid_conf.c
+++ libapache2-mod-fcgid-2.3.9/modules/fcgid/fcgid_conf.c
@@ -169,9 +169,15 @@ void *merge_fcgid_server_config(apr_pool
     return merged;
 }
 
-void *create_fcgid_dir_config(apr_pool_t * p, char *dummy)
+void *create_fcgid_dir_config(apr_pool_t * p, char *context)
 {
+    static int dir_id = 0;
+
     fcgid_dir_conf *config = apr_pcalloc(p, sizeof(fcgid_dir_conf));
+    ++dir_id;
+
+    config->dir_id = dir_id;
+    config->context = context;
 
     config->wrapper_info_hash = apr_hash_make(p);
     /* config->authenticator_info = NULL; */
@@ -180,6 +186,7 @@ void *create_fcgid_dir_config(apr_pool_t
     config->authorizer_authoritative = 1;
     /* config->access_info = NULL; */
     config->access_authoritative = 1;
+    /* config->default_init_env = NULL;*/
     return (void *) config;
 }
 
@@ -190,6 +197,21 @@ void *merge_fcgid_dir_config(apr_pool_t
     fcgid_dir_conf *merged =
       (fcgid_dir_conf *) apr_pmemdup(p, local, sizeof(fcgid_dir_conf));
 
+    /* Merge environment variables */
+    if (base->default_init_env == NULL) {
+        /* merged already set to local */
+    }
+    else if (local->default_init_env == NULL) {
+        merged->default_init_env = base->default_init_env;
+    }
+    else {
+        merged->default_init_env =
+          apr_table_copy(p, base->default_init_env);
+        apr_table_overlap(merged->default_init_env,
+                          local->default_init_env,
+                          APR_OVERLAP_TABLES_SET);
+    }
+
     merged->wrapper_info_hash =
       apr_hash_overlay(p, local->wrapper_info_hash,
                        base->wrapper_info_hash);
@@ -570,15 +592,27 @@ static void add_envvar_to_table(apr_tabl
     apr_table_set(t, name, value ? value : "");
 }
 
-const char *add_default_env_vars(cmd_parms * cmd, void *dummy,
+const char *add_default_env_vars(cmd_parms * cmd, void *dir_config,
                                  const char *name, const char *value)
 {
+    if (cmd->path != NULL) { /* dir context (Directory / Files / Location) */
+        fcgid_dir_conf *dconfig = ap_get_module_config(cmd->context, &fcgid_module);
+
+        if (dconfig->default_init_env == NULL)
+            dconfig->default_init_env = apr_table_make(cmd->pool, 20);
+    
+        add_envvar_to_table(dconfig->default_init_env, cmd->pool, name, value);
+
+        return NULL;
+    }
+
     fcgid_server_conf *config =
         ap_get_module_config(cmd->server->module_config, &fcgid_module);
     if (config->default_init_env == NULL)
         config->default_init_env = apr_table_make(cmd->pool, 20);
-
+    
     add_envvar_to_table(config->default_init_env, cmd->pool, name, value);
+
     return NULL;
 }
 
@@ -935,13 +969,17 @@ fcgid_cmd_conf *get_wrapper_info(const c
     return NULL;
 }
 
-static int set_cmd_envvars(fcgid_cmd_env *cmdenv, apr_table_t *envvars)
+static int set_cmd_envvars(fcgid_cmd_env *cmdenv, apr_table_t *envvars, apr_table_t *denvvars)
 {
     const apr_array_header_t *envvars_arr;
     const apr_table_entry_t *envvars_entry;
     int i;
     int overflow = 0;
 
+    if (denvvars) { /* directory environment overwrites vhost environment */
+	    envvars = denvvars;
+    }
+
     if (envvars) {
         envvars_arr = apr_table_elts(envvars);
         envvars_entry = (apr_table_entry_t *) envvars_arr->elts;
@@ -1106,7 +1144,7 @@ const char *set_cmd_options(cmd_parms *c
                             option);
     }
 
-    if ((overflow = set_cmd_envvars(cmdopts->cmdenv, envvars)) != 0) {
+    if ((overflow = set_cmd_envvars(cmdopts->cmdenv, envvars, NULL)) != 0) {
         return apr_psprintf(cmd->pool, "mod_fcgid: environment variable table "
                             "overflow; increase INITENV_CNT in fcgid_pm.h from"
                             " %d to at least %d",
@@ -1122,6 +1160,8 @@ void get_cmd_options(request_rec *r, con
                      fcgid_cmd_options *cmdopts,
                      fcgid_cmd_env *cmdenv)
 {
+    fcgid_dir_conf *dconf = ap_get_module_config(r->per_dir_config, &fcgid_module);
+
     fcgid_server_conf *sconf =
         ap_get_module_config(r->server->module_config, &fcgid_module);
     fcgid_cmd_options *cmd_specific = apr_hash_get(sconf->cmdopts_hash,
@@ -1149,7 +1189,7 @@ void get_cmd_options(request_rec *r, con
     cmdopts->min_class_process_count = sconf->min_class_process_count;
     cmdopts->proc_lifetime = sconf->proc_lifetime;
 
-    if ((overflow = set_cmd_envvars(cmdenv, sconf->default_init_env)) != 0) {
+    if ((overflow = set_cmd_envvars(cmdenv, sconf->default_init_env, dconf->default_init_env)) != 0) {
         ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
                       "mod_fcgid: %d environment variables dropped; increase "
                       "INITENV_CNT in fcgid_pm.h from %d to at least %d",
Index: libapache2-mod-fcgid-2.3.9/modules/fcgid/mod_fcgid.c
===================================================================
--- libapache2-mod-fcgid-2.3.9.orig/modules/fcgid/mod_fcgid.c
+++ libapache2-mod-fcgid-2.3.9/modules/fcgid/mod_fcgid.c
@@ -306,6 +306,8 @@ static int fcgidsort(fcgid_procnode **e1
         return cmp;
     if ((*e1)->vhost_id != (*e2)->vhost_id)
         return (*e1)->vhost_id > (*e2)->vhost_id ? 1 : -1;
+    if ((*e1)->dir_id != (*e2)->dir_id)
+        return (*e1)->dir_id > (*e2)->dir_id ? 1 : -1;
     if ((*e1)->diewhy != (*e2)->diewhy)
         return (*e1)->diewhy > (*e2)->diewhy ? 1 : -1;
     if ((*e1)->node_type != (*e2)->node_type)
@@ -353,6 +355,7 @@ static int fcgid_status_hook(request_rec
     const char *last_cmdline = "";
     apr_time_t now;
     int last_vhost_id = -1;
+    int last_dir_id = -1;
     const char *basename, *tmpbasename;
     fcgid_procnode *proc_table = proctable_get_table_array();
     fcgid_procnode *error_list_header = proctable_get_error_list();
@@ -425,7 +428,8 @@ static int fcgid_status_hook(request_rec
         if (current_node->inode != last_inode || current_node->deviceid != last_deviceid
             || current_node->gid != last_gid || current_node->uid != last_uid
             || strcmp(current_node->cmdline, last_cmdline)
-            || current_node->vhost_id != last_vhost_id) {
+            || current_node->vhost_id != last_vhost_id
+	    || current_node->dir_id != last_dir_id) {
             if (index != 0)
                  ap_rputs("</table>\n\n", r);
 
@@ -438,8 +442,8 @@ static int fcgid_status_hook(request_rec
                 basename++;
 	    else
                 basename = tmpbasename;
-            ap_rprintf(r, "<hr />\n<b>Process: %s</b>&nbsp;&nbsp;(%s)<br />\n",
-                       basename, current_node->cmdline);
+            ap_rprintf(r, "<hr />\n<b>Process: %s</b>&nbsp;&nbsp;(%s at %s)<br />\n",
+                       basename, current_node->cmdline, current_node->context);
 
             /* Create a new table for this process info */
             ap_rputs("\n\n<table border=\"0\"><tr>"
@@ -453,6 +457,7 @@ static int fcgid_status_hook(request_rec
             last_uid = current_node->uid;
             last_cmdline = current_node->cmdline;
             last_vhost_id = current_node->vhost_id;
+            last_dir_id = current_node->dir_id;
         }
 
         ap_rprintf(r, "<tr><td>%" APR_PID_T_FMT "</td><td>%" APR_TIME_T_FMT "</td><td>%" APR_TIME_T_FMT "</td><td>%d</td><td>%s</td></tr>",
@@ -751,7 +756,7 @@ static const command_rec fcgid_cmds[] =
                   "a fastcgi application will be killed after handling a request for BusyTimeout"),
     AP_INIT_RAW_ARGS("FcgidCmdOptions", set_cmd_options, NULL, RSRC_CONF,
                      "set processing options for a FastCGI command"),
-    AP_INIT_TAKE12("FcgidInitialEnv", add_default_env_vars, NULL, RSRC_CONF,
+    AP_INIT_TAKE12("FcgidInitialEnv", add_default_env_vars, NULL, ACCESS_CONF | RSRC_CONF,
                    "an environment variable name and optional value to pass to FastCGI."),
     AP_INIT_TAKE1("FcgidMaxProcessesPerClass",
                   set_max_class_process,
Index: libapache2-mod-fcgid-2.3.9/modules/fcgid/fcgid_conf.h
===================================================================
--- libapache2-mod-fcgid-2.3.9.orig/modules/fcgid/fcgid_conf.h
+++ libapache2-mod-fcgid-2.3.9/modules/fcgid/fcgid_conf.h
@@ -130,6 +130,11 @@ typedef struct {
     fcgid_cmd_conf *access_info;
     int access_authoritative;
     int access_authoritative_set;
+    
+    /* context info */
+    apr_table_t *default_init_env;
+    int dir_id;
+    const char *context;
 } fcgid_dir_conf;
 
 /* processing options which are sent to the PM with a spawn request
Index: libapache2-mod-fcgid-2.3.9/modules/fcgid/fcgid_bridge.c
===================================================================
--- libapache2-mod-fcgid-2.3.9.orig/modules/fcgid/fcgid_bridge.c
+++ libapache2-mod-fcgid-2.3.9/modules/fcgid/fcgid_bridge.c
@@ -60,6 +60,7 @@ static fcgid_procnode *apply_free_procno
             && current_node->deviceid == deviceid
             && !strcmp(current_node->cmdline, cmdline)
             && current_node->vhost_id == command->vhost_id
+	    && current_node->dir_id == command->dir_id
             && current_node->uid == uid && current_node->gid == gid) {
             /* Unlink from idle list */
             previous_node->next_index = current_node->next_index;
@@ -140,6 +141,7 @@ static int count_busy_processes(request_
             && current_node->deviceid == command->deviceid
             && !strcmp(current_node->cmdline, command->cmdline)
             && current_node->vhost_id == command->vhost_id
+            && current_node->dir_id == command->dir_id
             && current_node->uid == command->uid
             && current_node->gid == command->gid) {
             result++;
Index: libapache2-mod-fcgid-2.3.9/modules/fcgid/fcgid_pm.h
===================================================================
--- libapache2-mod-fcgid-2.3.9.orig/modules/fcgid/fcgid_pm.h
+++ libapache2-mod-fcgid-2.3.9/modules/fcgid/fcgid_pm.h
@@ -29,6 +29,8 @@ typedef struct {
      * module may have copied it for per-request customization
      */
     int vhost_id;
+    int dir_id;
+    const char* context;
     char server_hostname[32];   /* for logging only; ok to truncate */
     uid_t uid;                  /* For suEXEC */
     gid_t gid;                  /* For suEXEC */
Index: libapache2-mod-fcgid-2.3.9/modules/fcgid/fcgid_pm_main.c
===================================================================
--- libapache2-mod-fcgid-2.3.9.orig/modules/fcgid/fcgid_pm_main.c
+++ libapache2-mod-fcgid-2.3.9/modules/fcgid/fcgid_pm_main.c
@@ -563,6 +563,8 @@ fastcgi_spawn(fcgid_command * command, s
     apr_cpystrn(procnode->cmdline, command->cmdline, sizeof procnode->cmdline);
 
     procnode->vhost_id = command->vhost_id;
+    procnode->dir_id = command->dir_id;
+    procnode->context = command->context;
     procnode->uid = command->uid;
     procnode->gid = command->gid;
     procnode->start_time = procnode->last_active_time = apr_time_now();
Index: libapache2-mod-fcgid-2.3.9/modules/fcgid/fcgid_pm_unix.c
===================================================================
--- libapache2-mod-fcgid-2.3.9.orig/modules/fcgid/fcgid_pm_unix.c
+++ libapache2-mod-fcgid-2.3.9/modules/fcgid/fcgid_pm_unix.c
@@ -426,6 +426,8 @@ void procmgr_init_spawn_cmd(fcgid_comman
     ap_unix_identity_t *ugid;
     fcgid_server_conf *sconf =
         ap_get_module_config(r->server->module_config, &fcgid_module);
+    fcgid_dir_conf *dconf =
+        ap_get_module_config(r->per_dir_config, &fcgid_module);
 
     /* suEXEC check */
     if ((ugid = ap_run_get_suexec_identity(r))) {
@@ -447,6 +449,8 @@ void procmgr_init_spawn_cmd(fcgid_comman
     command->deviceid = cmd_conf->deviceid;
     command->inode = cmd_conf->inode;
     command->vhost_id = sconf->vhost_id;
+    command->dir_id = dconf->dir_id;
+    command->context = dconf->context;
     if (r->server->server_hostname) {
         apr_cpystrn(command->server_hostname, r->server->server_hostname,
                     sizeof command->server_hostname);
Index: libapache2-mod-fcgid-2.3.9/modules/fcgid/fcgid_pm_win.c
===================================================================
--- libapache2-mod-fcgid-2.3.9.orig/modules/fcgid/fcgid_pm_win.c
+++ libapache2-mod-fcgid-2.3.9/modules/fcgid/fcgid_pm_win.c
@@ -135,6 +135,8 @@ void procmgr_init_spawn_cmd(fcgid_comman
 {
     fcgid_server_conf *sconf =
         ap_get_module_config(r->server->module_config, &fcgid_module);
+    fcgid_dir_conf *dconf =
+        ap_get_module_config(r->per_dir_config, &fcgid_module);
 
     /* no truncation should ever occur */
     AP_DEBUG_ASSERT(sizeof command->cgipath > strlen(cmd_conf->cgipath));
@@ -148,6 +150,8 @@ void procmgr_init_spawn_cmd(fcgid_comman
     command->gid = (gid_t) - 1;
     command->userdir = 0;
     command->vhost_id = sconf->vhost_id;
+    command->dir_id = dconf->dir_id;
+    command->context = dconf->context;
     if (r->server->server_hostname) {
         apr_cpystrn(command->server_hostname, r->server->server_hostname,
                     sizeof command->server_hostname);
Index: libapache2-mod-fcgid-2.3.9/modules/fcgid/fcgid_proctbl.h
===================================================================
--- libapache2-mod-fcgid-2.3.9.orig/modules/fcgid/fcgid_proctbl.h
+++ libapache2-mod-fcgid-2.3.9/modules/fcgid/fcgid_proctbl.h
@@ -52,6 +52,8 @@ typedef struct {
     int vhost_id;               /* the vhost to which this process belongs (the server_rec
                                  * addr fails with some mass-vhost mods which allocate
                                  * them per-request) */
+    int dir_id;                 /* process class connected to dir */
+    const char* context;        /* dir/location of process class */
     apr_time_t start_time;      /* the time of this process create */
     apr_time_t last_active_time;    /* the time this process last active */
     int requests_handled;       /* number of requests process has handled */
Index: libapache2-mod-fcgid-2.3.9/modules/fcgid/fcgid_spawn_ctl.c
===================================================================
--- libapache2-mod-fcgid-2.3.9.orig/modules/fcgid/fcgid_spawn_ctl.c
+++ libapache2-mod-fcgid-2.3.9/modules/fcgid/fcgid_spawn_ctl.c
@@ -30,6 +30,7 @@ struct fcgid_stat_node {
     gid_t gid;
     const char *cmdline;
     int vhost_id;
+    int dir_id;
     int score;
     int process_counter;
     int max_class_process_count;
@@ -62,6 +63,7 @@ register_life_death(server_rec * main_se
             && current_node->deviceid == procnode->deviceid
             && !strcmp(current_node->cmdline, procnode->cmdline)
             && current_node->vhost_id == procnode->vhost_id
+            && current_node->dir_id == procnode->dir_id
             && current_node->uid == procnode->uid
             && current_node->gid == procnode->gid)
             break;
@@ -80,6 +82,7 @@ register_life_death(server_rec * main_se
         current_node->inode = procnode->inode;
         current_node->cmdline = apr_pstrdup(g_stat_pool, procnode->cmdline);
         current_node->vhost_id = procnode->vhost_id;
+        current_node->dir_id = procnode->dir_id;
         current_node->uid = procnode->uid;
         current_node->gid = procnode->gid;
         current_node->last_stat_time = now;
@@ -179,6 +182,7 @@ int is_spawn_allowed(server_rec * main_s
             && current_node->deviceid == command->deviceid
             && !strcmp(current_node->cmdline, command->cmdline)
             && current_node->vhost_id == command->vhost_id
+            && current_node->dir_id == command->dir_id
             && current_node->uid == command->uid
             && current_node->gid == command->gid)
             break;
@@ -238,6 +242,7 @@ int is_kill_allowed(server_rec * main_se
             && current_node->deviceid == procnode->deviceid
             && !strcmp(current_node->cmdline, procnode->cmdline)
             && current_node->vhost_id == procnode->vhost_id
+            && current_node->dir_id == procnode->dir_id
             && current_node->uid == procnode->uid
             && current_node->gid == procnode->gid)
             break;