You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

100 lines
2.4 KiB

  1. /* SLiM - Simple Login Manager
  2. Copyright (C) 2007 Martin Parm
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. */
  8. #ifndef _PAM_H_
  9. #define _PAM_H_
  10. #include <string>
  11. #include <security/pam_appl.h>
  12. #ifdef __LIBPAM_VERSION
  13. #include <security/pam_misc.h>
  14. #endif
  15. namespace PAM {
  16. class Exception{
  17. public:
  18. int errnum;
  19. std::string errstr;
  20. std::string func_name;
  21. Exception(pam_handle_t* _pam_handle,
  22. const std::string& _func_name,
  23. int _errnum);
  24. virtual ~Exception(void);
  25. };
  26. class Auth_Exception: public Exception{
  27. public:
  28. Auth_Exception(pam_handle_t* _pam_handle,
  29. const std::string& _func_name,
  30. int _errnum);
  31. };
  32. class Cred_Exception: public Exception{
  33. public:
  34. Cred_Exception(pam_handle_t* _pam_handle,
  35. const std::string& _func_name,
  36. int _errnum);
  37. };
  38. class Authenticator{
  39. private:
  40. struct pam_conv pam_conversation;
  41. pam_handle_t* pam_handle;
  42. int last_result;
  43. int _end(void);
  44. public:
  45. typedef int (conversation)(int num_msg,
  46. const struct pam_message **msg,
  47. struct pam_response **resp,
  48. void *appdata_ptr);
  49. enum ItemType {
  50. Service = PAM_SERVICE,
  51. User = PAM_USER,
  52. User_Prompt = PAM_USER_PROMPT,
  53. TTY = PAM_TTY,
  54. Requestor = PAM_RUSER,
  55. Host = PAM_RHOST,
  56. Conv = PAM_CONV,
  57. #ifdef __LIBPAM_VERSION
  58. /* Fail_Delay = PAM_FAIL_DELAY */
  59. #endif
  60. };
  61. public:
  62. Authenticator(conversation* conv, void* data=0);
  63. ~Authenticator(void);
  64. void start(const std::string& service);
  65. void end(void);
  66. void set_item(const ItemType item, const void* value);
  67. const void* get_item(const ItemType item);
  68. #ifdef __LIBPAM_VERSION
  69. void fail_delay(const unsigned int micro_sec);
  70. #endif
  71. void authenticate(void);
  72. void open_session(void);
  73. void close_session(void);
  74. void setenv(const std::string& key, const std::string& value);
  75. void delenv(const std::string& key);
  76. const char* getenv(const std::string& key);
  77. char** getenvlist(void);
  78. private:
  79. /* Explicitly disable copy constructor and copy assignment */
  80. Authenticator(const PAM::Authenticator&);
  81. Authenticator& operator=(const PAM::Authenticator&);
  82. };
  83. }
  84. std::ostream& operator<<( std::ostream& os, const PAM::Exception& e);
  85. #endif /* _PAM_H_ */