0
|
1 <?php
|
|
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 * Copyright (C) 2005-2013, The Roundcube Dev Team
|
|
24 *
|
|
25 * This program is free software: you can redistribute it and/or modify
|
|
26 * it under the terms of the GNU General Public License as published by
|
|
27 * the Free Software Foundation, either version 3 of the License, or
|
|
28 * (at your option) any later version.
|
|
29 *
|
|
30 * This program is distributed in the hope that it will be useful,
|
|
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
33 * GNU General Public License for more details.
|
|
34 *
|
|
35 * You should have received a copy of the GNU General Public License
|
|
36 * along with this program. If not, see http://www.gnu.org/licenses/.
|
|
37 */
|
|
38
|
|
39 class rcube_smb_password
|
|
40 {
|
|
41
|
|
42 public function save($currpass, $newpass)
|
|
43 {
|
|
44 $host = rcmail::get_instance()->config->get('password_smb_host','localhost');
|
|
45 $bin = rcmail::get_instance()->config->get('password_smb_cmd','/usr/bin/smbpasswd');
|
|
46 $username = $_SESSION['username'];
|
|
47
|
|
48 $host = rcube_utils::parse_host($host);
|
|
49 $tmpfile = tempnam(sys_get_temp_dir(),'smb');
|
|
50 $cmd = $bin . ' -r ' . $host . ' -s -U "' . $username . '" > ' . $tmpfile . ' 2>&1';
|
|
51 $handle = @popen($cmd, 'w');
|
|
52
|
|
53 fputs($handle, $currpass."\n");
|
|
54 fputs($handle, $newpass."\n");
|
|
55 fputs($handle, $newpass."\n");
|
|
56 @pclose($handle);
|
|
57 $res = file($tmpfile);
|
|
58 unlink($tmpfile);
|
|
59
|
|
60 if (strstr($res[count($res) - 1], 'Password changed for user') !== false) {
|
|
61 return PASSWORD_SUCCESS;
|
|
62 }
|
|
63 else {
|
|
64 rcube::raise_error(array(
|
|
65 'code' => 600,
|
|
66 'type' => 'php',
|
|
67 'file' => __FILE__, 'line' => __LINE__,
|
|
68 'message' => "Password plugin: Unable to execute $cmd"
|
|
69 ), true, false);
|
|
70 }
|
|
71
|
|
72 return PASSWORD_ERROR;
|
|
73 }
|
|
74 }
|