nas-samba: fix home dir ownership and permissions for Samba access

This commit is contained in:
2026-04-26 06:03:10 +00:00
parent 580eec66cd
commit bdd2e4e2a5

View File

@@ -175,7 +175,8 @@ function createSystemUser(username, password) {
execSync(`id -u "${username}" >/dev/null 2>&1 || useradd -M -s /usr/sbin/nologin "${username}"`);
const homeDir = path.join(HOME_BASE, username);
fs.mkdirSync(homeDir, { recursive: true });
execSync(`chown "${username}":nogroup "${homeDir}"`);
execSync(`chown -R "${username}":"${username}" "${homeDir}"`);
execSync(`chmod 0700 "${homeDir}"`);
const escaped = password.replace(/'/g, "'\\''");
execSync(`printf '%s\\n%s\\n' '${escaped}' '${escaped}' | smbpasswd -a -s "${username}"`);
}
@@ -1682,7 +1683,8 @@ function main() {
fs.mkdirSync(homeDir, { recursive: true });
try {
execSync(`id -u "${u.username}" >/dev/null 2>&1 || useradd -M -s /usr/sbin/nologin "${u.username}"`);
execSync(`chown "${u.username}":nogroup "${homeDir}"`);
execSync(`chown -R "${u.username}":"${u.username}" "${homeDir}"`);
execSync(`chmod 0700 "${homeDir}"`);
// Set Samba password only if user not already in TDB (first run or migration)
try {
execSync(`pdbedit -u "${u.username}" >/dev/null 2>&1`);