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.

pam.php 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * PAM Password Driver
  4. *
  5. * @version 2.0
  6. * @author Aleksander Machniak
  7. *
  8. * Copyright (C) 2005-2013, The Roundcube Dev Team
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see http://www.gnu.org/licenses/.
  22. */
  23. class rcube_pam_password
  24. {
  25. function save($currpass, $newpass)
  26. {
  27. $user = $_SESSION['username'];
  28. $error = '';
  29. if (extension_loaded('pam') || extension_loaded('pam_auth')) {
  30. if (pam_auth($user, $currpass, $error, false)) {
  31. if (pam_chpass($user, $currpass, $newpass)) {
  32. return PASSWORD_SUCCESS;
  33. }
  34. }
  35. else {
  36. rcube::raise_error(array(
  37. 'code' => 600,
  38. 'type' => 'php',
  39. 'file' => __FILE__, 'line' => __LINE__,
  40. 'message' => "Password plugin: PAM authentication failed for user $user: $error"
  41. ), true, false);
  42. }
  43. }
  44. else {
  45. rcube::raise_error(array(
  46. 'code' => 600,
  47. 'type' => 'php',
  48. 'file' => __FILE__, 'line' => __LINE__,
  49. 'message' => "Password plugin: PECL-PAM module not loaded"
  50. ), true, false);
  51. }
  52. return PASSWORD_ERROR;
  53. }
  54. }