Guest User

Untitled

a guest
Jul 18th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. require "pam"
  2.  
  3. class PamWrapper
  4. def initialize
  5. @login = nil
  6. @password = nil
  7. end
  8.  
  9. def conv_callback
  10. password = @password ? @password : nil
  11.  
  12. [PAM::Response.new(password, 0)]
  13. end
  14.  
  15. def set_pairs(user=nil, password=nil)
  16. @user = user
  17. @password = password
  18. self
  19. end
  20.  
  21. def auth
  22. user = @user ? @user : nil
  23. conv = proc{conv_callback}
  24. conv_data = ""
  25.  
  26. PAM.start("system-auth", user, conv, conv_data){|pam|
  27. begin
  28. pam.authenticate(0)
  29. rescue PAM::PAM_USER_UNKNOWN
  30. print("unknown user: #{pam.get_item(PAM::PAM_USER)}")
  31. raise pam.status.inspect
  32. rescue PAM::PAM_AUTH_ERR
  33. print("authentication error: #{pam.get_item(PAM::PAM_USER)}\n")
  34. print("error code = #{pam.status}\n")
  35. raise pam.status.inspect
  36. rescue PAM::PAMError
  37. print("error code = #{pam.status}\n")
  38. raise pam.status.inspect
  39. end
  40.  
  41. print("\n",
  42. "authenticated!\n")
  43. }
  44. end
  45. end
Add Comment
Please, Sign In to add comment