Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-04-04 11:30:41 +0300
committerGitHub <noreply@github.com>2020-04-04 11:30:41 +0300
commit4a1ca15c6a6e1e868985203e31762a486bd35f94 (patch)
tree74244a2320fafc405f01af9dc78f0769118ffccd /apps
parent6fa10f377a3b33aea528aa5c1806e9bc94269454 (diff)
parentc678af22b0be3c3886ad18d9672b678669368c84 (diff)
Merge pull request #20176 from nextcloud/backport/20123/stable17
[stable17] Bugfix - Prevent PHP Warning for count on null on LDAP
Diffstat (limited to 'apps')
-rw-r--r--apps/user_ldap/lib/User/User.php54
1 files changed, 26 insertions, 28 deletions
diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php
index 31a33d6aa1d..d73f7ded3b4 100644
--- a/apps/user_ldap/lib/User/User.php
+++ b/apps/user_ldap/lib/User/User.php
@@ -125,7 +125,7 @@ class User {
IConfig $config, FilesystemHelper $fs, Image $image,
LogWrapper $log, IAvatarManager $avatarManager, IUserManager $userManager,
INotificationManager $notificationManager) {
-
+
if ($username === null) {
$log->log("uid for '$dn' must not be null!", ILogger::ERROR);
throw new \InvalidArgumentException('uid must not be null!');
@@ -683,7 +683,7 @@ class User {
* @throws \OC\ServerNotAvailableException
*/
public function updateExtStorageHome(string $valueFromLDAP = null):string {
- if($valueFromLDAP === null) {
+ if ($valueFromLDAP === null) {
$extHomeValues = $this->access->readAttribute($this->getDN(), $this->connection->ldapExtStorageHomeAttribute);
} else {
$extHomeValues = [$valueFromLDAP];
@@ -709,21 +709,21 @@ class User {
return;//password expiry handling disabled
}
$uid = $params['uid'];
- if(isset($uid) && $uid === $this->getUsername()) {
+ if (isset($uid) && $uid === $this->getUsername()) {
//retrieve relevant user attributes
$result = $this->access->search('objectclass=*', array($this->dn), ['pwdpolicysubentry', 'pwdgraceusetime', 'pwdreset', 'pwdchangedtime']);
-
- if(array_key_exists('pwdpolicysubentry', $result[0])) {
+
+ if (array_key_exists('pwdpolicysubentry', $result[0])) {
$pwdPolicySubentry = $result[0]['pwdpolicysubentry'];
- if($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)){
+ if ($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)){
$ppolicyDN = $pwdPolicySubentry[0];//custom ppolicy DN
}
}
-
- $pwdGraceUseTime = array_key_exists('pwdgraceusetime', $result[0]) ? $result[0]['pwdgraceusetime'] : null;
- $pwdReset = array_key_exists('pwdreset', $result[0]) ? $result[0]['pwdreset'] : null;
- $pwdChangedTime = array_key_exists('pwdchangedtime', $result[0]) ? $result[0]['pwdchangedtime'] : null;
-
+
+ $pwdGraceUseTime = array_key_exists('pwdgraceusetime', $result[0]) ? $result[0]['pwdgraceusetime'] : [];
+ $pwdReset = array_key_exists('pwdreset', $result[0]) ? $result[0]['pwdreset'] : [];
+ $pwdChangedTime = array_key_exists('pwdchangedtime', $result[0]) ? $result[0]['pwdchangedtime'] : [];
+
//retrieve relevant password policy attributes
$cacheKey = 'ppolicyAttributes' . $ppolicyDN;
$result = $this->connection->getFromCache($cacheKey);
@@ -731,17 +731,15 @@ class User {
$result = $this->access->search('objectclass=*', array($ppolicyDN), ['pwdgraceauthnlimit', 'pwdmaxage', 'pwdexpirewarning']);
$this->connection->writeToCache($cacheKey, $result);
}
-
- $pwdGraceAuthNLimit = array_key_exists('pwdgraceauthnlimit', $result[0]) ? $result[0]['pwdgraceauthnlimit'] : null;
- $pwdMaxAge = array_key_exists('pwdmaxage', $result[0]) ? $result[0]['pwdmaxage'] : null;
- $pwdExpireWarning = array_key_exists('pwdexpirewarning', $result[0]) ? $result[0]['pwdexpirewarning'] : null;
-
+
+ $pwdGraceAuthNLimit = array_key_exists('pwdgraceauthnlimit', $result[0]) ? $result[0]['pwdgraceauthnlimit'] : [];
+ $pwdMaxAge = array_key_exists('pwdmaxage', $result[0]) ? $result[0]['pwdmaxage'] : [];
+ $pwdExpireWarning = array_key_exists('pwdexpirewarning', $result[0]) ? $result[0]['pwdexpirewarning'] : [];
+
//handle grace login
- $pwdGraceUseTimeCount = count($pwdGraceUseTime);
- if($pwdGraceUseTime && $pwdGraceUseTimeCount > 0) { //was this a grace login?
- if($pwdGraceAuthNLimit
- && (count($pwdGraceAuthNLimit) > 0)
- &&($pwdGraceUseTimeCount < (int)$pwdGraceAuthNLimit[0])) { //at least one more grace login available?
+ if (!empty($pwdGraceUseTime)) { //was this a grace login?
+ if (!empty($pwdGraceAuthNLimit)
+ && count($pwdGraceUseTime) < (int)$pwdGraceAuthNLimit[0]) { //at least one more grace login available?
$this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid)));
@@ -752,24 +750,24 @@ class User {
exit();
}
//handle pwdReset attribute
- if($pwdReset && (count($pwdReset) > 0) && $pwdReset[0] === 'TRUE') { //user must change his password
+ if (!empty($pwdReset) && $pwdReset[0] === 'TRUE') { //user must change his password
$this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid)));
exit();
}
//handle password expiry warning
- if($pwdChangedTime && (count($pwdChangedTime) > 0)) {
- if($pwdMaxAge && (count($pwdMaxAge) > 0)
- && $pwdExpireWarning && (count($pwdExpireWarning) > 0)) {
+ if (!empty($pwdChangedTime)) {
+ if (!empty($pwdMaxAge)
+ && !empty($pwdExpireWarning)) {
$pwdMaxAgeInt = (int)$pwdMaxAge[0];
$pwdExpireWarningInt = (int)$pwdExpireWarning[0];
- if($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0){
+ if ($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0){
$pwdChangedTimeDt = \DateTime::createFromFormat('YmdHisZ', $pwdChangedTime[0]);
$pwdChangedTimeDt->add(new \DateInterval('PT'.$pwdMaxAgeInt.'S'));
$currentDateTime = new \DateTime();
$secondsToExpiry = $pwdChangedTimeDt->getTimestamp() - $currentDateTime->getTimestamp();
- if($secondsToExpiry <= $pwdExpireWarningInt) {
+ if ($secondsToExpiry <= $pwdExpireWarningInt) {
//remove last password expiry warning if any
$notification = $this->notificationManager->createNotification();
$notification->setApp('user_ldap')
@@ -782,7 +780,7 @@ class User {
$notification->setApp('user_ldap')
->setUser($uid)
->setDateTime($currentDateTime)
- ->setObject('pwd_exp_warn', $uid)
+ ->setObject('pwd_exp_warn', $uid)
->setSubject('pwd_exp_warn_days', [(int) ceil($secondsToExpiry / 60 / 60 / 24)])
;
$this->notificationManager->notify($notification);