Getting ejabberd to work with an already set database of users.

Im working on getting ejabberd to interface with an already set database of users. I modified the ejabberd_auth_odbc.erl to query a database in a different manner, i figured just modifying the sql queries would make it work the way i needed.

basically i changed the queries throughout the file, here is an example of the function check_password:

----------------------------------------------------
ORIGINAL:
----------------------------------------------------
check_password(User, Server, Password) ->
case jlib:nodeprep(User) of
error ->
false;
LUser ->
Username = ejabberd_odbc:escape(LUser),
case catch ejabberd_odbc:sql_query(
jlib:nameprep(Server),
*****************************************************>["select password from users "
*****************************************************>"where username='", Username, "';"]) of
{selected, ["password"], [{Password}]} ->
true;
_ ->
false
end
end.
----------------------------------------------------
MODIFICATION:
----------------------------------------------------
check_password(User, Server, Password) ->
case jlib:nodeprep(User) of
error ->
false;
LUser ->
Username = ejabberd_odbc:escape(LUser),
case catch ejabberd_odbc:sql_query(
jlib:nameprep(Server),
*****************************************************>["select myUserpass as password from myDB.myUsers as users "
*****************************************************>"where myUsername='", Username, "';"]) of
{selected, ["password"], [{Password}]} ->
true;
_ ->
false
end
end.
----------------------------------------------------

The only thing modified were the SQL queries, but i even made it keep the same column names. unfortunately this made the "make" command when compiling dump errors glore giving me about 50+ errors such as the following.

Warning: variable 'Extra' is unused

I also have the odbc info in my ejabberd.cfg

{auth_method, odbc}.
{odbc_server, {mysql, "IP", "DB", "USER", "PW"}}.

Any help would be greatly appreciated.

Thanks,
Jeffrey R.

Warnings from where?

dS_Jeffrey wrote:

The only thing modified were the SQL queries, but i even made it keep the same column names. unfortunately this made the "make" command when compiling dump errors glore giving me about 50+ errors such as the following.

Warning: variable 'Extra' is unused

That's not an error, it's just a warning ;)

Are you sure that those lines come from the ejabberd_auth_odbc module? There are many ejabberd modules that do produce many such warnings, but it seems that ejabberd_auth_odbc from ejabberd 1.1.1 compiles without warnings. If your changes have increased the number of warnings, you should pay attention, otherwise it will probably work anyway.

Well, it compiles cleanly

Well, it compiles cleanly without the modifications, it seems as tho the variables are getting mixed up somewhere thus it starts throwing warnings.

These are the errors i get when i try to authenticate a user.

---------------------------------------------------------------------------------

ejabberd.log wrote:

