Skip to content

Commit

Permalink
Better handle of SMB mount with special characters in username/passwo…
Browse files Browse the repository at this point in the history
…rd (#1448)
  • Loading branch information
marcelveldt authored Jul 5, 2024
1 parent 85a8827 commit b8739e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
6 changes: 2 additions & 4 deletions music_assistant/server/helpers/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,10 @@ async def wait(self) -> int:
return self._returncode


async def check_output(*args: str) -> tuple[int, bytes]:
async def check_output(*args: str, env: dict[str, str] | None = None) -> tuple[int, bytes]:
"""Run subprocess and return returncode and output."""
proc = await asyncio.create_subprocess_exec(
*args,
stderr=asyncio.subprocess.STDOUT,
stdout=asyncio.subprocess.PIPE,
*args, stderr=asyncio.subprocess.STDOUT, stdout=asyncio.subprocess.PIPE, env=env
)
stdout, _ = await proc.communicate()
return (proc.returncode, stdout)
Expand Down
17 changes: 9 additions & 8 deletions music_assistant/server/providers/filesystem_smb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,22 +185,18 @@ async def mount(self) -> None:
subfolder = subfolder[:-1]

if platform.system() == "Darwin":
# NOTE: MacOS does not support special characters in the username/password
password_str = f":{password}" if password else ""
mount_cmd = [
"mount",
"-t",
"smbfs",
f"//{username}:{password_str}@{server}/{share}{subfolder}",
f"//{username}{password_str}@{server}/{share}{subfolder}",
self.base_path,
]

elif platform.system() == "Linux":
options = [
"rw",
f'username="{username}"',
]
if password:
options.append(f'password="{password}"')
options = ["rw"]
if mount_options := self.config.get_value(CONF_MOUNT_OPTIONS):
options += mount_options.split(",")

Expand All @@ -224,8 +220,13 @@ async def mount(self) -> None:
"Using mount command: %s",
[m.replace(password, "########") if password else m for m in mount_cmd],
)
env_vars = {
"USER": username,
}
if password:
env_vars["PASSWD"] = password

returncode, output = await check_output(*mount_cmd)
returncode, output = await check_output(*mount_cmd, env=env_vars)
if returncode != 0:
msg = f"SMB mount failed with error: {output.decode()}"
raise LoginFailed(msg)
Expand Down

0 comments on commit b8739e7

Please sign in to comment.