Skip to content
Merged
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
59 changes: 59 additions & 0 deletions src/dfm-mount/private/dnetworkmounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@

#include "dnetworkmounter.h"

#include <QDBusInterface>

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

View workflow job for this annotation

GitHub Actions / cppcheck

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

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

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

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

View workflow job for this annotation

GitHub Actions / cppcheck

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

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

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

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

View workflow job for this annotation

GitHub Actions / cppcheck

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

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

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

Check warning on line 12 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 12 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 <QUrl>

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

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QUrl> 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: <QUrl> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDebug>

Check warning on line 14 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 14 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 15 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 15 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>

#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 <unistd.h>

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

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <unistd.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: <unistd.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

DFM_MOUNT_USE_NS

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
Expand Down Expand Up @@ -167,9 +170,13 @@
if (err)
qDebug() << "query password failed: " << passwd << err->message;
else {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// 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()));
#else
passwd.insert(kLoginPasswd, QString(pwd));
#endif
}
}
return passwds;
Expand Down Expand Up @@ -537,12 +544,56 @@
delete finalize;
}

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

// Prepare passwd
const QByteArray passwdBytes = passwd.toLocal8Bit();

// Create pipe
int pipefds[2];
if (pipe(pipefds) == -1) {
qCritical() << "Failed to create pipe:" << strerror(errno);
return QVariant("");
}

// pipefds[0] is for reading
// pipefds[1] is for writing
int read_fd = pipefds[0];
int write_fd = pipefds[1];

// Write passwd to pipe
qint64 bytesWritten = write(write_fd, passwdBytes.constData(), passwdBytes.size());
close(write_fd);
if (bytesWritten != passwdBytes.size()) {
qCritical() << "Failed to write passwd to pipe.";
close(read_fd);
return QVariant("");
}

// Create file descriptor wrapper
QDBusUnixFileDescriptor dbusFd(read_fd);
// read_fd has been copied to QDBusUnixFileDescriptor
close(read_fd);

qDebug() << "Successfully created fd for passwd transmission";
return QVariant::fromValue(dbusFd);
}

DNetworkMounter::MountRet DNetworkMounter::mountWithUserInput(const QString &address,
const MountPassInfo info)
{
QVariantMap param { { kLoginUser, info.userName },
{ kLoginDomain, info.domain },
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
{ kLoginPasswd, info.passwd },
#else
{ kLoginPasswd, preparePasswd(info.passwd) },
#endif
{ kLoginTimeout, info.timeout },
{ kMountFsType, "cifs" } };

Expand All @@ -562,11 +613,15 @@
err = DeviceError::kNoError;

if (!info.anonymous && info.savePasswd != NetworkMountPasswdSaveMode::kNeverSavePasswd) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// 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);
#else
savePasswd(address, info);
#endif
}
}

Expand All @@ -583,7 +638,11 @@
for (const auto &login : infos) {
QVariantMap param { { kLoginUser, login.value(kSchemaUser, "") },
{ kLoginDomain, login.value(kSchemaDomain, "") },
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
{ kLoginPasswd, login.value(kLoginPasswd, "") },
#else
{ kLoginPasswd, preparePasswd(login.value(kLoginPasswd, "").toString()) },
#endif
{ kLoginTimeout, secs },
{ kMountFsType, "cifs" } };

Expand Down
Loading