Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 42 additions & 13 deletions src/dfm-mount/private/dnetworkmounter.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 - 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand All @@ -10,12 +10,15 @@
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QUrl>
#include <QDebug>

Check warning on line 13 in src/dfm-mount/private/dnetworkmounter.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 13 in src/dfm-mount/private/dnetworkmounter.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTimer>

Check warning on line 14 in src/dfm-mount/private/dnetworkmounter.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTimer> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 14 in src/dfm-mount/private/dnetworkmounter.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QTimer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QtConcurrent>

Check warning on line 15 in src/dfm-mount/private/dnetworkmounter.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QtConcurrent> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 15 in src/dfm-mount/private/dnetworkmounter.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QtConcurrent> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusUnixFileDescriptor>

Check warning on line 16 in src/dfm-mount/private/dnetworkmounter.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusUnixFileDescriptor> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 16 in src/dfm-mount/private/dnetworkmounter.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QDBusUnixFileDescriptor> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <libmount.h>

Check warning on line 18 in src/dfm-mount/private/dnetworkmounter.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <libmount.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 18 in src/dfm-mount/private/dnetworkmounter.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <libmount.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <sys/mman.h>

Check warning on line 20 in src/dfm-mount/private/dnetworkmounter.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <sys/mman.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 20 in src/dfm-mount/private/dnetworkmounter.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <sys/mman.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

DFM_MOUNT_USE_NS

static constexpr char kDaemonService[] { "com.deepin.filemanager.daemon" };
Expand Down Expand Up @@ -148,9 +151,7 @@
if (err)
qDebug() << "query password failed: " << passwd << err->message;
else {
// since daemon accept base64-ed passwd to mount cifs, cleartext should be encoded with base64
// see commit of dde-file-manager: 3b50664d4034754b15c1a516cfaab8c7fbdd3db9
passwd.insert(kLoginPasswd, QString(QByteArray(pwd).toBase64()));
passwd.insert(kLoginPasswd, pwd);
}
}
return passwds;
Expand Down Expand Up @@ -471,12 +472,45 @@
delete finalize;
}

static QVariant preparePasswd(const QString &passwd)
{
if (passwd.isEmpty()) {
qCritical() << "Created empty QVariant for empty passwd";
return QVariant("");
}

int fd = memfd_create("DBusFD", MFD_CLOEXEC);
if (fd < 0) {
qCritical() << "Failed to create memfd for data transfer";
return QVariant("");
}

QByteArray byteData = passwd.toUtf8();
ssize_t written = ::write(fd, byteData.constData(), byteData.size());
if (written < 0 || static_cast<ssize_t>(byteData.size()) != written) {
qCritical() << "Failed to write data to memfd";
::close(fd);
return QVariant("");
}

if (lseek(fd, 0, SEEK_SET) < 0) {
qCritical() << "Failed to seek memfd to beginning";
::close(fd);
return QVariant("");
}

QDBusUnixFileDescriptor dbusFd;
dbusFd.giveFileDescriptor(fd);

return QVariant::fromValue(dbusFd);
}

DNetworkMounter::MountRet DNetworkMounter::mountWithUserInput(const QString &address,
const MountPassInfo info)
{
QVariantMap param { { kLoginUser, info.userName },
{ kLoginDomain, info.domain },
{ kLoginPasswd, info.passwd },
{ kLoginPasswd, preparePasswd(info.passwd) },
{ kLoginTimeout, info.timeout },
{ kMountFsType, "cifs" } };

Expand All @@ -495,13 +529,8 @@
if (ok) {
err = DeviceError::kNoError;

if (!info.anonymous && info.savePasswd != NetworkMountPasswdSaveMode::kNeverSavePasswd) {
// since passwd from user input is base64-ed data, so the passwd should be decoded into cleartext for saving.
// associated commit of dde-file-manager: 3b50664d4034754b15c1a516cfaab8c7fbdd3db9
auto _info = info;
_info.passwd = QByteArray::fromBase64(info.passwd.toLocal8Bit());
savePasswd(address, _info);
}
if (!info.anonymous && info.savePasswd != NetworkMountPasswdSaveMode::kNeverSavePasswd)
savePasswd(address, info);
}

return { ok, err, mpt };
Expand All @@ -517,7 +546,7 @@
for (const auto &login : infos) {
QVariantMap param { { kLoginUser, login.value(kSchemaUser, "") },
{ kLoginDomain, login.value(kSchemaDomain, "") },
{ kLoginPasswd, login.value(kLoginPasswd, "") },
{ kLoginPasswd, preparePasswd(login.value(kLoginPasswd, "").toString()) },
{ kLoginTimeout, secs },
{ kMountFsType, "cifs" } };

Expand Down
Loading