diff --git a/smb/CMakeLists.txt b/smb/CMakeLists.txt index 890c2fed..bd2a3e81 100644 --- a/smb/CMakeLists.txt +++ b/smb/CMakeLists.txt @@ -1,65 +1,75 @@ option(BUILD_KDSoapWSDiscoveryClient "Automatically build WSD client if a system one isn't found." ON) find_package(KDSoapWSDiscoveryClient QUIET) set(INTERNAL_WSDCLIENT ${BUILD_KDSoapWSDiscoveryClient}) if(KDSoapWSDiscoveryClient_FOUND) set(INTERNAL_WSDCLIENT OFF) endif() if(INTERNAL_WSDCLIENT) # Special internal version, mangled to be a STATIC lib. # This is only useful and necessary until the library has # its API finalized and gotten a stable release. add_subdirectory(kdsoap-ws-discovery-client) endif() add_feature_info("Internal KDSoapWSDiscoveryClient" INTERNAL_WSDCLIENT "Building using internal client because a system-provided version could not be found.") add_feature_info("SMB DNS-SD Discovery" HAVE_KDNSSD_WITH_SIGNAL_RACE_PROTECTION "Discover SMB hosts via DNS-SD/Avahi/Bonjour. KF5DNSSD >= 5.54 is required to support this.") add_definitions(-DTRANSLATION_DOMAIN=\"kio5_smb\") include(CheckIncludeFile) set(CMAKE_AUTOMAKE ON) check_include_file(utime.h HAVE_UTIME_H) configure_file(config-smb.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-smb.h) set(kio_smb_PART_SRCS kio_smb.cpp kio_smb_auth.cpp kio_smb_browse.cpp kio_smb_config.cpp kio_smb_dir.cpp kio_smb_file.cpp smburl.cpp kio_smb_mount.cpp wsdiscoverer.cpp dnssddiscoverer.cpp discovery.cpp ) ecm_qt_declare_logging_category(kio_smb_PART_SRCS HEADER smb-logsettings.h IDENTIFIER KIO_SMB_LOG CATEGORY_NAME log_kio_smb) include_directories(${SAMBA_INCLUDE_DIR}) -add_library(kio_smb MODULE ${kio_smb_PART_SRCS}) - -target_link_libraries(kio_smb +# Intermediate static lib target for reuse in testing. +add_library(kio_smb_static STATIC ${kio_smb_PART_SRCS}) +target_include_directories(kio_smb_static + PUBLIC + "$" +) +target_link_libraries(kio_smb_static KF5::KIOCore KF5::I18n ${SAMBA_LIBRARIES} Qt5::Network KF5::DNSSD KDSoap::WSDiscoveryClient ) +# Final plugin target. +add_library(kio_smb MODULE main.cpp) +target_link_libraries(kio_smb + kio_smb_static +) + set_target_properties(kio_smb PROPERTIES OUTPUT_NAME "smb") set_target_properties(kio_smb PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/kio") install(TARGETS kio_smb DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/kio) install(FILES smb-network.desktop DESTINATION ${KDE_INSTALL_DATADIR}/konqueror/dirtree/remote) install(FILES smb-network.desktop DESTINATION ${KDE_INSTALL_DATADIR}/remoteview) diff --git a/smb/kio_smb.cpp b/smb/kio_smb.cpp index ed28e2fa..d097a4c5 100644 --- a/smb/kio_smb.cpp +++ b/smb/kio_smb.cpp @@ -1,116 +1,101 @@ ///////////////////////////////////////////////////////////////////////////// // // Project: SMB kioslave for KDE // // File: Top level implementation file for kio_smb.cpp // // Abstract: member function implementations for SMBSlave // // Author(s): Matthew Peterson // //--------------------------------------------------------------------------- // // Copyright (c) 2000 Caldera Systems, Inc. // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the // Free Software Foundation; either version 2.1 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; see the file COPYING. If not, please obtain // a copy from https://www.gnu.org/copyleft/gpl.html // ///////////////////////////////////////////////////////////////////////////// #include "kio_smb.h" #include "smburl.h" #include #include // Pseudo plugin class to embed meta data class KIOPluginForMetaData : public QObject { Q_OBJECT Q_PLUGIN_METADATA(IID "org.kde.kio.slave.smb" FILE "smb.json") }; bool needsEEXISTWorkaround() { /* There is an issue with some libsmbclient versions that return EEXIST * return code from smbc_opendir() instead of EPERM when the user * tries to access a resource that requires login authetification. * We are working around the issue by treating EEXIST as a special case * of "invalid/unavailable credentials" if we detect that we are using * the affected versions of libsmbclient * * Upstream bug report: https://bugzilla.samba.org/show_bug.cgi?id=13050 */ static const QVersionNumber firstBrokenVer {4, 7, 0}; static const QVersionNumber lastBrokenVer {4, 7, 6}; const QVersionNumber currentVer = QVersionNumber::fromString(smbc_version()); qCDebug(KIO_SMB_LOG) << "Using libsmbclient library version" << currentVer; if (currentVer >= firstBrokenVer && currentVer <= lastBrokenVer) { qCDebug(KIO_SMB_LOG) << "Detected broken libsmbclient version" << currentVer; return true; } return false; } SMBSlave::SMBSlave(const QByteArray &pool, const QByteArray &app) : SlaveBase("smb", pool, app) , m_openFd(-1) , m_enableEEXISTWorkaround(needsEEXISTWorkaround()) { m_initialized_smbc = false; // read in the default workgroup info... reparseConfiguration(); // initialize the library... auth_initialize_smbc(); } SMBSlave::~SMBSlave() = default; void SMBSlave::virtual_hook(int id, void *data) { switch (id) { case SlaveBase::GetFileSystemFreeSpace: { QUrl *url = static_cast(data); fileSystemFreeSpace(*url); } break; case SlaveBase::Truncate: { auto length = static_cast(data); truncate(*length); } break; default: { SlaveBase::virtual_hook(id, data); } break; } } -int Q_DECL_EXPORT kdemain(int argc, char **argv) -{ - QCoreApplication app(argc, argv); - if (argc != 4) { - qCDebug(KIO_SMB_LOG) << "Usage: kio_smb protocol domain-socket1 domain-socket2"; - return -1; - } - - SMBSlave slave(argv[2], argv[3]); - - slave.dispatchLoop(); - - return 0; -} - #include "kio_smb.moc" diff --git a/smb/main.cpp b/smb/main.cpp new file mode 100644 index 00000000..979aab71 --- /dev/null +++ b/smb/main.cpp @@ -0,0 +1,46 @@ +///////////////////////////////////////////////////////////////////////////// +// +// Project: SMB kioslave for KDE +// +// Abstract: member function implementations for SMBSlave +// +// Author(s): Matthew Peterson +// +//--------------------------------------------------------------------------- +// +// Copyright (c) 2000 Caldera Systems, Inc. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, please obtain +// a copy from https://www.gnu.org/copyleft/gpl.html +// +///////////////////////////////////////////////////////////////////////////// + +#include + +#include "kio_smb.h" + +extern "C" int Q_DECL_EXPORT kdemain(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + if (argc != 4) { + qCDebug(KIO_SMB_LOG) << "Usage: kio_smb protocol domain-socket1 domain-socket2"; + return -1; + } + + SMBSlave slave(argv[2], argv[3]); + slave.dispatchLoop(); + + return 0; +} +