1
0
Fork 0
mirror of https://github.com/processone/ejabberd synced 2025-10-03 17:59:31 +02:00

Fix mnesia to sql exporter after changes to auth tables

Conversion functions used by ej2sql module was not updated after change
that did allow storing multiple passwords per user, which made us skip
passwords that were updated to new format, this fixes this problem.

This fixes issue #4391
This commit is contained in:
Paweł Chmielowski 2025-06-02 18:19:03 +02:00
parent b4a917db09
commit 591e15f0f6

View file

@ -406,40 +406,44 @@ which_users_exists(LServer, LUsers) ->
export(_Server) -> export(_Server) ->
[{passwd, [{passwd,
fun(Host, #passwd{us = {LUser, LServer}, password = Password}) fun(Host, #passwd{us = {LUser, LServer, plain}, password = Password})
when LServer == Host, when LServer == Host,
is_binary(Password) -> is_binary(Password) ->
[?SQL("delete from users where username=%(LUser)s and %(LServer)H;"), [?SQL("delete from users where username=%(LUser)s and type=1 and %(LServer)H;"),
?SQL_INSERT( ?SQL_INSERT(
"users", "users",
["username=%(LUser)s", ["username=%(LUser)s",
"server_host=%(LServer)s", "server_host=%(LServer)s",
"type=1",
"password=%(Password)s"])]; "password=%(Password)s"])];
(Host, {passwd, {LUser, LServer}, (Host, {passwd, {LUser, LServer, _},
{scram, StoredKey1, ServerKey, Salt, IterationCount}}) {scram, StoredKey, ServerKey, Salt, IterationCount}})
when LServer == Host -> when LServer == Host ->
Hash = sha, Hash = sha,
StoredKey = scram_hash_encode(Hash, StoredKey1), Type = hash_to_num(Hash),
[?SQL("delete from users where username=%(LUser)s and %(LServer)H;"), [?SQL("delete from users where username=%(LUser)s and type=%(Type)d and %(LServer)H;"),
?SQL_INSERT( ?SQL_INSERT(
"users", "users",
["username=%(LUser)s", ["username=%(LUser)s",
"server_host=%(LServer)s", "server_host=%(LServer)s",
"type=%(Type)d",
"password=%(StoredKey)s", "password=%(StoredKey)s",
"serverkey=%(ServerKey)s", "serverkey=%(ServerKey)s",
"salt=%(Salt)s", "salt=%(Salt)s",
"iterationcount=%(IterationCount)d"])]; "iterationcount=%(IterationCount)d"])];
(Host, #passwd{us = {LUser, LServer}, password = #scram{} = Scram}) (Host, #passwd{us = {LUser, LServer, _}, password = #scram{} = Scram})
when LServer == Host -> when LServer == Host ->
StoredKey = scram_hash_encode(Scram#scram.hash, Scram#scram.storedkey), StoredKey = Scram#scram.storedkey,
ServerKey = Scram#scram.serverkey, ServerKey = Scram#scram.serverkey,
Salt = Scram#scram.salt, Salt = Scram#scram.salt,
IterationCount = Scram#scram.iterationcount, IterationCount = Scram#scram.iterationcount,
[?SQL("delete from users where username=%(LUser)s and %(LServer)H;"), Type = hash_to_num(Scram#scram.hash),
[?SQL("delete from users where username=%(LUser)s and type=%(Type)d and %(LServer)H;"),
?SQL_INSERT( ?SQL_INSERT(
"users", "users",
["username=%(LUser)s", ["username=%(LUser)s",
"server_host=%(LServer)s", "server_host=%(LServer)s",
"type=%(Type)d",
"password=%(StoredKey)s", "password=%(StoredKey)s",
"serverkey=%(ServerKey)s", "serverkey=%(ServerKey)s",
"salt=%(Salt)s", "salt=%(Salt)s",