Commit a1775f44 authored by Harald Sitter's avatar Harald Sitter 🏳🌈
Browse files

smb: ecm clang-format the entire code base

Summary:
over the past 20 years smb has gathered a whole bunch of different
styles with varying indention and code styles. time to unify again

I've done some cherry picking of the clang-format run since it had
a tendency of worsening some long lines.

Test Plan: builds and still lists stuff

Reviewers: ngraham

Subscribers: kde-frameworks-devel, kfm-devel

Tags: #dolphin, #frameworks

Differential Revision: https://phabricator.kde.org/D27676
parent 74850eb2
......@@ -21,8 +21,8 @@
#ifndef DISCOVERY_H
#define DISCOVERY_H
#include <QSharedPointer>
#include <KIO/UDSEntry>
#include <QSharedPointer>
class Discovery
{
......@@ -50,4 +50,3 @@ public:
};
#endif // DISCOVERY_H
......@@ -78,8 +78,7 @@ DNSSDDiscoverer::DNSSDDiscoverer()
}
}
connect(service.data(), &KDNSSD::RemoteService::resolved,
this, [=] {
connect(service.data(), &KDNSSD::RemoteService::resolved, this, [=] {
++m_resolvedCount;
emit newDiscovery(Discovery::Ptr(new DNSSDDiscovery(service)));
maybeFinish();
......
......@@ -23,8 +23,8 @@
#include <QObject>
#include <DNSSD/ServiceBrowser>
#include <DNSSD/RemoteService>
#include <DNSSD/ServiceBrowser>
#include "discovery.h"
......@@ -55,7 +55,7 @@ private:
void stop() override;
void maybeFinish();
KDNSSD::ServiceBrowser m_browser { QStringLiteral("_smb._tcp") };
KDNSSD::ServiceBrowser m_browser {QStringLiteral("_smb._tcp")};
QList<KDNSSD::RemoteService::Ptr> m_services;
int m_resolvedCount = 0;
bool m_disconnected = false;
......
......@@ -51,8 +51,8 @@ bool needsEEXISTWorkaround()
*
* 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};
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;
......@@ -65,27 +65,25 @@ bool needsEEXISTWorkaround()
return false;
}
//===========================================================================
SMBSlave::SMBSlave(const QByteArray& pool, const QByteArray& app)
: SlaveBase( "smb", pool, app ),
m_openFd(-1),
m_enableEEXISTWorkaround(needsEEXISTWorkaround())
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...
// read in the default workgroup info...
reparseConfiguration();
//initialize the library...
// initialize the library...
auth_initialize_smbc();
}
//===========================================================================
SMBSlave::~SMBSlave() = default;
void SMBSlave::virtual_hook(int id, void *data) {
switch(id) {
void SMBSlave::virtual_hook(int id, void *data)
{
switch (id) {
case SlaveBase::GetFileSystemFreeSpace: {
QUrl *url = static_cast<QUrl *>(data);
fileSystemFreeSpace(*url);
......@@ -100,17 +98,15 @@ void SMBSlave::virtual_hook(int id, void *data) {
}
}
//===========================================================================
int Q_DECL_EXPORT kdemain( int argc, char **argv )
int Q_DECL_EXPORT kdemain(int argc, char **argv)
{
QCoreApplication app(argc, argv);
if( argc != 4 )
{
if (argc != 4) {
qCDebug(KIO_SMB_LOG) << "Usage: kio_smb protocol domain-socket1 domain-socket2";
return -1;
}
SMBSlave slave( argv[2], argv[3] );
SMBSlave slave(argv[2], argv[3]);
slave.dispatchLoop();
......
......@@ -32,7 +32,6 @@
//
/////////////////////////////////////////////////////////////////////////////
#ifndef KIO_SMB_H_INCLUDED
#define KIO_SMB_H_INCLUDED
......@@ -49,30 +48,29 @@
//-----------------------------
// Standard C library includes
//-----------------------------
#include <arpa/inet.h>
#include <errno.h>
#include <net/if.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
#include <time.h>
//-----------------------------
// Qt includes
//-----------------------------
#include <QLoggingCategory>
#include <QObject>
#include <QUrl>
#include <QLoggingCategory>
//-------------------------------
// Samba client library includes
//-------------------------------
extern "C"
{
extern "C" {
#include <libsmbclient.h>
}
......@@ -81,19 +79,17 @@ extern "C"
//---------------------------
#include "kio_smb_internal.h"
#define MAX_XFER_BUF_SIZE 65534
#define MAX_XFER_BUF_SIZE 65534
using namespace KIO;
//===========================================================================
class SMBSlave : public QObject, public KIO::SlaveBase
{
Q_OBJECT
private:
class SMBError {
class SMBError
{
public:
int kioErrorId;
QString errorString;
......@@ -102,33 +98,34 @@ private:
//---------------------------------------------------------------------
// please make sure your private data does not duplicate existing data
//---------------------------------------------------------------------
bool m_initialized_smbc;
bool m_initialized_smbc;
/**
* From Controlcenter
*/
QString m_default_user;
QString m_default_workgroup = QStringLiteral("WORKGROUP"); // overwritten with value from smbc
QString m_default_password;
QString m_default_encoding;
QString m_default_user;
QString m_default_workgroup = QStringLiteral("WORKGROUP"); // overwritten with value from smbc
QString m_default_password;
QString m_default_encoding;
/**
* we store the current url, it's needed for
* callback authorization method
*/
SMBUrl m_current_url;
SMBUrl m_current_url;
/**
* From Controlcenter, show SHARE$ or not
*/
// bool m_showHiddenShares; //currently unused, Alex <neundorf@kde.org>
// bool m_showHiddenShares; //currently unused, Alex <neundorf@kde.org>
/**
* libsmbclient need global variables to store in,
* else it crashes on exit next method after use cache_stat,
* looks like gcc (C/C++) failure
*/
struct stat st{};
struct stat st {
};
protected:
//---------------------------------------------
......@@ -136,7 +133,6 @@ protected:
//---------------------------------------------
// (please prefix functions with auth)
/**
* Description : Initializes the libsmbclient
* Return : true on success false with errno set on error
......@@ -145,12 +141,11 @@ protected:
int checkPassword(SMBUrl &url);
//---------------------------------------------
// Cache functions (kio_smb_auth.cpp)
//---------------------------------------------
//Stat methods
// Stat methods
//-----------------------------------------
// Browsing functions (kio_smb_browse.cpp)
......@@ -163,7 +158,7 @@ protected:
* Parameter : SMBUrl the url to stat
* Return : cache_stat() return code
*/
int browse_stat_path(const SMBUrl& url, UDSEntry& udsentry);
int browse_stat_path(const SMBUrl &url, UDSEntry &udsentry);
/**
* Description : call smbc_stat and return stats of the url
......@@ -174,20 +169,18 @@ protected:
* method segfault on returning try to change the stat*
* variable
*/
int cache_stat( const SMBUrl& url, struct stat* st );
int cache_stat(const SMBUrl &url, struct stat *st);
//---------------------------------------------
// Configuration functions (kio_smb_config.cpp)
//---------------------------------------------
// (please prefix functions with config)
//---------------------------------------
// Directory functions (kio_smb_dir.cpp)
//---------------------------------------
// (please prefix functions with dir)
//--------------------------------------
// File IO functions (kio_smb_file.cpp)
//--------------------------------------
......@@ -197,7 +190,6 @@ protected:
// Misc functions (this file)
//----------------------------
/**
* Description : correct a given URL
* valid URL's are
......@@ -214,21 +206,16 @@ protected:
* Parameter : QUrl the url to check
* Return : new QUrl if it is corrected. else the same QUrl
*/
QUrl checkURL(const QUrl& kurl) const;
QUrl checkURL(const QUrl &kurl) const;
void reportError(const SMBUrl& url, const int errNum);
void reportWarning(const SMBUrl& url, const int errNum);
void reportError(const SMBUrl &url, const int errNum);
void reportWarning(const SMBUrl &url, const int errNum);
public:
//-----------------------------------------------------------------------
// smbclient authentication callback (note that this is called by the
// global ::auth_smbc_get_data() call.
void auth_smbc_get_data(const char *server,const char *share,
char *workgroup, int wgmaxlen,
char *username, int unmaxlen,
char *password, int pwmaxlen);
void auth_smbc_get_data(const char *server, const char *share, char *workgroup, int wgmaxlen, char *username, int unmaxlen, char *password, int pwmaxlen);
//-----------------------------------------------------------------------
// Overwritten functions from the base class that define the operation of
......@@ -237,52 +224,52 @@ public:
//-----------------------------------------------------------------------
// Functions overwritten in kio_smb.cpp
SMBSlave(const QByteArray& pool, const QByteArray& app);
SMBSlave(const QByteArray &pool, const QByteArray &app);
~SMBSlave() override;
// Functions overwritten in kio_smb_browse.cpp
void listDir( const QUrl& url ) override;
void stat( const QUrl& url ) override;
void listDir(const QUrl &url) override;
void stat(const QUrl &url) override;
// Functions overwritten in kio_smb_config.cpp
void reparseConfiguration() override;
// Functions overwritten in kio_smb_dir.cpp
void copy( const QUrl& src, const QUrl &dst, int permissions, KIO::JobFlags flags ) override;
void del( const QUrl& kurl, bool isfile) override;
void mkdir( const QUrl& kurl, int permissions ) override;
void rename( const QUrl& src, const QUrl& dest, KIO::JobFlags flags ) override;
void copy(const QUrl &src, const QUrl &dst, int permissions, KIO::JobFlags flags) override;
void del(const QUrl &kurl, bool isfile) override;
void mkdir(const QUrl &kurl, int permissions) override;
void rename(const QUrl &src, const QUrl &dest, KIO::JobFlags flags) override;
// Functions overwritten in kio_smb_file.cpp
void get( const QUrl& kurl ) override;
void put( const QUrl& kurl, int permissions, KIO::JobFlags flags ) override;
void open( const QUrl& kurl, QIODevice::OpenMode mode ) override;
void read( KIO::filesize_t bytesRequested ) override;
void write( const QByteArray &fileData ) override;
void seek( KIO::filesize_t offset ) override;
void truncate( KIO::filesize_t length );
void get(const QUrl &kurl) override;
void put(const QUrl &kurl, int permissions, KIO::JobFlags flags) override;
void open(const QUrl &kurl, QIODevice::OpenMode mode) override;
void read(KIO::filesize_t bytesRequested) override;
void write(const QByteArray &fileData) override;
void seek(KIO::filesize_t offset) override;
void truncate(KIO::filesize_t length);
void close() override;
// Functions not implemented (yet)
//virtual void setHost(const QString& host, int port, const QString& user, const QString& pass);
//virtual void openConnection();
//virtual void closeConnection();
//virtual void slave_status();
void special( const QByteArray & ) override;
// virtual void setHost(const QString& host, int port, const QString& user, const QString& pass);
// virtual void openConnection();
// virtual void closeConnection();
// virtual void slave_status();
void special(const QByteArray &) override;
protected:
void virtual_hook(int id, void *data) override;
private:
SMBError errnumToKioError(const SMBUrl& url, const int errNum);
void smbCopy(const QUrl& src, const QUrl &dst, int permissions, KIO::JobFlags flags);
void smbCopyGet(const QUrl& ksrc, const QUrl& kdst, int permissions, KIO::JobFlags flags);
void smbCopyPut(const QUrl& ksrc, const QUrl& kdst, int permissions, KIO::JobFlags flags);
SMBError errnumToKioError(const SMBUrl &url, const int errNum);
void smbCopy(const QUrl &src, const QUrl &dst, int permissions, KIO::JobFlags flags);
void smbCopyGet(const QUrl &ksrc, const QUrl &kdst, int permissions, KIO::JobFlags flags);
void smbCopyPut(const QUrl &ksrc, const QUrl &kdst, int permissions, KIO::JobFlags flags);
bool workaroundEEXIST(const int errNum) const;
void fileSystemFreeSpace(const QUrl &url);
/**
/**
* Used in open(), read(), write(), and close()
* FIXME Placing these in the private section above causes m_openUrl = kurl
* to fail in SMBSlave::open. Need to find out why this is.
......@@ -297,26 +284,14 @@ private:
//==========================================================================
// the global libsmbclient authentication callback function
extern "C"
{
void auth_smbc_get_data(SMBCCTX * context,
const char *server,const char *share,
char *workgroup, int wgmaxlen,
char *username, int unmaxlen,
char *password, int pwmaxlen);
extern "C" {
void auth_smbc_get_data(SMBCCTX *context, const char *server, const char *share, char *workgroup, int wgmaxlen, char *username, int unmaxlen, char *password, int pwmaxlen);
}
//===========================================================================
// Main slave entrypoint (see kio_smb.cpp)
extern "C"
{
int kdemain( int argc, char **argv );
extern "C" {
int kdemain(int argc, char **argv);
}
#endif //#endif KIO_SMB_H_INCLUDED
#endif //#endif KIO_SMB_H_INCLUDED
......@@ -32,25 +32,22 @@
#include "kio_smb.h"
#include "kio_smb_internal.h"
#include <cstdlib>
#include <kconfig.h>
#include <kconfiggroup.h>
#include <klocalizedstring.h>
#include <cstdlib>
// call for libsmbclient
//==========================================================================
void auth_smbc_get_data(SMBCCTX * context,
const char *server,const char *share,
char *workgroup, int wgmaxlen,
char *username, int unmaxlen,
char *password, int pwmaxlen)
//==========================================================================
{
if (context != nullptr) {
#ifdef DEPRECATED_SMBC_INTERFACE
auto *theSlave = static_cast<SMBSlave*>(smbc_getOptionUserData(context));
auto *theSlave = static_cast<SMBSlave *>(smbc_getOptionUserData(context));
#else
auto *theSlave = static_cast<SMBSlave*>(smbc_option_get(context, "user_data"));
auto *theSlave = static_cast<SMBSlave *>(smbc_option_get(context, "user_data"));
#endif
theSlave->auth_smbc_get_data(server, share,
workgroup,wgmaxlen,
......@@ -60,17 +57,14 @@ void auth_smbc_get_data(SMBCCTX * context,
}
//--------------------------------------------------------------------------
void SMBSlave::auth_smbc_get_data(const char *server,const char *share,
char *workgroup, int wgmaxlen,
char *username, int unmaxlen,
char *password, int pwmaxlen)
//--------------------------------------------------------------------------
{
//check this to see if we "really" need to authenticate...
// check this to see if we "really" need to authenticate...
SMBUrlType t = m_current_url.getType();
if( t == SMBURLTYPE_ENTIRE_NETWORK )
{
if (t == SMBURLTYPE_ENTIRE_NETWORK) {
qCDebug(KIO_SMB_LOG) << "we don't really need to authenticate for this top level url, returning";
return;
}
......@@ -98,16 +92,12 @@ void SMBSlave::auth_smbc_get_data(const char *server,const char *share,
qCDebug(KIO_SMB_LOG) << "libsmb-auth-callback URL:" << info.url;
if ( !checkCachedAuthentication( info ) )
{
if ( m_default_user.isEmpty() )
{
if (!checkCachedAuthentication(info)) {
if (m_default_user.isEmpty()) {
// ok, we do not know the password. Let's try anonymous before we try for real
info.username = "anonymous";
info.password.clear();
}
else
{
} else {
// user defined a default username/password in kcontrol; try this
info.username = m_default_user;
info.password = m_default_password;
......@@ -154,17 +144,15 @@ int SMBSlave::checkPassword(SMBUrl &url)
info.setExtraField("anonymous", true); // arbitrary default for dialog
info.setExtraField("domain", m_default_workgroup);
if ( share.isEmpty() )
info.prompt = i18n(
"<qt>Please enter authentication information for <b>%1</b></qt>" ,
url.host() );
if (share.isEmpty())
info.prompt = i18n("<qt>Please enter authentication information for <b>%1</b></qt>", url.host());
else
info.prompt = i18n(
"Please enter authentication information for:\n"
"Server = %1\n"
"Share = %2" ,
url.host() ,
share );
"Please enter authentication information for:\n"
"Server = %1\n"
"Share = %2",
url.host(),
share);
info.username = url.userName();
qCDebug(KIO_SMB_LOG) << "call openPasswordDialog for " << info.url;
......@@ -186,10 +174,6 @@ int SMBSlave::checkPassword(SMBUrl &url)
return passwordDialogErrorCode;
}
//--------------------------------------------------------------------------
// Initializes the smbclient library
//
// Returns: 0 on success -1 with errno set on error
bool SMBSlave::auth_initialize_smbc()
{
if (m_initialized_smbc) {
......@@ -219,7 +203,7 @@ bool SMBSlave::auth_initialize_smbc()
#else
smb_context->debug = debug_level;
smb_context->callbacks.auth_fn = NULL;
smbc_option_set(smb_context, "auth_function", (void*)::auth_smbc_get_data);
smbc_option_set(smb_context, "auth_function", (void *)::auth_smbc_get_data);
smbc_option_set(smb_context, "user_data", this);
#if defined(SMB_CTX_FLAG_USE_KERBEROS) && defined(SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS)
......
This diff is collapsed.
......@@ -35,31 +35,30 @@
#include <kconfiggroup.h>
#include <QTextCodec>
//===========================================================================
void SMBSlave::reparseConfiguration()
{
KConfig cfg("kioslaverc", KConfig::NoGlobals);
const KConfigGroup group = cfg.group("Browser Settings/SMBro");
m_default_user = group.readEntry("User");
// m_default_workgroup=group.readEntry("Workgroup");
// m_showHiddenShares=group.readEntry("ShowHiddenShares", QVariant(false)).toBool();
KConfig cfg("kioslaverc", KConfig::NoGlobals);
const KConfigGroup group = cfg.group("Browser Settings/SMBro");
m_default_user = group.readEntry("User");
// m_default_workgroup=group.readEntry("Workgroup");
// m_showHiddenShares=group.readEntry("ShowHiddenShares", QVariant(false)).toBool();
QString m_encoding = QTextCodec::codecForLocale()->name();
m_default_encoding = group.readEntry( "Encoding", m_encoding.toLower() );
QString m_encoding = QTextCodec::codecForLocale()->name();
m_default_encoding = group.readEntry("Encoding", m_encoding.toLower());
// unscramble, taken from Nicola Brodu's smb ioslave
//not really secure, but better than storing the plain password
QString scrambled = group.readEntry( "Password" );
m_default_password = "";
for (int i=0; i<scrambled.length()/3; i++)
{
QChar qc1 = scrambled[i*3];
QChar qc2 = scrambled[i*3+1];
QChar qc3 = scrambled[i*3+2];
unsigned int a1 = qc1.toLatin1() - '0';
unsigned int a2 = qc2.toLatin1() - 'A';
unsigned int a3 = qc3.toLatin1() - '0';
unsigned int num = ((a1 & 0x3F) << 10) | ((a2& 0x1F) << 5) | (a3 & 0x1F);
m_default_password[i] = QChar((uchar)((num - 17) ^ 173)); // restore
}
// unscramble, taken from Nicola Brodu's smb ioslave
// not really secure, but better than storing the plain password
QString scrambled = group.readEntry("Password");
m_default_password = "";
for (int i = 0; i < scrambled.length() / 3; i++) {
QChar qc1 = scrambled[i * 3];
QChar qc2 = scrambled[i * 3 + 1];
QChar qc3 = scrambled[i * 3 + 2];
unsigned int a1 = qc1.toLatin1() - '0';
unsigned int a2 = qc2.toLatin1() - 'A';
unsigned int a3 = qc3.toLatin1() - '0';
unsigned int num = ((a1 & 0x3F) << 10) | ((a2 & 0x1F) << 5) | (a3 & 0x1F);
m_default_password[i] = QChar((uchar)((num - 17) ^ 173)); // restore
}
}
This diff is collapsed.
......@@ -29,28 +29,26 @@
//
/////////////////////////////////////////////////////////////////////////////
#include "kio_smb.h"
#include "kio_smb_internal.h"
#include <QVarLengthArray>
#include <QDateTime>
#include <QMimeDatabase>
#include <QMimeType>
#include <QVarLengthArray>
//===========================================================================
void SMBSlave::get( const QUrl& kurl )
void SMBSlave::get(const QUrl &kurl)
{
char buf[MAX_XFER_BUF_SIZE];
int filefd = 0;
int errNum = 0;
ssize_t bytesread = 0;
char buf[MAX_XFER_BUF_SIZE];
int filefd = 0;
int errNum = 0;
ssize_t bytesread = 0;
// time_t curtime = 0;
// time_t lasttime = 0; // Disabled durint port to Qt5/KF5. Seems to be unused.
// time_t starttime = 0; // Disabled durint port to Qt5/KF5. Seems to be unused.
KIO::filesize_t totalbytesread = 0;
QByteArray filedata;
SMBUrl url;
KIO::filesize_t totalbytesread = 0;
QByteArray filedata;
SMBUrl url;
qCDebug(KIO_SMB_LOG) << kurl;