Skip to content

Commit

Permalink
remove multiple warnings (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Coutadeur committed Nov 4, 2024
1 parent 6d58338 commit 5eed1ef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
17 changes: 10 additions & 7 deletions src/Ltb/Directory/ActiveDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function isLocked($ldap, $dn, $config) : bool {
}

# Get lockoutTime
$lockoutTime = $entry[0]['lockouttime'][0];
$lockoutTime = $entry[0]['lockouttime'][0] ?? 0;

# Get unlock date
$unlockDate = $this->getUnlockDate($ldap, $dn, $config);
Expand Down Expand Up @@ -53,7 +53,7 @@ public function getLockDate($ldap, $dn) : ?DateTime {
}

# Get lockoutTime
$lockoutTime = $entry[0]['lockouttime'][0];
$lockoutTime = $entry[0]['lockouttime'][0] ?? 0;

if ( !$lockoutTime or $lockoutTime === 0) {
return $lockDate;
Expand Down Expand Up @@ -119,7 +119,7 @@ public function isPasswordExpired($ldap, $dn, $config) : bool {
}

# Get pwdLastSet
$pwdLastSet = $entry[0]['pwdlastset'][0];
$pwdLastSet = $entry[0]['pwdlastset'][0] ?? null;

if (!$pwdLastSet) {
return false;
Expand Down Expand Up @@ -155,7 +155,7 @@ public function getPasswordExpirationDate($ldap, $dn, $config) : ?DateTime {
}

# Get pwdLastSet
$pwdLastSet = $entry[0]['pwdlastset'][0];
$pwdLastSet = $entry[0]['pwdlastset'][0] ?? null;

if ( !$pwdLastSet or $pwdLastSet === 0) {
return $expirationDate;
Expand Down Expand Up @@ -206,7 +206,8 @@ public function resetAtNextConnection($ldap, $dn) : bool {
$entry = \Ltb\PhpLDAP::ldap_get_entries($ldap, $search);
}

if ($entry[0]['pwdlastset'] and $entry[0]['pwdlastset'][0] === 0) {
$pwdlastset = $entry[0]['pwdlastset'][0] ?? null;
if ( isset($pwdlastset) and $pwdlastset === 0) {
return true;
} else {
return false;
Expand Down Expand Up @@ -312,8 +313,10 @@ public function getPwdPolicyConfiguration($ldap, $entry_dn, $default_ppolicy_dn)
}

$ppolicyConfig["dn"] = $entry[0]["dn"];
$ppolicyConfig["lockout_duration"] = $entry[0]["lockoutduration"][0] / -10000000 ;
$ppolicyConfig["password_max_age"] = $entry[0]["maxpwdage"][0] / -10000000;
$lockoutduration = $entry[0]["lockoutduration"][0] ?? 0;
$ppolicyConfig["lockout_duration"] = $lockoutduration / -10000000 ;
$password_max_age = $entry[0]["maxpwdage"][0] ?? 0;
$ppolicyConfig["password_max_age"] = $password_max_age / -10000000;
$ppolicyConfig["lockout_enabled"] = false;

return $ppolicyConfig;
Expand Down
18 changes: 10 additions & 8 deletions src/Ltb/Directory/OpenLDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function isLocked($ldap, $dn, $config) : bool {
}

# Get pwdAccountLockedTime
$pwdAccountLockedTime = $entry[0]['pwdaccountlockedtime'][0];
$pwdAccountLockedTime = $entry[0]['pwdaccountlockedtime'][0] ?? null;

if (!$pwdAccountLockedTime) {
return false;
Expand Down Expand Up @@ -55,7 +55,7 @@ public function getLockDate($ldap, $dn) : ?DateTime {
}

# Get pwdAccountLockedTime
$pwdAccountLockedTime = $entry[0]['pwdaccountlockedtime'][0];
$pwdAccountLockedTime = $entry[0]['pwdaccountlockedtime'][0] ?? null;

if (!$pwdAccountLockedTime or $pwdAccountLockedTime === "000001010000Z") {
return $lockDate;
Expand Down Expand Up @@ -127,7 +127,7 @@ public function isPasswordExpired($ldap, $dn, $config) : bool {
}

# Get pwdChangedTime
$pwdChangedTime = $entry[0]['pwdchangedtime'][0];
$pwdChangedTime = $entry[0]['pwdchangedtime'][0] ?? null;

if (!$pwdChangedTime) {
return false;
Expand Down Expand Up @@ -163,7 +163,7 @@ public function getPasswordExpirationDate($ldap, $dn, $config) : ?DateTime {
}

# Get pwdChangedTime
$pwdChangedTime = $entry[0]['pwdchangedtime'][0];
$pwdChangedTime = $entry[0]['pwdchangedtime'][0] ?? null;

if (!$pwdChangedTime) {
return $expirationDate;
Expand Down Expand Up @@ -213,7 +213,8 @@ public function resetAtNextConnection($ldap, $dn) : bool {
$entry = \Ltb\PhpLDAP::ldap_get_entries($ldap, $search);
}

if ($entry[0]['pwdreset'] and $entry[0]['pwdreset'][0] === "TRUE") {
$pwdreset = $entry[0]['pwdreset'][0] ?? null;
if( isset($pwdreset) and $pwdreset === "TRUE" ) {
return true;
} else {
return false;
Expand Down Expand Up @@ -307,9 +308,10 @@ public function getPwdPolicyConfiguration($ldap, $entry_dn, $default_ppolicy_dn)
}

$ppolicyConfig["dn"] = $entry[0]["dn"];
$ppolicyConfig["lockout_duration"] = $entry[0]["pwdlockoutduration"][0];
$ppolicyConfig["password_max_age"] = $entry[0]["pwdmaxage"][0];
$ppolicyConfig["lockout_enabled"] = strtolower($entry[0]['pwdlockout'][0]) == "true" ? true : false;
$ppolicyConfig["lockout_duration"] = $entry[0]["pwdlockoutduration"][0] ?? 0;
$ppolicyConfig["password_max_age"] = $entry[0]["pwdmaxage"][0] ?? 0;
$pwdlockout = $entry[0]['pwdlockout'][0] ?? false;
$ppolicyConfig["lockout_enabled"] = strtolower($pwdlockout) == "true" ? true : false;

return $ppolicyConfig;
}
Expand Down

0 comments on commit 5eed1ef

Please sign in to comment.