From 457b20bce7642092238911c7a184075c2e02643d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 21 May 2020 16:49:46 +0100 Subject: [PATCH 1/8] Util: Support "include" in configuration An example of how to use this will come in a moment. Signed-off-by: Ian Jackson --- Util.pm | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Util.pm b/Util.pm index c292a1a..ebf4712 100644 --- a/Util.pm +++ b/Util.pm @@ -391,11 +391,22 @@ sub LDAPUpdate { ################### # Config file stuff sub ReadConfigFile { + our %config = { }; + &ReadSomeConfigFile($configfile, \%config); + return %config; +} + +sub ReadSomeConfigFile { # reads a config file and results a hashref with the results - my (%config, $attr, $setting); - open (F, "<$configfile") || &HTMLError("Cannot open $configfile: $!"); - while () { + my ($file, $config) = @_; + my ($attr, $setting); + my $fh = new IO::File $file, '<' || &HTMLError("Cannot open config file $file: $!"); + while (<$fh>) { chomp; + if (s{^include\s+(?!=)}{}) { + &ReadSomeConfigFile($_, $config); + next; + } if ((!/^\s*#/) && ($_ ne "")) { # Chop off any trailing comments s/#.*//; @@ -405,11 +416,10 @@ sub ReadConfigFile { $setting =~ s/;$//; $attr =~ s/^\s+//; $attr =~ s/\s+$//; $setting =~ s/^\s+//; $setting =~ s/\s+$//; - $config{$attr} = $setting; + $config->{$attr} = $setting; } } - close F; - return %config; + close $fh; } sub UpgradeConnection($) { -- GitLab From 7a440c0be0a979fe181f018911ec23d9eac8c505 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 21 May 2020 16:50:18 +0100 Subject: [PATCH 2/8] Util: Honour USERDIR_LDAP_CONF env var If this is set, read that as our config, rather than the hardcoded file in /etc. This will make it possible to test this code from a clean git tree. Signed-off-by: Ian Jackson --- Util.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Util.pm b/Util.pm index ebf4712..6edee15 100644 --- a/Util.pm +++ b/Util.pm @@ -13,7 +13,7 @@ use Crypt::CBC; use Digest::HMAC_SHA1 qw(hmac_sha1_hex); my $blocksize = 8; # A blowfish block is 8 bytes -my $configfile = "/etc/userdir-ldap/userdir-ldap.conf"; +my $configfile = $ENV{USERDIR_LDAP_CONF} // "/etc/userdir-ldap/userdir-ldap.conf"; #my $configfile = "/home/randolph/html/debian/perl/userdir-ldap.conf"; my %config = &ReadConfigFile; -- GitLab From bfdd89b7f2599a1b5161443a581f40094a205032 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 21 May 2020 16:51:01 +0100 Subject: [PATCH 3/8] test-debian.conf: Recipe for testing this code from a clean tree. Signed-off-by: Ian Jackson --- test-debian.conf | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test-debian.conf diff --git a/test-debian.conf b/test-debian.conf new file mode 100644 index 0000000..5a871b9 --- /dev/null +++ b/test-debian.conf @@ -0,0 +1,17 @@ +# Testing config file for ldap scripts + +# For testing in a chroot on (say) a porterbox, +# apt-get install libcgi-pm-perl libdate-manip-perl libnet-ldap-perl +# libcrypt-cbc-perllibdigest-hmac-perl w3m +# Copy +# master.debian.org:/etc/userdir-ldap/userdir-ldap.conf +# into your "..". +# +# Then +# USERDIR_LDAP_CONF=test-debian.conf REQUEST_METHOD=GET \ +# QUERY_STRING='host=amdahl' ./machines.cgi >t.html && w3m ./t.html + +include ../userdir-ldap.conf + +templatesdir = "html"; +hosthtml = "html/hostinfo.wml"; -- GitLab From 3f21bb5523fa19c2bfbd31eb486f77f816cf2ccc Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 21 May 2020 17:21:20 +0100 Subject: [PATCH 4/8] machines.cgi: Refactor hidden filter code We are going to want to put something else under this same condition in a moment. No functional change. Signed-off-by: Ian Jackson --- machines.cgi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/machines.cgi b/machines.cgi index ce18f0f..e9a08ae 100755 --- a/machines.cgi +++ b/machines.cgi @@ -166,7 +166,9 @@ foreach $dn (sort {$entries->{$a}->{host}->[0] cmp $entries->{$b}->{host}->[0]} $selected = " selected "; } - $hostlist .= "