Skip to content

Commit

Permalink
Function for reset at next connection
Browse files Browse the repository at this point in the history
  • Loading branch information
coudot committed Jul 24, 2024
1 parent 696a407 commit e9bdceb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Ltb/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ public function getPasswordExpirationDate($ldap, $dn, $config) : ?DateTime;
* Modify the password
*/
public function modifyPassword($ldap, $dn, $password, $forceReset) : bool;

/*
* Should user reset password at next connection?
*/
public function resetAtNextConnection($ldap, $dn) : bool;
}
19 changes: 19 additions & 0 deletions src/Ltb/Directory/ActiveDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,25 @@ public function modifyPassword($ldap, $dn, $password, $forceReset) : bool {
} else {
return true;
}
}

public function resetAtNextConnection($ldap, $dn) : bool {

# Get entry
$search = \Ltb\PhpLDAP::ldap_read($ldap, $dn, "(objectClass=*)", array('pwdlastset'));
$errno = \Ltb\PhpLDAP::ldap_errno($ldap);

if ( $errno ) {
error_log("LDAP - Search error $errno (".ldap_error($ldap).")");
return $expirationDate;
} else {
$entry = \Ltb\PhpLDAP::ldap_get_entries($ldap, $search);
}

if ($entry[0]['pwdlastset'] and $entry[0]['pwdlastset'][0] == 0) {
return true;
} else {
return false;
}
}
}
20 changes: 20 additions & 0 deletions src/Ltb/Directory/OpenLDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,24 @@ public function modifyPassword($ldap, $dn, $password, $forceReset) : bool {
return true;
}
}

public function resetAtNextConnection($ldap, $dn) : bool {

# Get entry
$search = \Ltb\PhpLDAP::ldap_read($ldap, $dn, "(objectClass=*)", array('pwdreset'));
$errno = \Ltb\PhpLDAP::ldap_errno($ldap);

if ( $errno ) {
error_log("LDAP - Search error $errno (".ldap_error($ldap).")");
return $expirationDate;
} else {
$entry = \Ltb\PhpLDAP::ldap_get_entries($ldap, $search);
}

if ($entry[0]['pwdreset'] and $entry[0]['pwdreset'][0] === "TRUE") {
return true;
} else {
return false;
}
}
}

0 comments on commit e9bdceb

Please sign in to comment.