开发者

ejabberd php mysql external auth failure and termination

I am trying to setup extauth with ejabberd, however i just cannot get it working (even after googling for a fix on web). I have set following inside ejabberd.cfg:

{auth_method, external}.
{extauth_program, "/etc/ejabberd/extauth.class.php"}.

When i restart ejabberd after updating configs, I see this towards the end of ejabberd.log:

=ERROR REPORT==== 2010-12-26 15:38:10 ===
C(<0.4476.0>:extauth:110) : normal

=INFO REPORT==== 2010-12-26 15:38:10 ===
I(<0.4181.0>:ejabberd_app:69) : ejabberd 2.1.x is started in the node

My extauth script is nothing but derived from check_mysql.php.txt, but without any database link as of now. Here is the complete script i am trying to work with:

<?php

error_reporting(1);

class imAuth {

    function __construct() {
        $this->log = fopen('/etc/ejabberd/extauth.log', 'a');
        $this->openstd();
    }

    function openstd() {
        $this->stdout = @fopen("php://stdout", "w");
        $this->stdin = @fopen("php://stdin", "r");
    }

    function out($data) {
        @fwrite($this->stdout, $data);
        $dump = @unpack("nn", $data);
        $dump = $dump["n"];
        $this->logg("OUT: ". $dump);
    }

    function closestd() {
        @fclose($this->stdin);
        @fclose($this->stdout);
    }

    function stop() {
        $this->logg("Shutting down ...");
        @fclose($this->log);
        $this->closestd();
        exit(0);
    }

    function logg($data) {
        fwrite($this->log, $data."\n");
    }

    function splitcomm() {
        return explode(":", $this->data);
    }

    function checkuser() {
        return true;
    }

    function checkpass() {
        return true;
    }

    function command() {
        $data = $this->splitcomm();
        $this->logg("Processing command ".$data[0]);

        switch($data[0]) {
            case 'isuser':
                $log = $data[1];
                $ret = $this->checkuser();
                break;
            case 'auth':
                $log = $data[1].":".$data[2].":".md5($data[3]);
                $ret = $this->checkpass();
                break;
            case 'setpass':
                $ret = false;
                break;
            default:
                $this->stop();
                break;
        }

        $ret = ($ret) ? 1 : 0;
        if(strlen($data[0]) > 0 && strlen($log) > 0) {
            $this->logg("Command : ".$data[0].":".$log." ==> ".$ret." ");
        }

        return @pack("nn", 2, $return);
    }

    function readstdin() {
        $l = @fgets($this->stdin, 3);
        $length = @unpack("n", $l);
        $len = $length["1"];

        if($len > 0) {
            $this->logg("Reading $len bytes ... ");
            $data = @fgets($this->stdin, $len+1);
            $this->data = $data;
            $this->logg("IN: ".$data);
        }
    }

    function play() {
        do {
            $this->readstdin();
            $length = strlen($this->data);
            $ret = $this->command();
     开发者_如何学编程       $this->logg("RE:".$ret);
            $this->out($ret);
            $this->data = null;
        } while(true);
    }

}

$auth = new imAuth();
$auth->play();

?>

When my client tries to log into chat, i see following inside ejabberd.log:

=ERROR REPORT==== 2010-12-26 15:38:31 ===
** State machine <0.4566.0> terminating
** Last event in was {xmlstreamelement,
                     {xmlelement,"auth",
                         [{"xmlns","urn:ietf:params:xml:ns:xmpp-sasl"},
                          {"mechanism","PLAIN"}],
                         [{xmlcdata,
                              <<"AGpheGwAbGlmZWlzbGlmZTI1QSFAKCk=">>}]}}
** When State == wait_for_feature_request
**      Data  == {state,{socket_state,gen_tcp,#Port<0.34718>,<0.4565.0>},
                    ejabberd_socket,#Ref<0.0.0.104846>,false,"103115738",
                    {sasl_state,"jabber","dev.jaxl.im",[],
                                #Fun<ejabberd_c2s.1.30334249>,
                                #Fun<ejabberd_c2s.2.32721014>,
                                #Fun<ejabberd_c2s.3.7052687>,undefined,
                                undefined},
                    c2s,c2s_shaper,false,false,false,false,
                    [verify_none],
                    false,undefined,[],"dev.jaxl.im",[],undefined,
                    {pres_t,0},
                    {pres_f,0},
                    {pres_a,0},
                    {pres_i,0},
                    undefined,undefined,undefined,false,
                    {userlist,none,[],false},
                    unknown,unknown,
                    {{127,0,0,1},33227},
                    "en"}
** Reason for termination =
** {badarg,[{extauth,call_port,2},
        {ejabberd_auth_external,check_password_extauth,3},
        {ejabberd_auth,check_password_loop,2},
        {cyrsasl_plain,mech_step,2},
        {cyrsasl,server_step,2},
        {ejabberd_c2s,wait_for_feature_request,2},
        {p1_fsm,handle_msg,10},
        {proc_lib,init_p_do_apply,3}]}

I have tested my script by running via command line directly /path/to/php /etc/ejabberd/extauth.class.php and passed parameters via STDIN and it behaves expectedly.

I also tried modifying permissions of extauth.class.php as well as extauth.log with no results.

Can someone with experience help me get through this?


I had some problem. I tested my auth php script from user root, then tried

root@vm1096:/root~$ su ejabberd                                                                                                                                                                     [20:55:57]
sh-3.2$ /var/lib/ejabberd/joomla-auth.php

Warning: fopen(/var/log/ejabberd/exauth.log): failed to open stream: Permission denied in /var/lib/ejabberd/joomla-auth.php on line 105

Call Stack:
    0.0009     125028   1. {main}() /var/lib/ejabberd/joomla-auth.php:0
    0.0009     127136   2. exAuth->__construct() /var/lib/ejabberd/joomla-auth.php:75
    0.0010     127780   3. fopen() /var/lib/ejabberd/joomla-auth.php:105

It was line, that write log file. Check your script by su ejabberd and set right access for your script:

chmod 700 /var/lib/ejabberd/joomla-auth.php
chown ejabberd:ejabberd /var/lib/ejabberd/joomla-auth.php
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