processone / ejabberd-contrib

Growing and curated ejabberd contributions repository - PR or ask to join !
http://ejabberd.im
250 stars 137 forks source link

ejabberd-18.04 ejabberd_auth_http not compiling #254

Closed ranbirs closed 6 years ago

ranbirs commented 6 years ago

Hi we are using 18.04 and ejabberd_auth_http is now no longer compiling it was working a month ago, can it be fixed? or is there an older branch we can compile from?

opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/ejabberd_auth_http.erl:33: can't find include file "scram.hrl" /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/ejabberd_auth_http.erl:86: record scram undefined /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/ejabberd_auth_http.erl:247: record scram undefined /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:31: can't find include file "scram.hrl" /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:116: undefined macro 'SCRAM_DEFAULT_ITERATION_COUNT' /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:130: undefined macro 'SCRAM_DEFAULT_ITERATION_COUNT' /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:45: function iterations/0 undefined /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:45: function password_to_scram/1 undefined /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:121: function iterations/0 undefined /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:124: function iterations/0 undefined /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:132: record scram undefined /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:139: record scram undefined /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:145: record scram undefined /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:146: record scram undefined /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:149: record scram undefined /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:151: record scram undefined /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:153: variable 'IterationCount' is unbound /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:155: variable 'ServerKey' is unbound /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:155: variable 'StoredKey' is unbound /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:156: variable 'Salt' is unbound /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:161: record scram undefined /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:175: record scram undefined /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:176: record scram undefined /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:177: record scram undefined /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:178: record scram undefined /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:180: type scram() undefined /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:181: record scram undefined /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:182: variable 'StoredKey' is unbound /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:135: Warning: call to crypto:rand_bytes/1 will fail, since it was removed in 20.0; use crypto:strong_rand_bytes/1 /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:137: Warning: variable 'StoredKey' is unused /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:138: Warning: variable 'ServerKey' is unused /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:160: Warning: variable 'IterationCount' is unused /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:160: Warning: variable 'Salt' is unused /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:160: Warning: variable 'ServerKey' is unused /opt/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:160: Warning: variable 'StoredKey' is unused

badlop commented 6 years ago

I updated it to compile with recent ejabberd git repository. You can create a personal branch, and revert this commit https://github.com/processone/ejabberd-contrib/commit/7191ddd6f325b521fd29ad770f8419a65210bb19 until you update to a recent ejabberd.

ranbirs commented 6 years ago

Thanks i'll do that, it would be handy if there was some tags referencing the last supported working version

adiii717 commented 6 years ago

@badlop getting this error can you look into this please /home/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/ejabberd_auth_http.erl:33: can't find include file "scram2.hrl" Error: {compilation_failed,"/home/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl"}

@ranbirs did you resolve the problem?

@badlop compilation error with other versions, while unknown option auth_opt in 18.06.

Also agree @ranbirs it was working from a year and suddenly all our Auto scaling instance throwing this error.

badlop commented 6 years ago

How did you compile it? With ejabberd git, this works:

$ ejabberdctl modules_update_specs 
$ ejabberdctl modules_installed
$ ejabberdctl module_install ejabberd_auth_http
/home/badlop/.ejabberd-modules/sources/ejabberd-contrib/ejabberd_auth_http/src/scram2.erl:135:
  Warning: crypto:rand_bytes/1 is deprecated and will be removed in a future release;
  use crypto:strong_rand_bytes/1
$
ranbirs commented 6 years ago

@Adiii717 we fixed it by reverting the changes that were made here https://github.com/processone/ejabberd-contrib/commit/7191ddd6f325b521fd29ad770f8419a65210bb19#diff-2e168d8df1bdda63ad5ca683050c2585

badlop commented 6 years ago

Ahh, right! If the module is installed only in ~/.ejabberd-modules, the beam file will only be read when loading external modules. The problem is that the configuration is checked before that, and by that time the beam file hasn't been loaded yet.

This was not a problem in older versions, because an unknown option provoked a warning, but now it provokes the server stop.

The only solution I could find is to copy the file ejabberd_auth_http.beam with all the other ejabberd core files, so that it will be read immediately at server start, and its options will be accepted when reading the configuration files.

weiss commented 6 years ago

Does this also happen if you put the module configuration into $CONTRIB_MODULES_CONF_DIR/ejabberd_auth_http.yml (where $CONTRIB_MODULES_CONF_DIR is the path specified in your ejabberdctl.cfg or ejabberd/.ejabberd-modules/conf/ by default)?

badlop commented 6 years ago

Yes, the problem still happens, because that "contrib" config file is read together with the main config file, sometime before the "contrib" module beams are read.

badlop commented 6 years ago

Here is a proposed patch to load ext_mod modules just before reading the configuration, so ejabberd_auth_http options are accepted. I wonder why this was not done since the beginning...

diff --git a/src/ejabberd_app.erl b/src/ejabberd_app.erl
index 284be384b..61fba1d66 100644
--- a/src/ejabberd_app.erl
+++ b/src/ejabberd_app.erl
@@ -45,6 +45,7 @@ start(normal, _Args) ->
     start_elixir_application(),
     ejabberd:check_app(ejabberd),
     setup_if_elixir_conf_used(),
+    ext_mod:load_modules(),
     case ejabberd_config:start() of
    ok ->
        ejabberd_mnesia:start(),
diff --git a/src/ext_mod.erl b/src/ext_mod.erl
index 59cbb87b6..cc162a9be 100644
--- a/src/ext_mod.erl
+++ b/src/ext_mod.erl
@@ -29,7 +29,7 @@
 -behaviour(gen_server).
 -author("Christophe Romain <christophe.romain@process-one.net>").

--export([start_link/0, update/0, check/1,
+-export([start_link/0, update/0, check/1, load_modules/0,
          available_command/0, available/0, available/1,
          installed_command/0, installed/0, installed/1,
          install/1, uninstall/1, upgrade/0, upgrade/1,
@@ -54,13 +54,15 @@ start_link() ->

 init([]) ->
     process_flag(trap_exit, true),
-    [code:add_patha(module_ebin_dir(Module))
-     || {Module, _} <- installed()],
     application:start(inets),
     inets:start(httpc, [{profile, ext_mod}]),
     ejabberd_commands:register_commands(get_commands_spec()),
     {ok, #state{}}.

+load_modules() ->
+    [code:add_patha(module_ebin_dir(Module))
+     || {Module, _} <- installed()].
+
 handle_call(_Request, _From, State) ->
     Reply = ok,
     {reply, Reply, State}.
zinid commented 6 years ago

@badlop there is a function get_modules() in ejabberd_config.erl which does almost the same. Maybe it's better to improve it there?

badlop commented 6 years ago

That get_modules() function gets the list of modules available, it doesn't make changes. Is it a good idea to load ebin files from external modules in the configuration code? I see no relation between those tasks, except there is a prerequisite of loading the modules before reading the config.