httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iga...@apache.org
Subject svn commit: r943424 - in /httpd/sandbox/mod_allowmethods: ./ SConstruct mod_allowmethods.c
Date Wed, 12 May 2010 09:58:48 GMT
Author: igalic
Date: Wed May 12 09:58:48 2010
New Revision: 943424

URL: http://svn.apache.org/viewvc?rev=943424&view=rev
Log:
Adding pqerna's mod_allowmethods to Sandbox. Will supplement documentation and their like
later.

Added:
    httpd/sandbox/mod_allowmethods/
    httpd/sandbox/mod_allowmethods/SConstruct
    httpd/sandbox/mod_allowmethods/mod_allowmethods.c

Added: httpd/sandbox/mod_allowmethods/SConstruct
URL: http://svn.apache.org/viewvc/httpd/sandbox/mod_allowmethods/SConstruct?rev=943424&view=auto
==============================================================================
--- httpd/sandbox/mod_allowmethods/SConstruct (added)
+++ httpd/sandbox/mod_allowmethods/SConstruct Wed May 12 09:58:48 2010
@@ -0,0 +1,80 @@
+#!/usr/bin/env scons
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import subprocess
+from os.path import join as pjoin
+
+EnsureSConsVersion(1, 1, 0)
+
+
+opts = Variables('build.py')
+
+opts.Add(PathVariable('APXS', 'Path apxs','/usr/sbin/apxs'))
+
+env = Environment(options=opts)
+
+def get_output(cmd):
+    s = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+    out = s.communicate()[0]
+    s.wait()
+    return out.strip()
+    
+def apxs_query(path, key):
+    cmd = [path, "-q", key]
+    return get_output(cmd)
+
+apr_config = apxs_query(env["APXS"], 'APR_CONFIG')
+apu_config = apxs_query(env["APXS"], 'APU_CONFIG')
+
+env.Replace(CC = apxs_query(env["APXS"], 'CC'))
+env.Replace(CPP = apxs_query(env["APXS"], 'CPP'))
+
+# This is a hack to set the RPATH on some operating systems... make me more 
+# portable later....
+p1 = get_output([apr_config, '--bindir'])
+p1 = pjoin(p1[:p1.rfind('/')], 'lib')
+p2 = get_output([apr_config, '--bindir'])
+p2 = pjoin(p2[:p2.rfind('/')], 'lib')
+env.AppendUnique(RPATH = [p1, p2])
+
+env.ParseConfig(apr_config + ' --cflags --cppflags --includes --ldflags')
+env.ParseConfig(apu_config + ' --includes  --ldflags')
+
+# TODO: Move to httpd-config when it comes out !
+env.ParseConfig(env['APXS'] + ' -q EXTRA_CFLAGS')
+env.ParseConfig(env['APXS'] + ' -q EXTRA_CPPFLAGS')
+env.ParseConfig(env['APXS'] + ' -q EXTRA_LIBS')
+
+env.AppendUnique(CPPPATH = [apxs_query(env['APXS'], 'exp_includedir')])
+if env['PLATFORM'] == 'darwin':
+    env.AppendUnique(LINKFLAGS = ['-undefined', 'dynamic_lookup'])
+
+modsources = Split("""mod_allowmethods.c""")
+
+env.ParseConfig(apr_config + ' --link-ld --libs')
+env.ParseConfig(apu_config + ' --link-ld --libs')
+module = env.LoadableModule(target = "mod_allowmethods.so", source = [modsources], SHLIBPREFIX='')
+
+mod_path = apxs_query(env["APXS"], 'exp_libexecdir')
+bin_path = apxs_query(env["APXS"], 'exp_bindir')
+imod = env.Install(mod_path, source = [module])
+env.Alias('install', [imod])
+
+targets = [module]
+
+env.Default(targets)

