Bug 58304

Summary: Unexpected Warnings from Macro Use in 2.4
Product: Apache httpd-2 Reporter: Tom Browder <tom.browder>
Component: mod_macroAssignee: Apache HTTPD Bugs Mailing List <bugs>
Status: RESOLVED FIXED    
Severity: normal CC: rjollos, tom.browder
Priority: P2    
Version: 2.5-HEAD   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: Add warning about syntax clash

Description Tom Browder 2015-08-30 17:01:19 UTC
Starting with 2.4.12 and still existing in 2.4.16, when using a Macro definition for virtual hosts, I get repeated warnings to stdout that the macro variables are undefined every time apache is started or during a syntax check: 

root@dedi2:/home/tbrowde# apachectl -t
[Sun Aug 30 16:39:35.097827 2015] [core:warn] [pid 4101:tid 140105241839360] AH00111: Config variable ${PROJECT} is not defined
[Sun Aug 30 16:39:35.097911 2015] [core:warn] [pid 4101:tid 140105241839360] AH00111: Config variable ${TLD} is not defined
[Sun Aug 30 16:39:35.098007 2015] [core:warn] [pid 4101:tid 140105241839360] AH00111: Config variable ${PROJECT} is not defined
[Sun Aug 30 16:39:35.098021 2015] [core:warn] [pid 4101:tid 140105241839360] AH00111: Config variable ${TLD} is not defined
[Sun Aug 30 16:39:35.098562 2015] [core:warn] [pid 4101:tid 140105241839360] AH00111: Config variable ${PROJECT} is not defined
[Sun Aug 30 16:39:35.098575 2015] [core:warn] [pid 4101:tid 140105241839360] AH00111: Config variable ${TLD} is not defined
[Sun Aug 30 16:39:35.098889 2015] [core:warn] [pid 4101:tid 140105241839360] AH00111: Config variable ${PROJECT} is not defined
[Sun Aug 30 16:39:35.098904 2015] [core:warn] [pid 4101:tid 140105241839360] AH00111: Config variable ${TLD} is not defined
Syntax OK

I am using three macros that are defined in the httpd.conf file as follows:

<Macro VHOST_NONTLS ${PROJECT} ${TLD}>
  <VirtualHost *:80>
    ServerName  ${PROJECT}.${TLD}
    ServerAlias *.${PROJECT}.${TLD}
    DocumentRoot /home/web-server/${PROJECT}.${TLD}/public
  </VirtualHost>
</Macro>
Use VHOST_NONTLS niceville.pm          org
UndefMacro VHOST_NONTLS

<Macro VHOST_FREE_CERT_TLS ${PROJECT} ${TLD}>
  <VirtualHost *:80>
    ServerName  ${PROJECT}.${TLD}
    ServerAlias *.${PROJECT}.${TLD}
    # enforce ssl/tls
    Redirect Permanent / https://${PROJECT}.${TLD}/
  </VirtualHost>
</Macro>
Use VHOST_FREE_CERT_TLS  computertechnwf  org
UndefMacro VHOST_FREE_CERT_TLS

<Macro VHOST_WILDCARD_TLS ${PROJECT} ${TLD}>
  <VirtualHost *:80>
    ServerName  ${PROJECT}.${TLD}
    ServerAlias *.${PROJECT}.${TLD}
    # enforce ssl/tls
    Redirect Permanent / https://${PROJECT}.${TLD}/
  </VirtualHost>
  # ...
</Macro>
Use VHOST_WILDCARD_TLS highlandsprings61     org
UndefMacro VHOST_WILDCARD_TLS
Comment 1 Marc Stern 2015-09-04 06:43:45 UTC
${VAR} is interpreted as a defined variable (http://httpd.apache.org/docs/2.4/mod/core.html#define). It's equivalent to %{VAR}.

mod_macro uses the syntax $var but also ${var}, which is mandatory if you want the variable to be a part of a string, like in "${var}abc".
The syntax clashes with the Define directive, so it should be changed. Ans %{var} clashes with mod_rewrite.

This doe not only give a warning but could lead to a real mismatch between something defined as a local parameter and somebody else defining it at a global level as a defined config variable.

To make interpolation not clash with another module, we should use another character (instead of an existing one or on top of?) like &{var}.
Comment 2 Marc Stern 2016-07-06 07:11:15 UTC
Created attachment 34013 [details]
Add warning about syntax clash

In case a macro argument uses the syntax ${...}, adds a warning that it clashes with the 'Define' directive
Comment 3 Darren Embry 2022-06-30 16:07:56 UTC
This fix appears to have been in Apache 2 for quite some time.

I'm marking RESOLVED/Fixed.

This appears to remedy bug 59299.

I've filed bug 66153 related to the mod_macro documentation.