Add helpers required to handle multichannel connections
authorSachin Prabhu <sprabhu@redhat.com>
Tue, 17 Sep 2019 12:23:36 +0000 (13:23 +0100)
committerStefan Metzmacher <metze@samba.org>
Tue, 28 Jan 2020 12:26:51 +0000 (13:26 +0100)
Add the following helpers
smb_has_multiple_channels()
smb_get_next_connection()
smb_get_latest_client_connection()

Signed-off-by: Sachin Prabhu <sprabhu@redhat.com>
source3/smbd/globals.h
source3/smbd/smb2_server.c

index 16f3cb09dcd5ac9592a3dcde3e7ae4a253fd8f52..56b411ecc59efdf18969a0dff8e1e49f36a66b0e 100644 (file)
@@ -903,4 +903,11 @@ extern struct smbXsrv_client *global_smbXsrv_client;
 
 void smbd_init_globals(void);
 
+bool smb_has_multiple_channels(struct smbXsrv_client *client);
+struct smbXsrv_connection *smb_get_latest_client_connection
+                                               (struct smbXsrv_client *client);
+struct smbXsrv_connection
+       *smb_get_next_connection(struct smbXsrv_connection *main_channel,
+                                struct smbXsrv_connection *prev_channel);
+
 #endif /* _SOURCE3_SMBD_GLOBALS_H_ */
index 2149048721a1e93a22b9dc322ff60f7c816289d5..fa607f217f027b56a5c17d95a91b27df5a6876a2 100644 (file)
@@ -3493,6 +3493,50 @@ NTSTATUS smbd_smb2_request_error_ex(struct smbd_smb2_request *req,
        return smbd_smb2_request_done_ex(req, status, body, info, __location__);
 }
 
+bool smb_has_multiple_channels(struct smbXsrv_client *client)
+{
+       struct smbXsrv_connection *c = NULL;
+       struct smbXsrv_connection *cn = NULL;
+
+       c = DLIST_TAIL(client->connections);
+       cn = DLIST_PREV(c);
+
+       return (cn != c);
+}
+
+struct smbXsrv_connection *smb_get_latest_client_connection
+                                               (struct smbXsrv_client *client)
+{
+       return DLIST_TAIL(client->connections);
+}
+
+struct smbXsrv_connection
+       *smb_get_next_connection(struct smbXsrv_connection *main_channel,
+                                struct smbXsrv_connection *prev_channel)
+{
+       struct smbXsrv_client *client = main_channel->client;
+       struct smbXsrv_connection *ret;
+
+       if (prev_channel == NULL) {
+               ret = DLIST_TAIL(client->connections);
+               if (ret == main_channel) {
+                       ret = DLIST_PREV(ret);
+               }
+               return ret;
+       }
+
+       /* We need to ensure that the previous connection is still available. */
+       for (ret = DLIST_TAIL(client->connections);
+                       ret != NULL;
+                       ret = DLIST_PREV(ret)) {
+               if (ret != prev_channel) {
+                       continue;
+               }
+               ret = DLIST_PREV(ret);
+               return ret;
+       }
+       return NULL;
+}
 
 struct smbd_smb2_send_break_state {
        struct smbd_smb2_send_queue queue_entry;