1 |
2cd8d942
|
Pierre POMES
|
<?php
|
2 |
|
|
/*
|
3 |
|
|
* login_sasl_client.php
|
4 |
|
|
*
|
5 |
|
|
* @(#) $Id: login_sasl_client.php,v 1.2 2004/11/17 08:00:37 mlemos Exp $
|
6 |
|
|
*
|
7 |
|
|
*/
|
8 |
|
|
|
9 |
|
|
define("SASL_LOGIN_STATE_START", 0);
|
10 |
|
|
define("SASL_LOGIN_STATE_IDENTIFY_USER", 1);
|
11 |
|
|
define("SASL_LOGIN_STATE_IDENTIFY_PASSWORD", 2);
|
12 |
|
|
define("SASL_LOGIN_STATE_DONE", 3);
|
13 |
|
|
|
14 |
|
|
class login_sasl_client_class
|
15 |
|
|
{
|
16 |
|
|
var $credentials=array();
|
17 |
|
|
var $state=SASL_LOGIN_STATE_START;
|
18 |
|
|
|
19 |
|
|
Function Initialize(&$client)
|
20 |
|
|
{
|
21 |
|
|
return(1);
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
Function Start(&$client, &$message, &$interactions)
|
25 |
|
|
{
|
26 |
|
|
if($this->state!=SASL_LOGIN_STATE_START)
|
27 |
|
|
{
|
28 |
|
|
$client->error="LOGIN authentication state is not at the start";
|
29 |
|
|
return(SASL_FAIL);
|
30 |
|
|
}
|
31 |
|
|
$this->credentials=array(
|
32 |
|
|
"user"=>"",
|
33 |
|
|
"password"=>"",
|
34 |
|
|
"realm"=>""
|
35 |
|
|
);
|
36 |
|
|
$defaults=array(
|
37 |
|
|
"realm"=>""
|
38 |
|
|
);
|
39 |
|
|
$status=$client->GetCredentials($this->credentials,$defaults,$interactions);
|
40 |
|
|
if($status==SASL_CONTINUE)
|
41 |
|
|
$this->state=SASL_LOGIN_STATE_IDENTIFY_USER;
|
42 |
|
|
Unset($message);
|
43 |
|
|
return($status);
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
Function Step(&$client, $response, &$message, &$interactions)
|
47 |
|
|
{
|
48 |
|
|
switch($this->state)
|
49 |
|
|
{
|
50 |
|
|
case SASL_LOGIN_STATE_IDENTIFY_USER:
|
51 |
|
|
$message=$this->credentials["user"].(strlen($this->credentials["realm"]) ? "@".$this->credentials["realm"] : "");
|
52 |
|
|
$this->state=SASL_LOGIN_STATE_IDENTIFY_PASSWORD;
|
53 |
|
|
break;
|
54 |
|
|
case SASL_LOGIN_STATE_IDENTIFY_PASSWORD:
|
55 |
|
|
$message=$this->credentials["password"];
|
56 |
|
|
$this->state=SASL_LOGIN_STATE_DONE;
|
57 |
|
|
break;
|
58 |
|
|
case SASL_LOGIN_STATE_DONE:
|
59 |
|
|
$client->error="LOGIN authentication was finished without success";
|
60 |
|
|
break;
|
61 |
|
|
default:
|
62 |
|
|
$client->error="invalid LOGIN authentication step state";
|
63 |
|
|
return(SASL_FAIL);
|
64 |
|
|
}
|
65 |
|
|
return(SASL_CONTINUE);
|
66 |
|
|
}
|
67 |
|
|
};
|
68 |
|
|
|
69 |
|
|
?>
|