From 591e15f0f6e8a5992da33fa0892c3d6dde2ff5b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chmielowski?= Date: Mon, 2 Jun 2025 18:19:03 +0200 Subject: [PATCH] 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 --- src/ejabberd_auth_sql.erl | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/ejabberd_auth_sql.erl b/src/ejabberd_auth_sql.erl index b8ff98615..747a42598 100644 --- a/src/ejabberd_auth_sql.erl +++ b/src/ejabberd_auth_sql.erl @@ -406,40 +406,44 @@ which_users_exists(LServer, LUsers) -> export(_Server) -> [{passwd, - fun(Host, #passwd{us = {LUser, LServer}, password = Password}) + fun(Host, #passwd{us = {LUser, LServer, plain}, password = Password}) when LServer == Host, 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( "users", ["username=%(LUser)s", "server_host=%(LServer)s", + "type=1", "password=%(Password)s"])]; - (Host, {passwd, {LUser, LServer}, - {scram, StoredKey1, ServerKey, Salt, IterationCount}}) + (Host, {passwd, {LUser, LServer, _}, + {scram, StoredKey, ServerKey, Salt, IterationCount}}) when LServer == Host -> Hash = sha, - StoredKey = scram_hash_encode(Hash, StoredKey1), - [?SQL("delete from users where username=%(LUser)s and %(LServer)H;"), + Type = hash_to_num(Hash), + [?SQL("delete from users where username=%(LUser)s and type=%(Type)d and %(LServer)H;"), ?SQL_INSERT( "users", ["username=%(LUser)s", "server_host=%(LServer)s", + "type=%(Type)d", "password=%(StoredKey)s", "serverkey=%(ServerKey)s", "salt=%(Salt)s", "iterationcount=%(IterationCount)d"])]; - (Host, #passwd{us = {LUser, LServer}, password = #scram{} = Scram}) + (Host, #passwd{us = {LUser, LServer, _}, password = #scram{} = Scram}) when LServer == Host -> - StoredKey = scram_hash_encode(Scram#scram.hash, Scram#scram.storedkey), + StoredKey = Scram#scram.storedkey, ServerKey = Scram#scram.serverkey, Salt = Scram#scram.salt, 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( "users", ["username=%(LUser)s", "server_host=%(LServer)s", + "type=%(Type)d", "password=%(StoredKey)s", "serverkey=%(ServerKey)s", "salt=%(Salt)s",