Added: httpd/sandbox/mod_allowmethods/mod_allowmethods.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/mod_allowmethods/mod_allowmethods.c?rev=943424&view=auto
==============================================================================
--- httpd/sandbox/mod_allowmethods/mod_allowmethods.c (added)
+++ httpd/sandbox/mod_allowmethods/mod_allowmethods.c Wed May 12 09:58:48 2010
@@ -0,0 +1,139 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "httpd.h"
+#include "http_core.h"
+#include "http_config.h"
+#include "http_protocol.h"
+#include "http_log.h"
+#include "apr_strings.h"
+
+/**
+ * This module makes it easy to restrict what HTTP methods can be ran against
+ * a server.
+ *
+ * It provides one comand:
+ *    AllowMethods
+ * This command takes a list of HTTP methods to allow.
+ *
+ *  The most common configuration should be like this:
+ *   <Directory />
+ *    AllowMethods GET HEAD OPTIONS
+ *   </Directory>
+ *   <Directory /special/cgi-bin>
+ *      AllowMethods GET HEAD OPTIONS POST
+ *   </Directory>
+ *  Non-matching methods will be returned a status 405 (method not allowed)
+ *  
+ *  To allow all methods, and effectively turn off mod_allowmethods, use:
+ *    AllowMethods reset
+ */
+
+typedef struct am_conf_t {
+  int allowed;
+} am_conf_t;
+
+module AP_MODULE_DECLARE_DATA allowmethods_module;
+
+static int am_check_access(request_rec *r)
+{
+  int method = r->method_number;
+  am_conf_t *conf;
+  
+  conf = (am_conf_t *) ap_get_module_config(r->per_dir_config,
+                                            &allowmethods_module);
+  if (!conf || conf->allowed == 0) {
+    return DECLINED;
+  }
+  
+  r->allowed = conf->allowed;
+
+  if (conf->allowed & (AP_METHOD_BIT << method)) {
+    return DECLINED;
+  }
+  
+  ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+                  "client method denied by server configuration: '%s' to %s%s",
+                  r->method,
+                  r->filename ? "" : "uri ",
+                  r->filename ? r->filename : r->uri);
+  
+  return HTTP_METHOD_NOT_ALLOWED;
+}
+
+static void *am_create_conf(apr_pool_t * p, char *dummy)
+{
+  am_conf_t *conf = apr_pcalloc(p, sizeof(am_conf_t));
+  
+  conf->allowed = 0;
+  return conf;
+}
+
+static void* am_merge_conf(apr_pool_t* pool, void* a, void* b) {
+  am_conf_t* base = (am_conf_t*) a;
+  am_conf_t* add = (am_conf_t*) b;
+  am_conf_t* conf = apr_palloc(pool, sizeof(am_conf_t));
+  
+  conf->allowed = add->allowed ? add->allowed : base->allowed;
+
+  return conf;
+}
+
+static const char *am_allowmethods(cmd_parms *cmd, void *d, int argc, char *const argv[])
+{
+  int i;
+  am_conf_t* conf = (am_conf_t*) d;
+  if (argc == 1) {
+    if (strcasecmp("reset", argv[0]) == 0) {
+      conf->allowed = 0;
+      return NULL;
+    }
+  }
+
+  for (i = 0; i < argc; i++) {
+    int m = 0;
+    m = ap_method_number_of(argv[i]);
+    if (m == M_INVALID) {
+      return apr_pstrcat(cmd->pool, "AllowMethods: Invalid Method '", argv[i], "'", NULL);
+    }
+
+    conf->allowed |= (AP_METHOD_BIT << m);
+  }
+  return NULL;
+}
+
+static void am_register_hooks(apr_pool_t * p)
+{
+  ap_hook_access_checker(am_check_access, NULL, NULL, APR_HOOK_REALLY_FIRST);
+}
+
+static const command_rec am_cmds[] = {
+  AP_INIT_TAKE_ARGV("AllowMethods", am_allowmethods, NULL,
+              ACCESS_CONF,
+              "only allow specific methods"),
+  {NULL}
+};
+
+module AP_MODULE_DECLARE_DATA allowmethods_module = {
+  STANDARD20_MODULE_STUFF,
+  am_create_conf,
+  am_merge_conf,
+  NULL,
+  NULL,
+  am_cmds,
+  am_register_hooks,
+};
+



Mime
View raw message