X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fuserdir-ldap-cgi.git;a=blobdiff_plain;f=update.cgi;h=3cf1900f1ac8e1cd01bac60dc08fc6077ee4cf61;hp=223559f276b32786f05c8604892b29be428a1db2;hb=HEAD;hpb=cf6454a1b253861a7167037e07cc2693bf4fe66a diff --git a/update.cgi b/update.cgi index 223559f..3cf1900 100755 --- a/update.cgi +++ b/update.cgi @@ -3,6 +3,7 @@ # $Id: update.cgi,v 1.13 2006/12/28 02:44:02 rmurray Exp $ # (c) 1999 Randolph Chung. Licensed under the GPL. # (c) 2006 Ryan Murray. Licensed under the GPL. +# Copyright (c) 2008, 2011, 2012, 2014, 2015 Peter Palfrader use lib '.'; use strict vars; @@ -10,10 +11,13 @@ use strict vars; use CGI; use Data::UUID; use Digest::HMAC_SHA1 qw(hmac_sha1_hex); +use Digest::MD5 qw(md5_hex); use Util; use English; use URI::Escape; -use Net::LDAP qw(:all); +use Crypt::PasswdMD5; +use Net::LDAP qw(LDAP_SUCCESS LDAP_PROTOCOL_ERROR); +use Net::LDAP::Util qw(ldap_explode_dn); my %config = &Util::ReadConfigFile; @@ -22,13 +26,21 @@ my $proto = ($ENV{HTTPS} ? "https" : "http"); my $id = $query->param('id'); my $authtoken = $query->param('authtoken'); -my $password = &Util::CheckAuthToken($authtoken); -my $editdn = $query->param('editdn'); + +my $password = undef; + +if ($authtoken || $id) { + $password = Util::TouchAuthToken($authtoken, $id); +} else { + $password = ''; + $id = ''; + $authtoken = ''; +} if ($proto eq "http" || !($id && $password)) { print "Location: https://$ENV{SERVER_NAME}/$config{webloginhtml}\n\n"; exit; -} +} my $ldap; @@ -41,7 +53,8 @@ sub DieHandler { $ldap->unbind if (defined($ldap)); } -$SIG{__DIE__} = \&DieHandler; +#$SIG{__DIE__} = \&DieHandler; +my $editdn = "uid=$id,$config{basedn}"; $ldap = Net::LDAP->new($config{ldaphost}); &Util::UpgradeConnection($ldap) unless $config{usessl} eq 'False'; @@ -61,7 +74,7 @@ if (!$auth) { $mesg = $ldap->search(base => $editdn, filter => "uid=*"); $mesg->code && &Util::HTMLError($mesg->error); - + my $entries = $mesg->as_struct; if ($mesg->count != 1) { # complain and quit @@ -77,14 +90,13 @@ my $entry = $entries->{$dns[0]}; if (!($query->param('doupdate'))) { # Not yet update, just fill in the form with the current values my %data; - + # Fill in %data # First do the easy stuff - this catches most of the cases foreach (keys(%$entry)) { $data{$_} = $entry->{$_}->[0]; + $data{$_} = CGI::escapeHTML($data{$_}) if defined $data{$_}; } - - $data{gender} = 9 if not $data{gender}; # Now we have to fill in the rest that needs some processing... $data{id} = $id; @@ -92,6 +104,7 @@ if (!($query->param('doupdate'))) { $data{editdn} = $editdn; $data{staddress} = $entry->{postaladdress}->[0]; $data{staddress} =~ s/\$/\n/; + $data{staddress} = CGI::escapeHTML($data{staddress}); $data{countryname} = &Util::LookupCountry($data{c}); if ($data{mailgreylisting} eq "TRUE") { @@ -105,41 +118,61 @@ if (!($query->param('doupdate'))) { } else { $data{mailcallout} = ""; } - - $data{email} = join(", ", @{$entry->{emailforward}}); - - my $genderselect = ''; + + $data{maildefaultoptions} ||= 'TRUE'; + + if ($data{maildefaultoptions} eq "TRUE") { + $data{maildefaultoptions} = " checked"; + } else { + $data{maildefaultoptions} = ""; + } + + $data{mailcontentinspectionaction} ||= 'reject'; + + $data{email} = CGI::escapeHTML(join(", ", @{$entry->{emailforward}})); + + my $mailcontentselect = ' (delete)\n"; + + (delete)\n"; $sudopassword .= $e; if ($status eq 'unconfirmed') { - my $data = join(':', 'confirm-new-password', $uuid, $hosts, $crypted); + my $data = join(':', 'confirm-new-password', 'sudo', $data{'uid'}, $uuid, $hosts, $crypted); my $hmac = hmac_sha1_hex( $data, $hmac_key); - $confirmstring .= "confirm sudopassword $uuid $hosts $hmac\n"; + $confirmstring .= CGI::escapeHTML("confirm sudopassword $uuid $hosts $hmac\n"); } }; if ($confirmstring ne '') { - $confirmstring = "
To confirm your new sudo passwords send signed mail to changes\@db.debian.org with a signed body containing these lines:
$confirmstring
"; + $confirmstring = "
To confirm your new sudo passwords send signed mail to changes\@$config{maildomain} with a signed body containing these lines:
$confirmstring
"; } my $sudopasswordhosts = '