1 |
#ifndef PAMWRAPPER_H |
2 |
#define PAMWRAPPER_H |
3 |
|
4 |
#include <security/pam_appl.h> |
5 |
#include <security/pam_misc.h> |
6 |
|
7 |
#include <string> |
8 |
|
9 |
/* virtual class - cannot be instantiated |
10 |
* you have to create a derived class and implement/override the 4 |
11 |
* virtual memberfunctions of this class |
12 |
*/ |
13 |
|
14 |
class PamWrapper { |
15 |
private: |
16 |
pam_handle_t *m_pamh; |
17 |
bool m_isStarted; |
18 |
std::string m_service; |
19 |
pam_conv m_conv; |
20 |
public: |
21 |
PamWrapper(std::string service); |
22 |
virtual ~PamWrapper(); |
23 |
|
24 |
// standard PAM functions |
25 |
int start(std::string username = ""); |
26 |
int authenticate(int flags = 0); |
27 |
int account(int flags = 0); |
28 |
int end(int status = 0); |
29 |
|
30 |
int setCred(int flags = 0); |
31 |
int openSession(int flags = 0); |
32 |
int closeSession(int flags = 0); |
33 |
int changeAuthToken(int flags = 0); |
34 |
|
35 |
// PAM utility functions |
36 |
std::string strError(int err); |
37 |
int putEnv(std::string nameValue); |
38 |
std::string getEnv(std::string name); |
39 |
//std::vector<std::string> getEnvList(); |
40 |
|
41 |
int setItem(int item_type, const void *item); |
42 |
int getItem(int item_type, const void **item); |
43 |
int failDelay(unsigned int usec); |
44 |
|
45 |
//override these functions, in your derived class |
46 |
virtual std::string promptEchoOff(std::string prompt) = 0; |
47 |
virtual std::string promptEchoOn(std::string prompt) = 0; |
48 |
virtual void errorMsg(std::string msg) = 0; |
49 |
virtual void textInfo(std::string msg) = 0; |
50 |
|
51 |
//all-in-one function |
52 |
//calls start(), authenticate(), account() and end() |
53 |
//returns true if auth and account where OK |
54 |
bool checkUser(std::string username = "", bool checkAccount = true); |
55 |
}; |
56 |
|
57 |
|
58 |
#endif //PAMWRAPPER_H |