File: PAM.h

package info (click to toggle)
slim 1.3.6-4
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,456 kB
  • ctags: 472
  • sloc: cpp: 4,085; ansic: 209; sh: 196; makefile: 24
file content (99 lines) | stat: -rw-r--r-- 2,440 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* SLiM - Simple Login Manager
   Copyright (C) 2007 Martin Parm

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
*/

#ifndef _PAM_H_
#define _PAM_H_
#include <string>
#include <security/pam_appl.h>

#ifdef __LIBPAM_VERSION
#include <security/pam_misc.h>
#endif

namespace PAM {
	class Exception{
	public:
		int errnum;
		std::string errstr;
		std::string func_name;
		Exception(pam_handle_t* _pam_handle,
				  const std::string& _func_name,
				  int _errnum);
		virtual ~Exception(void);
	};

	class Auth_Exception: public Exception{
	public:
		Auth_Exception(pam_handle_t* _pam_handle,
					   const std::string& _func_name,
					   int _errnum);
	};

	class Cred_Exception: public Exception{
	public:
		Cred_Exception(pam_handle_t* _pam_handle,
					   const std::string& _func_name,
					   int _errnum);
	};


	class Authenticator{
	private:
		struct pam_conv pam_conversation;
		pam_handle_t* pam_handle;
		int last_result;

		int _end(void);
	public:
		typedef int (conversation)(int num_msg,
						   const struct pam_message **msg,
						   struct pam_response **resp,
						   void *appdata_ptr);

		enum ItemType {
			Service	 = PAM_SERVICE,
			User		= PAM_USER,
			User_Prompt = PAM_USER_PROMPT,
			TTY		 = PAM_TTY,
			Requestor   = PAM_RUSER,
			Host		= PAM_RHOST,
			Conv		= PAM_CONV,
#ifdef __LIBPAM_VERSION
			/* Fail_Delay  = PAM_FAIL_DELAY */
#endif
		};

	public:
		Authenticator(conversation* conv, void* data=0);
		~Authenticator(void);
		
		void start(const std::string& service);
		void end(void);
		void set_item(const ItemType item, const void* value);
		const void* get_item(const ItemType item);
#ifdef __LIBPAM_VERSION
		void fail_delay(const unsigned int micro_sec);
#endif
		void authenticate(void);
		void open_session(void);
		void close_session(void);
		void setenv(const std::string& key, const std::string& value);
		void delenv(const std::string& key);
		const char* getenv(const std::string& key);
		char** getenvlist(void);

	private:
		/* Explicitly disable copy constructor and copy assignment */
		Authenticator(const PAM::Authenticator&);
		Authenticator& operator=(const PAM::Authenticator&);
	};
}

std::ostream& operator<<( std::ostream& os, const PAM::Exception& e);
#endif /* _PAM_H_ */