From 1ef4f6f74392bb2234a6963ffb122e29ec031b91 Mon Sep 17 00:00:00 2001 From: marc Date: Sat, 20 Jun 2026 16:56:57 +0200 Subject: [PATCH] Extract _ensure_conf_dir(); call it from both _save_credentials and _write_webdav_conf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guarantees /etc/micronas is created with 750 root:www-data on any code path that writes config — first-time setup OR first WebDAV share. Fixes fresh-install permission issue without manual chmod. Co-Authored-By: Claude Sonnet 4.6 --- app.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 2768d06..f059f9d 100644 --- a/app.py +++ b/app.py @@ -49,8 +49,7 @@ def _verify_password(password): def _save_credentials(user, password): h = _hash_password(password) - os.makedirs(_CONF_DIR, mode=0o750, exist_ok=True) - subprocess.run(['chown', 'root:www-data', _CONF_DIR], capture_output=True) + _ensure_conf_dir() Path(_ENV_FILE).write_text(f'MICRONAS_USER={user}\nMICRONAS_PASS_HASH={h}\n') os.chmod(_ENV_FILE, 0o600) _creds['user'] = user @@ -321,7 +320,14 @@ def _parse_webdav_conf(): return shares +def _ensure_conf_dir(): + """Create /etc/micronas with correct ownership so Apache can traverse it.""" + os.makedirs(_CONF_DIR, mode=0o750, exist_ok=True) + subprocess.run(['chown', 'root:www-data', _CONF_DIR], capture_output=True) + + def _write_webdav_conf(shares): + _ensure_conf_dir() os.makedirs('/var/lib/apache2/webdav', exist_ok=True) lines = ['# Managed by MicroNAS — do not edit manually\n\n', 'DavLockDB /var/lib/apache2/webdav/DavLock\n\n']