ejabberd php mysql 外部身份验证失败并终止

发布于 2024-10-09 09:52:07 字数 5318 浏览 0 评论 0原文

我正在尝试使用 ejabberd 设置 extauth,但是我无法让它工作(即使在谷歌搜索网络上的修复程序之后)。我在 ejabberd.cfg 中设置了以下内容:

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

当我更新配置后重新启动 ejabberd 时,我在 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

我的 extauth 脚本只不过是源自 check_mysql.php.txt,但目前没有任何数据库链接。这是我正在尝试使用的完整脚本:

<?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();

?>

当我的客户尝试登录聊天时,我在 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}]}

我已经通过直接通过命令行运行来测试我的脚本/path/to/php /etc/ejabberd/extauth.class.php 并通过 STDIN 传递参数,其行为符合预期。

我还尝试修改 extauth.class.php 和 extauth.log 的权限,但没有结果。

有经验的人可以帮我解决这个问题吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红ご颜醉 2024-10-16 09:52:07

我遇到了一些问题。我从用户 root 测试了我的 auth php 脚本,然后尝试了

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

写入日志文件的行。通过 su ejabberd 检查您的脚本并为您的脚本设置正确的访问权限:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文