try with creds file
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 30 Aug 2024 12:10:43 +0000 (14:10 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 30 Aug 2024 12:10:43 +0000 (14:10 +0200)
music_assistant/server/providers/filesystem_smb/__init__.py

index e8192b00113985d912171c43dc8c816844b9927e..9a7a4c98ad585f195d32fd3734bf0d1b1407e23f 100644 (file)
@@ -6,6 +6,8 @@ import os
 import platform
 from typing import TYPE_CHECKING
 
+import aiofiles
+
 from music_assistant.common.helpers.util import get_ip_from_host
 from music_assistant.common.models.config_entries import ConfigEntry, ConfigValueType
 from music_assistant.common.models.enums import ConfigEntryType
@@ -162,6 +164,14 @@ class SMBFileSystemProvider(LocalFileSystemProvider):
         password = self.config.get_value(CONF_PASSWORD)
         share = str(self.config.get_value(CONF_SHARE))
 
+        # somehow alpine doesn't accept the PASSWD env var and passing it in the options string
+        # means we cant support any special characters, so alternative is to use a credentials file
+        creds_file = f"/tmp/{self.instance_id}_smb_creds"  # noqa: S108
+        async with aiofiles.open(creds_file, "w") as _file:
+            await _file.write(f"username={username}\n")
+            if password:
+                await _file.write(f"password={password}\n")
+
         # handle optional subfolder
         subfolder = str(self.config.get_value(CONF_SUBFOLDER))
         if subfolder:
@@ -186,15 +196,8 @@ class SMBFileSystemProvider(LocalFileSystemProvider):
             options = ["rw"]
             if mount_options := str(self.config.get_value(CONF_MOUNT_OPTIONS)):
                 options += mount_options.split(",")
-            options.append(f"username={username}")
+            options.append(f"credentials={creds_file}")
             options_str = ",".join(options)
-
-            env_vars = {
-                **os.environ,
-            }
-            if password:
-                env_vars["PASSWD"] = str(password)
-
             mount_cmd = [
                 "mount",
                 "-t",
@@ -214,7 +217,8 @@ class SMBFileSystemProvider(LocalFileSystemProvider):
             "Using mount command: %s",
             " ".join([m.replace(str(password), "########") if password else m for m in mount_cmd]),
         )
-        returncode, output = await check_output(*mount_cmd, env=env_vars)
+        returncode, output = await check_output(*mount_cmd)
+        self.mass.create_task(os.remove, creds_file)
         if returncode != 0:
             msg = f"SMB mount failed with error: {output.decode()}"
             raise LoginFailed(msg)