]> granicus.if.org Git - apache/commitdiff
Allow any mutex to accept a 'filename' ... and always root it to the
authorWilliam A. Rowe Jr <wrowe@apache.org>
Thu, 27 Mar 2003 23:32:42 +0000 (23:32 +0000)
committerWilliam A. Rowe Jr <wrowe@apache.org>
Thu, 27 Mar 2003 23:32:42 +0000 (23:32 +0000)
  server root unless we are using posixsem, which can't handle big paths.
  This reorganization should make the code much more readable because
  all of the common code is at the beginning and end of the function,
  simplifing the long conditional test case block.

  This patch allows SSLMutex default:logs/ssl_mutex syntax.  It also
  removes the mod_ssl historical '.pid' suffixes - that isn't how Apache2
  specifies files.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@99094 13f79535-47bb-0310-9956-ffa450edef68

modules/ssl/ssl_engine_config.c

index f3020edbe568e7de0403c7d1bda7734bd7ca6d4f..02f5fa20c60a7f1ec68271e4b0502fa032ad7522 100644 (file)
@@ -368,11 +368,20 @@ void *ssl_config_perdir_merge(apr_pool_t *p, void *basev, void *addv)
 
 const char *ssl_cmd_SSLMutex(cmd_parms *cmd,
                              void *dcfg,
-                             const char *arg)
+                             const char *arg_)
 {
     const char *err;
     SSLModConfigRec *mc = myModConfig(cmd->server);
-
+    /* Split arg_ into meth and file */
+    char *meth = apr_pstrdup(cmd->server->process->pool, arg_);
+    char *file = strchr(meth, ':');
+    if (file) {
+        *(file++) = '\0';
+        if (!*file) {
+            file = NULL;
+        }
+    }
+    
     if ((err = ap_check_cmd_context(cmd, GLOBAL_ONLY))) {
         return err;
     }
@@ -380,97 +389,87 @@ const char *ssl_cmd_SSLMutex(cmd_parms *cmd,
     if (ssl_config_global_isfixed(mc)) {
         return NULL;
     }
-
-    if (strcEQ(arg, "none") || strcEQ(arg, "no")) {
+    if (!strcasecmp(meth, "none") || !strcasecmp(meth, "no")) {
         mc->nMutexMode  = SSL_MUTEXMODE_NONE;
+        return NULL;
     }
+
+    /* APR determines temporary filename unless overridden below,
+     * we presume file indicates an szMutexFile is a file path
+     * unless the method sets szMutexFile=file and NULLs file
+     */
+    mc->nMutexMode  = SSL_MUTEXMODE_USED;
+    mc->szMutexFile = NULL;
+
     /* NOTE: previously, 'yes' implied 'sem' */
-    else if (strcEQ(arg, "default") || strcEQ(arg, "yes")) {
-        mc->nMutexMode  = SSL_MUTEXMODE_USED;
+    if (!strcasecmp(meth, "default") || !strcasecmp(meth, "yes")) {
         mc->nMutexMech = APR_LOCK_DEFAULT;
-        mc->szMutexFile = NULL; /* APR determines temporary filename */
     }
 #if APR_HAS_FLOCK_SERIALIZE
-    else if (strlen(arg) > 6 && strcEQn(arg, "flock:", 6)) {
-        const char *file = ap_server_root_relative(cmd->pool, arg+6);
-        if (!file) {
-            return apr_pstrcat(cmd->pool, "Invalid SSLMutex flock: path ", 
-                               arg+6, NULL);
-        }
-        mc->nMutexMode  = SSL_MUTEXMODE_USED;
+    else if (!strcasecmp(meth, "flock") && file) {
         mc->nMutexMech = APR_LOCK_FLOCK;
-        mc->szMutexFile = apr_psprintf(mc->pPool, "%s.%lu",
-                                       file, (unsigned long)getpid());
     }
 #endif
 #if APR_HAS_FCNTL_SERIALIZE
-    else if (strlen(arg) > 6 && strcEQn(arg, "fcntl:", 6)) {
-        const char *file = ap_server_root_relative(cmd->pool, arg+6);
-        if (!file) {
-            return apr_pstrcat(cmd->pool, "Invalid SSLMutex fcntl: path ", 
-                               arg+6, NULL);
-        }
-        mc->nMutexMode  = SSL_MUTEXMODE_USED;
+    else if (!strcasecmp(meth, "fcntl") && file) {
         mc->nMutexMech = APR_LOCK_FCNTL;
-        mc->szMutexFile = apr_psprintf(mc->pPool, "%s.%lu",
-                                       file, (unsigned long)getpid());
     }
 #endif
 #if APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM)
-    else if (strcEQ(arg, "sysvsem")) {
-        mc->nMutexMode  = SSL_MUTEXMODE_USED;
+    else if (!strcasecmp(meth, "sysvsem") && file) {
         mc->nMutexMech = APR_LOCK_SYSVSEM;
-        mc->szMutexFile = NULL; /* APR determines temporary filename */
     }
 #endif
 #if APR_HAS_POSIXSEM_SERIALIZE
-    else if (strcEQ(arg, "posixsem")) {
-        mc->nMutexMode  = SSL_MUTEXMODE_USED;
+    else if (!strcasecmp(meth, "posixsem")) {
         mc->nMutexMech = APR_LOCK_POSIXSEM;
-        mc->szMutexFile = NULL; /* APR determines temporary filename */
+        mc->szMutexFile = file;
+        file = NULL;
     }
 #endif
 #if APR_HAS_PROC_PTHREAD_SERIALIZE
-    else if (strcEQ(arg, "pthread")) {
-        mc->nMutexMode  = SSL_MUTEXMODE_USED;
+    else if (!strcasecmp(meth, "pthread")) {
         mc->nMutexMech = APR_LOCK_PROC_PTHREAD;
-        mc->szMutexFile = NULL; /* APR determines temporary filename */
     }
 #endif
-#if APR_HAS_FLOCK_SERIALIZE || APR_HAS_FCNTL_SERIALIZE
-    else if (strlen(arg) > 5 && strcEQn(arg, "file:", 5)) {
-        const char *file = ap_server_root_relative(cmd->pool, arg+5);
-        if (!file) {
-            return apr_pstrcat(cmd->pool, "Invalid SSLMutex file: path ", 
-                               arg+5, NULL);
-        }
-        mc->nMutexMode  = SSL_MUTEXMODE_USED;
 #if APR_HAS_FLOCK_SERIALIZE
+    else if (!strcasecmp(meth, "file") && file) {
         mc->nMutexMech  = APR_LOCK_FLOCK;
-#endif
-#if APR_HAS_FCNTL_SERIALIZE
+    }
+#elif APR_HAS_FCNTL_SERIALIZE
+    else if (!strcasecmp(meth, "file") && file) {
         mc->nMutexMech  = APR_LOCK_FCNTL;
-#endif
-        mc->szMutexFile =
-            apr_psprintf(mc->pPool, "%s.%lu",
-                         file, (unsigned long)getpid());
     }
 #endif
-#if (APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM)) || APR_HAS_POSIXSEM_SERIALIZE
-    else if (strcEQ(arg, "sem")) {
-        mc->nMutexMode  = SSL_MUTEXMODE_USED;
 #if APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM)
+    else if (!strcasecmp(meth, "sem")) {
         mc->nMutexMech  = APR_LOCK_SYSVSEM;
-#endif
-#if APR_HAS_POSIXSEM_SERIALIZE
+    }
+#elif APR_HAS_POSIXSEM_SERIALIZE
+    else if (!strcasecmp(meth, "sem")) {
         mc->nMutexMech  = APR_LOCK_POSIXSEM;
-#endif
-        mc->szMutexFile = NULL; /* APR determines temporary filename */
+        /* Posix/SysV semaphores aren't file based, use the literal name 
+         * if provided and fall back on APR's default if not.
+         */
+        mc->szMutexFile = file;
+        file = NULL;
     }
 #endif
     else {
-        return apr_pstrcat(cmd->pool, "Invalid SSLMutex argument ", 
-                           arg, " (", ssl_valid_ssl_mutex_string, ")", NULL);
+        return apr_pstrcat(cmd->pool, "Invalid SSLMutex argument ", arg_,
+                           " (", ssl_valid_ssl_mutex_string, ")", NULL);
+    }
+
+    /* Unless the method above assumed responsibility for setting up
+     * mc->szMutexFile and NULLing out file, presume it is a file we
+     * are looking to use
+     */
+    if (file) {
+        mc->szMutexFile = ap_server_root_relative(cmd->pool, file);
+        if (!mc->szMutexFile) {
+            return apr_pstrcat(cmd->pool, "Invalid SSLMutex ", meth, 
+                               ": filepath ", file, NULL);
+        }
     }
 
     return NULL;