diff options
author | feld <feld@feld.me> | 2024-07-01 20:38:20 +0000 |
---|---|---|
committer | feld <feld@feld.me> | 2024-07-01 20:38:20 +0000 |
commit | 7a4687562a827a77d0025f181a319287948d69a1 (patch) | |
tree | 2ee7b9261732ae22d33fb14b0e9a58f8679344e6 | |
parent | e1981264a3e1a4d043ed99b0c8b0cbcc72a29e7a (diff) | |
parent | 2fe1e96f2b663094572f539c8da009ba8579475b (diff) | |
download | pleroma-7a4687562a827a77d0025f181a319287948d69a1.tar.gz pleroma-7a4687562a827a77d0025f181a319287948d69a1.zip |
Merge branch 'fix/ldap' into 'develop'
Fix LDAP support
See merge request pleroma/pleroma!4168
-rw-r--r-- | changelog.d/ldap.fix | 1 | ||||
-rw-r--r-- | lib/pleroma/web/auth/ldap_authenticator.ex | 45 | ||||
-rw-r--r-- | mix.exs | 3 |
3 files changed, 30 insertions, 19 deletions
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 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 - } - - 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) + # 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) - 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 @@ -80,7 +80,8 @@ defmodule Pleroma.Mixfile do :comeonin, :fast_sanitize, :os_mon, - :ssl + :ssl, + :eldap ] ++ logger_application(), included_applications: [:ex_syslogger] ] |