Completed
Pull Request — master (#9635)
by Robin
45:49 queued 23:51
created
apps/files_external/lib/AppInfo/Application.php 1 patch
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -66,89 +66,89 @@
 block discarded – undo
66 66
  */
67 67
 class Application extends App implements IBackendProvider, IAuthMechanismProvider {
68 68
 
69
-	public function __construct(array $urlParams = array()) {
70
-		parent::__construct('files_external', $urlParams);
71
-
72
-		$container = $this->getContainer();
73
-
74
-		$container->registerService(IUserMountCache::class, function (IAppContainer $c) {
75
-			return $c->getServer()->query('UserMountCache');
76
-		});
77
-
78
-		$backendService = $container->query(BackendService::class);
79
-		$backendService->registerBackendProvider($this);
80
-		$backendService->registerAuthMechanismProvider($this);
81
-
82
-		// force-load auth mechanisms since some will register hooks
83
-		// TODO: obsolete these and use the TokenProvider to get the user's password from the session
84
-		$this->getAuthMechanisms();
85
-
86
-		// app developers: do NOT depend on this! it will disappear with oC 9.0!
87
-		\OC::$server->getEventDispatcher()->dispatch(
88
-			'OCA\\Files_External::loadAdditionalBackends'
89
-		);
90
-	}
91
-
92
-	/**
93
-	 * @{inheritdoc}
94
-	 */
95
-	public function getBackends() {
96
-		$container = $this->getContainer();
97
-
98
-		$backends = [
99
-			$container->query(Local::class),
100
-			$container->query(FTP::class),
101
-			$container->query(DAV::class),
102
-			$container->query(OwnCloud::class),
103
-			$container->query(SFTP::class),
104
-			$container->query(AmazonS3::class),
105
-			$container->query(Swift::class),
106
-			$container->query(SFTP_Key::class),
107
-			$container->query(SMB::class),
108
-			$container->query(SMB_OC::class),
109
-		];
110
-
111
-		return $backends;
112
-	}
113
-
114
-	/**
115
-	 * @{inheritdoc}
116
-	 */
117
-	public function getAuthMechanisms() {
118
-		$container = $this->getContainer();
119
-
120
-		return [
121
-			// AuthMechanism::SCHEME_NULL mechanism
122
-			$container->query(NullMechanism::class),
123
-
124
-			// AuthMechanism::SCHEME_BUILTIN mechanism
125
-			$container->query(Builtin::class),
126
-
127
-			// AuthMechanism::SCHEME_PASSWORD mechanisms
128
-			$container->query(Password::class),
129
-			$container->query(SessionCredentials::class),
130
-			$container->query(LoginCredentials::class),
131
-			$container->query(UserProvided::class),
132
-			$container->query(GlobalAuth::class),
133
-
134
-			// AuthMechanism::SCHEME_OAUTH1 mechanisms
135
-			$container->query(OAuth1::class),
136
-
137
-			// AuthMechanism::SCHEME_OAUTH2 mechanisms
138
-			$container->query(OAuth2::class),
139
-
140
-			// AuthMechanism::SCHEME_PUBLICKEY mechanisms
141
-			$container->query(RSA::class),
142
-
143
-			// AuthMechanism::SCHEME_OPENSTACK mechanisms
144
-			$container->query(OpenStackV2::class),
145
-			$container->query(OpenStackV3::class),
146
-			$container->query(Rackspace::class),
147
-
148
-			// Specialized mechanisms
149
-			$container->query(AccessKey::class),
150
-			$container->query(KerberosAuth::class),
151
-		];
152
-	}
69
+    public function __construct(array $urlParams = array()) {
70
+        parent::__construct('files_external', $urlParams);
71
+
72
+        $container = $this->getContainer();
73
+
74
+        $container->registerService(IUserMountCache::class, function (IAppContainer $c) {
75
+            return $c->getServer()->query('UserMountCache');
76
+        });
77
+
78
+        $backendService = $container->query(BackendService::class);
79
+        $backendService->registerBackendProvider($this);
80
+        $backendService->registerAuthMechanismProvider($this);
81
+
82
+        // force-load auth mechanisms since some will register hooks
83
+        // TODO: obsolete these and use the TokenProvider to get the user's password from the session
84
+        $this->getAuthMechanisms();
85
+
86
+        // app developers: do NOT depend on this! it will disappear with oC 9.0!
87
+        \OC::$server->getEventDispatcher()->dispatch(
88
+            'OCA\\Files_External::loadAdditionalBackends'
89
+        );
90
+    }
91
+
92
+    /**
93
+     * @{inheritdoc}
94
+     */
95
+    public function getBackends() {
96
+        $container = $this->getContainer();
97
+
98
+        $backends = [
99
+            $container->query(Local::class),
100
+            $container->query(FTP::class),
101
+            $container->query(DAV::class),
102
+            $container->query(OwnCloud::class),
103
+            $container->query(SFTP::class),
104
+            $container->query(AmazonS3::class),
105
+            $container->query(Swift::class),
106
+            $container->query(SFTP_Key::class),
107
+            $container->query(SMB::class),
108
+            $container->query(SMB_OC::class),
109
+        ];
110
+
111
+        return $backends;
112
+    }
113
+
114
+    /**
115
+     * @{inheritdoc}
116
+     */
117
+    public function getAuthMechanisms() {
118
+        $container = $this->getContainer();
119
+
120
+        return [
121
+            // AuthMechanism::SCHEME_NULL mechanism
122
+            $container->query(NullMechanism::class),
123
+
124
+            // AuthMechanism::SCHEME_BUILTIN mechanism
125
+            $container->query(Builtin::class),
126
+
127
+            // AuthMechanism::SCHEME_PASSWORD mechanisms
128
+            $container->query(Password::class),
129
+            $container->query(SessionCredentials::class),
130
+            $container->query(LoginCredentials::class),
131
+            $container->query(UserProvided::class),
132
+            $container->query(GlobalAuth::class),
133
+
134
+            // AuthMechanism::SCHEME_OAUTH1 mechanisms
135
+            $container->query(OAuth1::class),
136
+
137
+            // AuthMechanism::SCHEME_OAUTH2 mechanisms
138
+            $container->query(OAuth2::class),
139
+
140
+            // AuthMechanism::SCHEME_PUBLICKEY mechanisms
141
+            $container->query(RSA::class),
142
+
143
+            // AuthMechanism::SCHEME_OPENSTACK mechanisms
144
+            $container->query(OpenStackV2::class),
145
+            $container->query(OpenStackV3::class),
146
+            $container->query(Rackspace::class),
147
+
148
+            // Specialized mechanisms
149
+            $container->query(AccessKey::class),
150
+            $container->query(KerberosAuth::class),
151
+        ];
152
+    }
153 153
 
154 154
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Backend/SMB.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -35,50 +35,50 @@
 block discarded – undo
35 35
 
36 36
 class SMB extends Backend {
37 37
 
38
-	use LegacyDependencyCheckPolyfill;
38
+    use LegacyDependencyCheckPolyfill;
39 39
 
40
-	public function __construct(IL10N $l, Password $legacyAuth) {
41
-		$this
42
-			->setIdentifier('smb')
43
-			->addIdentifierAlias('\OC\Files\Storage\SMB')// legacy compat
44
-			->setStorageClass('\OCA\Files_External\Lib\Storage\SMB')
45
-			->setText($l->t('SMB / CIFS'))
46
-			->addParameters([
47
-				new DefinitionParameter('host', $l->t('Host')),
48
-				new DefinitionParameter('share', $l->t('Share')),
49
-				(new DefinitionParameter('root', $l->t('Remote subfolder')))
50
-					->setFlag(DefinitionParameter::FLAG_OPTIONAL),
51
-				(new DefinitionParameter('domain', $l->t('Domain')))
52
-					->setFlag(DefinitionParameter::FLAG_OPTIONAL),
53
-			])
54
-			->addAuthScheme(AuthMechanism::SCHEME_PASSWORD)
55
-			->addAuthScheme(AuthMechanism::SCHEME_SMB)
56
-			->setLegacyAuthMechanism($legacyAuth);
57
-	}
40
+    public function __construct(IL10N $l, Password $legacyAuth) {
41
+        $this
42
+            ->setIdentifier('smb')
43
+            ->addIdentifierAlias('\OC\Files\Storage\SMB')// legacy compat
44
+            ->setStorageClass('\OCA\Files_External\Lib\Storage\SMB')
45
+            ->setText($l->t('SMB / CIFS'))
46
+            ->addParameters([
47
+                new DefinitionParameter('host', $l->t('Host')),
48
+                new DefinitionParameter('share', $l->t('Share')),
49
+                (new DefinitionParameter('root', $l->t('Remote subfolder')))
50
+                    ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
51
+                (new DefinitionParameter('domain', $l->t('Domain')))
52
+                    ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
53
+            ])
54
+            ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD)
55
+            ->addAuthScheme(AuthMechanism::SCHEME_SMB)
56
+            ->setLegacyAuthMechanism($legacyAuth);
57
+    }
58 58
 
59
-	/**
60
-	 * @param StorageConfig $storage
61
-	 * @param IUser $user
62
-	 */
63
-	public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
64
-		$auth = $storage->getAuthMechanism();
65
-		if ($auth->getScheme() === AuthMechanism::SCHEME_PASSWORD) {
66
-			$smbAuth = new BasicAuth(
67
-				$storage->getBackendOption('user'),
68
-				$storage->getBackendOption('domain'),
69
-				$storage->getBackendOption('password')
70
-			);
71
-		} else {
72
-			switch ($auth->getIdentifier()) {
73
-				case 'smb::kerberos':
74
-					$smbAuth = new KerberosAuth();
75
-					break;
76
-				default:
77
-					throw new \InvalidArgumentException('unknown authentication backend');
78
-			}
79
-		}
59
+    /**
60
+     * @param StorageConfig $storage
61
+     * @param IUser $user
62
+     */
63
+    public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
64
+        $auth = $storage->getAuthMechanism();
65
+        if ($auth->getScheme() === AuthMechanism::SCHEME_PASSWORD) {
66
+            $smbAuth = new BasicAuth(
67
+                $storage->getBackendOption('user'),
68
+                $storage->getBackendOption('domain'),
69
+                $storage->getBackendOption('password')
70
+            );
71
+        } else {
72
+            switch ($auth->getIdentifier()) {
73
+                case 'smb::kerberos':
74
+                    $smbAuth = new KerberosAuth();
75
+                    break;
76
+                default:
77
+                    throw new \InvalidArgumentException('unknown authentication backend');
78
+            }
79
+        }
80 80
 
81
-		$storage->setBackendOption('auth', $smbAuth);
82
-	}
81
+        $storage->setBackendOption('auth', $smbAuth);
82
+    }
83 83
 
