Project

General

Profile

« Previous | Next » 

Revision 8413

Added by Jing Tao over 10 years ago

Add the code to check if the stored the uidnext is a number or not.

View differences:

src/perl/ldapweb.cgi
42 42
use DateTime::Duration; # for substracting
43 43
use Captcha::reCAPTCHA; # for protection against spams
44 44
use Cwd 'abs_path';
45
use Scalar::Util qw(looks_like_number);
45 46

  
46 47
# Global configuration paramters
47 48
# This entire block (including skin parsing) could be pushed out to a separate .pm file
......
91 92

  
92 93
my $emailVerification= 'emailverification';
93 94

  
95
 my $dn_store_next_uid=$properties->getProperty('ldap.nextuid.storing.dn');
96
 my $attribute_name_store_next_uid = $properties->getProperty('ldap.nextuid.storing.attributename');
97

  
94 98
# Import all of the HTML form fields as variables
95 99
import_names('FORM');
96 100

  
......
947 951
        
948 952
        Somebody (hopefully you) requested that your account password be reset.  
949 953
        Your temporary password is below. Please change it as soon as possible 
950
        at: $contextUrl.
954
        at: $contextUrl/style/skins/account/.
951 955

  
952 956
            Username: $username
953 957
        Organization: $org
......
1143 1147
    
1144 1148
    ################create an account under tmp subtree 
1145 1149
    
1150
     my $dn_store_next_uid=$properties->getProperty('ldap.nextuid.storing.dn');
1151
    my $attribute_name_store_next_uid = $properties->getProperty('ldap.nextuid.storing.attributename');
1146 1152
    #get the next avaliable uid number. If it fails, the program will exist.
1147 1153
    my $nextUidNumber = getNextUidNumber($ldapUsername, $ldapPassword);
1148 1154
    if(!$nextUidNumber) {
1149 1155
        print "Content-type: text/html\n\n";
1150 1156
         my $sender;
1151 1157
        $sender = $skinProperties->getProperty("email.recipient") or $sender = $properties->getProperty('email.recipient');
1152
        my $errorMessage = "The Identity Service can't get the next avaliable uid number.  Please try again.  If the issue persists, please contact the administrator - $sender.";
1158
        my $errorMessage = "The Identity Service can't get the next avaliable uid number. Please try again.  If the issue persists, please contact the administrator - $sender.
1159
                           The possible reasons are: the dn - $dn_store_next_uid or its attribute - $attribute_name_store_next_uid don't exist; the value of the attribute - $attribute_name_store_next_uid
1160
                           is not a number; or lots of users were registering and you couldn't get a lock on the dn - $dn_store_next_uid.";
1153 1161
        fullTemplate(['register'], { stage => "register",
1154 1162
                                     allParams => $allParams,
1155 1163
                                     errorMessage => $errorMessage });
......
1235 1243
    From: $sender
1236 1244
    Subject: New Account Activation
1237 1245
        
1238
    Somebody (hopefully you) registered an account on $contextUrl.  
1246
    Somebody (hopefully you) registered an account on $contextUrl/style/skins/account/.  
1239 1247
    Please click the following link to activate your account.
1240 1248
    If the link doesn't work, please copy the link to your browser:
1241 1249
    
......
1580 1588

  
1581 1589
#Method to get the next avaliable uid number. We use the mechanism - http://www.rexconsulting.net/ldap-protocol-uidNumber.html
1582 1590
sub getNextUidNumber {
1583
    my $base=$properties->getProperty('ldap.nextuid.storing.dn');
1584
    my $uid_attribute_name = $properties->getProperty('ldap.nextuid.storing.attributename');
1591

  
1585 1592
    my $maxAttempt = $properties->getProperty('ldap.nextuid.maxattempt');
1586 1593
    
1587 1594
    my $ldapUsername = shift;
......
1604 1611
        my $bindresult = $ldap->bind( version => 3, dn => $ldapUsername, password => $ldapPassword);
1605 1612
        #read the uid value stored in uidObject class
1606 1613
        for(my $index=0; $index<$maxAttempt; $index++) {
1607
            $mesg = $ldap->search(base  => $base, filter => '(objectClass=*)');
1614
            $mesg = $ldap->search(base  => $dn_store_next_uid, filter => '(objectClass=*)');
1608 1615
            if ($mesg->count() > 0) {
1609
                debug("Find the cn - $base");
1616
                debug("Find the cn - $dn_store_next_uid");
1610 1617
                $entry = $mesg->pop_entry;
1611
                $uidNumber = $entry->get_value($uid_attribute_name);
1618
                $uidNumber = $entry->get_value($attribute_name_store_next_uid);
1612 1619
                if($uidNumber) {
1613
                    debug("uid number is $uidNumber");
1614
                    #remove the uid attribute with the read value
1615
                    my $delMesg = $ldap->modify($base, delete => { $uid_attribute_name => $uidNumber});
1616
                    if($delMesg->is_error()) {
1617
                        my $error=$delMesg->error();
1618
                        my $errorName = $delMesg->error_name();
1619
                        debug("can't remove the attribute - $error");
1620
                        debug("can't remove the attribute and the error name - $errorName");
1621
                        #can't remove the attribute with the specified value - that means somebody modify the value in another route, so try it again
1622
                    } else {
1623
                        debug("Remove the attribute successfully and write a new increased value back");
1624
                        my $newValue = $uidNumber +1;
1625
                        $delMesg = $ldap->modify($base, add => {$uid_attribute_name => $newValue});
1626
                        $realUidNumber = $uidNumber;
1627
                        last;
1620
                    if (looks_like_number($uidNumber)) {
1621
                        debug("uid number is $uidNumber");
1622
                        #remove the uid attribute with the read value
1623
                        my $delMesg = $ldap->modify($dn_store_next_uid, delete => { $attribute_name_store_next_uid => $uidNumber});
1624
                        if($delMesg->is_error()) {
1625
                            my $error=$delMesg->error();
1626
                            my $errorName = $delMesg->error_name();
1627
                            debug("can't remove the attribute - $error");
1628
                            debug("can't remove the attribute and the error name - $errorName");
1629
                            #can't remove the attribute with the specified value - that means somebody modify the value in another route, so try it again
1630
                        } else {
1631
                            debug("Remove the attribute successfully and write a new increased value back");
1632
                            my $newValue = $uidNumber +1;
1633
                            $delMesg = $ldap->modify($dn_store_next_uid, add => {$attribute_name_store_next_uid => $newValue});
1634
                            $realUidNumber = $uidNumber;
1635
                            last;
1636
                        }
1628 1637
                    }
1638
                    
1629 1639
               } else {
1630
                 debug("can't find the attribute - $uid_attribute_name in the $base and we will try again");
1640
                 debug("can't find the attribute - $attribute_name_store_next_uid in the $dn_store_next_uid and we will try again");
1631 1641
               }
1632 1642
            } 
1633 1643
        }

Also available in: Unified diff