1: <?php
2: /**
3: * The Horde_Auth_Smbclient class provides an smbclient implementation of
4: * the Horde authentication system.
5: *
6: * Copyright 1999-2012 Horde LLC (http://www.horde.org/)
7: *
8: * See the enclosed file COPYING for license information (LGPL). If you did
9: * not receive this file, http://www.horde.org/licenses/lgpl21
10: *
11: * @author Jon Parise <jon@horde.org>
12: * @author Marcus I. Ryan <marcus@riboflavin.net>
13: * @category Horde
14: * @license http://www.horde.org/licenses/lgpl21 LGPL-2.1
15: * @package Auth
16: */
17: class Horde_Auth_Smbclient extends Horde_Auth_Base
18: {
19: /**
20: * Constructor.
21: *
22: * @param array $params Parameters:
23: * <pre>
24: * 'domain' - (string) [REQUIRED] The domain name to authenticate with.
25: * 'group' - Group name that the user must be a member of.
26: * DEFAULT: none
27: * 'hostspec' - (string) [REQUIRED] IP, DNS Name, or NetBios name of the
28: * SMB server to authenticate with.
29: * 'smbclient_path' - (string) [REQUIRED] The location of the smbclient
30: * utility.
31: * </pre>
32: *
33: * @throws InvalidArgumentException
34: */
35: public function __construct(array $params = array())
36: {
37: foreach (array('hostspec', 'domain', 'smbclient_path') as $val) {
38: throw new InvalidArgumentException('Missing ' . $val . ' parameter.');
39: }
40:
41: parent::__construct($params);
42: }
43:
44: /**
45: * Find out if the given set of login credentials are valid.
46: *
47: * @param string $userId The userId to check.
48: * @param array $credentials An array of login credentials.
49: *
50: * @throws Horde_Auth_Exception
51: */
52: protected function _authenticate($userId, $credentials)
53: {
54: if (empty($credentials['password'])) {
55: throw new Horde_Auth_Exception('', Horde_Auth::REASON_BADLOGIN);
56: }
57:
58: /* Authenticate. */
59: $cmdline = implode(' ', array(
60: $this->_params['smbclient_path'],
61: '-L',
62: $this->_params['hostspec'],
63: '-W',
64: $this->_params['domain'],
65: '-U',
66: $userId
67: ));
68:
69: $sc = popen($cmdline, 'w');
70: if ($sc === false) {
71: throw new Horde_Auth_Exception('Unable to execute smbclient.');
72: }
73:
74: fwrite($sc, $credentials['password']);
75: $rc = pclose($sc);
76:
77: if (intval($rc & 0xff) != 0) {
78: throw new Horde_Auth_Exception('', Horde_Auth::REASON_BADLOGIN);
79: }
80: }
81:
82: }
83: