X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=Util.pm;h=2b5b266323c970b332d4e4f26c5eded205095f84;hb=b774f5ea60c257eac26a01b2c071a4a982542ec4;hp=e30faa6b864c4b030e650f78720e07ef2504f543;hpb=a73b62401a9f32ff9c6279609ed7ac67a56ffbde;p=mirror%2Fuserdir-ldap-cgi.git diff --git a/Util.pm b/Util.pm index e30faa6..2b5b266 100644 --- a/Util.pm +++ b/Util.pm @@ -3,6 +3,7 @@ package Util; use strict; use Date::Manip qw(ParseDate); +use Net::LDAP qw(:all); my $blocksize = 8; # A blowfish block is 8 bytes my $configfile = "/etc/userdir-ldap/userdir-ldap.conf"; @@ -171,15 +172,17 @@ sub FormatFingerPrint { $out .= " " if ($_ == 7); } } else { - foreach (0..int(length($in)/2)) { + foreach (0..int(length($in)/4)) { $out .= substr($in, $_*4, 4)." "; } } + chop $out; return $out; } sub FetchKey { my $fingerprint = shift; + my $signatures = shift; my ($out, $keyringparam) = undef; foreach (split(/:/, $config{keyrings})) { @@ -191,9 +194,11 @@ sub FetchKey { local $ENV{PATH} = ''; $/ = undef; # just suck it up .... - open(FP, "$config{gpg} --no-options --no-default-keyring $keyringparam --list-sigs --fingerprint $fingerprint|"); - $out = ; - close FP; + if ($signatures) { + open(FP, "$config{gpg} --no-options --no-default-keyring $keyringparam --list-sigs --fingerprint $fingerprint|"); + $out = ; + close FP; + } open(FP, "$config{gpg} --no-options --no-default-keyring $keyringparam --export -a $fingerprint|"); $out .= ; close FP; @@ -253,7 +258,7 @@ sub LookupCountry { my $htmlhdrsent = 0; sub HTMLSendHeader { - print "Content-type: text/html\n\n" if (!$htmlhdrsent); + print "Content-type: text/html; charset=utf-8\n\n" if (!$htmlhdrsent); $htmlhdrsent = 1; } @@ -322,7 +327,8 @@ sub ReadConfigFile { if ((!/^\s*#/) && ($_ ne "")) { # Chop off any trailing comments s/#.*//; - ($attr, $setting) = split(/=/, $_, 2); + /([^=]+)=(.*)/; + ($attr, $setting) = ($1, $2); $setting =~ s/"//g; #" $setting =~ s/;$//; $attr =~ s/^\s+//; $attr =~ s/\s+$//; @@ -334,4 +340,17 @@ sub ReadConfigFile { return %config; } +sub UpgradeConnection($) { + my ($ldap) = @_; + my $mesg = $ldap->start_tls( + verify => 'require', + capath => '/etc/ssl/certs/' + ); + $mesg->sync; + if ($mesg->code != LDAP_SUCCESS) { + print "Content-type: text/html; charset=utf-8\n\n"; + print "

STARTTLS failed: "..$mesg->error."

\n"; + exit(1); + }; +}; 1;