Problem
User can not log into nextcloud. An internal server error is reported
Environment
UCS 4-48
Nextcloud 21.0.3 and files_external 1.12.x
Solution
It seems that there is a bug in nextcloud version 21.0.3 or extension files_external 1.12.x. See:
nextcloud:master
← alacn1:master
opened 01:44PM - 10 Nov 21 UTC
When using external mount with "Global credentials, user entered", users without… it set won't be able to login.
This happens because BasicAuth requires username and password as string, but will be null when user didn't set it yet.
Since the commit: 66781e74ada3fd22bb5b246a59897ac146cda4dd update icewind/smb to 3.4.0
the file `apps/files_external/3rdparty/icewind/smb/src/BasicAuth.php` was changed to use php 7.4 typed properties.
```
- public function __construct($username, $workgroup, $password) {
+ public function __construct(string $username, ?string $workgroup, string $password) {
```
BasicAuth with null as arg will throw a TypeError, that is a subclass of Error, not subclass of Exception.
`apps/files_external/lib/Lib/Backend/SMB.php`
```
public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
[...]
$smbAuth = new BasicAuth(
$storage->getBackendOption('user'),
$storage->getBackendOption('domain'),
$storage->getBackendOption('password')
);
```
Because Error class type it won't catch it at FailedStorage:
`apps/files_external/lib/Config/ConfigAdapter.php`
```
public function getMountsForUser(IUser $user, IStorageFactory $loader) {
[...]
$storages = array_map(function (StorageConfig $storageConfig) use ($user) {
try {
$this->prepareStorageConfig($storageConfig, $user);
return $this->constructStorage($storageConfig);
} catch (\Exception $e) {
// propagate exception into filesystem
return new FailedStorage(['exception' => $e]);
}
}, $storageConfigs);
```
The proposed fix is to check if user and password is string instead of null, and throw InvalidArgumentException if it's not.
`apps/files_external/lib/Lib/Backend/SMB.php`
```
public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
[...]
if(!is_string($storage->getBackendOption('user')) || !is_string($storage->getBackendOption('password')))
throw new \InvalidArgumentException('user or password is not set');
```
This commit can be cherry-picked to master, stable22, stable21.
It fixes #28229 and #26697.
That bugreport includes a code correction, that helped two customers already. You can try that in your environment:
univention-app shell nextcloud sed -i -s "/=== AuthMechanism::SCHEME_PASSWORD) {/a \\\t\t\tif(\!is_string(\$storage->getBackendOption('user')) || \!is_string(\$storage->getBackendOption('password')))\n\t\t\t\tthrow new \\InvalidArgumentException('user or password
is not set');" /var/www/html/apps/files_external/lib/Lib/Backend/SMB.php
If you want to revert this, you can run:
univention-app reinitialize nextcloud