gpam.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 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 // ===
20 
21 #ifndef G_PAM_H
22 #define G_PAM_H
23 
24 #include "gdef.h"
25 #include "gexception.h"
26 #include <string>
27 #include <vector>
28 
30 namespace G
31 {
32  class Pam ;
33  class PamImp ;
34 }
35 
58 class G::Pam
59 {
60 public:
62  struct Item
63  {
64  const std::string in_type ; // "password", "prompt", "error", "info"
65  const std::string in ; // password prompt, non-password prompt, error text, infomation message, etc
66  std::string out ; // password, or whatever was prompted for
67  bool out_defined ; // to be set to true if 'out' is assigned
68  } ;
69  typedef std::vector<Item> ItemArray ;
70 
72  class Error : public G::Exception
73  {
74  public: int m_pam_error ;
75  public: Error( const std::string & op , int pam_error ) ;
76  public: Error( const std::string & op , int pam_error , const char * ) ;
77  } ;
78 
79  Pam( const std::string & app , const std::string & user , bool silent ) ;
81 
82  virtual ~Pam() ;
84 
85  bool authenticate( bool require_token ) ;
92 
93  std::string name() const ;
97 
98  void checkAccount( bool require_token ) ;
101 
102  void establishCredentials() ;
105 
106  void openSession() ;
108 
109  void closeSession() ;
111 
112  void deleteCredentials() ;
114 
115  void reinitialiseCredentials() ;
117 
118  void refreshCredentials() ;
120 
121  virtual void converse( ItemArray & ) = 0 ;
138 
139  virtual void delay( unsigned int usec ) = 0 ;
154 
155 private:
156  Pam( const Pam & ) ; // not implemented
157  void operator=( const Pam & ) ; // not implemented
158 
159 private:
160  PamImp * m_imp ;
161 } ;
162 
163 #endif
164 
std::string out
Definition: gpam.h:66
virtual void converse(ItemArray &)=0
Called to pass a message to the user, or request a password etc.
Error(const std::string &op, int pam_error)
Definition: gpam.cpp:27
void closeSession()
Closes a session.
Definition: gpam_linux.cpp:385
const std::string in_type
Definition: gpam.h:64
std::string name() const
Returns the authenticated user name.
Definition: gpam_linux.cpp:418
void refreshCredentials()
Refreshes credentials.
Definition: gpam_linux.cpp:401
void checkAccount(bool require_token)
Does "account management", checking that the authenticated user is currently allowed to use the syste...
Definition: gpam_linux.cpp:367
bool out_defined
Definition: gpam.h:67
void reinitialiseCredentials()
Reinitialises credentials.
Definition: gpam_linux.cpp:396
std::vector< Item > ItemArray
Definition: gpam.h:69
void openSession()
Starts a session.
Definition: gpam_linux.cpp:379
An exception class used by G::Pam.
Definition: gpam.h:72
void establishCredentials()
Embues the authenticated user with their credentials, such as "tickets" in the form of environment va...
Definition: gpam_linux.cpp:373
A structure used by G::Pam to hold conversation items.
Definition: gpam.h:62
bool authenticate(bool require_token)
Authenticates the user.
Definition: gpam_linux.cpp:361
Low-level classes.
Pam(const std::string &app, const std::string &user, bool silent)
Constructor.
Definition: gpam_linux.cpp:351
virtual void delay(unsigned int usec)=0
Called when the pam library wants the application to introduce a delay to prevent brute-force attacks...
Definition: gpam_linux.cpp:406
A pimple-pattern implementation class for Pam.
Definition: gpam_linux.cpp:60
A general-purpose exception class derived from std::exception and containing a std::string.
Definition: gexception.h:44
virtual ~Pam()
Destructor.
Definition: gpam_linux.cpp:356
void deleteCredentials()
Deletes credentials.
Definition: gpam_linux.cpp:391
const std::string in
Definition: gpam.h:65
int m_pam_error
Definition: gpam.h:74
A thin abstract interface to the system PAM library.
Definition: gpam.h:58