E-MailRelay

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gsecretsfile.h
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 /// \file gsecretsfile.h
19 ///
20
21 #ifndef G_AUTH_SECRETS_FILE_H
22 #define G_AUTH_SECRETS_FILE_H
23
24 #include "gdef.h"
25 #include "gpath.h"
26 #include "gdatetime.h"
27 #include "gsecret.h"
28 #include <string>
29 #include <vector>
30 #include <map>
31 #include <set>
32 #include <iostream>
33 #include <utility>
34
35 namespace GAuth
36 {
37 class SecretsFile ;
38 }
39
40 /// \class GAuth::SecretsFile
41 /// A class to read authentication secrets from file, used by GAuth::Secrets.
42 /// Updates to the file are detected automatically.
43 ///
44 class GAuth::SecretsFile
45 {
46 public:
47 SecretsFile( const G::Path & path , bool auto_reread , const std::string & debug_name ,
48 const std::string & server_type = std::string() ) ;
49 ///< Constructor to read "client" and "<server-type>" records
50 ///< from the named file. The server type defaults to "server".
51 ///< The filename path is optional; see valid().
52
53 ~SecretsFile() ;
54 ///< Destructor.
55
56 bool valid() const ;
57 ///< Returns true if the file path was supplied in the ctor.
58
59 Secret clientSecret( const std::string & encoding_type ) const ;
60 ///< Returns the client id and secret for the given encoding-type.
61 ///< Returns the empty string if none.
62
63 Secret serverSecret( const std::string & encoding_type , const std::string & id ) const ;
64 ///< Returns the server secret for the given id and encoding-type.
65 ///< Returns the empty string if none.
66
67 std::pair<std::string,std::string> serverTrust( const std::string & address_range ) const ;
68 ///< Returns a non-empty trustee name if the server trusts clients
69 ///< in the given address range, together with context information.
70
71 std::string path() const ;
72 ///< Returns the file path, as supplied to the ctor.
73
74 bool contains( const std::string & server_encoding_type ) const ;
75 ///< Returns true if the given server encoding-type is represented.
76
77 private:
78 void process( unsigned int , std::string side , std::string , std::string , std::string ) ;
79 void warning( unsigned int , const std::string & , const std::string & ) ;
80 static std::string canonical( const std::string & encoding_type ) ;
81 static std::string serverKey( std::string , const std::string & ) ;
82 static std::string clientKey( std::string ) ;
83 void read( const G::Path & ) ;
84 void read( std::istream & ) ;
85 void reread() const ;
86 void reread(int) ;
87 static G::EpochTime readFileTime( const G::Path & ) ;
88 static std::string context( unsigned int ) ;
89
90 private:
91 struct Value { Value(const std::string &s_,unsigned int n_):s(s_),n(n_) {} std::string s ; unsigned int n ; } ;
92 typedef std::map<std::string,Value> Map ;
93 typedef std::set<std::string> Set ;
94 typedef std::pair<unsigned long,std::string> Warning ;
95 typedef std::vector<Warning> Warnings ;
96 G::Path m_path ;
97 bool m_auto ;
98 std::string m_debug_name ;
99 std::string m_server_type ;
100 bool m_valid ;
101 Map m_map ;
102 Set m_types ;
103 Warnings m_warnings ;
104 G::EpochTime m_file_time ;
105 G::EpochTime m_check_time ;
106 } ;
107
108 #endif
G::EpochTime
A subsecond-resolution timestamp based on a time_t.
Definition: gdatetime.h:39
GAuth::SecretsFile::serverTrust
std::pair< std::string, std::string > serverTrust(const std::string &address_range) const
Returns a non-empty trustee name if the server trusts clients in the given address range...
Definition: gsecretsfile.cpp:260
GAuth::SecretsFile::SecretsFile
SecretsFile(const G::Path &path, bool auto_reread, const std::string &debug_name, const std::string &server_type=std::string())
Constructor to read "client" and "" records from the named file.
Definition: gsecretsfile.cpp:38
GAuth::SecretsFile::valid
bool valid() const
Returns true if the file path was supplied in the ctor.
Definition: gsecretsfile.cpp:58
GAuth::SecretsFile::~SecretsFile
~SecretsFile()
Destructor.
Definition: gsecretsfile.cpp:54
gsecret.h
GAuth::SecretsFile::serverSecret
Secret serverSecret(const std::string &encoding_type, const std::string &id) const
Returns the server secret for the given id and encoding-type.
Definition: gsecretsfile.cpp:242
GAuth::SecretsFile
A class to read authentication secrets from file, used by GAuth::Secrets.
Definition: gsecretsfile.h:44
GAuth::SecretsFile::path
std::string path() const
Returns the file path, as supplied to the ctor.
Definition: gsecretsfile.cpp:274
GAuth::SecretsFile::clientSecret
Secret clientSecret(const std::string &encoding_type) const
Returns the client id and secret for the given encoding-type.
Definition: gsecretsfile.cpp:225
GAuth::SecretsFile::contains
bool contains(const std::string &server_encoding_type) const
Returns true if the given server encoding-type is represented.
Definition: gsecretsfile.cpp:279
gdatetime.h
gpath.h
GAuth
SASL authentication classes.
Definition: gcram.h:30
GAuth::Secret
Encapsulates a shared secret from the secrets file plus the associated userid.
Definition: gsecret.h:42
G::Path
A Path object represents a file system path.
Definition: gpath.h:72