From 0504b5b880e829f631abd5fec891e6ce1adc9204 Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 22 Apr 2026 01:08:15 +0200 Subject: [PATCH] Read Samba config from registry instead of smb.conf Use 'net conf list' to read global config parameters from Samba registry. This is more reliable than parsing smb.conf, especially when using 'include = registry' in smb.conf. Co-Authored-By: Patrick --- backend/services/shares.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/backend/services/shares.py b/backend/services/shares.py index e62ea8b..3d47f35 100644 --- a/backend/services/shares.py +++ b/backend/services/shares.py @@ -180,18 +180,21 @@ class SharesManager: return False def get_samba_global_config(self) -> Dict[str, Any]: - """Read Samba global configuration section as structured key-value pairs""" - if not SAMBA_CONFIG.exists(): - return {"parameters": []} - + """Read Samba global configuration from registry using 'net conf list'""" try: - with open(SAMBA_CONFIG, 'r') as f: - content = f.read() + result = subprocess.run( + ['net', 'conf', 'list'], + capture_output=True, + text=True, + timeout=10 + ) + + if result.returncode != 0: + return {"parameters": []} parameters = [] - lines = content.split('\n') in_global = False - for line in lines: + for line in result.stdout.split('\n'): if line.strip().startswith('[global]'): in_global = True continue @@ -210,7 +213,7 @@ class SharesManager: return {"parameters": parameters} except Exception as e: - logger.error(f"Error reading Samba global config: {e}") + logger.error(f"Error reading Samba registry config: {e}") return {"parameters": []} def set_samba_global_config(self, config_text: str) -> bool: