Thomas Bruederli
2013-06-20 07c6c69eca8751c0e96a846afb30c24ab2638b1f
commit | author | age
48e9c1 1 <?php
T 2
3 /**
4  * smb Driver
5  *
6  * Driver that adds functionality to change the systems user password via
7  * the 'smbpasswd' command.
8  *
9  * For installation instructions please read the README file.
10  *
11  * @version 2.0
12  * @author Andy Theuninck <gohanman@gmail.com)
13  *
14  * Based on chpasswd roundcubemail password driver by
15  * @author Alex Cartwright <acartwright@mutinydesign.co.uk)
16  * and smbpasswd horde passwd driver by
17  * @author  Rene Lund Jensen <Rene@lundjensen.net>
18  *
19  * Configuration settings:
20  * password_smb_host    => samba host (default: localhost)
21  * password_smb_cmd => smbpasswd binary (default: /usr/bin/smbpasswd)
22  */
23
24 class rcube_smb_password
25 {
26
27     public function save($currpass, $newpass)
28     {
e0d466 29         $host     = rcmail::get_instance()->config->get('password_smb_host','localhost');
AM 30         $bin      = rcmail::get_instance()->config->get('password_smb_cmd','/usr/bin/smbpasswd');
48e9c1 31         $username = $_SESSION['username'];
T 32
e0d466 33         $host     = rcube_utils::parse_host($host);
AM 34         $tmpfile  = tempnam(sys_get_temp_dir(),'smb');
35         $cmd      = $bin . ' -r ' . $host . ' -s -U "' . $username . '" > ' . $tmpfile . ' 2>&1';
36         $handle   = @popen($cmd, 'w');
37
48e9c1 38         fputs($handle, $currpass."\n");
T 39         fputs($handle, $newpass."\n");
40         fputs($handle, $newpass."\n");
41         @pclose($handle);
42         $res = file($tmpfile);
43         unlink($tmpfile);
44
45         if (strstr($res[count($res) - 1], 'Password changed for user') !== false) {
46             return PASSWORD_SUCCESS;
47         }
48         else {
61be82 49             rcube::raise_error(array(
48e9c1 50                 'code' => 600,
T 51                 'type' => 'php',
52                 'file' => __FILE__, 'line' => __LINE__,
53                 'message' => "Password plugin: Unable to execute $cmd"
54                 ), true, false);
55         }
56
57         return PASSWORD_ERROR;
58     }
59
60 }