No matter what script I try, I can't get extauth to work. I've tried the same things both on Mac OS X Tiger (installed with Fink) and also on my server which is running Gentoo Linux using the binary installer from process one. No errors get logged, either by ejabberd or the script itself. Ejabberd will accept the connection, and then just hang there.
First I tried the contributed script "check_mysql.php" only modifying the mysql login stuff at the top, and then the checkpass and checkuser functions:
function checkpass() { /* * Put here your code to check password * $this->jabber_user * $this->jabber_pass * $this->jabber_server */ $jabber_hashed_pass = md5($this->jabber_pass); $query = sprintf("SELECT pass FROM users WHERE (name='%s');", $this->jabber_user); $result = mysql_query($query, $this->mysock); if ($result) { $row = mysql_fetch_assoc($result); $db_hashed_pass = md5($row['pass']); if ($jabber_hashed_pass == $db_hashed_pass) { return true; } } return false; } function checkuser() { /* * Put here your code to check user * $this->jabber_user * $this->jabber_pass * $this->jabber_server */ $query = sprintf("SELECT name FROM users WHERE (name='%s');", $this->jabber_user); $result = mysql_query($query, $this->mysock); if ($result) { return true; } return false; }
Then I tried making my own little script in python just to test, and it still had the same problem.
#!/usr/bin/python import struct import sys DOMAIN = 'foobar.us' DB = { 'zaylea' : 'secret' } while 1: nread = sys.stdin.read(2) length = struct.unpack('h', nread) nread = sys.stdin.read(length) op, user, password = nread.split(':', 3) jid = '@'.join([user, DOMAIN]) result = 0 if op == 'auth': if DB.has_key(user) and (DB[user] == password) : result = 1 elif op == 'setpass': pass elif op == 'isuser': if DB.has_key(user): result = 1 out = struct.pack('!hh', 2, result) sys.stdout.write(out)
I've tried the extauth with mysql and perl script too and it also does the same thing as the other scripts, but I'm not very fond of perl, so I'm not going to bother with that one anymore.
I have this feeling that what I'm doing wrong is going to be something silly and obvious, but I've been trying to figure it out for 3 days. If anybody has any hints as to what I'm doing wrong, I would greatly appreciate it.
First of all, you have to
First of all, you have to read bytes in big-endian order, also struct.unpack returns a tuple and you have to obtain first element from it.
So, the string:
Should looks like this:
The second: splitting
is incorrect, because the "auth" and "setpass" operations have user,domain,password as its arguments and the "isuser" operation has user,domain as it arguments.
And the third: you have to flush() sys.stdout after all write() methods.
The string seems to include
The string seems to include the 'domain' now..
method:username:domain:password