File indexing completed on 2024-04-28 04:58:00

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2000 Caldera Systems Inc.
0004     SPDX-FileContributor: Matthew Peterson <mpeterson@caldera.com>
0005 */
0006 
0007 #include "kio_smb.h"
0008 #include <QCoreApplication>
0009 #include <QVersionNumber>
0010 
0011 // Pseudo plugin class to embed meta data
0012 class KIOPluginForMetaData : public QObject
0013 {
0014     Q_OBJECT
0015     Q_PLUGIN_METADATA(IID "org.kde.kio.worker.smb" FILE "smb.json")
0016 };
0017 
0018 bool needsEEXISTWorkaround()
0019 {
0020     /* There is an issue with some libsmbclient versions that return EEXIST
0021      * return code from smbc_opendir() instead of EPERM when the user
0022      * tries to access a resource that requires login authetication.
0023      * We are working around the issue by treating EEXIST as a special case
0024      * of "invalid/unavailable credentials" if we detect that we are using
0025      * the affected versions of libsmbclient
0026      *
0027      * Upstream bug report: https://bugzilla.samba.org/show_bug.cgi?id=13050
0028      */
0029     static const QVersionNumber firstBrokenVer{4, 7, 0};
0030     static const QVersionNumber lastBrokenVer{4, 7, 6};
0031 
0032     const QVersionNumber currentVer = QVersionNumber::fromString(smbc_version());
0033     qCDebug(KIO_SMB_LOG) << "Using libsmbclient library version" << currentVer;
0034 
0035     if (currentVer >= firstBrokenVer && currentVer <= lastBrokenVer) {
0036         qCDebug(KIO_SMB_LOG) << "Detected broken libsmbclient version" << currentVer;
0037         return true;
0038     }
0039 
0040     return false;
0041 }
0042 
0043 SMBWorker::SMBWorker(const QByteArray &pool, const QByteArray &app)
0044     : WorkerBase("smb", pool, app)
0045     , m_openFd(-1)
0046     , m_enableEEXISTWorkaround(needsEEXISTWorkaround())
0047 {
0048 }
0049 
0050 WorkerFrontend::WorkerFrontend(SMBWorker &worker)
0051     : m_worker(worker)
0052 {
0053 }
0054 
0055 bool WorkerFrontend::checkCachedAuthentication(AuthInfo &info)
0056 {
0057     return m_worker.checkCachedAuthentication(info);
0058 }
0059 
0060 #include "kio_smb.moc"
0061 #include "moc_kio_smb.cpp"