Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

smb.php 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * smb Driver
  4. *
  5. * Driver that adds functionality to change the systems user password via
  6. * the 'smbpasswd' command.
  7. *
  8. * For installation instructions please read the README file.
  9. *
  10. * @version 2.0
  11. * @author Andy Theuninck <gohanman@gmail.com)
  12. *
  13. * Based on chpasswd roundcubemail password driver by
  14. * @author Alex Cartwright <acartwright@mutinydesign.co.uk)
  15. * and smbpasswd horde passwd driver by
  16. * @author Rene Lund Jensen <Rene@lundjensen.net>
  17. *
  18. * Configuration settings:
  19. * password_smb_host => samba host (default: localhost)
  20. * password_smb_cmd => smbpasswd binary (default: /usr/bin/smbpasswd)
  21. *
  22. * Copyright (C) 2005-2013, The Roundcube Dev Team
  23. *
  24. * This program is free software: you can redistribute it and/or modify
  25. * it under the terms of the GNU General Public License as published by
  26. * the Free Software Foundation, either version 3 of the License, or
  27. * (at your option) any later version.
  28. *
  29. * This program is distributed in the hope that it will be useful,
  30. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  32. * GNU General Public License for more details.
  33. *
  34. * You should have received a copy of the GNU General Public License
  35. * along with this program. If not, see http://www.gnu.org/licenses/.
  36. */
  37. class rcube_smb_password
  38. {
  39. public function save($currpass, $newpass)
  40. {
  41. $host = rcmail::get_instance()->config->get('password_smb_host','localhost');
  42. $bin = rcmail::get_instance()->config->get('password_smb_cmd','/usr/bin/smbpasswd');
  43. $username = $_SESSION['username'];
  44. $host = rcube_utils::parse_host($host);
  45. $tmpfile = tempnam(sys_get_temp_dir(),'smb');
  46. $cmd = $bin . ' -r ' . $host . ' -s -U "' . $username . '" > ' . $tmpfile . ' 2>&1';
  47. $handle = @popen($cmd, 'w');
  48. fputs($handle, $currpass."\n");
  49. fputs($handle, $newpass."\n");
  50. fputs($handle, $newpass."\n");
  51. @pclose($handle);
  52. $res = file($tmpfile);
  53. unlink($tmpfile);
  54. if (strstr($res[count($res) - 1], 'Password changed for user') !== false) {
  55. return PASSWORD_SUCCESS;
  56. }
  57. else {
  58. rcube::raise_error(array(
  59. 'code' => 600,
  60. 'type' => 'php',
  61. 'file' => __FILE__, 'line' => __LINE__,
  62. 'message' => "Password plugin: Unable to execute $cmd"
  63. ), true, false);
  64. }
  65. return PASSWORD_ERROR;
  66. }
  67. }