Skip to content

Commit

Permalink
chore: [security] check authentication for sharecontrol
Browse files Browse the repository at this point in the history
as title

Log: as title
  • Loading branch information
Johnson-zs committed Sep 11, 2024
1 parent 91b0b02 commit 31e9c7b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
11 changes: 5 additions & 6 deletions src/plugins/common/dfmplugin-dirshare/utils/usersharehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> reply = userShareInter->asyncCall(DaemonServiceIFace::kFuncCloseShare, name, true);
QDBusReply<bool> 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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 31e9c7b

Please sign in to comment.