ejabberd icon indicating copy to clipboard operation
ejabberd copied to clipboard

Import from Prosody with "roster" has: "approved" attribute.

Open istoph opened this issue 2 years ago • 1 comments

When I try to import a slightly larger instance of Prosody, I get some errors.

Environment

  • ejabberd commit 9ab60935a448bd5f66a984db47cde9aed1202cf1
  • Erlang version: Erlang (SMP,ASYNC_THREADS) (BEAM) emulator version 13.1.5
  • OS: Debian GNU/Linux 12 (bookworm)
  • Installed from: source

Errors from cli:

ejabberdctl import_prosody "/var/lib/prosody/"

Unhandled exception occurred executing the command:
** exception error: no function clause matching 
                  prosody2ejabberd:'-convert_roster_item/4-fun-1-'({<<"approved">>,
                                                                    <<"true">>},
                                                                   [{roster,
                                                                     {<<"user">>,
                                                                      <<"5222.de">>,
                                                                      {<<"admin">>,
                                                                       <<"5222.de">>,
                                                                       <<>>}},
                                                                     {<<"user">>,
                                                                      <<"5222.de">>},
                                                                     {<<"admin">>,
                                                                      <<"5222.de">>,
                                                                      <<>>},
                                                                     <<>>,
                                                                     none,
                                                                     none,[],
                                                                     <<>>,
                                                                     []}]) (src/prosody2ejabberd.erl, line 311)
   in function  lists:foldl/3 (lists.erl, line 1350)
   in call from lists:flatmap_1/2 (lists.erl, line 1335)
   in call from lists:flatmap_1/2 (lists.erl, line 1335)
   in call from prosody2ejabberd:convert_data/4 (src/prosody2ejabberd.erl, line 162)
   in call from lists:foreach_1/2 (lists.erl, line 1442)
   in call from ejabberd_ctl:call_command/4 (src/ejabberd_ctl.erl, line 327)
   in call from ejabberd_ctl:try_call_command/4 (src/ejabberd_ctl.erl, line 288)

Example minimal reproducible:

/var/lib/prosody/5222%2ede/roster/user.dat

return {
    [false] = {
        ["version"] = 360;
        ["pending"] = {};
    };
    ["[email protected]"] = {
        ["approved"] = "true";
        ["groups"] = {};
        ["subscription"] = "both";
    };
};

Bug description

The user [email protected] will be import. He has entered [email protected] as a contact and is also countersigned with ["approved"] = "true".

I have added the following roundtrip to line 325:

		     ({<<"approved">>, _}, _) ->
			  [];

But it would make more sense to adopt this attribute as well.

istoph avatar Apr 01 '24 20:04 istoph

Nice finding! prosody2ejabberd didn't know how to handle the approved attribute.

In fact, it is an optional attribute and it seems not implemented in ejabberd or the xmpp erlang library. The import code should be able to handle it, even if it does not store the content.

I've committed a fix for this problem, and also included a fix for previous code that forgot R. It seems to work great with your example.

Notice this commit is slightly different than your patch, because you were also fogetting R when handling approved.

badlop avatar Apr 04 '24 11:04 badlop

@badlop Thank you! I can confirm that your patch fixes the bug.

istoph avatar Apr 30 '24 21:04 istoph