E-MailRelay

gsecrets.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 Graeme Walker <graeme_walker@users.sourceforge.net>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16// ===
17///
18/// \file gsecrets.h
19///
20
21#ifndef G_AUTH_SECRETS_H
22#define G_AUTH_SECRETS_H
23
24#include "gdef.h"
25#include "gpath.h"
26#include "gexception.h"
27#include "gsaslserversecrets.h"
28#include "gsaslclientsecrets.h"
29
30 namespace GAuth
31{
32 class Secrets ;
33 class SecretsFile ;
34}
35
36//| \class GAuth::Secrets
37/// A simple interface for a store of secrets used in authentication.
38/// The default implementation uses a flat file.
39///
40 class GAuth::Secrets : public SaslClientSecrets , public SaslServerSecrets
41{
42 public:
43 G_EXCEPTION( OpenError , "cannot read secrets file" ) ;
44
45 static void check( const std::string & , const std::string & , const std::string & ) ;
46 ///< Checks the given secret sources. Logs warnings and throws
47 ///< an exception if there are any fatal errors.
48
49 Secrets( const std::string & source_storage_path , const std::string & debug_name ) ;
50 ///< Constructor. The connection string is a secrets file path
51 ///< or "/pam".
52 ///<
53 ///< The 'debug-name' is used in log and error messages to
54 ///< identify the repository.
55 ///<
56 ///< Throws on error, although an empty path is not
57 ///< considered an error: see valid().
58
59 Secrets() ;
60 ///< Default constructor for an in-valid(), empty-path object.
61
62 bool valid() const override ;
63 ///< Override from GAuth::Valid virtual base.
64
65 Secret serverSecret( const std::string & type , const std::string & id ) const override ;
66 ///< Override from GAuth::SaslServerSecrets.
67
68 bool contains( const std::string & type ) const override ;
69 ///< Override from GAuth::SaslServerSecrets.
70
71 public:
72 ~Secrets() override ;
73 Secrets( const Secrets & ) = delete ;
74 Secrets( Secrets && ) = delete ;
75 void operator=( const Secrets & ) = delete ;
76 void operator=( Secrets && ) = delete ;
77
78 private: // overrides
79 std::string source() const override ; // Override from GAuth::SaslServerSecrets.
80 Secret clientSecret( const std::string & type ) const override ; // Override from GAuth::SaslClientSecrets.
81 std::pair<std::string,std::string> serverTrust( const std::string & address_range ) const override ; // Override from GAuth::SaslServerSecrets.
82
83 private:
84 std::string m_source ;
85 std::unique_ptr<SecretsFile> m_imp ;
86} ;
87
88#endif
GAuth::SaslClientSecrets
An interface used by GAuth::SaslClient to obtain a client id and its authentication secret.
Definition: gsaslclientsecrets.h:39
GAuth::SaslServerSecrets
An interface used by GAuth::SaslServer to obtain authentication secrets.
Definition: gsaslserversecrets.h:40
GAuth::Secret
Encapsulates a shared secret from the secrets file plus the associated userid.
Definition: gsecret.h:42
GAuth::Secrets
A simple interface for a store of secrets used in authentication.
Definition: gsecrets.h:41
GAuth::Secrets::serverSecret
Secret serverSecret(const std::string &type, const std::string &id) const override
Override from GAuth::SaslServerSecrets.
Definition: gsecrets.cpp:72
GAuth::Secrets::contains
bool contains(const std::string &type) const override
Override from GAuth::SaslServerSecrets.
Definition: gsecrets.cpp:82
GAuth::Secrets::check
static void check(const std::string &, const std::string &, const std::string &)
Checks the given secret sources.
Definition: gsecrets.cpp:27
GAuth::Secrets::Secrets
Secrets()
Default constructor for an in-valid(), empty-path object.
Definition: gsecrets.cpp:48
GAuth::Secrets::valid
bool valid() const override
Override from GAuth::Valid virtual base.
Definition: gsecrets.cpp:62
gexception.h
gpath.h
gsaslclientsecrets.h
gsaslserversecrets.h
GAuth
SASL authentication classes.
Definition: gcram.cpp:36