1818#include < libmount.h>
1919
2020#include < unistd.h>
21+ #include < sys/mman.h>
2122
2223DFM_MOUNT_USE_NS
2324
@@ -170,13 +171,7 @@ QList<QVariantMap> DNetworkMounter::loginPasswd(const QString &address)
170171 if (err)
171172 qDebug () << " query password failed: " << passwd << err->message ;
172173 else {
173- #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
174- // since daemon accept base64-ed passwd to mount cifs, cleartext should be encoded with base64
175- // see commit of dde-file-manager: 3b50664d4034754b15c1a516cfaab8c7fbdd3db9
176- passwd.insert (kLoginPasswd , QString (QByteArray (pwd).toBase64 ()));
177- #else
178174 passwd.insert (kLoginPasswd , QString (pwd));
179- #endif
180175 }
181176 }
182177 return passwds;
@@ -551,36 +546,29 @@ static QVariant preparePasswd(const QString &passwd)
551546 return QVariant (" " );
552547 }
553548
554- // Prepare passwd
555- const QByteArray passwdBytes = passwd.toLocal8Bit ();
549+ int fd = memfd_create (" DBusFD" , MFD_CLOEXEC );
550+ if (fd < 0 ) {
551+ qCritical () << " Failed to create memfd for data transfer" ;
552+ return QVariant (" " );
553+ }
556554
557- // Create pipe
558- int pipefds[2 ];
559- if (pipe (pipefds) == -1 ) {
560- qCritical () << " Failed to create pipe:" << strerror (errno);
555+ QByteArray byteData = passwd.toUtf8 ();
556+ ssize_t written = ::write (fd, byteData.constData (), byteData.size ());
557+ if (written < 0 || static_cast <ssize_t >(byteData.size ()) != written) {
558+ qCritical () << " Failed to write data to memfd" ;
559+ ::close (fd);
561560 return QVariant (" " );
562561 }
563562
564- // pipefds[0] is for reading
565- // pipefds[1] is for writing
566- int read_fd = pipefds[0 ];
567- int write_fd = pipefds[1 ];
568-
569- // Write passwd to pipe
570- qint64 bytesWritten = write (write_fd, passwdBytes.constData (), passwdBytes.size ());
571- close (write_fd);
572- if (bytesWritten != passwdBytes.size ()) {
573- qCritical () << " Failed to write passwd to pipe." ;
574- close (read_fd);
563+ if (lseek (fd, 0 , SEEK_SET ) < 0 ) {
564+ qCritical () << " Failed to seek memfd to beginning" ;
565+ ::close (fd);
575566 return QVariant (" " );
576567 }
577568
578- // Create file descriptor wrapper
579- QDBusUnixFileDescriptor dbusFd (read_fd);
580- // read_fd has been copied to QDBusUnixFileDescriptor
581- close (read_fd);
569+ QDBusUnixFileDescriptor dbusFd;
570+ dbusFd.giveFileDescriptor (fd);
582571
583- qDebug () << " Successfully created fd for passwd transmission" ;
584572 return QVariant::fromValue (dbusFd);
585573}
586574
@@ -589,11 +577,7 @@ DNetworkMounter::MountRet DNetworkMounter::mountWithUserInput(const QString &add
589577{
590578 QVariantMap param { { kLoginUser , info.userName },
591579 { kLoginDomain , info.domain },
592- #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
593- { kLoginPasswd , info.passwd },
594- #else
595580 { kLoginPasswd , preparePasswd (info.passwd ) },
596- #endif
597581 { kLoginTimeout , info.timeout },
598582 { kMountFsType , " cifs" } };
599583
@@ -613,15 +597,7 @@ DNetworkMounter::MountRet DNetworkMounter::mountWithUserInput(const QString &add
613597 err = DeviceError::kNoError ;
614598
615599 if (!info.anonymous && info.savePasswd != NetworkMountPasswdSaveMode::kNeverSavePasswd ) {
616- #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
617- // since passwd from user input is base64-ed data, so the passwd should be decoded into cleartext for saving.
618- // associated commit of dde-file-manager: 3b50664d4034754b15c1a516cfaab8c7fbdd3db9
619- auto _info = info;
620- _info.passwd = QByteArray::fromBase64 (info.passwd .toLocal8Bit ());
621- savePasswd (address, _info);
622- #else
623600 savePasswd (address, info);
624- #endif
625601 }
626602 }
627603
@@ -638,11 +614,7 @@ DNetworkMounter::MountRet DNetworkMounter::mountWithSavedInfos(const QString &ad
638614 for (const auto &login : infos) {
639615 QVariantMap param { { kLoginUser , login.value (kSchemaUser , " " ) },
640616 { kLoginDomain , login.value (kSchemaDomain , " " ) },
641- #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
642- { kLoginPasswd , login.value (kLoginPasswd , " " ) },
643- #else
644617 { kLoginPasswd , preparePasswd (login.value (kLoginPasswd , " " ).toString ()) },
645- #endif
646618 { kLoginTimeout , secs },
647619 { kMountFsType , " cifs" } };
648620
0 commit comments