E-MailRelay

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gsecrets.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 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 // gsecrets.cpp
19 //
20
21 #include "gdef.h"
22 #include "gsecrets.h"
23 #include "gsecretsfile.h"
24 #include "gdebug.h"
25
26 GAuth::Secrets::Secrets( const std::string & path , const std::string & name , const std::string & type ) :
27 m_source(path) ,
28 m_imp(nullptr)
29 {
30 G_DEBUG( "GAuth::Secrets:ctor: [" << path << "]" ) ;
31 if( m_source != "/pam" )
32 m_imp = new SecretsFile(path,true,name,type) ;
33 }
34
35 GAuth::Secrets::Secrets() :
36 m_imp(nullptr)
37 {
38 if( m_source != "/pam" )
39 m_imp = new SecretsFile(std::string(),true,std::string(),std::string()) ;
40 }
41
42 GAuth::Secrets::~Secrets()
43 {
44 delete m_imp ;
45 }
46
47 std::string GAuth::Secrets::source() const
48 {
49 return m_source ;
50 }
51
52 bool GAuth::Secrets::valid() const
53 {
54 return m_source == "/pam" || m_imp->valid() ;
55 }
56
57 GAuth::Secret GAuth::Secrets::clientSecret( const std::string & mechanism ) const
58 {
59 return valid() ? m_imp->clientSecret(mechanism) : Secret::none() ;
60 }
61
62 GAuth::Secret GAuth::Secrets::serverSecret( const std::string & mechanism , const std::string & id ) const
63 {
64 return valid() ? m_imp->serverSecret( mechanism , id ) : Secret::none() ;
65 }
66
67 std::pair<std::string,std::string> GAuth::Secrets::serverTrust( const std::string & address_range ) const
68 {
69 return valid() ? m_imp->serverTrust( address_range ) : std::make_pair(std::string(),std::string()) ;
70 }
71
72 bool GAuth::Secrets::contains( const std::string & mechanism ) const
73 {
74 return valid() ? m_imp->contains( mechanism ) : false ;
75 }
76
77 /// \file gsecrets.cpp
GAuth::Secrets::clientSecret
virtual Secret clientSecret(const std::string &mechanism) const override
Override from GAuth::SaslClientSecrets.
Definition: gsecrets.cpp:57
GAuth::Secrets::valid
virtual bool valid() const override
Override from GAuth::Valid virtual base.
Definition: gsecrets.cpp:52
GAuth::Secrets::serverTrust
virtual std::pair< std::string, std::string > serverTrust(const std::string &address_range) const override
Override from GAuth::SaslServerSecrets.
Definition: gsecrets.cpp:67
GAuth::Secrets::Secrets
Secrets()
Default constructor for an in-valid(), empty-path object.
Definition: gsecrets.cpp:35
gsecretsfile.h
GAuth::SecretsFile
A class to read authentication secrets from file, used by GAuth::Secrets.
Definition: gsecretsfile.h:44
gsecrets.h
GAuth::Secrets::serverSecret
virtual Secret serverSecret(const std::string &mechanism, const std::string &id) const override
Override from GAuth::SaslServerSecrets.
Definition: gsecrets.cpp:62
GAuth::Secrets::~Secrets
virtual ~Secrets()
Destructor.
Definition: gsecrets.cpp:42
GAuth::Secrets::source
virtual std::string source() const override
Override from GAuth::SaslServerSecrets.
Definition: gsecrets.cpp:47
GAuth::Secret::none
static Secret none()
Factory function that returns a secret that is not valid() and has an empty id(). ...
Definition: gsecret.cpp:90
GAuth::Secrets::contains
virtual bool contains(const std::string &mechanism) const override
Override from GAuth::SaslServerSecrets.
Definition: gsecrets.cpp:72
GAuth::Secret
Encapsulates a shared secret from the secrets file plus the associated userid.
Definition: gsecret.h:42
gdebug.h