=ERROR REPORT==== 5-Sep-2006::15:44:30 ===
** State machine <0.292.0> terminating
** Last event in was {xmlstreamelement,
{xmlelement,"response",
[{"xmlns",
"urn:ietf:params:xml:ns:xmpp-sasl"}],
[{xmlcdata,
<<"dXNlcm5hbWU9ImplZmZyZXkiLHJlYWxtPSJ kaWdzYnkwNC5yaXQuZWR1Iixub25jZT0iMTI2OTYxMTkwNyIsY25vbmNlPSJkNTgyOTU3YWQ4MzQ4YjR iMjY4OTlmY2NjNmYxNzhhNTFiOWMwMTY0IixuYz0wMDAwMDAwMSxxb3A9YXV0aCxkaWdlc3QtdXJpPSJ 4bXBwL2RpZ3NieTA0LnJpdC5lZHUiLGNoYXJzZXQ9dXRmLTgscmVzcG9uc2U9YTFmN2ZiZTRiMDhlODI yNjUwY2I1YjY1NTIwMDE3ODU=">>}]}}
** When State == wait_for_sasl_response
** Data == {state,#Port<0.313>,
<0.293.0>,
gen_tcp,
"2996843388",
{sasl_state,"jabber",
"MYDOMAIN.COM",
[],
#Fun,
#Fun,
cyrsasl_digest,
{state,
3,
"1269611907",
undefined,
undefined,
#Fun}},
c2s,
c2s_shaper,
false,
false,
false,
false,
[],
false,
undefined,
[],
"MYDOMAIN.COM",
[],
undefined,
{0,nil},
{0,nil},
{0,nil},
{0,nil},
undefined,
undefined,
undefined,
false,
none,
[],
false}
** Reason for termination =
** {'module could not be loaded',[{ejabberd_odbc,escape,["jeffrey"]},
{ejabberd_auth_odbc,get_password,2},
{lists,foldl,3},
{cyrsasl_digest,mech_step,2},
{cyrsasl,server_step,2},
{ejabberd_c2s,wait_for_sasl_response,2},
{gen_fsm,handle_msg,7},
{proc_lib,init_p,5}]}

=CRASH REPORT==== 5-Sep-2006::15:44:30 ===
crasher:
pid: <0.292.0>
registered_name: []
error_info: {undef,[{ejabberd_odbc,escape,["jeffrey"]},
{ejabberd_auth_odbc,get_password,2},
{lists,foldl,3},
{cyrsasl_digest,mech_step,2},
{cyrsasl,server_step,2},
{ejabberd_c2s,wait_for_sasl_response,2},
{gen_fsm,handle_msg,7},
{proc_lib,init_p,5}]}
initial_call: {gen,init_it,
[gen_fsm,
<0.171.0>,
<0.171.0>,
ejabberd_c2s,
[{gen_tcp,#Port<0.313>},
[{access,c2s},{shaper,c2s_shaper}]],
[]]}
ancestors: [ejabberd_c2s_sup,ejabberd_sup,<0.40.0>]
messages: [{'$gen_event',closed}]
links: [<0.171.0>]
dictionary: []
trap_exit: false
status: running
heap_size: 1597
stack_size: 21
reductions: 14358
neighbours:

=SUPERVISOR REPORT==== 5-Sep-2006::15:44:30 ===
Supervisor: {local,ejabberd_c2s_sup}
Context: child_terminated
Reason: {undef,[{ejabberd_odbc,escape,["jeffrey"]},
{ejabberd_auth_odbc,get_password,2},
{lists,foldl,3},
{cyrsasl_digest,mech_step,2},
{cyrsasl,server_step,2},
{ejabberd_c2s,wait_for_sasl_response,2},
{gen_fsm,handle_msg,7},
{proc_lib,init_p,5}]}
Offender: [{pid,<0.292.0>},
{name,undefined},
{mfa,{ejabberd_c2s,start_link,
[{gen_tcp,#Port<0.313>},
[{access,c2s},{shaper,c2s_shaper}]]}},
{restart_type,temporary},
{shutdown,brutal_kill},
{child_type,worker}]

---------------------------------------------------------------------------------

--enable-odbc?

dS_Jeffrey wrote:

=ERROR REPORT==== 5-Sep-2006::15:44:30 ===
** State machine <0.292.0> terminating
** Last event in was {xmlstreamelement,
...
** Reason for termination =
** {'module could not be loaded',[{ejabberd_odbc,escape,["jeffrey"]},
{ejabberd_auth_odbc,get_password,2},
{lists,foldl,3},
{cyrsasl_digest,mech_step,2},
{cyrsasl,server_step,2},
{ejabberd_c2s,wait_for_sasl_response,2},
{gen_fsm,handle_msg,7},
{proc_lib,init_p,5}]}

=CRASH REPORT==== 5-Sep-2006::15:44:30 ===
crasher:
pid: <0.292.0>
registered_name: []
error_info: {undef,[{ejabberd_odbc,escape,["jeffrey"]},
...

We see that the function ejabberd_odbc:escape is undefined (undef), as the module ejabberd_odbc could not be loaded.

Did you configure ejabberd with --enable-odbc? It's not enabled by default. Or is there any other reason why the file ejabberd_odbc.beam is missing among the other beam files?

Thank you very much,

Thank you very much, compiling with --enable-odbc worked, it still gave me warnings and i still had to get the mysql beam files from https://support.process-one.net/doc/display/MESSENGER/Using+ejabberd+wit...

but i got the authentication to work with our database.

somethings dont completely work tho, such as the web interface, but thats another monster.

Thanks,
Jeffrey R. | dS

Syndicate content