processone / ejabberd

Robust, Ubiquitous and Massively Scalable Messaging Platform (XMPP, MQTT, SIP Server)
https://www.process-one.net/en/ejabberd/
Other
6k stars 1.5k forks source link

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

Closed istoph closed 2 months ago

istoph commented 3 months ago

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

Environment

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"] = {};
    };
    ["admin@5222.de"] = {
        ["approved"] = "true";
        ["groups"] = {};
        ["subscription"] = "both";
    };
};

Bug description

The user user@5222.de will be import. He has entered admin@5222.de 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.

badlop commented 3 months ago

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.

istoph commented 2 months ago

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