extauth: ejabberd not exec my script

Try to make extrenal auth by script. I read examples and write own script in ruby. I debug it, send first and second byte with length and other with plain text operation:username:domain:password. Script worked.

Quote:

class NeterDbAuthorization
def initialize(config_file = 'config.yml')
# load config
require 'yaml'
@cfg = YAML.load_file(config_file)

# load logger
if @cfg['log']['file']
require 'logger'
@log = Logger.new(@cfg['log']['file'])
log 'Start authorization'
end

# connect to db
require 'dbi'
@db = DBI.connect(
"DBI:#{@cfg['database']['type']}:database=#{@cfg['database']['database']};host=#{@cfg['database']['host']}",
@cfg['database']['username'],
@cfg['database']['password']
);

# listen input
buffer = String.new
while STDIN.sysread(2, buffer) && buffer.length == 2
debug 'Get packet'
length = buffer.unpack('n')[0]
debug "Packet length #{length}"
operation, username, domain, password = STDIN.sysread(length).split(':')
debug "Do '#{operation}' for '#{username}', '#{password}'"
STDOUT.syswrite(
[2, case operation
when 'auth', 'isuser'
send(operation, username, password)
when 'setpass'
0
else
log 'Unknown operation: ' + operation
0
end ].pack('nn')
)
end

rescue Exception => boom
debug "Error #{boom}" unless boom.instance_of? EOFError
ensure
disconnect
end

def auth(username, password)
@db.select_one(
'SELECT 1 FROM user WHERE login = ? AND password = ?',
username, password
) ? 1 : 0
end

def isuser(username)
@db.select_one(
'SELECT 1 FROM user WHERE login = ?',
username, password
) ? 1 : 0
end

def disconnect
log 'Port closed'
@db.disconnect if @db
exit
end

def log(message)
@log.info message if @log
end

def debug(message)
@log.debug message if @log && @cfg['log']['debug']
end
end

NeterDbAuthorization.new

I'm uncomment these lines in config and fill absolute path to my script in second parameter. Path is valid.

Quote:

{auth_method, external}.
{extauth_program, "/usr/local/etc/ejabberd/auth/test.rb"}.

I'm start ejabberd and connect to it by Miranda and see in log file:

Quote:

=ERROR REPORT==== 2006-07-01 02:03:45 ===
** State machine <0.7747.12> terminating
** Last event in was {xmlstreamelement,
{xmlelement,"iq",
[{"type","set"},{"id","mir_41"}],
[{xmlelement,
"query",
[{"xmlns","jabber:iq:auth"}],
[{xmlelement,
"username",
[],
[{xmlcdata,<<"shumkov">>}]},
{xmlelement,
"password",
[],
[{xmlcdata,<<"z8wBwf6d">>}]},
{xmlelement,
"resource",
[],
[{xmlcdata,<<"Miranda">>}]}]}]}}
** When State == wait_for_auth
** Data == {state,{tlssock,#Port<0.5886>,#Port<0.5887>},
<0.7748.12>,
tls,
"1281631548",
undefined,
c2s,
none,
false,
true,
false,
true,
[{certfile,"/usr/local/etc/ejabberd/geo.pem"}],
false,
undefined,
[],
"geometria.ru",
[],
undefined,
{0,nil},
{0,nil},
{0,nil},
{0,nil},
undefined,
undefined,
undefined,
false,
none,
[]}
** Reason for termination =
** {badarg,[{extauth,call_port,2},
{lists,any,2},
{ejabberd_c2s,wait_for_auth,2},
{gen_fsm,handle_msg,7},
{proc_lib,init_p,5}]}

In what a mistake? I look into auth script log file, and seen nothing. Script was not running? Why?

I'm try my perl script to

I'm try my perl script to auth, but it does not run too. Perhaps i'm not correct connect my script in ejabberd.cfg? I'm use this string:

Quote:

{auth_method, external}.
{extauth_program, "/usr/local/etc/ejabberd/auth/auth.pl"}.

My perl script:

Quote:

#!/usr/bin/perl -w
use strict;
use DBI();

my $g_db = DBI->connect("DBI:mysql:database=billing;host=192.168.0.137", "billing", "billing") or die "DB connect error\n";

while(1)
{
my $buf = "";
my $nread = sysread STDIN, $buf, 2;
last if $nread != 2;
my $len = unpack "n", $buf;
$nread = sysread STDIN, $buf, $len;
last if $nread != $len;

my($op, $user, $password) = split /:/, $buf;

my $result = 0;

if ($op eq 'auth')
{
$result = 1 if $g_db->selectcol_arrayref("SELECT 1 FROM user WHERE login = ? AND password = ?", undef, $user, $password);
}
elsif ($op eq 'setpass')
{
$result = 0;
}
elsif ($op eq 'isuser')
{
$result = 1 if $g_db->selectcol_arrayref("SELECT 1 FROM user WHERE login = ?", undef, $user);
}
else
{
$result = 0;
}
syswrite STDOUT, (pack "nn", 2, $result);

}

$g_db->disconnect;

Sorry for my english.

Sorry, errors was in my

Sorry, errors was in my scripts. Now extauth work.

How did you solve that error?

Hi, I have the same error but i don't know how to solve.

Syndicate content