]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
insert LoadModule/AddModule directives only outside of sections.
authorAndré Malo <nd@apache.org>
Sat, 22 Feb 2003 17:06:20 +0000 (17:06 +0000)
committerAndré Malo <nd@apache.org>
Sat, 22 Feb 2003 17:06:20 +0000 (17:06 +0000)
PR: 8712, 9012

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

src/CHANGES
src/support/apxs.pl

index 6f11ce6d2f408abe6c05c3aafe365a8a730182cd..06e8f01328023376fa25b6d2da2f9f17d0a2f1eb 100644 (file)
@@ -1,5 +1,8 @@
 Changes with Apache 1.3.28
 
+  *) Fix apxs to insert LoadModule/AddModule directives only outside of
+     sections. PR 8712, 9012.  [André Malo]
+
   *) Fix suexec compile error under SUNOS4, where strerror() doesn't
      exist. PR 5913, 9977.
      [Jonathan W Miner <Jonathan.W.Miner@lmco.com>]
index cd5ef61fa190f05f3fc6e8a6b4fcfd5c6b524270..eaed48b40ddb97a10eef71ae38e0e8faf50e663e 100644 (file)
@@ -543,9 +543,69 @@ if ($opt_i or $opt_e) {
         foreach $lmd (@lmd) {
             my $what = $opt_A ? "preparing" : "activating";
             if ($content !~ m|\n#?\s*$lmd|) {
-                 $content =~ s|^(.*\n#?\s*LoadModule\s+[^\n]+\n)|$1$c$lmd\n|sg;
+                # check for open <containers>, so that the new LoadModule
+                # directive always appears *outside* of an <container>.
+
+                my $before = ($content =~ m|^(.*\n)#?\s*LoadModule\s+[^\n]+\n|s)[0];
+
+                # the '()=' trick forces list context and the scalar
+                # assignment counts the number of list members (aka number
+                # of matches) then
+                my $cntopen = () = ($before =~ m|^\s*<[^/].*$|mg);
+                my $cntclose = () = ($before =~ m|^\s*</.*$|mg);
+
+                if ($cntopen == $cntclose) {
+                    # fine. Last LoadModule is contextless.
+                    $content =~ s|^(.*\n#?\s*LoadModule\s+[^\n]+\n)|$1$c$lmd\n|s;
+                }
+                elsif ($cntopen < $cntclose) {
+                    print STDERR 'Configuration file is not valid. There are '
+                                 . "sections closed before opened.\n";
+                    exit(1);
+                }
+                else {
+                    # put our cmd after the section containing the last
+                    # LoadModule.
+                    my $found =
+                    $content =~ s!\A (               # string and capture start
+                                  (?:(?:
+                                    ^\s*             # start of conf line with a
+                                    (?:[^<]|<[^/])   # directive which does not
+                                                     # start with '</'
+
+                                    .*(?:$)\n        # rest of the line.
+                                                     # the '$' is in parentheses
+                                                     # to avoid misinterpreting
+                                                     # the string "$\" as
+                                                     # perl variable.
+
+                                    )*               # catch as much as possible
+                                                     # of such lines. (including
+                                                     # zero)
+
+                                    ^\s*</.*(?:$)\n? # after the above, we
+                                                     # expect a config line with
+                                                     # a closing container (</)
+
+                                  ) {$cntopen}       # the whole pattern (bunch
+                                                     # of lines that end up with
+                                                     # a closing directive) must
+                                                     # be repeated $cntopen
+                                                     # times. That's it.
+                                                     # Simple, eh? ;-)
+
+                                  )                  # capture end
+                                 !$1$c$lmd\n!mx;
+
+                    unless ($found) {
+                        print STDERR 'Configuration file is not valid. There '
+                                     . "are sections opened and not closed.\n";
+                        exit(1);
+                    }
+                }
             } else {
-                 $content =~ s|^(.*\n)#?\s*$lmd[^\n]*\n|$1$c$lmd\n|sg;
+                # replace already existing LoadModule line
+                $content =~ s|^(.*\n)#?\s*$lmd[^\n]*\n|$1$c$lmd\n|s;
             }
             $lmd =~ m|LoadModule\s+(.+?)_module.*|;
             print STDERR "[$what module `$1' in $cfgbase.conf]\n";
@@ -553,9 +613,34 @@ if ($opt_i or $opt_e) {
         my $amd;
         foreach $amd (@amd) {
             if ($content !~ m|\n#?\s*$amd|) {
-                 $content =~ s|^(.*\n#?\s*AddModule\s+[^\n]+\n)|$1$c$amd\n|sg;
+                # check for open <containers> etc. see above for explanations.
+
+                my $before = ($content =~ m|^(.*\n)#?\s*AddModule\s+[^\n]+\n|s)[0];
+                my $cntopen = () = ($before =~ m|^\s*<[^/].*$|mg);
+                my $cntclose = () = ($before =~ m|^\s*</.*$|mg);
+
+                if ($cntopen == $cntclose) {
+                    $content =~ s|^(.*\n#?\s*AddModule\s+[^\n]+\n)|$1$c$amd\n|s;
+                }
+                elsif ($cntopen < $cntclose) {
+                    # cannot happen here, but who knows ...
+                    print STDERR 'Configuration file is not valid. There are '
+                                 . "sections closed before opened.\n";
+                    exit(1);
+                }
+                else {
+                    unless ($content =~ s!\A((?:(?:^\s*(?:[^<]|<[^/]).*(?:$)\n)*
+                                          ^\s*</.*(?:$)\n?){$cntopen})
+                                         !$1$c$amd\n!mx) {
+                        # cannot happen here, anyway.
+                        print STDERR 'Configuration file is not valid. There '
+                                     . "are sections opened and not closed.\n";
+                        exit(1);
+                    }
+                }
             } else {
-                 $content =~ s|^(.*\n)#?\s*$amd[^\n]*\n|$1$c$amd\n|sg;
+                # replace already existing AddModule line
+                $content =~ s|^(.*\n)#?\s*$amd[^\n]*\n|$1$c$amd\n|s;
             }
         }
         if (@lmd or @amd) {