Blame SOURCES/httpd-2.4.6-CVE-2015-3185.patch

008793
Index: server/request.c
008793
===================================================================
008793
--- a/server/request.c	(revision 1684524)
008793
+++ b/server/request.c	(revision 1684525)
008793
@@ -71,6 +71,7 @@
008793
     APR_HOOK_LINK(create_request)
008793
     APR_HOOK_LINK(post_perdir_config)
008793
     APR_HOOK_LINK(dirwalk_stat)
008793
+    APR_HOOK_LINK(force_authn)
008793
 )
008793
 
008793
 AP_IMPLEMENT_HOOK_RUN_FIRST(int,translate_name,
008793
@@ -97,6 +98,8 @@
008793
 AP_IMPLEMENT_HOOK_RUN_FIRST(apr_status_t,dirwalk_stat,
008793
                             (apr_finfo_t *finfo, request_rec *r, apr_int32_t wanted),
008793
                             (finfo, r, wanted), AP_DECLINED)
008793
+AP_IMPLEMENT_HOOK_RUN_FIRST(int,force_authn,
008793
+                          (request_rec *r), (r), DECLINED)
008793
 
008793
 static int auth_internal_per_conf = 0;
008793
 static int auth_internal_per_conf_hooks = 0;
008793
@@ -118,6 +121,39 @@
008793
     }
008793
 }
008793
 
008793
+AP_DECLARE(int) ap_some_authn_required(request_rec *r)
008793
+{
008793
+    int access_status;
008793
+
008793
+    switch (ap_satisfies(r)) {
008793
+    case SATISFY_ALL:
008793
+    case SATISFY_NOSPEC:
008793
+        if ((access_status = ap_run_access_checker(r)) != OK) {
008793
+            break;
008793
+        }
008793
+
008793
+        access_status = ap_run_access_checker_ex(r);
008793
+        if (access_status == DECLINED) {
008793
+            return TRUE;
008793
+        }
008793
+
008793
+        break;
008793
+    case SATISFY_ANY:
008793
+        if ((access_status = ap_run_access_checker(r)) == OK) {
008793
+            break;
008793
+        }
008793
+
008793
+        access_status = ap_run_access_checker_ex(r);
008793
+        if (access_status == DECLINED) {
008793
+            return TRUE;
008793
+        }
008793
+
008793
+        break;
008793
+    }
008793
+
008793
+    return FALSE;
008793
+}
008793
+
008793
 /* This is the master logic for processing requests.  Do NOT duplicate
008793
  * this logic elsewhere, or the security model will be broken by future
008793
  * API changes.  Each phase must be individually optimized to pick up
008793
@@ -232,15 +268,8 @@
008793
             }
008793
 
008793
             access_status = ap_run_access_checker_ex(r);
008793
-            if (access_status == OK) {
008793
-                ap_log_rerror(APLOG_MARK, APLOG_TRACE3, 0, r,
008793
-                              "request authorized without authentication by "
008793
-                              "access_checker_ex hook: %s", r->uri);
008793
-            }
008793
-            else if (access_status != DECLINED) {
008793
-                return decl_die(access_status, "check access", r);
008793
-            }
008793
-            else {
008793
+            if (access_status == DECLINED
008793
+                || (access_status == OK && ap_run_force_authn(r) == OK)) {
008793
                 if ((access_status = ap_run_check_user_id(r)) != OK) {
008793
                     return decl_die(access_status, "check user", r);
008793
                 }
008793
@@ -258,6 +287,14 @@
008793
                     return decl_die(access_status, "check authorization", r);
008793
                 }
008793
             }
008793
+            else if (access_status == OK) {
008793
+                ap_log_rerror(APLOG_MARK, APLOG_TRACE3, 0, r,
008793
+                              "request authorized without authentication by "
008793
+                              "access_checker_ex hook: %s", r->uri);
008793
+            }
008793
+            else {
008793
+                return decl_die(access_status, "check access", r);
008793
+            }
008793
             break;
008793
         case SATISFY_ANY:
008793
             if ((access_status = ap_run_access_checker(r)) == OK) {
008793
@@ -269,15 +306,8 @@
008793
             }
008793
 
008793
             access_status = ap_run_access_checker_ex(r);
008793
-            if (access_status == OK) {
008793
-                ap_log_rerror(APLOG_MARK, APLOG_TRACE3, 0, r,
008793
-                              "request authorized without authentication by "
008793
-                              "access_checker_ex hook: %s", r->uri);
008793
-            }
008793
-            else if (access_status != DECLINED) {
008793
-                return decl_die(access_status, "check access", r);
008793
-            }
008793
-            else {
008793
+            if (access_status == DECLINED
008793
+                || (access_status == OK && ap_run_force_authn(r) == OK)) {
008793
                 if ((access_status = ap_run_check_user_id(r)) != OK) {
008793
                     return decl_die(access_status, "check user", r);
008793
                 }
008793
@@ -295,6 +325,14 @@
008793
                     return decl_die(access_status, "check authorization", r);
008793
                 }
008793
             }
008793
+            else if (access_status == OK) {
008793
+                ap_log_rerror(APLOG_MARK, APLOG_TRACE3, 0, r,
008793
+                              "request authorized without authentication by "
008793
+                              "access_checker_ex hook: %s", r->uri);
008793
+            }
008793
+            else {
008793
+                return decl_die(access_status, "check access", r);
008793
+            }
008793
             break;
008793
         }
008793
     }
008793
Index: include/http_request.h
008793
===================================================================
008793
--- a/include/http_request.h	(revision 1684524)
008793
+++ b/include/http_request.h	(revision 1684525)
008793
@@ -185,6 +185,8 @@
008793
  * is required for the current request
008793
  * @param r The current request
008793
  * @return 1 if authentication is required, 0 otherwise
008793
+ * @bug Behavior changed in 2.4.x refactoring, API no longer usable
008793
+ * @deprecated @see ap_some_authn_required()
008793
  */
008793
 AP_DECLARE(int) ap_some_auth_required(request_rec *r);
008793
 
008793
@@ -539,6 +541,16 @@
008793
 AP_DECLARE_HOOK(int,post_perdir_config,(request_rec *r))
008793
 
008793
 /**
008793
+ * This hook allows a module to force authn to be required when
008793
+ * processing a request.
008793
+ * This hook should be registered with ap_hook_force_authn().
008793
+ * @param r The current request
008793
+ * @return OK (force authn), DECLINED (let later modules decide)
008793
+ * @ingroup hooks
008793
+ */
008793
+AP_DECLARE_HOOK(int,force_authn,(request_rec *r))
008793
+
008793
+/**
008793
  * This hook allows modules to handle/emulate the apr_stat() calls
008793
  * needed for directory walk.
008793
  * @param r The current request
008793
@@ -584,6 +596,17 @@
008793
 AP_DECLARE(apr_bucket *) ap_bucket_eor_create(apr_bucket_alloc_t *list,
008793
                                               request_rec *r);
008793
 
008793
+/**
008793
+ * Can be used within any handler to determine if any authentication
008793
+ * is required for the current request.  Note that if used with an
008793
+ * access_checker hook, an access_checker_ex hook or an authz provider; the
008793
+ * caller should take steps to avoid a loop since this function is
008793
+ * implemented by calling these hooks.
008793
+ * @param r The current request
008793
+ * @return TRUE if authentication is required, FALSE otherwise
008793
+ */
008793
+AP_DECLARE(int) ap_some_authn_required(request_rec *r);
008793
+
008793
 #ifdef __cplusplus
008793
 }
008793
 #endif