84 84
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Storage/SMB.php 2 patches
Indentation   +486 added lines, -486 removed lines patch added patch discarded remove patch
@@ -57,490 +57,490 @@
 block discarded – undo
57 57
 use OCP\ILogger;
58 58
 
59 59
 class SMB extends Common implements INotifyStorage {
60
-	/**
61
-	 * @var \Icewind\SMB\IServer
62
-	 */
63
-	protected $server;
64
-
65
-	/**
66
-	 * @var \Icewind\SMB\IShare
67
-	 */
68
-	protected $share;
69
-
70
-	/**
71
-	 * @var string
72
-	 */
73
-	protected $root;
74
-
75
-	/**
76
-	 * @var \Icewind\SMB\IFileInfo[]
77
-	 */
78
-	protected $statCache;
79
-
80
-	public function __construct($params) {
81
-		if (!isset($params['host'])) {
82
-			throw new \Exception('Invalid configuration, no host provided');
83
-		}
84
-
85
-		if (isset($params['auth'])) {
86
-			$auth = $params['auth'];
87
-		} else if (isset($params['user']) && isset($params['password']) && isset($params['share'])) {
88
-			$auth = new BasicAuth($params['user'], '', $params['password']);
89
-		} else {
90
-			throw new \Exception('Invalid configuration, no credentials provided');
91
-		}
92
-
93
-		$serverFactory = new ServerFactory();
94
-		$this->server = $serverFactory->createServer($params['host'], $auth);
95
-		$this->share = $this->server->getShare(trim($params['share'], '/'));
96
-
97
-		$this->root = $params['root'] ?? '/';
98
-		$this->root = '/' . ltrim($this->root, '/');
99
-		$this->root = rtrim($this->root, '/') . '/';
100
-
101
-		$this->statCache = new CappedMemoryCache();
102
-		parent::__construct($params);
103
-	}
104
-
105
-	/**
106
-	 * @return string
107
-	 */
108
-	public function getId() {
109
-		// FIXME: double slash to keep compatible with the old storage ids,
110
-		// failure to do so will lead to creation of a new storage id and
111
-		// loss of shares from the storage
112
-		return 'smb::' . $this->server->getAuth()->getUsername() . '@' . $this->server->getHost() . '//' . $this->share->getName() . '/' . $this->root;
113
-	}
114
-
115
-	/**
116
-	 * @param string $path
117
-	 * @return string
118
-	 */
119
-	protected function buildPath($path) {
120
-		return Filesystem::normalizePath($this->root . '/' . $path, true, false, true);
121
-	}
122
-
123
-	protected function relativePath($fullPath) {
124
-		if ($fullPath === $this->root) {
125
-			return '';
126
-		} else if (substr($fullPath, 0, strlen($this->root)) === $this->root) {
127
-			return substr($fullPath, strlen($this->root));
128
-		} else {
129
-			return null;
130
-		}
131
-	}
132
-
133
-	/**
134
-	 * @param string $path
135
-	 * @return \Icewind\SMB\IFileInfo
136
-	 * @throws StorageNotAvailableException
137
-	 */
138
-	protected function getFileInfo($path) {
139
-		try {
140
-			$path = $this->buildPath($path);
141
-			if (!isset($this->statCache[$path])) {
142
-				$this->statCache[$path] = $this->share->stat($path);
143
-			}
144
-			return $this->statCache[$path];
145
-		} catch (ConnectException $e) {
146
-			throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
147
-		}
148
-	}
149
-
150
-	/**
151
-	 * @param string $path
152
-	 * @return \Icewind\SMB\IFileInfo[]
153
-	 * @throws StorageNotAvailableException
154
-	 */
155
-	protected function getFolderContents($path) {
156
-		try {
157
-			$path = $this->buildPath($path);
158
-			$files = $this->share->dir($path);
159
-			foreach ($files as $file) {
160
-				$this->statCache[$path . '/' . $file->getName()] = $file;
161
-			}
162
-			return array_filter($files, function (IFileInfo $file) {
163
-				try {
164
-					return !$file->isHidden();
165
-				} catch (ForbiddenException $e) {
166
-					return false;
167
-				} catch (NotFoundException $e) {
168
-					return false;
169
-				}
170
-			});
171
-		} catch (ConnectException $e) {
172
-			throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
173
-		}
174
-	}
175
-
176
-	/**
177
-	 * @param \Icewind\SMB\IFileInfo $info
178
-	 * @return array
179
-	 */
180
-	protected function formatInfo($info) {
181
-		$result = [
182
-			'size' => $info->getSize(),
183
-			'mtime' => $info->getMTime(),
184
-		];
185
-		if ($info->isDirectory()) {
186
-			$result['type'] = 'dir';
187
-		} else {
188
-			$result['type'] = 'file';
189
-		}
190
-		return $result;
191
-	}
192
-
193
-	/**
194
-	 * Rename the files. If the source or the target is the root, the rename won't happen.
195
-	 *
196
-	 * @param string $source the old name of the path
197
-	 * @param string $target the new name of the path
198
-	 * @return bool true if the rename is successful, false otherwise
199
-	 */
200
-	public function rename($source, $target) {
201
-		if ($this->isRootDir($source) || $this->isRootDir($target)) {
202
-			return false;
203
-		}
204
-
205
-		$absoluteSource = $this->buildPath($source);
206
-		$absoluteTarget = $this->buildPath($target);
207
-		try {
208
-			$result = $this->share->rename($absoluteSource, $absoluteTarget);
209
-		} catch (AlreadyExistsException $e) {
210
-			$this->remove($target);
211
-			$result = $this->share->rename($absoluteSource, $absoluteTarget);
212
-		} catch (\Exception $e) {
213
-			\OC::$server->getLogger()->logException($e, ['level' => ILogger::WARN]);
214
-			return false;
215
-		}
216
-		unset($this->statCache[$absoluteSource], $this->statCache[$absoluteTarget]);
217
-		return $result;
218
-	}
219
-
220
-	public function stat($path) {
221
-		try {
222
-			$result = $this->formatInfo($this->getFileInfo($path));
223
-		} catch (ForbiddenException $e) {
224
-			return false;
225
-		} catch (NotFoundException $e) {
226
-			return false;
227
-		}
228
-		if ($this->remoteIsShare() && $this->isRootDir($path)) {
229
-			$result['mtime'] = $this->shareMTime();
230
-		}
231
-		return $result;
232
-	}
233
-
234
-	/**
235
-	 * get the best guess for the modification time of the share
236
-	 *
237
-	 * @return int
238
-	 */
239
-	private function shareMTime() {
240
-		$highestMTime = 0;
241
-		$files = $this->share->dir($this->root);
242
-		foreach ($files as $fileInfo) {
243
-			try {
244
-				if ($fileInfo->getMTime() > $highestMTime) {
245
-					$highestMTime = $fileInfo->getMTime();
246
-				}
247
-			} catch (NotFoundException $e) {
248
-				// Ignore this, can happen on unavailable DFS shares
249
-			}
250
-		}
251
-		return $highestMTime;
252
-	}
253
-
254
-	/**
255
-	 * Check if the path is our root dir (not the smb one)
256
-	 *
257
-	 * @param string $path the path
258
-	 * @return bool
259
-	 */
260
-	private function isRootDir($path) {
261
-		return $path === '' || $path === '/' || $path === '.';
262
-	}
263
-
264
-	/**
265
-	 * Check if our root points to a smb share
266
-	 *
267
-	 * @return bool true if our root points to a share false otherwise
268
-	 */
269
-	private function remoteIsShare() {
270
-		return $this->share->getName() && (!$this->root || $this->root === '/');
271
-	}
272
-
273
-	/**
274
-	 * @param string $path
275
-	 * @return bool
276
-	 */
277
-	public function unlink($path) {
278
-		if ($this->isRootDir($path)) {
279
-			return false;
280
-		}
281
-
282
-		try {
283
-			if ($this->is_dir($path)) {
284
-				return $this->rmdir($path);
285
-			} else {
286
-				$path = $this->buildPath($path);
287
-				unset($this->statCache[$path]);
288
-				$this->share->del($path);
289
-				return true;
290
-			}
291
-		} catch (NotFoundException $e) {
292
-			return false;
293
-		} catch (ForbiddenException $e) {
294
-			return false;
295
-		} catch (ConnectException $e) {
296
-			throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
297
-		}
298
-	}
299
-
300
-	/**
301
-	 * check if a file or folder has been updated since $time
302
-	 *
303
-	 * @param string $path
304
-	 * @param int $time
305
-	 * @return bool
306
-	 */
307
-	public function hasUpdated($path, $time) {
308
-		if (!$path and $this->root === '/') {
309
-			// mtime doesn't work for shares, but giving the nature of the backend,
310
-			// doing a full update is still just fast enough
311
-			return true;
312
-		} else {
313
-			$actualTime = $this->filemtime($path);
314
-			return $actualTime > $time;
315
-		}
316
-	}
317
-
318
-	/**
319
-	 * @param string $path
320
-	 * @param string $mode
321
-	 * @return resource|false
322
-	 */
323
-	public function fopen($path, $mode) {
324
-		$fullPath = $this->buildPath($path);
325
-		try {
326
-			switch ($mode) {
327
-				case 'r':
328
-				case 'rb':
329
-					if (!$this->file_exists($path)) {
330
-						return false;
331
-					}
332
-					return $this->share->read($fullPath);
333
-				case 'w':
334
-				case 'wb':
335
-					$source = $this->share->write($fullPath);
336
-					return CallBackWrapper::wrap($source, null, null, function () use ($fullPath) {
337
-						unset($this->statCache[$fullPath]);
338
-					});
339
-				case 'a':
340
-				case 'ab':
341
-				case 'r+':
342
-				case 'w+':
343
-				case 'wb+':
344
-				case 'a+':
345
-				case 'x':
346
-				case 'x+':
347
-				case 'c':
348
-				case 'c+':
349
-					//emulate these
350
-					if (strrpos($path, '.') !== false) {
351
-						$ext = substr($path, strrpos($path, '.'));
352
-					} else {
353
-						$ext = '';
354
-					}
355
-					if ($this->file_exists($path)) {
356
-						if (!$this->isUpdatable($path)) {
357
-							return false;
358
-						}
359
-						$tmpFile = $this->getCachedFile($path);
360
-					} else {
361
-						if (!$this->isCreatable(dirname($path))) {
362
-							return false;
363
-						}
364
-						$tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
365
-					}
366
-					$source = fopen($tmpFile, $mode);
367
-					$share = $this->share;
368
-					return CallbackWrapper::wrap($source, null, null, function () use ($tmpFile, $fullPath, $share) {
369
-						unset($this->statCache[$fullPath]);
370
-						$share->put($tmpFile, $fullPath);
371
-						unlink($tmpFile);
372
-					});
373
-			}
374
-			return false;
375
-		} catch (NotFoundException $e) {
376
-			return false;
377
-		} catch (ForbiddenException $e) {
378
-			return false;
379
-		} catch (ConnectException $e) {
380
-			throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
381
-		}
382
-	}
383
-
384
-	public function rmdir($path) {
385
-		if ($this->isRootDir($path)) {
386
-			return false;
387
-		}
388
-
389
-		try {
390
-			$this->statCache = array();
391
-			$content = $this->share->dir($this->buildPath($path));
392
-			foreach ($content as $file) {
393
-				if ($file->isDirectory()) {
394
-					$this->rmdir($path . '/' . $file->getName());
395
-				} else {
396
-					$this->share->del($file->getPath());
397
-				}
398
-			}
399
-			$this->share->rmdir($this->buildPath($path));
400
-			return true;
401
-		} catch (NotFoundException $e) {
402
-			return false;
403
-		} catch (ForbiddenException $e) {
404
-			return false;
405
-		} catch (ConnectException $e) {
406
-			throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
407
-		}
408
-	}
409
-
410
-	public function touch($path, $time = null) {
411
-		try {
412
-			if (!$this->file_exists($path)) {
413
-				$fh = $this->share->write($this->buildPath($path));
414
-				fclose($fh);
415
-				return true;
416
-			}
417
-			return false;
418
-		} catch (ConnectException $e) {
419
-			throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
420
-		}
421
-	}
422
-
423
-	public function opendir($path) {
424
-		try {
425
-			$files = $this->getFolderContents($path);
426
-		} catch (NotFoundException $e) {
427
-			return false;
428
-		} catch (ForbiddenException $e) {
429
-			return false;
430
-		}
431
-		$names = array_map(function ($info) {
432
-			/** @var \Icewind\SMB\IFileInfo $info */
433
-			return $info->getName();
434
-		}, $files);
435
-		return IteratorDirectory::wrap($names);
436
-	}
437
-
438
-	public function filetype($path) {
439
-		try {
440
-			return $this->getFileInfo($path)->isDirectory() ? 'dir' : 'file';
441
-		} catch (NotFoundException $e) {
442
-			return false;
443
-		} catch (ForbiddenException $e) {
444
-			return false;
445
-		}
446
-	}
447
-
448
-	public function mkdir($path) {
449
-		$path = $this->buildPath($path);
450
-		try {
451
-			$this->share->mkdir($path);
452
-			return true;
453
-		} catch (ConnectException $e) {
454
-			throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
455
-		} catch (Exception $e) {
456
-			return false;
457
-		}
458
-	}
459
-
460
-	public function file_exists($path) {
461
-		try {
462
-			$this->getFileInfo($path);
463
-			return true;
464
-		} catch (NotFoundException $e) {
465
-			return false;
466
-		} catch (ForbiddenException $e) {
467
-			return false;
468
-		} catch (ConnectException $e) {
469
-			throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
470
-		}
471
-	}
472
-
473
-	public function isReadable($path) {
474
-		try {
475
-			$info = $this->getFileInfo($path);
476
-			return !$info->isHidden();
477
-		} catch (NotFoundException $e) {
478
-			return false;
479
-		} catch (ForbiddenException $e) {
480
-			return false;
481
-		}
482
-	}
483
-
484
-	public function isUpdatable($path) {
485
-		try {
486
-			$info = $this->getFileInfo($path);
487
-			// following windows behaviour for read-only folders: they can be written into
488
-			// (https://support.microsoft.com/en-us/kb/326549 - "cause" section)
489
-			return !$info->isHidden() && (!$info->isReadOnly() || $this->is_dir($path));
490
-		} catch (NotFoundException $e) {
491
-			return false;
492
-		} catch (ForbiddenException $e) {
493
-			return false;
494
-		}
495
-	}
496
-
497
-	public function isDeletable($path) {
498
-		try {
499
-			$info = $this->getFileInfo($path);
500
-			return !$info->isHidden() && !$info->isReadOnly();
501
-		} catch (NotFoundException $e) {
502
-			return false;
503
-		} catch (ForbiddenException $e) {
504
-			return false;
505
-		}
506
-	}
507
-
508
-	/**
509
-	 * check if smbclient is installed
510
-	 */
511
-	public static function checkDependencies() {
512
-		return (
513
-			(bool)\OC_Helper::findBinaryPath('smbclient')
514
-			|| NativeServer::available(new System())
515
-		) ? true : ['smbclient'];
516
-	}
517
-
518
-	/**
519
-	 * Test a storage for availability
520
-	 *
521
-	 * @return bool
522
-	 */
523
-	public function test() {
524
-		try {
525
-			return parent::test();
526
-		} catch (Exception $e) {
527
-			return false;
528
-		}
529
-	}
530
-
531
-	public function listen($path, callable $callback) {
532
-		$this->notify($path)->listen(function (IChange $change) use ($callback) {
533
-			if ($change instanceof IRenameChange) {
534
-				return $callback($change->getType(), $change->getPath(), $change->getTargetPath());
535
-			} else {
536
-				return $callback($change->getType(), $change->getPath());
537
-			}
538
-		});
539
-	}
540
-
541
-	public function notify($path) {
542
-		$path = '/' . ltrim($path, '/');
543
-		$shareNotifyHandler = $this->share->notify($this->buildPath($path));
544
-		return new SMBNotifyHandler($shareNotifyHandler, $this->root);
545
-	}
60
+    /**
61
+     * @var \Icewind\SMB\IServer
62
+     */
63
+    protected $server;
64
+
65
+    /**
66
+     * @var \Icewind\SMB\IShare
67
+     */
68
+    protected $share;
69
+
70
+    /**
71
+     * @var string
72
+     */
73
+    protected $root;
74
+
75
+    /**
76
+     * @var \Icewind\SMB\IFileInfo[]
77
+     */
78
+    protected $statCache;
79
+
80
+    public function __construct($params) {
81
+        if (!isset($params['host'])) {
82
+            throw new \Exception('Invalid configuration, no host provided');
83
+        }
84
+
85
+        if (isset($params['auth'])) {
86
+            $auth = $params['auth'];
87
+        } else if (isset($params['user']) && isset($params['password']) && isset($params['share'])) {
88
+            $auth = new BasicAuth($params['user'], '', $params['password']);
89
+        } else {
90
+            throw new \Exception('Invalid configuration, no credentials provided');
91
+        }
92
+
93
+        $serverFactory = new ServerFactory();
94
+        $this->server = $serverFactory->createServer($params['host'], $auth);
95
+        $this->share = $this->server->getShare(trim($params['share'], '/'));
96
+
97
+        $this->root = $params['root'] ?? '/';
98
+        $this->root = '/' . ltrim($this->root, '/');
99
+        $this->root = rtrim($this->root, '/') . '/';
100
+
101
+        $this->statCache = new CappedMemoryCache();
102
+        parent::__construct($params);
103
+    }
104
+
105
+    /**
106
+     * @return string
107
+     */
108
+    public function getId() {
109
+        // FIXME: double slash to keep compatible with the old storage ids,
110
+        // failure to do so will lead to creation of a new storage id and
111
+        // loss of shares from the storage
112
+        return 'smb::' . $this->server->getAuth()->getUsername() . '@' . $this->server->getHost() . '//' . $this->share->getName() . '/' . $this->root;
113
+    }
114
+
115
+    /**
116
+     * @param string $path
117
+     * @return string
118
+     */
119
+    protected function buildPath($path) {
120
+        return Filesystem::normalizePath($this->root . '/' . $path, true, false, true);
121
+    }
122
+
123
+    protected function relativePath($fullPath) {
124
+        if ($fullPath === $this->root) {
125
+            return '';
126
+        } else if (substr($fullPath, 0, strlen($this->root)) === $this->root) {
127
+            return substr($fullPath, strlen($this->root));
128
+        } else {
129
+            return null;
130
+        }
131
+    }
132
+
133
+    /**
134
+     * @param string $path
135
+     * @return \Icewind\SMB\IFileInfo
136
+     * @throws StorageNotAvailableException
137
+     */
138
+    protected function getFileInfo($path) {
139
+        try {
140
+            $path = $this->buildPath($path);
141
+            if (!isset($this->statCache[$path])) {
142
+                $this->statCache[$path] = $this->share->stat($path);
143
+            }
144
+            return $this->statCache[$path];
145
+        } catch (ConnectException $e) {
146
+            throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
147
+        }
148
+    }
149
+
150
+    /**
151
+     * @param string $path
152
+     * @return \Icewind\SMB\IFileInfo[]
153
+     * @throws StorageNotAvailableException
154
+     */
155
+    protected function getFolderContents($path) {
156
+        try {
157
+            $path = $this->buildPath($path);
158
+            $files = $this->share->dir($path);
159
+            foreach ($files as $file) {
160
+                $this->statCache[$path . '/' . $file->getName()] = $file;
161
+            }
162
+            return array_filter($files, function (IFileInfo $file) {
163
+                try {
164
+                    return !$file->isHidden();
165
+                } catch (ForbiddenException $e) {
166
+                    return false;
167
+                } catch (NotFoundException $e) {
168
+                    return false;
169
+                }
170
+            });
171
+        } catch (ConnectException $e) {
172
+            throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
173
+        }
174
+    }
175
+
176
+    /**
177
+     * @param \Icewind\SMB\IFileInfo $info
178
+     * @return array
179
+     */
180
+    protected function formatInfo($info) {
181
+        $result = [
182
+            'size' => $info->getSize(),
183
+            'mtime' => $info->getMTime(),
184
+        ];
185
+        if ($info->isDirectory()) {
186
+            $result['type'] = 'dir';
187
+        } else {
188
+            $result['type'] = 'file';
189
+        }
190
+        return $result;
191
+    }
192
+
193
+    /**
194
+     * Rename the files. If the source or the target is the root, the rename won't happen.
195
+     *
196
+     * @param string $source the old name of the path
197
+     * @param string $target the new name of the path
198
+     * @return bool true if the rename is successful, false otherwise
199
+     */
200
+    public function rename($source, $target) {
201
+        if ($this->isRootDir($source) || $this->isRootDir($target)) {
202
+            return false;
203
+        }
204
+
205
+        $absoluteSource = $this->buildPath($source);
206
+        $absoluteTarget = $this->buildPath($target);
207
+        try {
208
+            $result = $this->share->rename($absoluteSource, $absoluteTarget);
209
+        } catch (AlreadyExistsException $e) {
210
+            $this->remove($target);
211
+            $result = $this->share->rename($absoluteSource, $absoluteTarget);
212
+        } catch (\Exception $e) {
213
+            \OC::$server->getLogger()->logException($e, ['level' => ILogger::WARN]);
214
+            return false;
215
+        }
216
+        unset($this->statCache[$absoluteSource], $this->statCache[$absoluteTarget]);
217
+        return $result;
218
+    }
219
+
220
+    public function stat($path) {
221
+        try {
222
+            $result = $this->formatInfo($this->getFileInfo($path));
223
+        } catch (ForbiddenException $e) {
224
+            return false;
225
+        } catch (NotFoundException $e) {
226
+            return false;
227
+        }
228
+        if ($this->remoteIsShare() && $this->isRootDir($path)) {
229
+            $result['mtime'] = $this->shareMTime();
230
+        }
231
+        return $result;
232
+    }
233
+
234
+    /**
235
+     * get the best guess for the modification time of the share
236
+     *
237
+     * @return int
238
+     */
239
+    private function shareMTime() {
240
+        $highestMTime = 0;
241
+        $files = $this->share->dir($this->root);
242
+        foreach ($files as $fileInfo) {
243
+            try {
244
+                if ($fileInfo->getMTime() > $highestMTime) {
245
+                    $highestMTime = $fileInfo->getMTime();
246
+                }
247
+            } catch (NotFoundException $e) {
248
+                // Ignore this, can happen on unavailable DFS shares
249
+            }
250
+        }
251
+        return $highestMTime;
252
+    }
253
+
254
+    /**
255
+     * Check if the path is our root dir (not the smb one)
256
+     *
257
+     * @param string $path the path
258
+     * @return bool
259
+     */
260
+    private function isRootDir($path) {
261
+        return $path === '' || $path === '/' || $path === '.';
262
+    }
263
+
264
+    /**
265
+     * Check if our root points to a smb share
266
+     *
267
+     * @return bool true if our root points to a share false otherwise
268
+     */
269
+    private function remoteIsShare() {
270
+        return $this->share->getName() && (!$this->root || $this->root === '/');
271
+    }
272
+
273
+    /**
274
+     * @param string $path
275
+     * @return bool
276
+     */
277
+    public function unlink($path) {
278
+        if ($this->isRootDir($path)) {
279
+            return false;
280
+        }
281
+
282
+        try {
283
+            if ($this->is_dir($path)) {
284
+                return $this->rmdir($path);
285
+            } else {
286
+                $path = $this->buildPath($path);
287
+                unset($this->statCache[$path]);
288
+                $this->share->del($path);
289
+                return true;
290
+            }
291
+        } catch (NotFoundException $e) {
292
+            return false;
293
+        } catch (ForbiddenException $e) {
294
+            return false;
295
+        } catch (ConnectException $e) {
296
+            throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
297
+        }
298
+    }
299
+
300
+    /**
301
+     * check if a file or folder has been updated since $time
302
+     *
303
+     * @param string $path
304
+     * @param int $time
305
+     * @return bool
306
+     */
307
+    public function hasUpdated($path, $time) {
308
+        if (!$path and $this->root === '/') {
309
+            // mtime doesn't work for shares, but giving the nature of the backend,
310
+            // doing a full update is still just fast enough
311
+            return true;
312
+        } else {
313
+            $actualTime = $this->filemtime($path);
314
+            return $actualTime > $time;
315
+        }
316
+    }
317
+
318
+    /**
319
+     * @param string $path
320
+     * @param string $mode
321
+     * @return resource|false
322
+     */
323
+    public function fopen($path, $mode) {
324
+        $fullPath = $this->buildPath($path);
325
+        try {
326
+            switch ($mode) {
327
+                case 'r':
328
+                case 'rb':
329
+                    if (!$this->file_exists($path)) {
330
+                        return false;
331
+                    }
332
+                    return $this->share->read($fullPath);
333
+                case 'w':
334
+                case 'wb':
335
+                    $source = $this->share->write($fullPath);
336
+                    return CallBackWrapper::wrap($source, null, null, function () use ($fullPath) {
337
+                        unset($this->statCache[$fullPath]);
338
+                    });
339
+                case 'a':
340
+                case 'ab':
341
+                case 'r+':
342
+                case 'w+':
343
+                case 'wb+':
344
+                case 'a+':
345
+                case 'x':
346
+                case 'x+':
347
+                case 'c':
348
+                case 'c+':
349
+                    //emulate these
350
+                    if (strrpos($path, '.') !== false) {
351
+                        $ext = substr($path, strrpos($path, '.'));
352
+                    } else {
353
+                        $ext = '';
354
+                    }
355
+                    if ($this->file_exists($path)) {
356
+                        if (!$this->isUpdatable($path)) {
357
+                            return false;
358
+                        }
359
+                        $tmpFile = $this->getCachedFile($path);
360
+                    } else {
361
+                        if (!$this->isCreatable(dirname($path))) {
362
+                            return false;
363
+                        }
364
+                        $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
365
+                    }
366
+                    $source = fopen($tmpFile, $mode);
367
+                    $share = $this->share;
368
+                    return CallbackWrapper::wrap($source, null, null, function () use ($tmpFile, $fullPath, $share) {
369
+                        unset($this->statCache[$fullPath]);
370
+                        $share->put($tmpFile, $fullPath);
371
+                        unlink($tmpFile);
372
+                    });
373
+            }
374
+            return false;
375
+        } catch (NotFoundException $e) {
376
+            return false;
377
+        } catch (ForbiddenException $e) {
378
+            return false;
379
+        } catch (ConnectException $e) {
380
+            throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
381
+        }
382
+    }
383
+
384
+    public function rmdir($path) {
385
+        if ($this->isRootDir($path)) {
386
+            return false;
387
+        }
388
+
389
+        try {
390
+            $this->statCache = array();
391
+            $content = $this->share->dir($this->buildPath($path));
392
+            foreach ($content as $file) {
393
+                if ($file->isDirectory()) {
394
+                    $this->rmdir($path . '/' . $file->getName());
395
+                } else {
396
+                    $this->share->del($file->getPath());
397
+                }
398
+            }
399
+            $this->share->rmdir($this->buildPath($path));
400
+            return true;
401
+        } catch (NotFoundException $e) {
402
+            return false;
403
+        } catch (ForbiddenException $e) {
404
+            return false;
405
+        } catch (ConnectException $e) {
406
+            throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
407
+        }
408
+    }
409
+
410
+    public function touch($path, $time = null) {
411
+        try {
412
+            if (!$this->file_exists($path)) {
413
+                $fh = $this->share->write($this->buildPath($path));
414
+                fclose($fh);
415
+                return true;
416
+            }
417
+            return false;
418
+        } catch (ConnectException $e) {
419
+            throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
420
+        }
421
+    }
422
+
423
+    public function opendir($path) {
424
+        try {
425
+            $files = $this->getFolderContents($path);
426
+        } catch (NotFoundException $e) {
427
+            return false;
428
+        } catch (ForbiddenException $e) {
429
+            return false;
430
+        }
431
+        $names = array_map(function ($info) {
432
+            /** @var \Icewind\SMB\IFileInfo $info */
433
+            return $info->getName();
434
+        }, $files);
435
+        return IteratorDirectory::wrap($names);
436
+    }
437
+
438
+    public function filetype($path) {
439
+        try {
440
+            return $this->getFileInfo($path)->isDirectory() ? 'dir' : 'file';
441
+        } catch (NotFoundException $e) {
442
+            return false;
443
+        } catch (ForbiddenException $e) {
444
+            return false;
445
+        }
446
+    }
447
+
448
+    public function mkdir($path) {
449
+        $path = $this->buildPath($path);
450
+        try {
451
+            $this->share->mkdir($path);
452
+            return true;
453
+        } catch (ConnectException $e) {
454
+            throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
455
+        } catch (Exception $e) {
456
+            return false;
457
+        }
458
+    }
459
+
460
+    public function file_exists($path) {
461
+        try {
462
+            $this->getFileInfo($path);
463
+            return true;
464
+        } catch (NotFoundException $e) {
465
+            return false;
466
+        } catch (ForbiddenException $e) {
467
+            return false;
468
+        } catch (ConnectException $e) {
469
+            throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
470
+        }
471
+    }
472
+
473
+    public function isReadable($path) {
474
+        try {
475
+            $info = $this->getFileInfo($path);
476
+            return !$info->isHidden();
477
+        } catch (NotFoundException $e) {
478
+            return false;
479
+        } catch (ForbiddenException $e) {
480
+            return false;
481
+        }
482
+    }
483
+
484
+    public function isUpdatable($path) {
485
+        try {
486
+            $info = $this->getFileInfo($path);
487
+            // following windows behaviour for read-only folders: they can be written into
488
+            // (https://support.microsoft.com/en-us/kb/326549 - "cause" section)
489
+            return !$info->isHidden() && (!$info->isReadOnly() || $this->is_dir($path));
490
+        } catch (NotFoundException $e) {
491
+            return false;
492
+        } catch (ForbiddenException $e) {
493
+            return false;
494
+        }
495
+    }
496
+
497
+    public function isDeletable($path) {
498
+        try {
499
+            $info = $this->getFileInfo($path);
500
+            return !$info->isHidden() && !$info->isReadOnly();
501
+        } catch (NotFoundException $e) {
502
+            return false;
503
+        } catch (ForbiddenException $e) {
504
+            return false;
505
+        }
506
+    }
507
+
508
+    /**
509
+     * check if smbclient is installed
510
+     */
511
+    public static function checkDependencies() {
512
+        return (
513
+            (bool)\OC_Helper::findBinaryPath('smbclient')
514
+            || NativeServer::available(new System())
515
+        ) ? true : ['smbclient'];
516
+    }
517
+
518
+    /**
519
+     * Test a storage for availability
520
+     *
521
+     * @return bool
522
+     */
523
+    public function test() {
524
+        try {
525
+            return parent::test();
526
+        } catch (Exception $e) {
527
+            return false;
528
+        }
529
+    }
530
+
531
+    public function listen($path, callable $callback) {
532
+        $this->notify($path)->listen(function (IChange $change) use ($callback) {
533
+            if ($change instanceof IRenameChange) {
534
+                return $callback($change->getType(), $change->getPath(), $change->getTargetPath());
535
+            } else {
536
+                return $callback($change->getType(), $change->getPath());
537
+            }
538
+        });
539
+    }
540
+
541
+    public function notify($path) {
542
+        $path = '/' . ltrim($path, '/');
543
+        $shareNotifyHandler = $this->share->notify($this->buildPath($path));
544
+        return new SMBNotifyHandler($shareNotifyHandler, $this->root);
545
+    }
546 546
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
 		$this->share = $this->server->getShare(trim($params['share'], '/'));
96 96
 
97 97
 		$this->root = $params['root'] ?? '/';
98
-		$this->root = '/' . ltrim($this->root, '/');
99
-		$this->root = rtrim($this->root, '/') . '/';
98
+		$this->root = '/'.ltrim($this->root, '/');
99
+		$this->root = rtrim($this->root, '/').'/';
100 100
 
101 101
 		$this->statCache = new CappedMemoryCache();
102 102
 		parent::__construct($params);
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 		// FIXME: double slash to keep compatible with the old storage ids,
110 110
 		// failure to do so will lead to creation of a new storage id and
111 111
 		// loss of shares from the storage
112
-		return 'smb::' . $this->server->getAuth()->getUsername() . '@' . $this->server->getHost() . '//' . $this->share->getName() . '/' . $this->root;
112
+		return 'smb::'.$this->server->getAuth()->getUsername().'@'.$this->server->getHost().'//'.$this->share->getName().'/'.$this->root;
113 113
 	}
