File indexing completed on 2024-04-28 04:58:02
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 extern "C" { 0009 #include <libsmbclient.h> 0010 } 0011 0012 #include <memory> 0013 0014 class SMBAuthenticator; 0015 0016 // Encapsulates an SMBC context 0017 class SMBContext 0018 { 0019 public: 0020 SMBContext(SMBAuthenticator *authenticator); 0021 0022 bool isValid() const; 0023 0024 SMBCCTX *smbcctx() const 0025 { 0026 return m_context.get(); 0027 } 0028 0029 operator SMBCCTX *() const 0030 { 0031 return smbcctx(); 0032 } 0033 0034 // Authenticator associated with this context. 0035 // TODO: getter only used in checkpassword, could be refactored away maybe 0036 SMBAuthenticator *authenticator() const 0037 { 0038 return m_authenticator.get(); 0039 } 0040 0041 private: 0042 static void 0043 auth_cb(SMBCCTX *context, const char *server, const char *share, char *workgroup, int wgmaxlen, char *username, int unmaxlen, char *password, int pwmaxlen); 0044 0045 static void freeContext(SMBCCTX *ptr); 0046 0047 std::unique_ptr<SMBCCTX, decltype(&freeContext)> m_context; 0048 std::unique_ptr<SMBAuthenticator> m_authenticator; 0049 };