]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbXsrv_session: split out smbXsrv_session_remove_channel()
authorStefan Metzmacher <metze@samba.org>
Tue, 9 Mar 2021 15:00:55 +0000 (16:00 +0100)
committerJeremy Allison <jra@samba.org>
Wed, 17 Mar 2021 00:49:32 +0000 (00:49 +0000)
It will be needed in other places and makes the logic in
smbXsrv_session_disconnect_xconn_callback() much simpler.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14532
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14512

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/globals.h
source3/smbd/smbXsrv_session.c

index daa2c103b3af51ee01b4ccc20bfe460f71a62f40..fd505dea289820f6c13238021eea40c71f70cc6a 100644 (file)
@@ -568,6 +568,8 @@ NTSTATUS smbXsrv_session_add_channel(struct smbXsrv_session *session,
                                     struct smbXsrv_connection *conn,
                                     NTTIME now,
                                     struct smbXsrv_channel_global0 **_c);
+NTSTATUS smbXsrv_session_remove_channel(struct smbXsrv_session *session,
+                                       struct smbXsrv_connection *xconn);
 NTSTATUS smbXsrv_session_disconnect_xconn(struct smbXsrv_connection *xconn);
 NTSTATUS smbXsrv_session_update(struct smbXsrv_session *session);
 struct smbXsrv_channel_global0;
index 1d7ebf9aff6c91c38600eec3dc0b9493587617c4..9bfdb8fbf04ac3abd55483fa60f3d486579ba65e 100644 (file)
@@ -1552,6 +1552,55 @@ NTSTATUS smbXsrv_session_create_auth(struct smbXsrv_session *session,
        return NT_STATUS_OK;
 }
 
+NTSTATUS smbXsrv_session_remove_channel(struct smbXsrv_session *session,
+                                       struct smbXsrv_connection *xconn)
+{
+       struct smbXsrv_session_auth0 *a = NULL;
+       struct smbXsrv_channel_global0 *c = NULL;
+       NTSTATUS status;
+       bool need_update = false;
+
+       status = smbXsrv_session_find_auth(session, xconn, 0, &a);
+       if (!NT_STATUS_IS_OK(status)) {
+               a = NULL;
+       }
+       status = smbXsrv_session_find_channel(session, xconn, &c);
+       if (!NT_STATUS_IS_OK(status)) {
+               c = NULL;
+       }
+       if (session->global->num_channels <= 1) {
+               /*
+                * The last channel is treated different
+                */
+               c = NULL;
+       }
+
+       if (a != NULL) {
+               smbXsrv_session_auth0_destructor(a);
+               a->connection = NULL;
+               need_update = true;
+       }
+
+       if (c != NULL) {
+               struct smbXsrv_session_global0 *global = session->global;
+               ptrdiff_t n;
+
+               n = (c - global->channels);
+               if (n >= global->num_channels || n < 0) {
+                       return NT_STATUS_INTERNAL_ERROR;
+               }
+               ARRAY_DEL_ELEMENT(global->channels, n, global->num_channels);
+               global->num_channels--;
+               need_update = true;
+       }
+
+       if (!need_update) {
+               return NT_STATUS_OK;
+       }
+
+       return smbXsrv_session_update(session);
+}
+
 struct smb2srv_session_shutdown_state {
        struct tevent_queue *wait_queue;
 };
@@ -1988,10 +2037,7 @@ static int smbXsrv_session_disconnect_xconn_callback(struct db_record *local_rec
        TDB_DATA val;
        void *ptr = NULL;
        struct smbXsrv_session *session = NULL;
-       struct smbXsrv_session_auth0 *a = NULL;
-       struct smbXsrv_channel_global0 *c = NULL;
        NTSTATUS status;
-       bool need_update = false;
 
        val = dbwrap_record_get_value(local_rec);
        if (val.dsize != sizeof(ptr)) {
@@ -2007,56 +2053,15 @@ static int smbXsrv_session_disconnect_xconn_callback(struct db_record *local_rec
        session = talloc_get_type_abort(ptr, struct smbXsrv_session);
 
        session->db_rec = local_rec;
-
-       status = smbXsrv_session_find_auth(session, state->xconn, 0, &a);
-       if (!NT_STATUS_IS_OK(status)) {
-               a = NULL;
-       }
-       status = smbXsrv_session_find_channel(session, state->xconn, &c);
+       status = smbXsrv_session_remove_channel(session, state->xconn);
+       session->db_rec = NULL;
        if (!NT_STATUS_IS_OK(status)) {
-               c = NULL;
-       }
-       if (session->global->num_channels <= 1) {
-               /*
-                * The last channel is treated different
-                */
-               c = NULL;
-       }
-
-       if (a != NULL) {
-               smbXsrv_session_auth0_destructor(a);
-               a->connection = NULL;
-               need_update = true;
-       }
-
-       if (c != NULL) {
-               struct smbXsrv_session_global0 *global = session->global;
-               ptrdiff_t n;
-
-               n = (c - global->channels);
-               if (n >= global->num_channels || n < 0) {
-                       status = NT_STATUS_INTERNAL_ERROR;
-                       if (NT_STATUS_IS_OK(state->first_status)) {
-                               state->first_status = status;
-                       }
-                       state->errors++;
-                       session->db_rec = NULL;
-                       return 0;
-               }
-               ARRAY_DEL_ELEMENT(global->channels, n, global->num_channels);
-               global->num_channels--;
-               need_update = true;
-       }
-
-       if (need_update) {
-               status = smbXsrv_session_update(session);
                if (NT_STATUS_IS_OK(state->first_status)) {
                        state->first_status = status;
                }
                state->errors++;
        }
 
-       session->db_rec = NULL;
        return 0;
 }