File 4983-ssh-refactor-maybe_send_banner-function.patch of Package erlang

From a97aca2aa1e9c2680fa6cd55b0103eed64aa4b5d Mon Sep 17 00:00:00 2001
From: Alexandre Rodrigues <alexandrejbr@live.com>
Date: Mon, 3 Feb 2025 10:46:45 +0100
Subject: [PATCH 3/4] ssh: refactor maybe_send_banner function

---
 lib/ssh/src/ssh_fsm_userauth_server.erl | 22 ++++++----------------
 lib/ssh/src/ssh_options.erl             |  2 +-
 2 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/lib/ssh/src/ssh_fsm_userauth_server.erl b/lib/ssh/src/ssh_fsm_userauth_server.erl
index 47d98c9376..960cee001f 100644
--- a/lib/ssh/src/ssh_fsm_userauth_server.erl
+++ b/lib/ssh/src/ssh_fsm_userauth_server.erl
@@ -216,25 +216,15 @@ retry_fun(User, Reason, #data{ssh_params = #ssh{opts = Opts,
     end.
 
 maybe_send_banner(D0 = #data{ssh_params = #ssh{userauth_banner_sent = false} = Ssh}, User) ->
-    Opts = Ssh#ssh.opts,
-    BannerText = case maps:get(bannerfun, Opts, undefined) of
-                     undefined ->
-                         <<>>;
-                     BannerFun when is_function(BannerFun, 1) ->
-                         %% Ignore bad banner texts
-                         case BannerFun(User) of
-                             B when is_binary(B) -> B;
-                             _ -> <<>>
-                         end
-                 end,
-    case BannerText of
-        <<>> ->
-            D0;
-        BannerText ->
+    BannerFun = ?GET_OPT(bannerfun, Ssh#ssh.opts),
+    case BannerFun(User) of
+        BannerText when is_binary(BannerText), byte_size(BannerText) > 0 ->
             Banner = #ssh_msg_userauth_banner{message = BannerText,
                                               language = <<>>},
             D = D0#data{ssh_params = Ssh#ssh{userauth_banner_sent = true}},
-            ssh_connection_handler:send_msg(Banner, D)
+            ssh_connection_handler:send_msg(Banner, D);
+        _ ->
+            D0
     end;
 maybe_send_banner(D, _) ->
     D.
diff --git a/lib/ssh/src/ssh_options.erl b/lib/ssh/src/ssh_options.erl
index a77233429a..fd2ad2288e 100644
--- a/lib/ssh/src/ssh_options.erl
+++ b/lib/ssh/src/ssh_options.erl
@@ -589,7 +589,7 @@ default(server) ->
            },
 
       bannerfun =>
-          #{default => undefined,
+          #{default => fun(_) -> <<>> end,
             chk => fun(V) -> check_function1(V) end,
             class => user_option
            },
-- 
2.43.0

openSUSE Build Service is sponsored by