apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From minf...@apache.org
Subject svn commit: r1187987 - in /apr/apr-util/branches/1.5.x/crypto: apr_crypto_nss.c apr_crypto_openssl.c
Date Sun, 23 Oct 2011 22:10:00 GMT
Author: minfrin
Date: Sun Oct 23 22:10:00 2011
New Revision: 1187987

URL: http://svn.apache.org/viewvc?rev=1187987&view=rev
Log:
Backport from apr-trunk to apr-util-1.5:
apr_crypto: Teach the apr_crypto_nss driver to support the "noinit" option
for where NSS is initialised elsewhere.

Modified:
    apr/apr-util/branches/1.5.x/crypto/apr_crypto_nss.c
    apr/apr-util/branches/1.5.x/crypto/apr_crypto_openssl.c

Modified: apr/apr-util/branches/1.5.x/crypto/apr_crypto_nss.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.5.x/crypto/apr_crypto_nss.c?rev=1187987&r1=1187986&r2=1187987&view=diff
==============================================================================
--- apr/apr-util/branches/1.5.x/crypto/apr_crypto_nss.c (original)
+++ apr/apr-util/branches/1.5.x/crypto/apr_crypto_nss.c Sun Oct 23 22:10:00 2011
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include "apr_lib.h"
 #include "apu.h"
 #include "apu_config.h"
 #include "apu_errno.h"
