File: smbcontext.h

package info (click to toggle)
kio-extras 4%3A22.12.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,768 kB
  • sloc: cpp: 26,898; ansic: 4,443; perl: 1,058; xml: 97; sh: 69; python: 28; makefile: 9
file content (52 lines) | stat: -rw-r--r-- 1,166 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
    SPDX-License-Identifier: GPL-2.0-or-later
    SPDX-FileCopyrightText: 2020 Harald Sitter <sitter@kde.org>
*/

#pragma once

extern "C" {
#include <libsmbclient.h>
}

#include <memory>

class SMBAuthenticator;

// Encapsulates an SMBC context
class SMBContext
{
public:
    SMBContext(SMBAuthenticator *authenticator);

    bool isValid() const;

    SMBCCTX *smbcctx() const
    {
        return m_context.get();
    }

    operator SMBCCTX *() const
    {
        return smbcctx();
    }

    // Authenticator associated with this context.
    // TODO: getter only used in checkpassword, could be refactored away maybe
    SMBAuthenticator *authenticator() const
    {
        return m_authenticator.get();
    }

private:
    static void auth_cb(SMBCCTX *context,
                        const char *server,const char *share,
                        char *workgroup, int wgmaxlen,
                        char *username, int unmaxlen,
                        char *password, int pwmaxlen);

    static void freeContext(SMBCCTX *ptr);

    std::unique_ptr<SMBCCTX, decltype(&freeContext)> m_context;
    std::unique_ptr<SMBAuthenticator> m_authenticator;
};