Revision 8818
Added by Jing Tao over 10 years ago
src/perl/ldapweb.cgi | ||
---|---|---|
317 | 317 |
'emailverification' => \&handleEmailVerification, |
318 | 318 |
'lookupname' => \&handleLookupName, |
319 | 319 |
'searchnamesbyemail'=> \&handleSearchNameByEmail, |
320 |
#'getnextuid' => \&getNextUidNumber,
|
|
320 |
#'getnextuid' => \&getExistingHighestUidNum,
|
|
321 | 321 |
); |
322 | 322 |
|
323 | 323 |
# call the appropriate routine based on the stage |
... | ... | |
1613 | 1613 |
$ldap = Net::LDAP->new($ldapurl, timeout => $timeout) or handleLDAPBindFailure($ldapurl); |
1614 | 1614 |
|
1615 | 1615 |
if ($ldap) { |
1616 |
my $existingHighUid=getExistingHighestUidNum($ldapUsername, $ldapPassword); |
|
1616 | 1617 |
$ldap->start_tls( verify => 'require', |
1617 | 1618 |
cafile => $ldapServerCACertFile); |
1618 | 1619 |
my $bindresult = $ldap->bind( version => 3, dn => $ldapUsername, password => $ldapPassword); |
... | ... | |
1636 | 1637 |
#can't remove the attribute with the specified value - that means somebody modify the value in another route, so try it again |
1637 | 1638 |
} else { |
1638 | 1639 |
debug("Remove the attribute successfully and write a new increased value back"); |
1640 |
if($uidNumber <= $existingHighUid ) { |
|
1641 |
debug("The stored uidNumber $uidNumber is less than the used uidNumber $existingHighUid, so we will use the new number which is $existingHighUid+1"); |
|
1642 |
$uidNumber = $existingHighUid +1; |
|
1643 |
} |
|
1639 | 1644 |
my $newValue = $uidNumber +1; |
1640 | 1645 |
$delMesg = $ldap->modify($dn_store_next_uid, add => {$attribute_name_store_next_uid => $newValue}); |
1641 | 1646 |
$realUidNumber = $uidNumber; |
... | ... | |
1653 | 1658 |
return $realUidNumber; |
1654 | 1659 |
} |
1655 | 1660 |
|
1661 |
#Method to get the existing high uidNumber in the account tree. |
|
1662 |
sub getExistingHighestUidNum { |
|
1663 |
my $ldapUsername = shift; |
|
1664 |
my $ldapPassword = shift; |
|
1665 |
|
|
1666 |
my $high; |
|
1667 |
my $ldap; |
|
1668 |
debug("ldap server: $ldapurl"); |
|
1669 |
|
|
1670 |
#if main ldap server is down, a html file containing warning message will be returned |
|
1671 |
$ldap = Net::LDAP->new($ldapurl, timeout => $timeout) or handleLDAPBindFailure($ldapurl); |
|
1672 |
debug("after creating a ldap server"); |
|
1673 |
if ($ldap) { |
|
1674 |
debug("before staring the tls"); |
|
1675 |
$ldap->start_tls( verify => 'require', |
|
1676 |
cafile => $ldapServerCACertFile); |
|
1677 |
debug("after staring the tls"); |
|
1678 |
my $bindresult = $ldap->bind( version => 3, dn => $ldapUsername, password => $ldapPassword); |
|
1679 |
debug("after binding ...."); |
|
1680 |
my $uids = $ldap->search( |
|
1681 |
base => "dc=ecoinformatics,dc=org", |
|
1682 |
scope => "sub", |
|
1683 |
filter => "uidNumber=*", |
|
1684 |
attrs => [ 'uidNumber' ], |
|
1685 |
); |
|
1686 |
debug("after searching.... $uids"); |
|
1687 |
return unless $uids->count; |
|
1688 |
debug("before sorting the returned uidNumber"); |
|
1689 |
my @uids; |
|
1690 |
if ($uids->count > 0) { |
|
1691 |
foreach my $uid ($uids->all_entries) { |
|
1692 |
push @uids, $uid->get_value('uidNumber'); |
|
1693 |
} |
|
1694 |
} |
|
1695 |
|
|
1696 |
@uids = sort { $b <=> $a } @uids; |
|
1697 |
$high = $uids[0]; |
|
1698 |
debug("the highest exiting uidnumber is $high"); |
|
1699 |
$ldap->unbind; # take down session |
|
1700 |
} |
|
1701 |
return $high; |
|
1656 | 1702 |
|
1703 |
} |
|
1704 |
|
|
1705 |
|
Also available in: Unified diff
In the getNextUidNumber method, a mechanism to look up the highest existing udiNumber was added.