Rajan
Rajan

Reputation: 43

Error with external auth via ejabberd

I am implementing external authentication in ejabberd. I am using a PHP MySQL script that is provided by ejabberd. Unfortunately it is giving me an error when I am trying to connect with user details which are stored in a table.

=ERROR REPORT==== 2013-04-11 13:17:54 ===
E(<0.269.0>:extauth:133) : extauth call '["auth","admin","localhost","admin"]' didn't receive
response

=INFO REPORT==== 2013-04-11 13:17:54 ===
I(<0.462.0>:ejabberd_c2s:649) :
({socket_state,ejabberd_http_bind,{http_bind,<0.461.0>,{{127,0,0,1},39426}},ejabberd_http_bind})
Failed authentication for admin@localhost

Can anybody help me on this?

Upvotes: 0

Views: 827

Answers (2)

ETech
ETech

Reputation: 1607

Spent 1 day trying to get work ejabberd authorization.
Problem basicly appears in blocking the process while reading from stdin.
Here is a solution for non-block symbol by symbol reading from descriptor:

function non_block_read($fd, &$data) {
    $read = array($fd);
    $write = array();
    $except = array();
    $result = stream_select($read, $write, $except, 0);
    if($result === false) {
                throw new Exception('stream_select failed');
        }
    if($result === 0) return false;
    $data.= stream_get_line($fd, 1);
    return true;
}

Here is the daemon code also to make lifetime reading cycle.

$fh  = fopen("php://stdin", 'r');
$fhout  = fopen("php://stdout", 'w');
$pdo = new PDO('mysql:host='.$host.';dbname='.$db, $user,$pass);
if(!$fh){
    die("Cannot open STDIN\n");
}
$aStr='';
$collect=false;
do {
        if (!non_block_read($fh,$aStr)) {
                if (strlen($aStr) > 0) {
                       $toAuth = substr(trim($aStr),1);
                       checkAuth($toAuth,$pdo,$fhout);
                       $aStr='';
                }
                else sleep (1);
        }
}
while (true);

Some explaination: checkAuth - any function that implements 'auth' and 'isuser' handlers.
sleep(1) - simple way to escape CPU load.
First symbol - service symbol that prepends the message and it differs from client to client, so I just cut it.
Here is reply code. Reply - true | false values.

$message =  @pack("nn", 2, $result);
fwrite($stdout, $message);
flush();

Enjoy.

Upvotes: 0

user425720
user425720

Reputation: 3598

The error says that you did not received response from external program in 60 seconds (thats the default timeout).

Did you define it in extauth_program in ejabberd.cfg?

Upvotes: 0

Related Questions