]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libsmb: Reduce indentation in SMBC_check_server() with an early return
authorVolker Lendecke <vl@samba.org>
Mon, 5 May 2025 10:43:58 +0000 (12:43 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 15 May 2025 14:03:34 +0000 (14:03 +0000)
Best reviewed with "git show -b"

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/libsmb/libsmb_server.c

index f8f50a01d18efc756705b0cb3986464ccc3c9824..44ed9ac400569d51275ba587059add02659eb5db 100644 (file)
@@ -48,6 +48,8 @@ SMBC_check_server(SMBCCTX * context,
 {
        struct cli_state *cli = server->cli;
        time_t now, next_echo;
+       unsigned char data[16] = {0};
+       NTSTATUS status;
 
        if (!cli_state_is_connected(cli)) {
                return 1;
@@ -56,45 +58,44 @@ SMBC_check_server(SMBCCTX * context,
        now = time_mono(NULL);
        next_echo = server->last_echo_time + cli->timeout/1000;
 
-       if (server->last_echo_time == (time_t)0 ||
-                       now > next_echo) {
-               unsigned char data[16] = {0};
-               NTSTATUS status = cli_echo(cli,
-                                       1,
-                                       data_blob_const(data, sizeof(data)));
-               if (!NT_STATUS_IS_OK(status)) {
-                       bool ok = false;
-                       /*
-                        * Some SMB2 servers (not Samba or Windows)
-                        * check the session status on SMB2_ECHO and return
-                        * NT_STATUS_USER_SESSION_DELETED
-                        * if the session was not set. That's OK, they still
-                        * replied.
-                        * BUG: https://bugzilla.samba.org/show_bug.cgi?id=13218
-                        */
-                       if (smbXcli_conn_protocol(cli->conn) >=
-                                       PROTOCOL_SMB2_02) {
-                               if (NT_STATUS_EQUAL(status,
-                                           NT_STATUS_USER_SESSION_DELETED)) {
-                                       ok = true;
-                               }
-                       }
-                       /*
-                        * Some NetApp servers return
-                        * NT_STATUS_INVALID_PARAMETER.That's OK, they still
-                        * replied.
-                        * BUG: https://bugzilla.samba.org/show_bug.cgi?id=13007
-                        */
+       if ((server->last_echo_time != 0) && (now <= next_echo)) {
+               return 0;
+       }
+
+       status = cli_echo(cli, 1, data_blob_const(data, sizeof(data)));
+       if (!NT_STATUS_IS_OK(status)) {
+               bool ok = false;
+               /*
+                * Some SMB2 servers (not Samba or Windows)
+                * check the session status on SMB2_ECHO and return
+                * NT_STATUS_USER_SESSION_DELETED
+                * if the session was not set. That's OK, they still
+                * replied.
+                * BUG: https://bugzilla.samba.org/show_bug.cgi?id=13218
+                */
+               if (smbXcli_conn_protocol(cli->conn) >=
+                   PROTOCOL_SMB2_02) {
                        if (NT_STATUS_EQUAL(status,
-                                       NT_STATUS_INVALID_PARAMETER)) {
+                                           NT_STATUS_USER_SESSION_DELETED)) {
                                ok = true;
                        }
-                       if (!ok) {
-                               return 1;
-                       }
                }
-               server->last_echo_time = now;
+               /*
+                * Some NetApp servers return
+                * NT_STATUS_INVALID_PARAMETER.That's OK, they still
+                * replied.
+                * BUG: https://bugzilla.samba.org/show_bug.cgi?id=13007
+                */
+               if (NT_STATUS_EQUAL(status,
+                                   NT_STATUS_INVALID_PARAMETER)) {
+                       ok = true;
+               }
+               if (!ok) {
+                       return 1;
+               }
        }
+
+       server->last_echo_time = now;
        return 0;
 }