X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;ds=sidebyside;f=Util.pm;h=8efabfb517959e15db7ad806cb2831608c5f5886;hb=be1495662e4a4404faa46a81befb2dbf30a794cd;hp=6117a4e6b9b60515dc462df53678ac30e2177b72;hpb=c862628abd43c8fa3f7f2c17b5540706c2d1f95a;p=mirror%2Fuserdir-ldap-cgi.git
diff --git a/Util.pm b/Util.pm
index 6117a4e..8efabfb 100644
--- a/Util.pm
+++ b/Util.pm
@@ -51,7 +51,9 @@ sub Encrypt {
my $input = shift;
my ($pos, $output);
- $input .= " " x ($blocksize - (length($input) % $blocksize)) if (length($input % $blocksize));
+ # prepend a length byte */
+ $input = chr(length($input)).$input;
+ $input .= "\001" x ($blocksize - (length($input) % $blocksize)) if (length($input % $blocksize));
for ($pos = 0; $pos < length($input); $pos += $blocksize) {
$output .= unpack("H16", $cipher->encrypt(substr($input, $pos, $blocksize))) if ($hascryptix);
@@ -64,7 +66,7 @@ sub Decrypt {
# trailing spaces are unimportant.
my $cipher = shift;
my $input = shift;
- my ($pos, $portion, $output);
+ my ($pos, $portion, $output, $len);
((length($input) % $blocksize) == 0) || &HTMLError("Password corrupted"); # should always be true...
@@ -72,8 +74,10 @@ sub Decrypt {
$portion = pack("H16", substr($input, $pos, $blocksize*2));
$output .= $cipher->decrypt($portion) if ($hascryptix);
}
-
- $output =~ s/ +$//;
+
+ # check length byte, discard junk
+ $len = substr($output, 0, 1);
+ $output = substr($output, 1, ord($len));
return $output;
}
@@ -115,7 +119,7 @@ sub ReadPasswordFromFile {
# check to make sure the time is positive, and that the auth token
# has not expired
my $tdiff = (time - $time);
- &HTMLError("Your authentication token has expired. Please relogin") if (($tdiff < 0) || ($tdiff > $config{authexpires}));
+ &HTMLError("Your authentication token has expired. Please relogin") if (($tdiff < 0) || ($tdiff > $config{authexpires}));
return Decrypt($cipher, $passwd);
}
@@ -186,7 +190,7 @@ sub FetchKey {
$fingerprint = "0x".$fingerprint;
$/ = undef; # just suck it up ....
- open(FP, "$config{gpg} --no-options --no-default-keyring $keyringparam --list-sigs --fingerprint $fingerprint|");
+ open(FP, "$config{gpg} --no-options --no-default-keyring $keyringparam --check-sigs --fingerprint $fingerprint|");
$out = ;
close FP;
open(FP, "$config{gpg} --no-options --no-default-keyring $keyringparam --export -a $fingerprint|");
@@ -221,7 +225,7 @@ sub FormatLastSeen {
$lastseen = (($d1 gt $d2) ? $lastseenpgp : $lastseenfrom);
}
- my ($date,$user,$list,$msgid) = ($lastseen =~ /^\[(.+?)\]\s+"(.+?)"\s+"(?:<(.+?)>.+?|\-)"\s+"<(.+?)>"/);
+ my ($date,$user,$list,$msgid) = ($lastseen =~ /^\[(.+?)\]\s+"(.+?)"\s+"(?:<(.+?)>.*?|\-)"\s+"<(.+?)>"/);
$list = "on $list" if ($list);
return "$date $list
Message ID: $msgid";
}
@@ -274,6 +278,38 @@ sub CheckLatLong {
}
}
+sub FixParams {
+ my $query = shift;
+ my $key;
+ my @names = $query->param;
+
+ foreach $key (@names) { # web security is a joke ...
+ $_ = $query->param($key);
+ s/&/&/g;
+ s/[<\x8B]/</g;
+ s/[>\x9B]/>/g;
+
+ $query->param($key, $_);
+ }
+}
+
+
+sub LDAPUpdate {
+ my $ldap = shift;
+ my $dn = shift;
+ my $attr = shift;
+ my $val = shift;
+ my $mesg;
+
+ if (!$val) {
+ $mesg = $ldap->modify($dn, delete => { $attr => [] });
+ } else {
+ $val = [ $val ] if (!ref($val));
+ $mesg = $ldap->modify($dn, replace => { $attr => $val });
+ $mesg->code && &Util::HTMLError("error updating $attr: ".$mesg->error);
+ }
+}
+
###################
# Config file stuff
sub ReadConfigFile {