From 3127c5f0af3f62fb4c0eca642e69ede8f395d9b4 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 1 Jul 2024 15:58:15 -0400 Subject: [PATCH 1/3] Fix automatic LDAP account registration on OTP 24.3+ --- lib/pleroma/web/auth/ldap_authenticator.ex | 45 +++++++++++++--------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/lib/pleroma/web/auth/ldap_authenticator.ex b/lib/pleroma/web/auth/ldap_authenticator.ex index 17ffd820d..c2c5eb1e5 100644 --- a/lib/pleroma/web/auth/ldap_authenticator.ex +++ b/lib/pleroma/web/auth/ldap_authenticator.ex @@ -102,28 +102,37 @@ defmodule Pleroma.Web.Auth.LDAPAuthenticator do {:scope, :eldap.wholeSubtree()}, {:timeout, @search_timeout} ]) do - {:ok, {:eldap_search_result, [{:eldap_entry, _, attributes}], _}} -> - params = %{ - name: name, - nickname: name, - password: nil - } + # The :eldap_search_result record structure changed in OTP 24.3 and added a controls field + # https://github.com/erlang/otp/pull/5538 + {:ok, {:eldap_search_result, [{:eldap_entry, _object, attributes}], _referrals}} -> + try_register(name, attributes) - params = - case List.keyfind(attributes, ~c"mail", 0) do - {_, [mail]} -> Map.put_new(params, :email, :erlang.list_to_binary(mail)) - _ -> params - end - - changeset = User.register_changeset_ldap(%User{}, params) - - case User.register(changeset) do - {:ok, user} -> user - error -> error - end + {:ok, {:eldap_search_result, [{:eldap_entry, _object, attributes}], _referrals, _controls}} -> + try_register(name, attributes) error -> error end end + + defp try_register(name, attributes) do + params = %{ + name: name, + nickname: name, + password: nil + } + + params = + case List.keyfind(attributes, ~c"mail", 0) do + {_, [mail]} -> Map.put_new(params, :email, :erlang.list_to_binary(mail)) + _ -> params + end + + changeset = User.register_changeset_ldap(%User{}, params) + + case User.register(changeset) do + {:ok, user} -> user + error -> error + end + end end From eb419b7ffdc227872df2b0e91c740ef8dca5656f Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 1 Jul 2024 15:58:49 -0400 Subject: [PATCH 2/3] Add eldap back to applications as the module functions were unavailable --- mix.exs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index 879c7a023..3ecbdc267 100644 --- a/mix.exs +++ b/mix.exs @@ -80,7 +80,8 @@ defmodule Pleroma.Mixfile do :comeonin, :fast_sanitize, :os_mon, - :ssl + :ssl, + :eldap ] ++ logger_application(), included_applications: [:ex_syslogger] ] From 2fe1e96f2b663094572f539c8da009ba8579475b Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 1 Jul 2024 16:02:13 -0400 Subject: [PATCH 3/3] Fix LDAP support --- changelog.d/ldap.fix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/ldap.fix diff --git a/changelog.d/ldap.fix b/changelog.d/ldap.fix new file mode 100644 index 000000000..9ca697287 --- /dev/null +++ b/changelog.d/ldap.fix @@ -0,0 +1 @@ +Fix LDAP support