Author: wrowe
Date: Wed Sep 14 09:50:41 2005
New Revision: 280884
URL: http://svn.apache.org/viewcvs?rev=280884&view=rev
Log:
Introduce the AspNet directive, to replace the test of Options
ExecCGI.
Now, to actually permit ASP.NET content, we need to test the
following;
To serve a real file AspNet files
To serve a directory AspNet directories (or simply dirs)
To serve not-a-file AspNet virtual
To serve any URL AspNet all (or simply on)
These can be combined, e.g. 'AspNet files virtual' would be valid, and
Apache would continue to serve directories.
Modified:
httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp
Modified: httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp
URL:
http://svn.apache.org/viewcvs/httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp?rev=280884&r1=280883&r2=280884&view=diff
==============================================================================
--- httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp (original)
+++ httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp Wed Sep 14
09:50:41 2005
@@ -184,8 +184,75 @@
return NULL;
}
+
+typedef enum {
+ ASPNET_OFF = 0,
+ ASPNET_UNSET = 2^0, // Must be a value, better to avoid legal
bits
+ ASPNET_FILES = 2^1,
+ ASPNET_DIRS = 2^2,
+ ASPNET_VIRTUAL = 2^3
+} asp_net_enable_t;
+
+typedef struct asp_net_dirconf_t {
+ int enable; // Bit flags of asp_net_enable_t values
+} asp_net_dirconf_t;
+
+static void *create_asp_net_dirconf(apr_pool_t *p, char *dummy)
+{
+ asp_net_dirconf_t *dirconf;
+ dirconf = (asp_net_dirconf_t*)apr_palloc(p,
sizeof(asp_net_dirconf_t));
+ dirconf->enable = ASPNET_UNSET;
+ return dirconf;
+}
+
+static void *merge_asp_net_dirconf(apr_pool_t *p, void *basev, void
*addv)
+{
+ asp_net_dirconf_t *base = (asp_net_dirconf_t*)basev;
+ asp_net_dirconf_t *add = (asp_net_dirconf_t*)addv;
+ asp_net_dirconf_t *res = +
(asp_net_dirconf_t*)apr_palloc(p, sizeof(asp_net_dirconf_t));
+ res->enable = (add->enable == ASPNET_UNSET) ? base->enable
+ : add->enable;
+ return add;
+}
+
+static const char *set_aspnet_enable(cmd_parms *cmd, void *dirconf_,
+ const char *enables)
+{
+ asp_net_dirconf_t *dirconf = (asp_net_dirconf_t *)dirconf_;
+
+ // Unset the AspNet flags before we toggle specific choices
+ dirconf->enable = ASPNET_OFF;
+
+ while (*enables) {
+ const char *enable = ap_getword_conf(cmd->pool, &enables);
+
+ if (!strcasecmp(enable, "on")
+ || !strcasecmp(enable, "all"))
+ dirconf->enable = ASPNET_FILES | ASPNET_DIRS |
ASPNET_VIRTUAL;
+ else if (!strcasecmp(enable, "off") + ||
!strcasecmp(enable, "none"))
+ dirconf->enable = ASPNET_OFF;
+ else if (!strcasecmp(enable, "files")) +
dirconf->enable |= ASPNET_FILES;
+ else if (!strcasecmp(enable, "dirs")
+ || !strcasecmp(enable, "directories")) +
dirconf->enable |= ASPNET_DIRS;
+ else if (!strcasecmp(enable, "virtual")) +
dirconf->enable |= ASPNET_VIRTUAL;
+ else {
+ return apr_pstrcat(cmd->pool, "Unrecognized AspNet
option ", + enable, NULL);
+ }
+ }
+ return NULL;
+}
+
+
static const command_rec asp_net_cmds[] =
{
+ AP_INIT_RAW_ARGS("AspNet", (cmd_func)set_aspnet_enable, NULL,
OR_OPTIONS,
+ "Allow ASP.NET to serve 'Files', 'Dirs', 'Virtual', 'All',
or 'None'"),
AP_INIT_TAKE1("AspNetVersion", (cmd_func)version_cmd, NULL,
RSRC_CONF,
"Select a specific ASP.NET version in the format v#.#.####"),
AP_INIT_TAKE2("AspNetMount", (cmd_func)mount_cmd, NULL, RSRC_CONF,
@@ -433,13 +500,6 @@
return DECLINED;
}
- if (r->finfo.filetype != APR_REG) {
- ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
- "mod_aspdotnet: File not found or unable to stat: %s",
- r->filename);
- return HTTP_NOT_FOUND;
- }
-
if (!r->uri || (r->uri[0] != '/')) {
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
"mod_aspdotnet: Forbidden, request URI was not
absolute: %s",
@@ -447,12 +507,48 @@
return HTTP_FORBIDDEN;
}
- if (!(ap_allow_options(r) & OPT_EXECCGI)) - {
+ asp_net_dirconf_t *dirconf = + (asp_net_dirconf_t
*)ap_get_module_config(r->per_dir_config,
+
&aspdotnet_module);
+
+ if (r->finfo.filetype == APR_REG) {
+ if (!(dirconf->enable & ASPNET_FILES)) + {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
+ "mod_aspdotnet: Forbidden, 'AspNet Files' is not
enabled for: %s"
+ " (file %s)", r->uri, r->filename);
+ return HTTP_FORBIDDEN;
+ }
+ }
+ else if (r->finfo.filetype == APR_DIR) {
+ if (!(dirconf->enable & ASPNET_DIRS)) + {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
+ "mod_aspdotnet: Forbidden, 'AspNet Dirs' is not
enabled for: %s"
+ " (directory %s)", r->uri, r->filename);
+ return HTTP_FORBIDDEN;
+ }
+ }
+ else if (!r->finfo.filetype) {
+ if (!(dirconf->enable & ASPNET_VIRTUAL)) + {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
+ "mod_aspdotnet: Forbidden, 'AspNet Virtual'"
+ "is not enabled for: %s", r->uri);
+ if (dirconf->enable & (ASPNET_FILES | ASPNET_DIRS))
+ {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO,
0, r, + "mod_aspdotnet: File not found or
unable to stat: %s",
+ r->filename);
+ }
+ return HTTP_NOT_FOUND;
+ }
+ }
+ else {
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
- "mod_aspdotnet: Forbidden, Options ExecCGI is not
set for: %s",
- r->filename);
- return HTTP_FORBIDDEN;
+ "mod_aspdotnet: Invalid file type for: %s (it is not "
+ "a recognized file or directory)", r->filename);
+ return HTTP_NOT_FOUND;
}
if ((r->used_path_info == AP_REQ_REJECT_PATH_INFO) &&
@@ -705,10 +801,10 @@
module AP_MODULE_DECLARE_DATA ::aspdotnet_module =
{
STANDARD20_MODULE_STUFF,
- NULL, /* dir config */
- NULL, /* merge dir config */
- create_asp_net_srvconf, /* server config */
- merge_asp_net_srvconf, /* merge server config */
+ create_asp_net_dirconf, /* dir config */
+ merge_asp_net_dirconf, /* merge dir config */
+ create_asp_net_srvconf, /* server config */
+ merge_asp_net_srvconf, /* merge server config */
asp_net_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};