114 114
 
115 115
 	/**
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 	 * @return string
118 118
 	 */
119 119
 	protected function buildPath($path) {
120
-		return Filesystem::normalizePath($this->root . '/' . $path, true, false, true);
120
+		return Filesystem::normalizePath($this->root.'/'.$path, true, false, true);
121 121
 	}
122 122
 
123 123
 	protected function relativePath($fullPath) {
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
 			$path = $this->buildPath($path);
158 158
 			$files = $this->share->dir($path);
159 159
 			foreach ($files as $file) {
160
-				$this->statCache[$path . '/' . $file->getName()] = $file;
160
+				$this->statCache[$path.'/'.$file->getName()] = $file;
161 161
 			}
162
-			return array_filter($files, function (IFileInfo $file) {
162
+			return array_filter($files, function(IFileInfo $file) {
163 163
 				try {
164 164
 					return !$file->isHidden();
165 165
 				} catch (ForbiddenException $e) {
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 				case 'w':
334 334
 				case 'wb':
335 335
 					$source = $this->share->write($fullPath);
336
-					return CallBackWrapper::wrap($source, null, null, function () use ($fullPath) {
336
+					return CallBackWrapper::wrap($source, null, null, function() use ($fullPath) {
337 337
 						unset($this->statCache[$fullPath]);
338 338
 					});
339 339
 				case 'a':
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 					}
366 366
 					$source = fopen($tmpFile, $mode);
367 367
 					$share = $this->share;
368
-					return CallbackWrapper::wrap($source, null, null, function () use ($tmpFile, $fullPath, $share) {
368
+					return CallbackWrapper::wrap($source, null, null, function() use ($tmpFile, $fullPath, $share) {
369 369
 						unset($this->statCache[$fullPath]);
370 370
 						$share->put($tmpFile, $fullPath);
371 371
 						unlink($tmpFile);
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 			$content = $this->share->dir($this->buildPath($path));
392 392
 			foreach ($content as $file) {
393 393
 				if ($file->isDirectory()) {
394
-					$this->rmdir($path . '/' . $file->getName());
394
+					$this->rmdir($path.'/'.$file->getName());
395 395
 				} else {
396 396
 					$this->share->del($file->getPath());
397 397
 				}
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 		} catch (ForbiddenException $e) {
429 429
 			return false;
430 430
 		}
431
-		$names = array_map(function ($info) {
431
+		$names = array_map(function($info) {
432 432
 			/** @var \Icewind\SMB\IFileInfo $info */
433 433
 			return $info->getName();
434 434
 		}, $files);
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
 	 */
511 511
 	public static function checkDependencies() {
512 512
 		return (
513
-			(bool)\OC_Helper::findBinaryPath('smbclient')
513
+			(bool) \OC_Helper::findBinaryPath('smbclient')
514 514
 			|| NativeServer::available(new System())
515 515
 		) ? true : ['smbclient'];
516 516
 	}
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
 	}
530 530
 
531 531
 	public function listen($path, callable $callback) {
532
-		$this->notify($path)->listen(function (IChange $change) use ($callback) {
532
+		$this->notify($path)->listen(function(IChange $change) use ($callback) {
533 533
 			if ($change instanceof IRenameChange) {
534 534
 				return $callback($change->getType(), $change->getPath(), $change->getTargetPath());
535 535
 			} else {
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 	}
540 540
 
541 541
 	public function notify($path) {
542
-		$path = '/' . ltrim($path, '/');
542
+		$path = '/'.ltrim($path, '/');
543 543
 		$shareNotifyHandler = $this->share->notify($this->buildPath($path));
544 544
 		return new SMBNotifyHandler($shareNotifyHandler, $this->root);
545 545
 	}
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Auth/SMB/KerberosAuth.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -25,10 +25,10 @@
 block discarded – undo
25 25
 use OCP\IL10N;
26 26
 
27 27
 class KerberosAuth extends AuthMechanism {
28
-	public function __construct(IL10N $l) {
29
-		$this
30
-			->setIdentifier('smb::kerberos')
31
-			->setScheme(self::SCHEME_SMB)
32
-			->setText($l->t('Kerberos ticket'));
33
-	}
28
+    public function __construct(IL10N $l) {
29
+        $this
30
+            ->setIdentifier('smb::kerberos')
31
+            ->setScheme(self::SCHEME_SMB)
32
+            ->setText($l->t('Kerberos ticket'));
33
+    }
34 34
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Auth/AuthMechanism.php 1 patch
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -52,72 +52,72 @@
 block discarded – undo
52 52
  */
53 53
 class AuthMechanism implements \JsonSerializable {
54 54
 
55
-	/** Standard authentication schemes */
56
-	const SCHEME_NULL = 'null';
57
-	const SCHEME_BUILTIN = 'builtin';
58
-	const SCHEME_PASSWORD = 'password';
59
-	const SCHEME_OAUTH1 = 'oauth1';
60
-	const SCHEME_OAUTH2 = 'oauth2';
61
-	const SCHEME_PUBLICKEY = 'publickey';
62
-	const SCHEME_OPENSTACK = 'openstack';
63
-	const SCHEME_SMB = 'smb';
55
+    /** Standard authentication schemes */
56
+    const SCHEME_NULL = 'null';
57
+    const SCHEME_BUILTIN = 'builtin';
58
+    const SCHEME_PASSWORD = 'password';
59
+    const SCHEME_OAUTH1 = 'oauth1';
60
+    const SCHEME_OAUTH2 = 'oauth2';
61
+    const SCHEME_PUBLICKEY = 'publickey';
62
+    const SCHEME_OPENSTACK = 'openstack';
63
+    const SCHEME_SMB = 'smb';
64 64
 
65
-	use VisibilityTrait;
66
-	use FrontendDefinitionTrait;
67
-	use StorageModifierTrait;
68
-	use IdentifierTrait;
65
+    use VisibilityTrait;
66
+    use FrontendDefinitionTrait;
67
+    use StorageModifierTrait;
68
+    use IdentifierTrait;
69 69
 
70
-	/** @var string */
71
-	protected $scheme;
70
+    /** @var string */
71
+    protected $scheme;
72 72
 
73
-	/**
74
-	 * Get the authentication scheme implemented
75
-	 * See self::SCHEME_* constants
76
-	 *
77
-	 * @return string
78
-	 */
79
-	public function getScheme() {
80
-		return $this->scheme;
81
-	}
73
+    /**
74
+     * Get the authentication scheme implemented
75
+     * See self::SCHEME_* constants
76
+     *
77
+     * @return string
78
+     */
79
+    public function getScheme() {
80
+        return $this->scheme;
81
+    }
82 82
 
83
-	/**
84
-	 * @param string $scheme
85
-	 * @return $this
86
-	 */
87
-	public function setScheme($scheme) {
88
-		$this->scheme = $scheme;
89
-		return $this;
90
-	}
83
+    /**
84
+     * @param string $scheme
85
+     * @return $this
86
+     */
87
+    public function setScheme($scheme) {
88
+        $this->scheme = $scheme;
89
+        return $this;
90
+    }
91 91
 
92
-	/**
93
-	 * Serialize into JSON for client-side JS
94
-	 *
95
-	 * @return array
96
-	 */
97
-	public function jsonSerialize() {
98
-		$data = $this->jsonSerializeDefinition();
99
-		$data += $this->jsonSerializeIdentifier();
92
+    /**
93
+     * Serialize into JSON for client-side JS
94
+     *
95
+     * @return array
96
+     */
97
+    public function jsonSerialize() {
98
+        $data = $this->jsonSerializeDefinition();
99
+        $data += $this->jsonSerializeIdentifier();
100 100
 
101
-		$data['scheme'] = $this->getScheme();
102
-		$data['visibility'] = $this->getVisibility();
101
+        $data['scheme'] = $this->getScheme();
102
+        $data['visibility'] = $this->getVisibility();
103 103
 
104
-		return $data;
105
-	}
104
+        return $data;
105
+    }
106 106
 
107
-	/**
108
-	 * Check if parameters are satisfied in a StorageConfig
109
-	 *
110
-	 * @param StorageConfig $storage
111
-	 * @return bool
112
-	 */
113
-	public function validateStorage(StorageConfig $storage) {
114
-		// does the backend actually support this scheme
115
-		$supportedSchemes = $storage->getBackend()->getAuthSchemes();
116
-		if (!isset($supportedSchemes[$this->getScheme()])) {
117
-			return false;
118
-		}
107
+    /**
108
+     * Check if parameters are satisfied in a StorageConfig
109
+     *
110
+     * @param StorageConfig $storage
111
+     * @return bool
112
+     */
113
+    public function validateStorage(StorageConfig $storage) {
114
+        // does the backend actually support this scheme
115
+        $supportedSchemes = $storage->getBackend()->getAuthSchemes();
116
+        if (!isset($supportedSchemes[$this->getScheme()])) {
117
+            return false;
118
+        }
119 119
 
120
-		return $this->validateStorageDefinition($storage);
121
-	}
120
+        return $this->validateStorageDefinition($storage);
121
+    }
122 122
 
123 123
 }
Please login to merge, or discard this patch.