From 31e9c7b3dd9889f8eea12b354b9fcc97c7aa0ddc Mon Sep 17 00:00:00 2001 From: Zhang Sheng Date: Wed, 11 Sep 2024 11:42:47 +0800 Subject: [PATCH] chore: [security] check authentication for sharecontrol as title Log: as title --- .../dfmplugin-dirshare/utils/usersharehelper.cpp | 11 +++++------ .../common/dfmplugin-dirshare/utils/usersharehelper.h | 2 +- .../daemonplugin-sharecontrol/sharecontroldbus.cpp | 10 +++++++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/plugins/common/dfmplugin-dirshare/utils/usersharehelper.cpp b/src/plugins/common/dfmplugin-dirshare/utils/usersharehelper.cpp index f3b2cf42e1..3f8aa57edc 100644 --- a/src/plugins/common/dfmplugin-dirshare/utils/usersharehelper.cpp +++ b/src/plugins/common/dfmplugin-dirshare/utils/usersharehelper.cpp @@ -422,18 +422,17 @@ void UserShareHelper::initMonitorPath() watcherManager->add(info.value(ShareInfoKeys::kPath).toString()); } -void UserShareHelper::removeShareByShareName(const QString &name) +void UserShareHelper::removeShareByShareName(const QString &name, bool silent) { - QDBusReply reply = userShareInter->asyncCall(DaemonServiceIFace::kFuncCloseShare, name, true); + QDBusReply reply = userShareInter->asyncCall(DaemonServiceIFace::kFuncCloseShare, name, !silent); if (reply.isValid() && reply.value()) { fmDebug() << "share closed: " << name; + runNetCmd(QStringList() << "usershare" + << "delete" << name); } else { fmWarning() << "share close failed: " << name << ", " << reply.error(); // TODO(xust) regular user cannot remove the sharing which shared by root user. and should raise an error dialog to notify user. } - - runNetCmd(QStringList() << "usershare" - << "delete" << name); } void UserShareHelper::removeShareWhenShareFolderDeleted(const QString &deletedPath) @@ -442,7 +441,7 @@ void UserShareHelper::removeShareWhenShareFolderDeleted(const QString &deletedPa if (shareName.isEmpty()) return; - removeShareByShareName(shareName); + removeShareByShareName(shareName, true); } ShareInfo UserShareHelper::getOldShareByNewShare(const ShareInfo &newShare) diff --git a/src/plugins/common/dfmplugin-dirshare/utils/usersharehelper.h b/src/plugins/common/dfmplugin-dirshare/utils/usersharehelper.h index 90e02f8b2b..bea8a3dc72 100644 --- a/src/plugins/common/dfmplugin-dirshare/utils/usersharehelper.h +++ b/src/plugins/common/dfmplugin-dirshare/utils/usersharehelper.h @@ -73,7 +73,7 @@ protected Q_SLOTS: void initConnect(); void initMonitorPath(); - void removeShareByShareName(const QString &name); + void removeShareByShareName(const QString &name, bool silent = false); void removeShareWhenShareFolderDeleted(const QString &deletedPath); ShareInfo getOldShareByNewShare(const ShareInfo &newShare); diff --git a/src/plugins/daemon/daemonplugin-sharecontrol/sharecontroldbus.cpp b/src/plugins/daemon/daemonplugin-sharecontrol/sharecontroldbus.cpp index c52a91122c..d775ef216d 100644 --- a/src/plugins/daemon/daemonplugin-sharecontrol/sharecontroldbus.cpp +++ b/src/plugins/daemon/daemonplugin-sharecontrol/sharecontroldbus.cpp @@ -39,6 +39,11 @@ bool ShareControlDBus::CloseSmbShareByShareName(const QString &name, bool show) return true; } + if (!checkAuthentication()) { + fmInfo() << "cannot close smb for" << name; + return false; + } + unsigned int suid = 0; QDBusConnection c = QDBusConnection::connectToBus(QDBusConnection::SystemBus, "org.freedesktop.DBus"); if (!c.isConnected()) { @@ -90,11 +95,10 @@ bool ShareControlDBus::SetUserSharePassword(const QString &name, const QString & bool ShareControlDBus::EnableSmbServices() { - // 创建链接文件之前已经提权了 这里就不需要再次判断权限了 - /*if (!checkAuthentication()) { + if (!checkAuthentication()) { fmDebug() << "EnableSmbServices"; return false; - }*/ + } QProcess sh; sh.start("ln -sf /lib/systemd/system/smbd.service /etc/systemd/system/multi-user.target.wants/smbd.service");