@@ -127,65 +128,69 @@ static apr_status_t crypto_init(apr_pool
     const char *keyPrefix = NULL;
     const char *certPrefix = NULL;
     const char *secmod = NULL;
+    int noinit = 0;
     PRUint32 flags = 0;
 
     struct {
         const char *field;
-        char *value;
+        const char *value;
+        int set;
     } fields[] = {
-        { "dir", NULL },
-        { "key3", NULL },
-        { "cert7", NULL },
-        { "secmod", NULL },
-        { NULL, NULL }
+        { "dir", NULL, 0 },
+        { "key3", NULL, 0 },
+        { "cert7", NULL, 0 },
+        { "secmod", NULL, 0 },
+        { "noinit", NULL, 0 },
+        { NULL, NULL, 0 }
     };
-    int i;
     const char *ptr;
-    const char *key;
     size_t klen;
-    const char *value;
-    size_t vlen;
-    static const char * const delims = " \r\n\t;|,";
-
-    /* sanity check - we can only initialise NSS once */
-    if (NSS_IsInitialized()) {
-        return APR_EREINIT;
-    }
-
-    /* snitch parsing from the MySQL driver */
-    for (ptr = strchr(params, '='); ptr; ptr = strchr(ptr, '=')) {
-        /* don't dereference memory that may not belong to us */
-        if (ptr == params) {
-            ++ptr;
-            continue;
-        }
-        for (key = ptr - 1; apr_isspace(*key); --key);
-        klen = 0;
-        while (apr_isalpha(*key)) {
-            if (key == params) {
-                /* Don't parse off the front of the params */
-                --key;
-                ++klen;
-                break;
-            }
-            --key;
-            ++klen;
+    char **elts = NULL;
+    char *elt;
+    int i = 0, j;
+    apr_status_t status;
+
+    if (APR_SUCCESS != (status = apr_tokenize_to_argv(params, &elts, pool))) {
+        return status;
+    }
+    while ((elt = elts[i])) {
+        ptr = strchr(elt, '=');
+        if (ptr) {
+            for (klen = ptr - elt; klen && apr_isspace(elt[klen - 1]); --klen);
+            ptr++;
+        }
+        else {
+            for (klen = strlen(elt); klen && apr_isspace(elt[klen - 1]); --klen);
         }
-        ++key;
-        for (value = ptr + 1; apr_isspace(*value); ++value);
-        vlen = strcspn(value, delims);
-        for (i = 0; fields[i].field != NULL; ++i) {
-            if (!strncasecmp(fields[i].field, key, klen)) {
-                fields[i].value = apr_pstrndup(pool, value, vlen);
+        elt[klen] = 0;
+
+        for (j = 0; fields[j].field != NULL; ++j) {
+            if (klen && !strcasecmp(fields[j].field, elt)) {
+                fields[j].set = 1;
+                if (ptr) {
+                    fields[j].value = ptr;
+                }
                 break;
             }
         }
-        ptr = value + vlen;
+
+        i++;
     }
     dir = fields[0].value;
     keyPrefix = fields[1].value;
     certPrefix = fields[2].value;
     secmod = fields[3].value;
+    noinit = fields[4].set;
+
+    /* if we've been asked to bypass, do so here */
+    if (noinit) {
+        return APR_SUCCESS;
+    }
+
+    /* sanity check - we can only initialise NSS once */
+    if (NSS_IsInitialized()) {
+        return APR_EREINIT;
+    }
 
     apr_pool_cleanup_register(pool, pool, crypto_shutdown_helper,
             apr_pool_cleanup_null);

Modified: apr/apr-util/branches/1.5.x/crypto/apr_crypto_openssl.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.5.x/crypto/apr_crypto_openssl.c?rev=1187987&r1=1187986&r2=1187987&view=diff
==============================================================================
--- apr/apr-util/branches/1.5.x/crypto/apr_crypto_openssl.c (original)
+++ apr/apr-util/branches/1.5.x/crypto/apr_crypto_openssl.c Sun Oct 23 22:10:00 2011
@@ -191,21 +191,50 @@ static apr_status_t crypto_make(apr_cryp
     apr_crypto_config_t *config = NULL;
     apr_crypto_t *f = apr_pcalloc(pool, sizeof(apr_crypto_t));
 
+    const char *engine;
+
     struct {
         const char *field;
-        char *value;
+        const char *value;
+        int set;
     } fields[] = {
-        { "engine", NULL },
-        { NULL, NULL }
+        { "engine", NULL, 0 },
+        { NULL, NULL, 0 }
     };
-    int i;
     const char *ptr;
-    const char *key;
     size_t klen;
-    const char *value;
-    size_t vlen;
-    static const char * const delims = " \r\n\t;|,";
-    const char *engine;
+    char **elts = NULL;
+    char *elt;
+    int i = 0, j;
+    apr_status_t status;
+
+    if (APR_SUCCESS != (status = apr_tokenize_to_argv(params, &elts, pool))) {
+        return status;
+    }
+    while ((elt = elts[i])) {
+        ptr = strchr(elt, '=');
+        if (ptr) {
+            for (klen = ptr - elt; klen && apr_isspace(elt[klen - 1]); --klen);
+            ptr++;
+        }
+        else {
+            for (klen = strlen(elt); klen && apr_isspace(elt[klen - 1]); --klen);
+        }
+        elt[klen] = 0;
+
+        for (j = 0; fields[j].field != NULL; ++j) {
+            if (!strcasecmp(fields[j].field, elt)) {
+                fields[j].set = 1;
+                if (ptr) {
+                    fields[j].value = ptr;
+                }
+                break;
+            }
+        }
+
+        i++;
+    }
+    engine = fields[0].value;
 
     if (!f) {
         return APR_ENOMEM;
@@ -247,38 +276,6 @@ static apr_status_t crypto_make(apr_cryp
     apr_pool_cleanup_register(pool, f, crypto_cleanup_helper,
             apr_pool_cleanup_null);
 
-    /* snitch parsing from the MySQL driver */
-    for (ptr = strchr(params, '='); ptr; ptr = strchr(ptr, '=')) {
-        /* don't dereference memory that may not belong to us */
-        if (ptr == params) {
-            ++ptr;
-            continue;
-        }
-        for (key = ptr - 1; apr_isspace(*key); --key);
-        klen = 0;
-        while (apr_isalpha(*key)) {
-            if (key == params) {
-                /* Don't parse off the front of the params */
-                --key;
-                ++klen;
-                break;
-            }
-            --key;
-            ++klen;
-        }
-        ++key;
-        for (value = ptr + 1; apr_isspace(*value); ++value);
-        vlen = strcspn(value, delims);
-        for (i = 0; fields[i].field != NULL; ++i) {
-            if (!strncasecmp(fields[i].field, key, klen)) {
-                fields[i].value = apr_pstrndup(pool, value, vlen);
-                break;
-            }
-        }
-        ptr = value + vlen;
-    }
-    engine = fields[0].value;
-
     if (engine) {
         config->engine = ENGINE_by_id(engine);
         if (!config->engine) {



Mime
View raw message