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 <patrick@perlbach24.de>
This commit is contained in:
@@ -180,18 +180,21 @@ class SharesManager:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def get_samba_global_config(self) -> Dict[str, Any]:
|
def get_samba_global_config(self) -> Dict[str, Any]:
|
||||||
"""Read Samba global configuration section as structured key-value pairs"""
|
"""Read Samba global configuration from registry using 'net conf list'"""
|
||||||
if not SAMBA_CONFIG.exists():
|
try:
|
||||||
|
result = subprocess.run(
|
||||||
|
['net', 'conf', 'list'],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
timeout=10
|
||||||
|
)
|
||||||
|
|
||||||
|
if result.returncode != 0:
|
||||||
return {"parameters": []}
|
return {"parameters": []}
|
||||||
|
|
||||||
try:
|
|
||||||
with open(SAMBA_CONFIG, 'r') as f:
|
|
||||||
content = f.read()
|
|
||||||
|
|
||||||
parameters = []
|
parameters = []
|
||||||
lines = content.split('\n')
|
|
||||||
in_global = False
|
in_global = False
|
||||||
for line in lines:
|
for line in result.stdout.split('\n'):
|
||||||
if line.strip().startswith('[global]'):
|
if line.strip().startswith('[global]'):
|
||||||
in_global = True
|
in_global = True
|
||||||
continue
|
continue
|
||||||
@@ -210,7 +213,7 @@ class SharesManager:
|
|||||||
|
|
||||||
return {"parameters": parameters}
|
return {"parameters": parameters}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error reading Samba global config: {e}")
|
logger.error(f"Error reading Samba registry config: {e}")
|
||||||
return {"parameters": []}
|
return {"parameters": []}
|
||||||
|
|
||||||
def set_samba_global_config(self, config_text: str) -> bool:
|
def set_samba_global_config(self, config_text: str) -> bool:
|
||||||
|
|||||||
Reference in New Issue
Block a user