You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by jo...@apache.org on 2026/09/24 15:31:56 UTC

svn commit: r1938494 - in httpd/httpd/trunk: . modules/md support/a2md

Author: jorton
Date: Thu Sep 24 15:31:56 2026
New Revision: 1938494

Log:
* modules/md/md_util.h, modules/md/md_util.c (md_util_exec_cmdline):
  New function, tokenizing only the configured command line and passing
  the remaining arguments verbatim.

* modules/md/md_acme_authz.c (md_acme_authz_update): Reject an
  authorization identifier which is not a DNS name or wildcard.
  (cha_dns_01_setup, cha_dns_01_teardown): Use md_util_exec_cmdline().

* modules/md/mod_md.c (notify): Use md_util_exec_cmdline() for
  MDNotifyCmd and MDMessageCmd.

* modules/md/md_acme_order.c (md_acme_order_start_challenges): Log the
  authz url, authz is NULL if the retrieve failed.

Co-Authored-By: Claude Opus 5 (1M context) <no...@anthropic.com>
GitHub: PR #768

Modified:
   httpd/httpd/trunk/CMakeLists.txt
   httpd/httpd/trunk/modules/md/md_acme_authz.c
   httpd/httpd/trunk/modules/md/md_acme_order.c
   httpd/httpd/trunk/modules/md/md_util.c
   httpd/httpd/trunk/modules/md/md_util.h
   httpd/httpd/trunk/modules/md/mod_md.c
   httpd/httpd/trunk/support/a2md/Makefile.in

Modified: httpd/httpd/trunk/CMakeLists.txt
==============================================================================
--- httpd/httpd/trunk/CMakeLists.txt	Thu Sep 24 14:53:41 2026	(r1938493)
+++ httpd/httpd/trunk/CMakeLists.txt	Thu Sep 24 15:31:56 2026	(r1938494)
@@ -1076,6 +1076,7 @@ IF(OPENSSL_FOUND AND CURL_FOUND AND JANS
   SET_TARGET_PROPERTIES(a2md PROPERTIES INCLUDE_DIRECTORIES "${tmp_includes}")
   TARGET_COMPILE_DEFINITIONS(a2md PRIVATE
       "APP_FILE"
+      "MD_A2MD_BUILD"
       "LONG_NAME=Apache HTTP Server a2md program"
       "BIN_NAME=a2md.exe"
   )

Modified: httpd/httpd/trunk/modules/md/md_acme_authz.c
==============================================================================
--- httpd/httpd/trunk/modules/md/md_acme_authz.c	Thu Sep 24 14:53:41 2026	(r1938493)
+++ httpd/httpd/trunk/modules/md/md_acme_authz.c	Thu Sep 24 15:31:56 2026	(r1938494)
@@ -136,7 +136,15 @@ apr_status_t md_acme_authz_update(md_acm
             
         authz->domain = md_json_gets(json, MD_KEY_IDENTIFIER, MD_KEY_VALUE, NULL); 
         authz->resource = json;
-        if (!strcmp(s, "pending")) {
+        if (!authz->domain
+            || (!md_dns_is_name(p, authz->domain, 1)
+                && !md_dns_is_wildcard(p, authz->domain))) {
+            /* The identifier names files in the store and is passed to the
+             * configured challenge commands. Only accept a DNS name here. */
+            err = "invalid identifier in response";
+            rv = APR_EINVAL;
+        }
+        else if (!strcmp(s, "pending")) {
             authz->state = MD_ACME_AUTHZ_S_PENDING;
             err = "challenge 'pending'";
             log_level = MD_LOG_DEBUG;
@@ -155,7 +163,7 @@ apr_status_t md_acme_authz_update(md_acm
         }
     }
 
-    if (json && authz->state == MD_ACME_AUTHZ_S_UNKNOWN) {
+    if (json && rv == APR_SUCCESS && authz->state == MD_ACME_AUTHZ_S_UNKNOWN) {
         err = "unable to understand response";
         rv = APR_EINVAL;
     }
@@ -423,8 +431,7 @@ static apr_status_t cha_dns_01_setup(md_
                                      const char **psetup_token, apr_pool_t *p)
 {
     const char *token;
-    const char * const *argv;
-    const char *cmdline, *dns01_cmd;
+    const char *dns01_cmd;
     apr_status_t rv;
     int exit_code, notify_server;
     authz_req_ctx ctx;
@@ -457,12 +464,13 @@ static apr_status_t cha_dns_01_setup(md_
         goto out;
     }
 
-    cmdline = apr_psprintf(p, "%s setup %s %s", dns01_cmd, authz->domain, token); 
     md_log_perror(MD_LOG_MARK, MD_LOG_DEBUG, 0, p, 
-                  "%s: dns-01 setup command: %s", authz->domain, cmdline);
+                  "%s: dns-01 setup command: %s setup %s %s",
+                  authz->domain, dns01_cmd, authz->domain, token);
 
-    apr_tokenize_to_argv(cmdline, (char***)&argv, p);
-    if (APR_SUCCESS != (rv = md_util_exec(p, argv[0], argv, &exit_code))) {
+    rv = md_util_exec_cmdline(p, dns01_cmd, &exit_code,
+                              "setup", authz->domain, token, NULL);
+    if (rv != APR_SUCCESS) {
         md_log_perror(MD_LOG_MARK, MD_LOG_WARNING, rv, p, 
                       "%s: dns-01 setup command failed to execute for %s", md->name, authz->domain);
         goto out;
@@ -500,8 +508,7 @@ out:
 static apr_status_t cha_dns_01_teardown(md_store_t *store, const char *domain, const md_t *md,
                                         apr_table_t *env, apr_pool_t *p)
 {
-    const char * const *argv;
-    const char *cmdline, *dns01_cmd, *dns01v;
+    const char *dns01_cmd, *dns01v, *token = NULL;
     char *tmp, *s;
     apr_status_t rv;
     int exit_code;
@@ -517,20 +524,24 @@ static apr_status_t cha_dns_01_teardown(
             md->name, domain);
         goto out;
     }
+    /* dns-01 setup tokens carry the token after the domain, separated by a space */
+    tmp = apr_pstrdup(p, domain);
+    s = strchr(tmp, ' ');
+    if (s) {
+        *s = '\0';
+        domain = tmp;
+        token = s + 1;
+    }
     dns01v = apr_table_get(env, MD_KEY_DNS01_VERSION);
     if (!dns01v || strcmp(dns01v, "2")) {
         /* use older version of teardown args with only domain, remove token */
-        tmp = apr_pstrdup(p, domain);
-        s = strchr(tmp, ' ');
-        if (s) {
-            *s = '\0';
-            domain = tmp;
-        }
+        token = NULL;
     }
 
-    cmdline = apr_psprintf(p, "%s teardown %s", dns01_cmd, domain); 
-    apr_tokenize_to_argv(cmdline, (char***)&argv, p);
-    if (APR_SUCCESS != (rv = md_util_exec(p, argv[0], argv, &exit_code)) || exit_code) {
+    /* a NULL token ends the argument list, e.g. is not passed on */
+    rv = md_util_exec_cmdline(p, dns01_cmd, &exit_code,
+                              "teardown", domain, token, NULL);
+    if (rv != APR_SUCCESS || exit_code) {
         md_log_perror(MD_LOG_MARK, MD_LOG_WARNING, rv, p, 
                       "%s: dns-01 teardown command failed (exit code=%d) for %s",
                       md->name, exit_code, domain);

Modified: httpd/httpd/trunk/modules/md/md_acme_order.c
==============================================================================
--- httpd/httpd/trunk/modules/md/md_acme_order.c	Thu Sep 24 14:53:41 2026	(r1938493)
+++ httpd/httpd/trunk/modules/md/md_acme_order.c	Thu Sep 24 15:31:56 2026	(r1938494)
@@ -459,8 +459,9 @@ apr_status_t md_acme_order_start_challen
         md_log_perror(MD_LOG_MARK, MD_LOG_DEBUG, rv, p, "%s: check AUTHZ at %s", md->name, url);
         
         if (APR_SUCCESS != (rv = md_acme_authz_retrieve(acme, p, url, &authz))) {
-            md_log_perror(MD_LOG_MARK, MD_LOG_DEBUG, rv, p, "%s: check authz for %s",
-                          md->name, authz->domain);
+            /* authz is NULL on failure, report the url we could not use */
+            md_log_perror(MD_LOG_MARK, MD_LOG_DEBUG, rv, p, "%s: check authz at %s",
+                          md->name, url);
             goto leave;
         }
 

Modified: httpd/httpd/trunk/modules/md/md_util.c
==============================================================================
--- httpd/httpd/trunk/modules/md/md_util.c	Thu Sep 24 14:53:41 2026	(r1938493)
+++ httpd/httpd/trunk/modules/md/md_util.c	Thu Sep 24 15:31:56 2026	(r1938494)
@@ -1119,6 +1119,39 @@ out:
     return rv;
 }
 
+apr_status_t md_util_exec_cmdline(apr_pool_t *p, const char *cmdline,
+                                  int *exit_code, ...)
+{
+    apr_array_header_t *argv;
+    char **cmd_argv;
+    const char *arg;
+    apr_status_t rv;
+    va_list ap;
+    int i;
+
+    *exit_code = 0;
+    rv = apr_tokenize_to_argv(cmdline, &cmd_argv, p);
+    if (rv != APR_SUCCESS) return rv;
+    if (!cmd_argv[0]) return APR_EINVAL;
+
+    /* The command line is configured by the administrator and parsed as such,
+     * the additional arguments may come from a remote party and are passed on
+     * verbatim, so that they can never become more than one argument. */
+    argv = apr_array_make(p, 8, sizeof(const char *));
+    for (i = 0; cmd_argv[i]; ++i) {
+        APR_ARRAY_PUSH(argv, const char *) = cmd_argv[i];
+    }
+    va_start(ap, exit_code);
+    while ((arg = va_arg(ap, const char *))) {
+        APR_ARRAY_PUSH(argv, const char *) = arg;
+    }
+    va_end(ap);
+    APR_ARRAY_PUSH(argv, const char *) = NULL;
+
+    return md_util_exec(p, APR_ARRAY_IDX(argv, 0, const char *),
+                        (const char * const *)argv->elts, exit_code);
+}
+
 /* base64 url encoding ****************************************************************************/
 
 #define N6 (unsigned int)-1

Modified: httpd/httpd/trunk/modules/md/md_util.h
==============================================================================
--- httpd/httpd/trunk/modules/md/md_util.h	Thu Sep 24 14:53:41 2026	(r1938493)
+++ httpd/httpd/trunk/modules/md/md_util.h	Thu Sep 24 15:31:56 2026	(r1938494)
@@ -30,6 +30,17 @@
 #define apr_cstr_casecmp apr_strnatcasecmp
 #endif
 
+/* a2md builds these sources standalone, without linking httpd, and defines
+ * MD_A2MD_BUILD to say so.  It must not see the httpd internals: on Windows
+ * ap_config.h pulls in os.h, whose exit() macro references ap_real_exit_code,
+ * a symbol only ApacheCore provides. */
+#ifdef MD_A2MD_BUILD
+#define MD_FN_ATTR_SENTINEL
+#else
+#include <ap_config.h>
+#define MD_FN_ATTR_SENTINEL AP_FN_ATTR_SENTINEL
+#endif
+
 struct apr_array_header_t;
 struct apr_table_t;
 
@@ -145,6 +156,18 @@ int md_array_str_add_missing(struct apr_
 apr_status_t md_util_exec(apr_pool_t *p, const char *cmd, const char * const *argv,
                           int *exit_code);
 
+/**
+ * Run the program given by `cmdline`, which is tokenized into the program name
+ * and its arguments. Any further arguments are taken from the NULL terminated
+ * varargs list and passed to the program verbatim, e.g. without tokenization,
+ * so that an argument which contains whitespace or quotes cannot turn into
+ * several arguments.
+ * @param cmdline    the program to run, with optional arguments
+ * @param exit_code  receives the exit code of the program
+ */
+apr_status_t md_util_exec_cmdline(apr_pool_t *p, const char *cmdline,
+                                  int *exit_code, ...) MD_FN_ATTR_SENTINEL;
+
 /**************************************************************************************************/
 /* dns name check */
 

Modified: httpd/httpd/trunk/modules/md/mod_md.c
==============================================================================
--- httpd/httpd/trunk/modules/md/mod_md.c	Thu Sep 24 14:53:41 2026	(r1938493)
+++ httpd/httpd/trunk/modules/md/mod_md.c	Thu Sep 24 15:31:56 2026	(r1938494)
@@ -151,8 +151,6 @@ static apr_status_t notify(md_job_t *job
                            md_result_t *result, apr_pool_t *p, void *baton)
 {
     md_mod_conf_t *mc = baton;
-    const char * const *argv;
-    const char *cmdline;
     int exit_code;
     apr_status_t rv = APR_SUCCESS;
     apr_time_t min_interim = 0;
@@ -180,10 +178,8 @@ static apr_status_t notify(md_job_t *job
 
     if (!strcmp("renewed", reason)) {
         if (mc->notify_cmd) {
-            cmdline = apr_psprintf(p, "%s %s", mc->notify_cmd, job->mdomain);
-            apr_tokenize_to_argv(cmdline, (char***)&argv, p);
-            rv = md_util_exec(p, argv[0], argv, &exit_code);
-
+            rv = md_util_exec_cmdline(p, mc->notify_cmd, &exit_code,
+                                      job->mdomain, NULL);
             if (APR_SUCCESS == rv && exit_code) rv = APR_EGENERAL;
             if (APR_SUCCESS != rv) {
                 md_result_problem_printf(result, rv, MD_RESULT_LOG_ID(APLOGNO(10108)),
@@ -199,10 +195,10 @@ static apr_status_t notify(md_job_t *job
                      "will be activated on next (graceful) server restart.", job->mdomain);
     }
     if (mc->message_cmd) {
-        cmdline = apr_psprintf(p, "%s %s %s", mc->message_cmd, reason, job->mdomain);
-        apr_tokenize_to_argv(cmdline, (char***)&argv, p);
-        rv = md_util_exec(p, argv[0], argv, &exit_code);
-
+        /* `reason` may carry a domain name from the ACME server, pass it as a
+         * single argument and never let it parse into more than one. */
+        rv = md_util_exec_cmdline(p, mc->message_cmd, &exit_code,
+                                  reason, job->mdomain, NULL);
         if (APR_SUCCESS == rv && exit_code) rv = APR_EGENERAL;
         if (APR_SUCCESS != rv) {
             md_result_problem_printf(result, rv, MD_RESULT_LOG_ID(APLOGNO(10109)),

Modified: httpd/httpd/trunk/support/a2md/Makefile.in
==============================================================================
--- httpd/httpd/trunk/support/a2md/Makefile.in	Thu Sep 24 14:53:41 2026	(r1938493)
+++ httpd/httpd/trunk/support/a2md/Makefile.in	Thu Sep 24 15:31:56 2026	(r1938494)
@@ -36,7 +36,7 @@ A2MD_CPPFLAGS = \
     -I$(top_srcdir)/include \
     -I$(top_srcdir)/modules/md \
     -I$(top_srcdir)/support/a2md \
-    -std=c99 -D_GNU_SOURCE \
+    -std=c99 -D_GNU_SOURCE -DMD_A2MD_BUILD \
     $(CPPFLAGS) $(EXTRA_CPPFLAGS) $(A2MD_CFLAGS)
 
 # -----------------------------------------------------------------------