1: <?php
2: /**
3: * IMSP authentication class for authentication through imtest.
4: *
5: * Required parameters:<pre>
6: * 'username' Username to logon to IMSP server as.
7: * 'password' Password for current user.
8: * 'server' The hostname of the IMSP server.
9: * 'port' The port of the IMSP server.
10: * 'socket' The named socket to use for connection
11: * 'command' Path to the imtest command on localhost
12: * 'auth_mechanism' Authentication method to use with imtest</pre>
13: *
14: * Copyright 2005-2007 Liam Hoekenga <liamr@umich.edu>
15: * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
16: *
17: * See the enclosed file COPYING for license information (LGPL). If you
18: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
19: *
20: * @author Liam Hoekenga <liamr@umich.edu>
21: * @author Michael J Rubinsky <mrubinsk@horde.org>
22: * @package Horde_Imsp
23: */
24: class Horde_Imsp_Auth_Imtest extends Horde_Imsp_Auth_Base
25: {
26: /**
27: * Private authentication function. Provides actual
28: * authentication code.
29: *
30: * @return boolean
31: */
32: protected function _authenticate()
33: {
34: $command = '';
35: $error_return = '';
36: if (strtolower($this->_params['auth_mechanism']) == 'gssapi' &&
37: isset($_SERVER['KRB5CCNAME'])) {
38: $command .= 'KRB5CCNAME=' . $_SERVER['KRB5CCNAME'];
39: }
40:
41: $command .= ' ' . $this->_params['command'].
42: ' -m ' . $this->_params['auth_mechanism'] .
43: ' -u ' . escapeshellarg($this->_params['username']) .
44: ' -a ' . escapeshellarg($this->_params['username']) .
45: ' -w ' . escapeshellarg($this->_params['password']).
46: ' -p ' . $this->_params['port'] .
47: ' -X ' . $this->_params['socket'] .
48: ' ' . $this->_params['server'];
49:
50: $conn_attempts = 0;
51: while ($conn_attempts++ < 4) {
52: $attempts = 0;
53: if (!file_exists($this->_params['socket'])) {
54: exec($command . ' > /dev/null 2>&1');
55: sleep(1);
56: while (!file_exists($this->_params['socket'])) {
57: usleep(200000);
58: if ($attempts++ > 5) {
59: $error_return = ': No socket after 10 seconds of trying!';
60: continue 2;
61: }
62: }
63: }
64: $fp = @fsockopen($this->_params['socket'], 0, $error_number, $error_string, 30);
65: $error_return = $error_string;
66: if ($fp) break;
67: unlink($this->_params['socket']);
68:
69: }
70: //Failure?
71: if (!empty($error_return)) {
72: throw new Horde_Imsp_Exception('Connection to IMSP host failed.');
73: }
74: //Success
75: // @TODO:
76: $this->_imsp->_stream = $fp;
77:
78: return true;
79: }
80:
81: /**
82: * Force a logout command to the imsp stream.
83: *
84: */
85: public function logout()
86: {
87: $this->_imsp->logout();
88: }
89:
90: /**
91: * Returns the driver type.
92: *
93: * @return string The type of this IMSP_Auth driver.
94: */
95: public function getDriverType()
96: {
97: return 'imtest';
98: }
99:
100: }
101: