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

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2020 Harald Sitter <sitter@kde.org>
0004 */
0005 
0006 #pragma once
0007 
0008 #include "smbcontext.h"
0009 
0010 #include <QString>
0011 
0012 namespace KIO
0013 {
0014 class AuthInfo;
0015 }
0016 
0017 // Abstracts WorkerBase API so Authenticator may be used without
0018 // a WorkerBase for the KDirNotify implementation)
0019 class SMBAbstractFrontend
0020 {
0021 public:
0022     virtual ~SMBAbstractFrontend() = default;
0023     virtual bool checkCachedAuthentication(KIO::AuthInfo &info) = 0;
0024 };
0025 
0026 // Base class for SMBC management + basic authentication
0027 class SMBAuthenticator
0028 {
0029 public:
0030     SMBAuthenticator(SMBAbstractFrontend &frontend);
0031 
0032     QString defaultWorkgroup() const;
0033     void setDefaultWorkgroup(const QString &workGroup);
0034 
0035     // Callback for authentication requests.
0036     void
0037     auth(SMBCCTX *context, const char *server, const char *share, char *workgroup, int wgmaxlen, char *username, int unmaxlen, char *password, int pwmaxlen);
0038 
0039 private:
0040     // Frontend for authentication requests.
0041     SMBAbstractFrontend &m_frontend;
0042 
0043     QString m_defaultUser;
0044     QString m_defaultPassword;
0045     QString m_defaultEncoding;
0046     QString m_defaultWorkgroup = QStringLiteral("WORKGROUP"); // overwritten with value from smbc
0047 
0048     Q_DISABLE_COPY(SMBAuthenticator)
0049 };