]> granicus.if.org Git - apache/commitdiff
Merge r1733523, r1733691 from trunk:
authorYann Ylavic <ylavic@apache.org>
Thu, 10 Mar 2016 12:27:49 +0000 (12:27 +0000)
committerYann Ylavic <ylavic@apache.org>
Thu, 10 Mar 2016 12:27:49 +0000 (12:27 +0000)
Use ap_array_str_contains to simplify code

Use ap_array_str_contains to simplify code
Remove a useless test (groups is always NULL)
Improve some style

Submitted by: jailletc36
Reviewed by: jailletc36, jim, ylavic
Backported by: ylavic

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1734395 13f79535-47bb-0310-9956-ffa450edef68

STATUS
modules/aaa/mod_authn_socache.c
modules/aaa/mod_authz_dbd.c

diff --git a/STATUS b/STATUS
index 953becf87dbd1c4e262f2cc41957c2721063847c..013cb6448f74be9bc05140daa29c83aabc43e9aa 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -112,12 +112,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
 
-  *) Use ap_array_str_contains to simplify code
-     trunk patch: http://svn.apache.org/r1733523
-                  http://svn.apache.org/r1733691
-     2.4.x patch: trunk patch works
-     +1: jailletc36, jim, ylavic
-
   *) mod_ssl: Don't lose track of the SSL context if the ssl_run_pre_handshake()
      hook returns an error.
      trunk patch: http://svn.apache.org/r1734006
index 051dde8d739fdfd2bb09aa12c32eb8546f854d56..550bc6619d2765aa03f0de8d21fcd6aa1616ab5b 100644 (file)
@@ -298,21 +298,13 @@ static void ap_authn_cache_store(request_rec *r, const char *module,
     authn_cache_dircfg *dcfg;
     const char *key;
     apr_time_t expiry;
-    int i;
-    int use_cache = 0;
 
     /* first check whether we're cacheing for this module */
     dcfg = ap_get_module_config(r->per_dir_config, &authn_socache_module);
     if (!configured || !dcfg->providers) {
         return;
     }
-    for (i = 0; i < dcfg->providers->nelts; ++i) {
-        if (!strcmp(module, APR_ARRAY_IDX(dcfg->providers, i, const char*))) {
-            use_cache = 1;
-            break;
-        }
-    }
-    if (!use_cache) {
+    if (!ap_array_str_contains(dcfg->providers, module)) {
         return;
     }
 
index 628a165dea9e0eb734e405ea6e9bc297e78b2d03..52aab3809a2a938eaee485f0b59d012335bc1635 100644 (file)
@@ -61,6 +61,7 @@ static void *authz_dbd_cr_cfg(apr_pool_t *pool, char *dummy)
     ret->redirect = -1;
     return ret;
 }
+
 static void *authz_dbd_merge_cfg(apr_pool_t *pool, void *BASE, void *ADD)
 {
     authz_dbd_cfg *base = BASE;
@@ -73,6 +74,7 @@ static void *authz_dbd_merge_cfg(apr_pool_t *pool, void *BASE, void *ADD)
     ret->redirect = (add->redirect == -1) ? base->redirect : add->redirect;
     return ret;
 }
+
 static const char *authz_dbd_prepare(cmd_parms *cmd, void *cfg,
                                      const char *query)
 {
@@ -96,6 +98,7 @@ static const char *authz_dbd_prepare(cmd_parms *cmd, void *cfg,
     /* save the label here for our own use */
     return ap_set_string_slot(cmd, cfg, label);
 }
+
 static const command_rec authz_dbd_cmds[] = {
     AP_INIT_FLAG("AuthzDBDLoginToReferer", ap_set_flag_slot,
                  (void*)APR_OFFSETOF(authz_dbd_cfg, redirect), ACCESS_CONF,
@@ -265,9 +268,9 @@ static authz_status dbdgroup_check_authorization(request_rec *r,
                                                  const char *require_args,
                                                  const void *parsed_require_args)
 {
-    int i, rv;
+    int rv;
     const char *w;
-    apr_array_header_t *groups = NULL;
+    apr_array_header_t *groups;
 
     const char *err = NULL;
     const ap_expr_info_t *expr = parsed_require_args;
@@ -281,12 +284,10 @@ static authz_status dbdgroup_check_authorization(request_rec *r,
         return AUTHZ_DENIED_NO_USER;
     }
 
-    if (groups == NULL) {
-        groups = apr_array_make(r->pool, 4, sizeof(const char*));
-        rv = authz_dbd_group_query(r, cfg, groups);
-        if (rv != OK) {
-            return AUTHZ_GENERAL_ERROR;
-        }
+    groups = apr_array_make(r->pool, 4, sizeof(const char*));
+    rv = authz_dbd_group_query(r, cfg, groups);
+    if (rv != OK) {
+        return AUTHZ_GENERAL_ERROR;
     }
 
     require = ap_expr_str_exec(r, expr, &err);
@@ -300,10 +301,8 @@ static authz_status dbdgroup_check_authorization(request_rec *r,
     t = require;
     while (t[0]) {
         w = ap_getword_white(r->pool, &t);
-        for (i=0; i < groups->nelts; ++i) {
-            if (!strcmp(w, ((const char**)groups->elts)[i])) {
-                return AUTHZ_GRANTED;
-            }
+        if (ap_array_str_contains(groups, w)) {
+            return AUTHZ_GRANTED;
         }
     }
 
@@ -339,18 +338,19 @@ static authz_status dbdlogout_check_authorization(request_rec *r,
 }
 
 static const char *dbd_parse_config(cmd_parms *cmd, const char *require_line,
-                                     const void **parsed_require_line)
+                                    const void **parsed_require_line)
 {
     const char *expr_err = NULL;
     ap_expr_info_t *expr;
 
     expr = ap_expr_parse_cmd(cmd, require_line, AP_EXPR_FLAG_STRING_RESULT,
-            &expr_err, NULL);
+                             &expr_err, NULL);
 
-    if (expr_err)
+    if (expr_err) {
         return apr_pstrcat(cmd->temp_pool,
                            "Cannot parse expression in require line: ",
                            expr_err, NULL);
+    }
 
     *parsed_require_line = expr;
 
@@ -369,7 +369,6 @@ static const authz_provider authz_dbdlogin_provider =
     NULL,
 };
 
-
 static const authz_provider authz_dbdlogout_provider =
 {
     &dbdlogout_check_authorization,
@@ -402,4 +401,3 @@ AP_DECLARE_MODULE(authz_dbd) =
     authz_dbd_cmds,
     authz_dbd_hooks
 };
-