Passed
Push — master ( 078203...c81798 )
by Joas
14:40 queued 14s
created
apps/user_ldap/lib/Notification/Notifier.php 1 patch
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -31,72 +31,72 @@
 block discarded – undo
31 31
 
32 32
 class Notifier implements INotifier {
33 33
 
34
-	/** @var IFactory */
35
-	protected $l10nFactory;
34
+    /** @var IFactory */
35
+    protected $l10nFactory;
36 36
 
37
-	/**
38
-	 * @param IFactory $l10nFactory
39
-	 */
40
-	public function __construct(\OCP\L10N\IFactory $l10nFactory) {
41
-		$this->l10nFactory = $l10nFactory;
42
-	}
37
+    /**
38
+     * @param IFactory $l10nFactory
39
+     */
40
+    public function __construct(\OCP\L10N\IFactory $l10nFactory) {
41
+        $this->l10nFactory = $l10nFactory;
42
+    }
43 43
 
44
-	/**
45
-	 * Identifier of the notifier, only use [a-z0-9_]
46
-	 *
47
-	 * @return string
48
-	 * @since 17.0.0
49
-	 */
50
-	public function getID(): string {
51
-		return 'user_ldap';
52
-	}
44
+    /**
45
+     * Identifier of the notifier, only use [a-z0-9_]
46
+     *
47
+     * @return string
48
+     * @since 17.0.0
49
+     */
50
+    public function getID(): string {
51
+        return 'user_ldap';
52
+    }
53 53
 
54
-	/**
55
-	 * Human readable name describing the notifier
56
-	 *
57
-	 * @return string
58
-	 * @since 17.0.0
59
-	 */
60
-	public function getName(): string {
61
-		return $this->l10nFactory->get('user_ldap')->t('LDAP User backend');
62
-	}
54
+    /**
55
+     * Human readable name describing the notifier
56
+     *
57
+     * @return string
58
+     * @since 17.0.0
59
+     */
60
+    public function getName(): string {
61
+        return $this->l10nFactory->get('user_ldap')->t('LDAP User backend');
62
+    }
63 63
 
64
-	/**
65
-	 * @param INotification $notification
66
-	 * @param string $languageCode The code of the language that should be used to prepare the notification
67
-	 * @return INotification
68
-	 * @throws \InvalidArgumentException When the notification was not prepared by a notifier
69
-	 */
70
-	public function prepare(INotification $notification, string $languageCode): INotification {
71
-		if ($notification->getApp() !== 'user_ldap') {
72
-			// Not my app => throw
73
-			throw new \InvalidArgumentException();
74
-		}
64
+    /**
65
+     * @param INotification $notification
66
+     * @param string $languageCode The code of the language that should be used to prepare the notification
67
+     * @return INotification
68
+     * @throws \InvalidArgumentException When the notification was not prepared by a notifier
69
+     */
70
+    public function prepare(INotification $notification, string $languageCode): INotification {
71
+        if ($notification->getApp() !== 'user_ldap') {
72
+            // Not my app => throw
73
+            throw new \InvalidArgumentException();
74
+        }
75 75
 
76
-		// Read the language from the notification
77
-		$l = $this->l10nFactory->get('user_ldap', $languageCode);
76
+        // Read the language from the notification
77
+        $l = $this->l10nFactory->get('user_ldap', $languageCode);
78 78
 
79
-		switch ($notification->getSubject()) {
80
-			// Deal with known subjects
81
-			case 'pwd_exp_warn_days':
82
-				$params = $notification->getSubjectParameters();
83
-				$days = (int) $params[0];
84
-				if ($days === 2) {
85
-					$notification->setParsedSubject($l->t('Your password will expire tomorrow.'));
86
-				} elseif ($days === 1) {
87
-					$notification->setParsedSubject($l->t('Your password will expire today.'));
88
-				} else {
89
-					$notification->setParsedSubject($l->n(
90
-						'Your password will expire within %n day.',
91
-						'Your password will expire within %n days.',
92
-						$days
93
-					));
94
-				}
95
-				return $notification;
79
+        switch ($notification->getSubject()) {
80
+            // Deal with known subjects
81
+            case 'pwd_exp_warn_days':
82
+                $params = $notification->getSubjectParameters();
83
+                $days = (int) $params[0];
84
+                if ($days === 2) {
85
+                    $notification->setParsedSubject($l->t('Your password will expire tomorrow.'));
86
+                } elseif ($days === 1) {
87
+                    $notification->setParsedSubject($l->t('Your password will expire today.'));
88
+                } else {
89
+                    $notification->setParsedSubject($l->n(
90
+                        'Your password will expire within %n day.',
91
+                        'Your password will expire within %n days.',
92
+                        $days
93
+                    ));
94
+                }
95
+                return $notification;
96 96
 
97
-			default:
98
-				// Unknown subject => Unknown notification => throw
99
-				throw new \InvalidArgumentException();
100
-		}
101
-	}
97
+            default:
98
+                // Unknown subject => Unknown notification => throw
99
+                throw new \InvalidArgumentException();
100
+        }
101
+    }
102 102
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Handler/ExtStorageConfigHandler.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -30,40 +30,40 @@
 block discarded – undo
30 30
 use OCA\User_LDAP\User_Proxy;
31 31
 
32 32
 class ExtStorageConfigHandler extends UserContext implements IConfigHandler {
33
-	use SimpleSubstitutionTrait;
33
+    use SimpleSubstitutionTrait;
34 34
 
35
-	/**
36
-	 * @param mixed $optionValue
37
-	 * @return mixed the same type as $optionValue
38
-	 * @since 16.0.0
39
-	 * @throws \Exception
40
-	 */
41
-	public function handle($optionValue) {
42
-		$this->placeholder = 'home';
43
-		$user = $this->getUser();
35
+    /**
36
+     * @param mixed $optionValue
37
+     * @return mixed the same type as $optionValue
38
+     * @since 16.0.0
39
+     * @throws \Exception
40
+     */
41
+    public function handle($optionValue) {
42
+        $this->placeholder = 'home';
43
+        $user = $this->getUser();
44 44
 
45
-		if ($user === null) {
46
-			return $optionValue;
47
-		}
45
+        if ($user === null) {
46
+            return $optionValue;
47
+        }
48 48
 
49
-		$backend = $user->getBackend();
50
-		if (!$backend instanceof User_Proxy) {
51
-			return $optionValue;
52
-		}
49
+        $backend = $user->getBackend();
50
+        if (!$backend instanceof User_Proxy) {
51
+            return $optionValue;
52
+        }
53 53
 
54
-		$access = $backend->getLDAPAccess($user->getUID());
55
-		if (!$access) {
56
-			return $optionValue;
57
-		}
54
+        $access = $backend->getLDAPAccess($user->getUID());
55
+        if (!$access) {
56
+            return $optionValue;
57
+        }
58 58
 
59
-		$attribute = $access->connection->ldapExtStorageHomeAttribute;
60
-		if (empty($attribute)) {
61
-			return $optionValue;
62
-		}
59
+        $attribute = $access->connection->ldapExtStorageHomeAttribute;
60
+        if (empty($attribute)) {
61
+            return $optionValue;
62
+        }
63 63
 
64
-		$ldapUser = $access->userManager->get($user->getUID());
65
-		$extHome = $ldapUser->getExtStorageHome();
64
+        $ldapUser = $access->userManager->get($user->getUID());
65
+        $extHome = $ldapUser->getExtStorageHome();
66 66
 
67
-		return $this->processInput($optionValue, $extHome);
68
-	}
67
+        return $this->processInput($optionValue, $extHome);
68
+    }
69 69
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/WizardResult.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -30,50 +30,50 @@
 block discarded – undo
30 30
 namespace OCA\User_LDAP;
31 31
 
32 32
 class WizardResult {
33
-	protected $changes = [];
34
-	protected $options = [];
35
-	protected $markedChange = false;
33
+    protected $changes = [];
34
+    protected $options = [];
35
+    protected $markedChange = false;
36 36
 
37
-	/**
38
-	 * @param string $key
39
-	 * @param mixed $value
40
-	 */
41
-	public function addChange($key, $value) {
42
-		$this->changes[$key] = $value;
43
-	}
37
+    /**
38
+     * @param string $key
39
+     * @param mixed $value
40
+     */
41
+    public function addChange($key, $value) {
42
+        $this->changes[$key] = $value;
43
+    }
44 44
 
45 45
 	
46
-	public function markChange() {
47
-		$this->markedChange = true;
48
-	}
46
+    public function markChange() {
47
+        $this->markedChange = true;
48
+    }
49 49
 
50
-	/**
51
-	 * @param string $key
52
-	 * @param array|string $values
53
-	 */
54
-	public function addOptions($key, $values) {
55
-		if (!is_array($values)) {
56
-			$values = [$values];
57
-		}
58
-		$this->options[$key] = $values;
59
-	}
50
+    /**
51
+     * @param string $key
52
+     * @param array|string $values
53
+     */
54
+    public function addOptions($key, $values) {
55
+        if (!is_array($values)) {
56
+            $values = [$values];
57
+        }
58
+        $this->options[$key] = $values;
59
+    }
60 60
 
61
-	/**
62
-	 * @return bool
63
-	 */
64
-	public function hasChanges() {
65
-		return (count($this->changes) > 0 || $this->markedChange);
66
-	}
61
+    /**
62
+     * @return bool
63
+     */
64
+    public function hasChanges() {
65
+        return (count($this->changes) > 0 || $this->markedChange);
66
+    }
67 67
 
68
-	/**
69
-	 * @return array
70
-	 */
71
-	public function getResultArray() {
72
-		$result = [];
73
-		$result['changes'] = $this->changes;
74
-		if (count($this->options) > 0) {
75
-			$result['options'] = $this->options;
76
-		}
77
-		return $result;
78
-	}
68
+    /**
69
+     * @return array
70
+     */
71
+    public function getResultArray() {
72
+        $result = [];
73
+        $result['changes'] = $this->changes;
74
+        if (count($this->options) > 0) {
75
+            $result['options'] = $this->options;
76
+        }
77
+        return $result;
78
+    }
79 79
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Migration/UUIDFixInsert.php 1 patch
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -33,69 +33,69 @@
 block discarded – undo
33 33
 
34 34
 class UUIDFixInsert implements IRepairStep {
35 35
 
36
-	/** @var IConfig */
37
-	protected $config;
36
+    /** @var IConfig */
37
+    protected $config;
38 38
 
39
-	/** @var UserMapping */
40
-	protected $userMapper;
39
+    /** @var UserMapping */
40
+    protected $userMapper;
41 41
 
42
-	/** @var GroupMapping */
43
-	protected $groupMapper;
42
+    /** @var GroupMapping */
43
+    protected $groupMapper;
44 44
 
45
-	/** @var IJobList */
46
-	protected $jobList;
45
+    /** @var IJobList */
46
+    protected $jobList;
47 47
 
48
-	public function __construct(IConfig $config, UserMapping $userMapper, GroupMapping $groupMapper, IJobList $jobList) {
49
-		$this->config = $config;
50
-		$this->userMapper = $userMapper;
51
-		$this->groupMapper = $groupMapper;
52
-		$this->jobList = $jobList;
53
-	}
48
+    public function __construct(IConfig $config, UserMapping $userMapper, GroupMapping $groupMapper, IJobList $jobList) {
49
+        $this->config = $config;
50
+        $this->userMapper = $userMapper;
51
+        $this->groupMapper = $groupMapper;
52
+        $this->jobList = $jobList;
53
+    }
54 54
 
55
-	/**
56
-	 * Returns the step's name
57
-	 *
58
-	 * @return string
59
-	 * @since 9.1.0
60
-	 */
61
-	public function getName() {
62
-		return 'Insert UUIDFix background job for user and group in batches';
63
-	}
55
+    /**
56
+     * Returns the step's name
57
+     *
58
+     * @return string
59
+     * @since 9.1.0
60
+     */
61
+    public function getName() {
62
+        return 'Insert UUIDFix background job for user and group in batches';
63
+    }
64 64
 
65
-	/**
66
-	 * Run repair step.
67
-	 * Must throw exception on error.
68
-	 *
69
-	 * @param IOutput $output
70
-	 * @throws \Exception in case of failure
71
-	 * @since 9.1.0
72
-	 */
73
-	public function run(IOutput $output) {
74
-		$installedVersion = $this->config->getAppValue('user_ldap', 'installed_version', '1.2.1');
75
-		if (version_compare($installedVersion, '1.2.1') !== -1) {
76
-			return;
77
-		}
65
+    /**
66
+     * Run repair step.
67
+     * Must throw exception on error.
68
+     *
69
+     * @param IOutput $output
70
+     * @throws \Exception in case of failure
71
+     * @since 9.1.0
72
+     */
73
+    public function run(IOutput $output) {
74
+        $installedVersion = $this->config->getAppValue('user_ldap', 'installed_version', '1.2.1');
75
+        if (version_compare($installedVersion, '1.2.1') !== -1) {
76
+            return;
77
+        }
78 78
 
79
-		foreach ([$this->userMapper, $this->groupMapper] as $mapper) {
80
-			$offset = 0;
81
-			$batchSize = 50;
82
-			$jobClass = $mapper instanceof UserMapping ? UUIDFixUser::class : UUIDFixGroup::class;
83
-			do {
84
-				$retry = false;
85
-				$records = $mapper->getList($offset, $batchSize);
86
-				if (count($records) === 0) {
87
-					continue;
88
-				}
89
-				try {
90
-					$this->jobList->add($jobClass, ['records' => $records]);
91
-					$offset += $batchSize;
92
-				} catch (\InvalidArgumentException $e) {
93
-					if (strpos($e->getMessage(), 'Background job arguments can\'t exceed 4000') !== false) {
94
-						$batchSize = (int)floor(count($records) * 0.8);
95
-						$retry = true;
96
-					}
97
-				}
98
-			} while (count($records) === $batchSize || $retry);
99
-		}
100
-	}
79
+        foreach ([$this->userMapper, $this->groupMapper] as $mapper) {
80
+            $offset = 0;
81
+            $batchSize = 50;
82
+            $jobClass = $mapper instanceof UserMapping ? UUIDFixUser::class : UUIDFixGroup::class;
83
+            do {
84
+                $retry = false;
85
+                $records = $mapper->getList($offset, $batchSize);
86
+                if (count($records) === 0) {
87
+                    continue;
88
+                }
89
+                try {
90
+                    $this->jobList->add($jobClass, ['records' => $records]);
91
+                    $offset += $batchSize;
92
+                } catch (\InvalidArgumentException $e) {
93
+                    if (strpos($e->getMessage(), 'Background job arguments can\'t exceed 4000') !== false) {
94
+                        $batchSize = (int)floor(count($records) * 0.8);
95
+                        $retry = true;
96
+                    }
97
+                }
98
+            } while (count($records) === $batchSize || $retry);
99
+        }
100
+    }
101 101
 }
Please login to merge, or discard this patch.
apps/user_ldap/templates/part.wizard-server.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -2,15 +2,15 @@
 block discarded – undo
2 2
 		<p>
3 3
 		<select id="ldap_serverconfig_chooser" name="ldap_serverconfig_chooser">
4 4
 		<?php
5
-		$i = 1;
6
-		$sel = ' selected';
7
-		foreach ($_['serverConfigurationPrefixes'] as $prefix) {
8
-			?>
5
+        $i = 1;
6
+        $sel = ' selected';
7
+        foreach ($_['serverConfigurationPrefixes'] as $prefix) {
8
+            ?>
9 9
 			<option value="<?php p($prefix); ?>"<?php p($sel);
10
-			$sel = ''; ?>><?php p($l->t('%s. Server:', [$i++])); ?> <?php p(' '.$_['serverConfigurationHosts'][$prefix]); ?></option>
10
+            $sel = ''; ?>><?php p($l->t('%s. Server:', [$i++])); ?> <?php p(' '.$_['serverConfigurationHosts'][$prefix]); ?></option>
11 11
 			<?php
12
-		}
13
-		?>
12
+        }
13
+        ?>
14 14
 		</select>
15 15
 		<button type="button" id="ldap_action_add_configuration"
16 16
 			name="ldap_action_add_configuration" class="icon-add icon-default-style"
Please login to merge, or discard this patch.
apps/user_ldap/ajax/setConfiguration.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -36,11 +36,11 @@
 block discarded – undo
36 36
 // only legacy checkboxes (Advanced and Expert tab) need to be handled here,
37 37
 // the Wizard-like tabs handle it on their own
38 38
 $chkboxes = ['ldap_configuration_active', 'ldap_override_main_server',
39
-	'ldap_turn_off_cert_check'];
39
+    'ldap_turn_off_cert_check'];
40 40
 foreach ($chkboxes as $boxid) {
41
-	if (!isset($_POST[$boxid])) {
42
-		$_POST[$boxid] = 0;
43
-	}
41
+    if (!isset($_POST[$boxid])) {
42
+        $_POST[$boxid] = 0;
43
+    }
44 44
 }
45 45
 
46 46
 $ldapWrapper = new OCA\User_LDAP\LDAP();
Please login to merge, or discard this patch.
apps/encryption/lib/Hooks/UserHooks.php 1 patch
Indentation   +300 added lines, -300 removed lines patch added patch discarded remove patch
@@ -44,304 +44,304 @@
 block discarded – undo
44 44
 
45 45
 class UserHooks implements IHook {
46 46
 
47
-	/**
48
-	 * list of user for which we perform a password reset
49
-	 * @var array
50
-	 */
51
-	protected static $passwordResetUsers = [];
52
-
53
-	/**
54
-	 * @var KeyManager
55
-	 */
56
-	private $keyManager;
57
-	/**
58
-	 * @var IUserManager
59
-	 */
60
-	private $userManager;
61
-	/**
62
-	 * @var ILogger
63
-	 */
64
-	private $logger;
65
-	/**
66
-	 * @var Setup
67
-	 */
68
-	private $userSetup;
69
-	/**
70
-	 * @var IUserSession
71
-	 */
72
-	private $userSession;
73
-	/**
74
-	 * @var Util
75
-	 */
76
-	private $util;
77
-	/**
78
-	 * @var Session
79
-	 */
80
-	private $session;
81
-	/**
82
-	 * @var Recovery
83
-	 */
84
-	private $recovery;
85
-	/**
86
-	 * @var Crypt
87
-	 */
88
-	private $crypt;
89
-
90
-	/**
91
-	 * UserHooks constructor.
92
-	 *
93
-	 * @param KeyManager $keyManager
94
-	 * @param IUserManager $userManager
95
-	 * @param ILogger $logger
96
-	 * @param Setup $userSetup
97
-	 * @param IUserSession $userSession
98
-	 * @param Util $util
99
-	 * @param Session $session
100
-	 * @param Crypt $crypt
101
-	 * @param Recovery $recovery
102
-	 */
103
-	public function __construct(KeyManager $keyManager,
104
-								IUserManager $userManager,
105
-								ILogger $logger,
106
-								Setup $userSetup,
107
-								IUserSession $userSession,
108
-								Util $util,
109
-								Session $session,
110
-								Crypt $crypt,
111
-								Recovery $recovery) {
112
-		$this->keyManager = $keyManager;
113
-		$this->userManager = $userManager;
114
-		$this->logger = $logger;
115
-		$this->userSetup = $userSetup;
116
-		$this->userSession = $userSession;
117
-		$this->util = $util;
118
-		$this->session = $session;
119
-		$this->recovery = $recovery;
120
-		$this->crypt = $crypt;
121
-	}
122
-
123
-	/**
124
-	 * Connects Hooks
125
-	 *
126
-	 * @return null
127
-	 */
128
-	public function addHooks() {
129
-		OCUtil::connectHook('OC_User', 'post_login', $this, 'login');
130
-		OCUtil::connectHook('OC_User', 'logout', $this, 'logout');
131
-
132
-		// this hooks only make sense if no master key is used
133
-		if ($this->util->isMasterKeyEnabled() === false) {
134
-			OCUtil::connectHook('OC_User',
135
-				'post_setPassword',
136
-				$this,
137
-				'setPassphrase');
138
-
139
-			OCUtil::connectHook('OC_User',
140
-				'pre_setPassword',
141
-				$this,
142
-				'preSetPassphrase');
143
-
144
-			OCUtil::connectHook('\OC\Core\LostPassword\Controller\LostController',
145
-				'post_passwordReset',
146
-				$this,
147
-				'postPasswordReset');
148
-
149
-			OCUtil::connectHook('\OC\Core\LostPassword\Controller\LostController',
150
-				'pre_passwordReset',
151
-				$this,
152
-				'prePasswordReset');
153
-
154
-			OCUtil::connectHook('OC_User',
155
-				'post_createUser',
156
-				$this,
157
-				'postCreateUser');
158
-
159
-			OCUtil::connectHook('OC_User',
160
-				'post_deleteUser',
161
-				$this,
162
-				'postDeleteUser');
163
-		}
164
-	}
165
-
166
-
167
-	/**
168
-	 * Startup encryption backend upon user login
169
-	 *
170
-	 * @note This method should never be called for users using client side encryption
171
-	 * @param array $params
172
-	 * @return boolean|null
173
-	 */
174
-	public function login($params) {
175
-		// ensure filesystem is loaded
176
-		if (!\OC\Files\Filesystem::$loaded) {
177
-			$this->setupFS($params['uid']);
178
-		}
179
-		if ($this->util->isMasterKeyEnabled() === false) {
180
-			$this->userSetup->setupUser($params['uid'], $params['password']);
181
-		}
182
-
183
-		$this->keyManager->init($params['uid'], $params['password']);
184
-	}
185
-
186
-	/**
187
-	 * remove keys from session during logout
188
-	 */
189
-	public function logout() {
190
-		$this->session->clear();
191
-	}
192
-
193
-	/**
194
-	 * setup encryption backend upon user created
195
-	 *
196
-	 * @note This method should never be called for users using client side encryption
197
-	 * @param array $params
198
-	 */
199
-	public function postCreateUser($params) {
200
-		$this->userSetup->setupUser($params['uid'], $params['password']);
201
-	}
202
-
203
-	/**
204
-	 * cleanup encryption backend upon user deleted
205
-	 *
206
-	 * @param array $params : uid, password
207
-	 * @note This method should never be called for users using client side encryption
208
-	 */
209
-	public function postDeleteUser($params) {
210
-		$this->keyManager->deletePublicKey($params['uid']);
211
-	}
212
-
213
-	public function prePasswordReset($params) {
214
-		$user = $params['uid'];
215
-		self::$passwordResetUsers[$user] = true;
216
-	}
217
-
218
-	public function postPasswordReset($params) {
219
-		$uid = $params['uid'];
220
-		$password = $params['password'];
221
-		$this->keyManager->backupUserKeys('passwordReset', $uid);
222
-		$this->keyManager->deleteUserKeys($uid);
223
-		$this->userSetup->setupUser($uid, $password);
224
-		unset(self::$passwordResetUsers[$uid]);
225
-	}
226
-
227
-	/**
228
-	 * If the password can't be changed within Nextcloud, than update the key password in advance.
229
-	 *
230
-	 * @param array $params : uid, password
231
-	 * @return boolean|null
232
-	 */
233
-	public function preSetPassphrase($params) {
234
-		$user = $this->userManager->get($params['uid']);
235
-
236
-		if ($user && !$user->canChangePassword()) {
237
-			$this->setPassphrase($params);
238
-		}
239
-	}
240
-
241
-	/**
242
-	 * Change a user's encryption passphrase
243
-	 *
244
-	 * @param array $params keys: uid, password
245
-	 * @return boolean|null
246
-	 */
247
-	public function setPassphrase($params) {
248
-
249
-		// if we are in the process to resetting a user password, we have nothing
250
-		// to do here
251
-		if (isset(self::$passwordResetUsers[$params['uid']])) {
252
-			return true;
253
-		}
254
-
255
-		// Get existing decrypted private key
256
-		$user = $this->userSession->getUser();
257
-
258
-		// current logged in user changes his own password
259
-		if ($user && $params['uid'] === $user->getUID()) {
260
-			$privateKey = $this->session->getPrivateKey();
261
-
262
-			// Encrypt private key with new user pwd as passphrase
263
-			$encryptedPrivateKey = $this->crypt->encryptPrivateKey($privateKey, $params['password'], $params['uid']);
264
-
265
-			// Save private key
266
-			if ($encryptedPrivateKey) {
267
-				$this->keyManager->setPrivateKey($user->getUID(),
268
-					$this->crypt->generateHeader() . $encryptedPrivateKey);
269
-			} else {
270
-				$this->logger->error('Encryption could not update users encryption password');
271
-			}
272
-
273
-			// NOTE: Session does not need to be updated as the
274
-			// private key has not changed, only the passphrase
275
-			// used to decrypt it has changed
276
-		} else { // admin changed the password for a different user, create new keys and re-encrypt file keys
277
-			$userId = $params['uid'];
278
-			$this->initMountPoints($userId);
279
-			$recoveryPassword = isset($params['recoveryPassword']) ? $params['recoveryPassword'] : null;
280
-
281
-			$recoveryKeyId = $this->keyManager->getRecoveryKeyId();
282
-			$recoveryKey = $this->keyManager->getSystemPrivateKey($recoveryKeyId);
283
-			try {
284
-				$decryptedRecoveryKey = $this->crypt->decryptPrivateKey($recoveryKey, $recoveryPassword);
285
-			} catch (\Exception $e) {
286
-				$decryptedRecoveryKey = false;
287
-			}
288
-			if ($decryptedRecoveryKey === false) {
289
-				$message = 'Can not decrypt the recovery key. Maybe you provided the wrong password. Try again.';
290
-				throw new GenericEncryptionException($message, $message);
291
-			}
292
-
293
-			// we generate new keys if...
294
-			// ...we have a recovery password and the user enabled the recovery key
295
-			// ...encryption was activated for the first time (no keys exists)
296
-			// ...the user doesn't have any files
297
-			if (
298
-				($this->recovery->isRecoveryEnabledForUser($userId) && $recoveryPassword)
299
-				|| !$this->keyManager->userHasKeys($userId)
300
-				|| !$this->util->userHasFiles($userId)
301
-			) {
302
-
303
-				// backup old keys
304
-				//$this->backupAllKeys('recovery');
305
-
306
-				$newUserPassword = $params['password'];
307
-
308
-				$keyPair = $this->crypt->createKeyPair();
309
-
310
-				// Save public key
311
-				$this->keyManager->setPublicKey($userId, $keyPair['publicKey']);
312
-
313
-				// Encrypt private key with new password
314
-				$encryptedKey = $this->crypt->encryptPrivateKey($keyPair['privateKey'], $newUserPassword, $userId);
315
-
316
-				if ($encryptedKey) {
317
-					$this->keyManager->setPrivateKey($userId, $this->crypt->generateHeader() . $encryptedKey);
318
-
319
-					if ($recoveryPassword) { // if recovery key is set we can re-encrypt the key files
320
-						$this->recovery->recoverUsersFiles($recoveryPassword, $userId);
321
-					}
322
-				} else {
323
-					$this->logger->error('Encryption Could not update users encryption password');
324
-				}
325
-			}
326
-		}
327
-	}
328
-
329
-	/**
330
-	 * init mount points for given user
331
-	 *
332
-	 * @param string $user
333
-	 * @throws \OC\User\NoUserException
334
-	 */
335
-	protected function initMountPoints($user) {
336
-		Filesystem::initMountPoints($user);
337
-	}
338
-
339
-	/**
340
-	 * setup file system for user
341
-	 *
342
-	 * @param string $uid user id
343
-	 */
344
-	protected function setupFS($uid) {
345
-		\OC_Util::setupFS($uid);
346
-	}
47
+    /**
48
+     * list of user for which we perform a password reset
49
+     * @var array
50
+     */
51
+    protected static $passwordResetUsers = [];
52
+
53
+    /**
54
+     * @var KeyManager
55
+     */
56
+    private $keyManager;
57
+    /**
58
+     * @var IUserManager
59
+     */
60
+    private $userManager;
61
+    /**
62
+     * @var ILogger
63
+     */
64
+    private $logger;
65
+    /**
66
+     * @var Setup
67
+     */
68
+    private $userSetup;
69
+    /**
70
+     * @var IUserSession
71
+     */
72
+    private $userSession;
73
+    /**
74
+     * @var Util
75
+     */
76
+    private $util;
77
+    /**
78
+     * @var Session
79
+     */
80
+    private $session;
81
+    /**
82
+     * @var Recovery
83
+     */
84
+    private $recovery;
85
+    /**
86
+     * @var Crypt
87
+     */
88
+    private $crypt;
89
+
90
+    /**
91
+     * UserHooks constructor.
92
+     *
93
+     * @param KeyManager $keyManager
94
+     * @param IUserManager $userManager
95
+     * @param ILogger $logger
96
+     * @param Setup $userSetup
97
+     * @param IUserSession $userSession
98
+     * @param Util $util
99
+     * @param Session $session
100
+     * @param Crypt $crypt
101
+     * @param Recovery $recovery
102
+     */
103
+    public function __construct(KeyManager $keyManager,
104
+                                IUserManager $userManager,
105
+                                ILogger $logger,
106
+                                Setup $userSetup,
107
+                                IUserSession $userSession,
108
+                                Util $util,
109
+                                Session $session,
110
+                                Crypt $crypt,
111
+                                Recovery $recovery) {
112
+        $this->keyManager = $keyManager;
113
+        $this->userManager = $userManager;
114
+        $this->logger = $logger;
115
+        $this->userSetup = $userSetup;
116
+        $this->userSession = $userSession;
117
+        $this->util = $util;
118
+        $this->session = $session;
119
+        $this->recovery = $recovery;
120
+        $this->crypt = $crypt;
121
+    }
122
+
123
+    /**
124
+     * Connects Hooks
125
+     *
126
+     * @return null
127
+     */
128
+    public function addHooks() {
129
+        OCUtil::connectHook('OC_User', 'post_login', $this, 'login');
130
+        OCUtil::connectHook('OC_User', 'logout', $this, 'logout');
131
+
132
+        // this hooks only make sense if no master key is used
133
+        if ($this->util->isMasterKeyEnabled() === false) {
134
+            OCUtil::connectHook('OC_User',
135
+                'post_setPassword',
136
+                $this,
137
+                'setPassphrase');
138
+
139
+            OCUtil::connectHook('OC_User',
140
+                'pre_setPassword',
141
+                $this,
142
+                'preSetPassphrase');
143
+
144
+            OCUtil::connectHook('\OC\Core\LostPassword\Controller\LostController',
145
+                'post_passwordReset',
146
+                $this,
147
+                'postPasswordReset');
148
+
149
+            OCUtil::connectHook('\OC\Core\LostPassword\Controller\LostController',
150
+                'pre_passwordReset',
151
+                $this,
152
+                'prePasswordReset');
153
+
154
+            OCUtil::connectHook('OC_User',
155
+                'post_createUser',
156
+                $this,
157
+                'postCreateUser');
158
+
159
+            OCUtil::connectHook('OC_User',
160
+                'post_deleteUser',
161
+                $this,
162
+                'postDeleteUser');
163
+        }
164
+    }
165
+
166
+
167
+    /**
168
+     * Startup encryption backend upon user login
169
+     *
170
+     * @note This method should never be called for users using client side encryption
171
+     * @param array $params
172
+     * @return boolean|null
173
+     */
174
+    public function login($params) {
175
+        // ensure filesystem is loaded
176
+        if (!\OC\Files\Filesystem::$loaded) {
177
+            $this->setupFS($params['uid']);
178
+        }
179
+        if ($this->util->isMasterKeyEnabled() === false) {
180
+            $this->userSetup->setupUser($params['uid'], $params['password']);
181
+        }
182
+
183
+        $this->keyManager->init($params['uid'], $params['password']);
184
+    }
185
+
186
+    /**
187
+     * remove keys from session during logout
188
+     */
189
+    public function logout() {
190
+        $this->session->clear();
191
+    }
192
+
193
+    /**
194
+     * setup encryption backend upon user created
195
+     *
196
+     * @note This method should never be called for users using client side encryption
197
+     * @param array $params
198
+     */
199
+    public function postCreateUser($params) {
200
+        $this->userSetup->setupUser($params['uid'], $params['password']);
201
+    }
202
+
203
+    /**
204
+     * cleanup encryption backend upon user deleted
205
+     *
206
+     * @param array $params : uid, password
207
+     * @note This method should never be called for users using client side encryption
208
+     */
209
+    public function postDeleteUser($params) {
210
+        $this->keyManager->deletePublicKey($params['uid']);
211
+    }
212
+
213
+    public function prePasswordReset($params) {
214
+        $user = $params['uid'];
215
+        self::$passwordResetUsers[$user] = true;
216
+    }
217
+
218
+    public function postPasswordReset($params) {
219
+        $uid = $params['uid'];
220
+        $password = $params['password'];
221
+        $this->keyManager->backupUserKeys('passwordReset', $uid);
222
+        $this->keyManager->deleteUserKeys($uid);
223
+        $this->userSetup->setupUser($uid, $password);
224
+        unset(self::$passwordResetUsers[$uid]);
225
+    }
226
+
227
+    /**
228
+     * If the password can't be changed within Nextcloud, than update the key password in advance.
229
+     *
230
+     * @param array $params : uid, password
231
+     * @return boolean|null
232
+     */
233
+    public function preSetPassphrase($params) {
234
+        $user = $this->userManager->get($params['uid']);
235
+
236
+        if ($user && !$user->canChangePassword()) {
237
+            $this->setPassphrase($params);
238
+        }
239
+    }
240
+
241
+    /**
242
+     * Change a user's encryption passphrase
243
+     *
244
+     * @param array $params keys: uid, password
245
+     * @return boolean|null
246
+     */
247
+    public function setPassphrase($params) {
248
+
249
+        // if we are in the process to resetting a user password, we have nothing
250
+        // to do here
251
+        if (isset(self::$passwordResetUsers[$params['uid']])) {
252
+            return true;
253
+        }
254
+
255
+        // Get existing decrypted private key
256
+        $user = $this->userSession->getUser();
257
+
258
+        // current logged in user changes his own password
259
+        if ($user && $params['uid'] === $user->getUID()) {
260
+            $privateKey = $this->session->getPrivateKey();
261
+
262
+            // Encrypt private key with new user pwd as passphrase
263
+            $encryptedPrivateKey = $this->crypt->encryptPrivateKey($privateKey, $params['password'], $params['uid']);
264
+
265
+            // Save private key
266
+            if ($encryptedPrivateKey) {
267
+                $this->keyManager->setPrivateKey($user->getUID(),
268
+                    $this->crypt->generateHeader() . $encryptedPrivateKey);
269
+            } else {
270
+                $this->logger->error('Encryption could not update users encryption password');
271
+            }
272
+
273
+            // NOTE: Session does not need to be updated as the
274
+            // private key has not changed, only the passphrase
275
+            // used to decrypt it has changed
276
+        } else { // admin changed the password for a different user, create new keys and re-encrypt file keys
277
+            $userId = $params['uid'];
278
+            $this->initMountPoints($userId);
279
+            $recoveryPassword = isset($params['recoveryPassword']) ? $params['recoveryPassword'] : null;
280
+
281
+            $recoveryKeyId = $this->keyManager->getRecoveryKeyId();
282
+            $recoveryKey = $this->keyManager->getSystemPrivateKey($recoveryKeyId);
283
+            try {
284
+                $decryptedRecoveryKey = $this->crypt->decryptPrivateKey($recoveryKey, $recoveryPassword);
285
+            } catch (\Exception $e) {
286
+                $decryptedRecoveryKey = false;
287
+            }
288
+            if ($decryptedRecoveryKey === false) {
289
+                $message = 'Can not decrypt the recovery key. Maybe you provided the wrong password. Try again.';
290
+                throw new GenericEncryptionException($message, $message);
291
+            }
292
+
293
+            // we generate new keys if...
294
+            // ...we have a recovery password and the user enabled the recovery key
295
+            // ...encryption was activated for the first time (no keys exists)
296
+            // ...the user doesn't have any files
297
+            if (
298
+                ($this->recovery->isRecoveryEnabledForUser($userId) && $recoveryPassword)
299
+                || !$this->keyManager->userHasKeys($userId)
300
+                || !$this->util->userHasFiles($userId)
301
+            ) {
302
+
303
+                // backup old keys
304
+                //$this->backupAllKeys('recovery');
305
+
306
+                $newUserPassword = $params['password'];
307
+
308
+                $keyPair = $this->crypt->createKeyPair();
309
+
310
+                // Save public key
311
+                $this->keyManager->setPublicKey($userId, $keyPair['publicKey']);
312
+
313
+                // Encrypt private key with new password
314
+                $encryptedKey = $this->crypt->encryptPrivateKey($keyPair['privateKey'], $newUserPassword, $userId);
315
+
316
+                if ($encryptedKey) {
317
+                    $this->keyManager->setPrivateKey($userId, $this->crypt->generateHeader() . $encryptedKey);
318
+
319
+                    if ($recoveryPassword) { // if recovery key is set we can re-encrypt the key files
320
+                        $this->recovery->recoverUsersFiles($recoveryPassword, $userId);
321
+                    }
322
+                } else {
323
+                    $this->logger->error('Encryption Could not update users encryption password');
324
+                }
325
+            }
326
+        }
327
+    }
328
+
329
+    /**
330
+     * init mount points for given user
331
+     *
332
+     * @param string $user
333
+     * @throws \OC\User\NoUserException
334
+     */
335
+    protected function initMountPoints($user) {
336
+        Filesystem::initMountPoints($user);
337
+    }
338
+
339
+    /**
340
+     * setup file system for user
341
+     *
342
+     * @param string $uid user id
343
+     */
344
+    protected function setupFS($uid) {
345
+        \OC_Util::setupFS($uid);
346
+    }
347 347
 }
Please login to merge, or discard this patch.
apps/settings/lib/Controller/LogSettingsController.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -35,28 +35,28 @@
 block discarded – undo
35 35
 
36 36
 class LogSettingsController extends Controller {
37 37
 
38
-	/** @var Log */
39
-	private $log;
38
+    /** @var Log */
39
+    private $log;
40 40
 
41
-	public function __construct(string $appName, IRequest $request, Log $logger) {
42
-		parent::__construct($appName, $request);
43
-		$this->log = $logger;
44
-	}
41
+    public function __construct(string $appName, IRequest $request, Log $logger) {
42
+        parent::__construct($appName, $request);
43
+        $this->log = $logger;
44
+    }
45 45
 
46
-	/**
47
-	 * download logfile
48
-	 *
49
-	 * @NoCSRFRequired
50
-	 *
51
-	 * @return StreamResponse
52
-	 */
53
-	public function download() {
54
-		if (!$this->log instanceof Log) {
55
-			throw new \UnexpectedValueException('Log file not available');
56
-		}
57
-		$resp = new StreamResponse($this->log->getLogPath());
58
-		$resp->addHeader('Content-Type', 'application/octet-stream');
59
-		$resp->addHeader('Content-Disposition', 'attachment; filename="nextcloud.log"');
60
-		return $resp;
61
-	}
46
+    /**
47
+     * download logfile
48
+     *
49
+     * @NoCSRFRequired
50
+     *
51
+     * @return StreamResponse
52
+     */
53
+    public function download() {
54
+        if (!$this->log instanceof Log) {
55
+            throw new \UnexpectedValueException('Log file not available');
56
+        }
57
+        $resp = new StreamResponse($this->log->getLogPath());
58
+        $resp->addHeader('Content-Type', 'application/octet-stream');
59
+        $resp->addHeader('Content-Disposition', 'attachment; filename="nextcloud.log"');
60
+        return $resp;
61
+    }
62 62
 }
Please login to merge, or discard this patch.
apps/settings/templates/settings/admin/overview.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -46,9 +46,9 @@
 block discarded – undo
46 46
 	</div>
47 47
 
48 48
 	<div id="postsetupchecks" data-check-wellknown="<?php if ($_['checkForWorkingWellKnownSetup']) {
49
-	p('true');
49
+    p('true');
50 50
 } else {
51
-	p('false');
51
+    p('false');
52 52
 } ?>">
53 53
 		<ul class="errors hidden"></ul>
54 54
 		<ul class="warnings hidden"></ul>
Please login to merge, or discard this patch.