1
|
<?php
|
2
|
/*
|
3
|
* plain_sasl_client.php
|
4
|
*
|
5
|
* @(#) $Id: plain_sasl_client.php,v 1.2 2004/11/17 08:00:37 mlemos Exp $
|
6
|
*
|
7
|
*/
|
8
|
|
9
|
define("SASL_PLAIN_STATE_START", 0);
|
10
|
define("SASL_PLAIN_STATE_IDENTIFY", 1);
|
11
|
define("SASL_PLAIN_STATE_DONE", 2);
|
12
|
|
13
|
define("SASL_PLAIN_DEFAULT_MODE", 0);
|
14
|
define("SASL_PLAIN_EXIM_MODE", 1);
|
15
|
define("SASL_PLAIN_EXIM_DOCUMENTATION_MODE", 2);
|
16
|
|
17
|
class plain_sasl_client_class
|
18
|
{
|
19
|
var $credentials=array();
|
20
|
var $state=SASL_PLAIN_STATE_START;
|
21
|
|
22
|
Function Initialize(&$client)
|
23
|
{
|
24
|
return(1);
|
25
|
}
|
26
|
|
27
|
Function Start(&$client, &$message, &$interactions)
|
28
|
{
|
29
|
if($this->state!=SASL_PLAIN_STATE_START)
|
30
|
{
|
31
|
$client->error="PLAIN authentication state is not at the start";
|
32
|
return(SASL_FAIL);
|
33
|
}
|
34
|
$this->credentials=array(
|
35
|
"user"=>"",
|
36
|
"password"=>"",
|
37
|
"realm"=>"",
|
38
|
"mode"=>""
|
39
|
);
|
40
|
$defaults=array(
|
41
|
"realm"=>"",
|
42
|
"mode"=>""
|
43
|
);
|
44
|
$status=$client->GetCredentials($this->credentials,$defaults,$interactions);
|
45
|
if($status==SASL_CONTINUE)
|
46
|
{
|
47
|
switch($this->credentials["mode"])
|
48
|
{
|
49
|
case SASL_PLAIN_EXIM_MODE:
|
50
|
$message=$this->credentials["user"]."\0".$this->credentials["password"]."\0";
|
51
|
break;
|
52
|
case SASL_PLAIN_EXIM_DOCUMENTATION_MODE:
|
53
|
$message="\0".$this->credentials["user"]."\0".$this->credentials["password"];
|
54
|
break;
|
55
|
default:
|
56
|
$message=$this->credentials["user"]."\0".$this->credentials["user"].(strlen($this->credentials["realm"]) ? "@".$this->credentials["realm"] : "")."\0".$this->credentials["password"];
|
57
|
break;
|
58
|
}
|
59
|
$this->state=SASL_PLAIN_STATE_DONE;
|
60
|
}
|
61
|
else
|
62
|
Unset($message);
|
63
|
return($status);
|
64
|
}
|
65
|
|
66
|
Function Step(&$client, $response, &$message, &$interactions)
|
67
|
{
|
68
|
switch($this->state)
|
69
|
{
|
70
|
/*
|
71
|
case SASL_PLAIN_STATE_IDENTIFY:
|
72
|
switch($this->credentials["mode"])
|
73
|
{
|
74
|
case SASL_PLAIN_EXIM_MODE:
|
75
|
$message=$this->credentials["user"]."\0".$this->credentials["password"]."\0";
|
76
|
break;
|
77
|
case SASL_PLAIN_EXIM_DOCUMENTATION_MODE:
|
78
|
$message="\0".$this->credentials["user"]."\0".$this->credentials["password"];
|
79
|
break;
|
80
|
default:
|
81
|
$message=$this->credentials["user"]."\0".$this->credentials["user"].(strlen($this->credentials["realm"]) ? "@".$this->credentials["realm"] : "")."\0".$this->credentials["password"];
|
82
|
break;
|
83
|
}
|
84
|
var_dump($message);
|
85
|
$this->state=SASL_PLAIN_STATE_DONE;
|
86
|
break;
|
87
|
*/
|
88
|
case SASL_PLAIN_STATE_DONE:
|
89
|
$client->error="PLAIN authentication was finished without success";
|
90
|
return(SASL_FAIL);
|
91
|
default:
|
92
|
$client->error="invalid PLAIN authentication step state";
|
93
|
return(SASL_FAIL);
|
94
|
}
|
95
|
return(SASL_CONTINUE);
|
96
|
}
|
97
|
};
|
98
|
|
99
|
?>
|