PdCom  5.3
Process data communication client
Loading...
Searching...
No Matches
SimpleLoginManager.h
Go to the documentation of this file.
1/*****************************************************************************
2 * vim:tw=78
3 *
4 * Copyright (C) 2021 Richard Hacker (lerichi at gmx dot net),
5 * Florian Pose (fp at igh dot de),
6 * Bjarne von Horn (vh at igh dot de).
7 *
8 * This file is part of the PdCom library.
9 *
10 * The PdCom library is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or (at your
13 * option) any later version.
14 *
15 * The PdCom library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with the PdCom library. If not, see <http://www.gnu.org/licenses/>.
22 *
23 *****************************************************************************/
24
26
27#ifndef PDCOM5_SIMPLELOGINMANAGER_H
28#define PDCOM5_SIMPLELOGINMANAGER_H
29
30#include "pdcom5-sasl_export.h"
31
32#include <memory>
33#include <pdcom5/Sasl.h>
34#include <stdexcept>
35#include <vector>
36
37extern "C" struct sasl_callback;
38
39namespace PdCom {
40namespace impl {
41class SimpleLoginManager;
42} // namespace impl
43
56
57class PDCOM5_SASL_EXPORT SimpleLoginManager : public Sasl
58{
59 friend class impl::SimpleLoginManager;
60 std::unique_ptr<impl::SimpleLoginManager> impl_;
61 void loginReply(const char *mechlist, const char *serverData, int finished)
62 override;
63
64 public:
72 static void InitLibrary(const char *plugin_path = nullptr);
75 static void FinalizeLibrary();
76
84 const char *remote_host,
85 sasl_callback *additional_callbacks = nullptr);
86 SimpleLoginManager(SimpleLoginManager &&) noexcept;
87 SimpleLoginManager &operator=(SimpleLoginManager &&) noexcept;
88
89
95 struct Cancel : std::exception
96 {};
97
99 enum class LoginResult {
100 Success,
101 Error,
102 Canceled,
105 };
106
107 protected:
108 virtual ~SimpleLoginManager();
109
124 bool login();
125
128 using Sasl::logout;
131 virtual std::string getAuthname() { throw Cancel(); }
134 virtual std::string getPassword() { throw Cancel(); }
137 virtual std::string
138 getRealm(const std::vector<const char *> & /* available realms */)
139 {
140 throw Cancel();
141 }
142
143 virtual std::string
144 getOption(const char * /*plugin_name*/, const char * /*option*/)
145 {
146 throw Cancel();
147 }
148
149 virtual std::string interact(
150 unsigned long /*id*/,
151 const char * /*challenge*/,
152 const char * /*prompt*/,
153 const char * /*default result*/)
154 {
155 throw Cancel();
156 }
157
161 virtual void completed(LoginResult result) = 0;
162
168 virtual void log(int level, const char *message);
169};
170
171} // namespace PdCom
172
173#endif // PDCOM5_SIMPLELOGINMANAGER_H
void logout()
Logout from server.
Wrapper for Cyrus SASL library.
Definition SimpleLoginManager.h:58
virtual std::string getOption(const char *, const char *)
SASL get option callback.
Definition SimpleLoginManager.h:144
SimpleLoginManager(const char *remote_host, sasl_callback *additional_callbacks=nullptr)
Constructor.
virtual std::string getPassword()
Callback to get password.
Definition SimpleLoginManager.h:134
virtual std::string getAuthname()
Callback to get login name.
Definition SimpleLoginManager.h:131
static void InitLibrary(const char *plugin_path=nullptr)
Sasl global initialization.
LoginResult
Result of login operation.
Definition SimpleLoginManager.h:99
@ NoSaslMechanism
No matching SASL Mechanism found on client machine.
Definition SimpleLoginManager.h:103
virtual std::string getRealm(const std::vector< const char * > &)
Callback to get realm.
Definition SimpleLoginManager.h:138
bool login()
Perform SASL login step.
virtual void log(int level, const char *message)
Log callback.
virtual std::string interact(unsigned long, const char *, const char *, const char *)
SASL interact callback.
Definition SimpleLoginManager.h:149
static void FinalizeLibrary()
Sasl global finalization.
virtual void completed(LoginResult result)=0
Authentification completed callback.
Exception for callback cancelation.
Definition SimpleLoginManager.h:96