From c1694bdfa93b41b41cc2d608c5160c34e3a09478 Mon Sep 17 00:00:00 2001 From: duffyduck Date: Tue, 14 Apr 2026 10:06:28 +0200 Subject: [PATCH] Fix ACL handling: prevent spurious overwrites and strip domain prefixes Two fixes in loadCurrentShare() / constructor: 1. Reset dirty flag after initial load so opening the Properties dialog (or triggering applyChanges from another plugin in the same dialog, e.g. a sibling FTP share tab) doesn't rewrite the share with stale combo values. 2. Strip Samba domain/authority prefixes like "DOMAIN\user" or "Unix User\user" when parsing usershare_acl, so the username comparison against /etc/passwd users succeeds and the combo boxes reflect the actual saved permissions. Applied identically to kf5 and kf6 variants. Co-Authored-By: Claude Opus 4.6 (1M context) --- kf5/src/smbshareplugin.cpp | 18 +++++++++++++++--- kf6/src/smbshareplugin.cpp | 18 +++++++++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/kf5/src/smbshareplugin.cpp b/kf5/src/smbshareplugin.cpp index c3ad936..5a03f13 100644 --- a/kf5/src/smbshareplugin.cpp +++ b/kf5/src/smbshareplugin.cpp @@ -150,8 +150,14 @@ SmbSharePlugin::SmbSharePlugin(QObject *parent, const QVariantList &args) // Load existing share info loadCurrentShare(); - // Initial UI state - onShareToggled(m_shareCheckBox->isChecked()); + // Initial UI state — apply enabled/disabled without marking dirty + m_nameEdit->setEnabled(m_shareCheckBox->isChecked()); + m_guestCheckBox->setEnabled(m_shareCheckBox->isChecked()); + m_usersWidget->setEnabled(m_shareCheckBox->isChecked()); + + // Reset dirty after all initial setup so opening the dialog doesn't + // trigger applyChanges() on this or other plugins. + setDirty(false); // Add the page as a tab properties->addPage(m_page, i18n("Share")); @@ -228,9 +234,15 @@ void SmbSharePlugin::loadCurrentShare() const int colonPos = entry.lastIndexOf(QLatin1Char(':')); if (colonPos < 0) continue; - const QString name = entry.left(colonPos); + QString name = entry.left(colonPos); const QString perm = entry.mid(colonPos + 1); + // Strip Samba domain/authority prefix, e.g. "DEBIANTERMINAL\duffy" + // or "Unix User\filiz" -> "duffy" / "filiz". + const int backslashPos = name.lastIndexOf(QLatin1Char('\\')); + if (backslashPos >= 0) + name = name.mid(backslashPos + 1); + for (auto &up : m_userPerms) { if (up.username.compare(name, Qt::CaseInsensitive) == 0) { up.combo->setCurrentIndex(indexForAcl(perm)); diff --git a/kf6/src/smbshareplugin.cpp b/kf6/src/smbshareplugin.cpp index c3ad936..5a03f13 100644 --- a/kf6/src/smbshareplugin.cpp +++ b/kf6/src/smbshareplugin.cpp @@ -150,8 +150,14 @@ SmbSharePlugin::SmbSharePlugin(QObject *parent, const QVariantList &args) // Load existing share info loadCurrentShare(); - // Initial UI state - onShareToggled(m_shareCheckBox->isChecked()); + // Initial UI state — apply enabled/disabled without marking dirty + m_nameEdit->setEnabled(m_shareCheckBox->isChecked()); + m_guestCheckBox->setEnabled(m_shareCheckBox->isChecked()); + m_usersWidget->setEnabled(m_shareCheckBox->isChecked()); + + // Reset dirty after all initial setup so opening the dialog doesn't + // trigger applyChanges() on this or other plugins. + setDirty(false); // Add the page as a tab properties->addPage(m_page, i18n("Share")); @@ -228,9 +234,15 @@ void SmbSharePlugin::loadCurrentShare() const int colonPos = entry.lastIndexOf(QLatin1Char(':')); if (colonPos < 0) continue; - const QString name = entry.left(colonPos); + QString name = entry.left(colonPos); const QString perm = entry.mid(colonPos + 1); + // Strip Samba domain/authority prefix, e.g. "DEBIANTERMINAL\duffy" + // or "Unix User\filiz" -> "duffy" / "filiz". + const int backslashPos = name.lastIndexOf(QLatin1Char('\\')); + if (backslashPos >= 0) + name = name.mid(backslashPos + 1); + for (auto &up : m_userPerms) { if (up.username.compare(name, Qt::CaseInsensitive) == 0) { up.combo->setCurrentIndex(indexForAcl(perm));