summaryrefslogtreecommitdiff
path: root/src/ejabberd_auth_sql.erl
diff options
context:
space:
mode:
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>2017-10-25 21:21:52 +0300
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>2017-10-25 21:21:52 +0300
commit29462f00538765d4cb90a3d085367c23a95df0d1 (patch)
treece8eb1ec5d640331ee72bb893a8bde8b995a2204 /src/ejabberd_auth_sql.erl
parentAllow dynamic node options on sql backends (diff)
Make it possible to convert to SQL for any current db_type
It is now possible to run `export` command even when the current `db_type` is not `sql`
Diffstat (limited to 'src/ejabberd_auth_sql.erl')
-rw-r--r--src/ejabberd_auth_sql.erl26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/ejabberd_auth_sql.erl b/src/ejabberd_auth_sql.erl
index 0d7c7b37..15e5076c 100644
--- a/src/ejabberd_auth_sql.erl
+++ b/src/ejabberd_auth_sql.erl
@@ -35,11 +35,12 @@
-export([start/1, stop/1, set_password/3, try_register/3,
get_users/2, count_users/2, get_password/2,
remove_user/2, store_type/1, plain_password_required/1,
- convert_to_scram/1, opt_type/1]).
+ convert_to_scram/1, opt_type/1, export/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
-include("ejabberd_sql_pt.hrl").
+-include("ejabberd_auth.hrl").
-define(SALT_LENGTH, 16).
@@ -288,6 +289,29 @@ convert_to_scram(Server) ->
end
end.
+export(_Server) ->
+ [{passwd,
+ fun(Host, #passwd{us = {LUser, LServer}, password = Password})
+ when LServer == Host,
+ is_binary(Password) ->
+ [?SQL("delete from users where username=%(LUser)s;"),
+ ?SQL("insert into users(username, password) "
+ "values (%(LUser)s, %(Password)s);")];
+ (Host, #passwd{us = {LUser, LServer}, password = #scram{} = Scram})
+ when LServer == Host ->
+ StoredKey = Scram#scram.storedkey,
+ ServerKey = Scram#scram.serverkey,
+ Salt = Scram#scram.salt,
+ IterationCount = Scram#scram.iterationcount,
+ [?SQL("delete from users where username=%(LUser)s;"),
+ ?SQL("insert into users(username, password, serverkey, salt, "
+ "iterationcount) "
+ "values (%(LUser)s, %(StoredKey)s, %(ServerKey)s,"
+ " %(Salt)s, %(IterationCount)d);")];
+ (_Host, _R) ->
+ []
+ end}].
+
-spec opt_type(pgsql_users_number_estimate) -> fun((boolean()) -> boolean());
(atom()) -> [atom()].
opt_type(pgsql_users_number_estimate) ->