Skip to content

Commit d28c717

Browse files
committed
configure: improve auto detection of unsafeallow3f flag support
1 parent 4c66aa5 commit d28c717

File tree

4 files changed

+47
-48
lines changed

4 files changed

+47
-48
lines changed

Changes

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ next:
3636
- extra_opts may extend or modify lists
3737
- add clone button
3838
- show active rules
39+
- Apache:
40+
- add UnsafeAllow3F for Ubuntu packages
3941

4042
3.20.2 Wed Dec 18 17:43:10 CET 2024
4143
- unescape escaped characters in expanded command

MANIFEST

+1
Original file line numberDiff line numberDiff line change
@@ -2362,6 +2362,7 @@ support/0002-log4perl.conf.patch
23622362
support/0003-thruk_data_scripts.patch
23632363
support/0004-fcgish.patch
23642364
support/0005-logrotate.patch
2365+
support/apache-test-unsafeallow.conf
23652366
support/apache_fcgid.conf
23662367
support/apache_fcgid.conf.apache22
23672368
support/convert_old_datafile.pl

configure

+36-48
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,20 @@ $options->{'thruk-libs'} = '' if $options->{'nolibs'};
9898

9999
# recent apaches might require the UnsafeAllow3F flag
100100
if(!$options->{'nounsafeallow3f'} && !$options->{'unsafeallow3f'}) {
101-
# try to autodetect
102-
my($os, $ver) = _get_os();
103-
if($os eq 'rhel' && $ver >= 8) {
104-
$options->{'unsafeallow3f'} = 1;
105-
}
106-
if($os eq 'debian' && ($ver eq 'sid' || $ver >= 11)) {
107-
$options->{'unsafeallow3f'} = 1;
101+
my($apache_bin, $module_dir) = _get_apache();
102+
if($apache_bin && $module_dir) {
103+
my $src = _read('./support/apache-test-unsafeallow.conf');
104+
require File::Temp;
105+
my($fh, $tmpfile) = File::Temp::tempfile();
106+
$src =~ s%###APACHE_MODULE_DIR###%$module_dir%g;
107+
print $fh $src;
108+
close($fh);
109+
my $cmd = "$apache_bin -t -f $tmpfile 2>&1";
110+
`$cmd 2>&1`;
111+
if($? == 0) {
112+
$options->{'unsafeallow3f'} = 1;
113+
}
114+
unlink($tmpfile);
108115
}
109116
}
110117
if($options->{'nounsafeallow3f'}) {
@@ -201,53 +208,34 @@ EOT
201208

202209
exit;
203210

204-
# try to detect os and version
205-
sub _get_os {
206-
my($os, $version) = ("", 0);
207-
local $/ = undef;
211+
# try to detect apache
212+
sub _get_apache {
213+
my($apache_bin, $module_dir);
208214

209-
# right now, we only need rhel/rocky/alma
210-
if(-e '/etc/redhat-release') {
211-
my $release_file = '/etc/redhat-release';
212-
open(my $fh, '<', $release_file) or die("cannot read $release_file: $!");
213-
my $release_info = <$fh>;
214-
close $fh;
215-
216-
if ($release_info =~ /^(.*?)(?: release)? ([\d.]+)/) {
217-
my $version = $2;
218-
$version =~ s/\..*$//gmx; # we only need the major number
219-
return("rhel", 0+$version);
220-
} else {
221-
die(sprintf("Unable to detect distribution and version from %s:\n%s", $release_file, $release_info));
222-
}
223-
} elsif(-e '/etc/os-release') {
224-
my $release_file = '/etc/os-release';
225-
open(my $fh, '<', $release_file) or die("cannot read $release_file: $!");
226-
my $release_info = <$fh>;
227-
close $fh;
228-
229-
for my $line (split/\n/mx, $release_info) {
230-
if($line =~ /^ID="?(.*?)"?$/mx) {
231-
$os = $1;
232-
}
233-
if($line =~ /^VERSION_ID="?(.*?)"?$/mx) {
234-
$version = $1;
235-
$version =~ s/\..*$//gmx; # we only need the major number
236-
}
237-
if($line =~ /^PRETTY_NAME=.*\/sid\"$/mx) {
238-
$version = "sid";
239-
}
215+
for my $bin (qw(/sbin/apache2 /usr/sbin/apache2 /usr/sbin/httpd usr/sbin/httpd2-prefork)) {
216+
if(-x $bin) {
217+
$apache_bin = $bin;
218+
last;
240219
}
220+
}
241221

242-
if ($os && $version) {
243-
return($os, $version) if $version eq 'sid';
244-
return($os, 0+$version);
245-
} else {
246-
die(sprintf("Unable to detect distribution and version from %s:\n%s", $release_file, $release_info));
222+
for my $dir (qw(/usr/lib64/httpd/modules /usr/lib/apache2/modules /usr/lib64/apache2-prefork /usr/lib64/httpd/modules)) {
223+
if(-x $dir) {
224+
$module_dir = $dir;
225+
last;
247226
}
248227
}
249228

250-
return($os, $version);
229+
return($apache_bin, $module_dir);
230+
}
231+
232+
sub _read {
233+
my($file) = @_;
234+
local $/ = undef;
235+
open(my $fh, '<', $file) or die("cannot read file: $file: $!");
236+
my $data = <$fh>;
237+
close($fh);
238+
return $data;
251239
}
252240

253241
1;

support/apache-test-unsafeallow.conf

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
LoadModule mpm_prefork_module ###APACHE_MODULE_DIR###/mod_mpm_prefork.so
2+
LoadModule rewrite_module ###APACHE_MODULE_DIR###/mod_rewrite.so
3+
4+
DocumentRoot /
5+
ServerRoot /
6+
ErrorLog /dev/null
7+
8+
RewriteRule / / [UnsafeAllow3F]

0 commit comments

Comments
 (0)