From eebd287ab9c3591f3550aa94e910cf702009304a Mon Sep 17 00:00:00 2001
From: Thomas Guillem <thomas@gllm.fr>
Date: Mon, 16 Dec 2024 09:22:38 +0100
Subject: [PATCH 1/3] smb2: prefix local functions with vlc_

To avoid conflicts with smb2.h

(cherry picked from commit 9adc93c1a52e02c78d395660a52d4e276c49ee1f)
---
 modules/access/smb2.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/modules/access/smb2.c b/modules/access/smb2.c
index b1bebf0b6bd4..d43b97ed3bfe 100644
--- a/modules/access/smb2.c
+++ b/modules/access/smb2.c
@@ -161,7 +161,7 @@ vlc_smb2_op_reset(struct vlc_smb2_op *op, struct smb2_context **smb2p)
 }
 
 static int
-smb2_check_status(struct vlc_smb2_op *op, const char *psz_func, int status)
+vlc_smb2_check_status(struct vlc_smb2_op *op, const char *psz_func, int status)
 {
     if (status < 0)
     {
@@ -179,12 +179,12 @@ smb2_check_status(struct vlc_smb2_op *op, const char *psz_func, int status)
 }
 
 static void
-smb2_set_error(struct vlc_smb2_op *op, const char *psz_func, int err)
+vlc_smb2_set_error(struct vlc_smb2_op *op, const char *psz_func, int err)
 {
     if (op->log && err != -EINTR)
         msg_Err(op->log, "%s failed: %d, %s", psz_func, err, smb2_get_error(op->smb2));
 
-    /* Don't override if set via smb2_check_status */
+    /* Don't override if set via vlc_smb2_check_status */
     if (op->error_status == 0)
         op->error_status = err;
 
@@ -194,10 +194,10 @@ smb2_set_error(struct vlc_smb2_op *op, const char *psz_func, int err)
 }
 
 #define VLC_SMB2_CHECK_STATUS(op, status) \
-    smb2_check_status(op, __func__, status)
+    vlc_smb2_check_status(op, __func__, status)
 
 #define VLC_SMB2_SET_ERROR(op, func, err) \
-    smb2_set_error(op, func, err)
+    vlc_smb2_set_error(op, func, err)
 
 #define VLC_SMB2_STATUS_DENIED(x) (x == -ECONNREFUSED || x == -EACCES)
 
-- 
GitLab


From 3d29b50f6c62720f70809b270ca6a5228077c907 Mon Sep 17 00:00:00 2001
From: Thomas Guillem <thomas@gllm.fr>
Date: Mon, 16 Dec 2024 13:16:37 +0100
Subject: [PATCH 2/3] smb2: rework ShareEnum

To prepare for the next commit.

(cherry picked from commit 94db6cdc13b58c50dd98836e6e9aeec92851dbe7)
---
 modules/access/smb2.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/modules/access/smb2.c b/modules/access/smb2.c
index d43b97ed3bfe..57a2612b8b1e 100644
--- a/modules/access/smb2.c
+++ b/modules/access/smb2.c
@@ -502,16 +502,21 @@ ShareEnum(stream_t *access, input_item_node_t *p_node)
     vlc_readdir_helper_init(&rdh, access, p_node);
 
     struct srvsvc_netsharectr *ctr = sys->share_enum->ctr;
+    size_t ctr_count = ctr->ctr1.count;
+
     for (uint32_t iinfo = 0;
-         iinfo < ctr->ctr1.count && ret == VLC_SUCCESS; ++iinfo)
+         iinfo < ctr_count && ret == VLC_SUCCESS; ++iinfo)
     {
        struct srvsvc_netshareinfo1 *info = &ctr->ctr1.array[iinfo];
-       if (info->type & SHARE_TYPE_HIDDEN)
+       const char *name = info->name;
+       uint32_t type = info->type;
+
+       if (type & SHARE_TYPE_HIDDEN)
            continue;
-       switch (info->type & 0x3)
+       switch (type & 0x3)
        {
            case SHARE_TYPE_DISKTREE:
-               ret = AddItem(access, &rdh, info->name, ITEM_TYPE_DIRECTORY);
+               ret = AddItem(access, &rdh, name, ITEM_TYPE_DIRECTORY);
                break;
        }
     }
-- 
GitLab


From ab68c3d2d9a760fad73242b8306563ce2be3cb5c Mon Sep 17 00:00:00 2001
From: Thomas Guillem <thomas@gllm.fr>
Date: Mon, 16 Dec 2024 09:42:19 +0100
Subject: [PATCH 3/3] smb2: update latest net share API

(cherry picked from commit 8c8c28be69349435171f5bee237b807cee2b017d)
---
 modules/access/smb2.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/modules/access/smb2.c b/modules/access/smb2.c
index 57a2612b8b1e..6cdd37eb63cc 100644
--- a/modules/access/smb2.c
+++ b/modules/access/smb2.c
@@ -117,7 +117,11 @@ struct access_sys
     struct smb2_context *   smb2;
     struct smb2fh *         smb2fh;
     struct smb2dir *        smb2dir;
+#ifdef LIBSMB2_SHARE_ENUM_V2
+    struct srvsvc_NetrShareEnum_rep *share_enum;
+#else
     struct srvsvc_netshareenumall_rep *share_enum;
+#endif
     uint64_t                smb2_size;
     vlc_url_t               encoded_url;
     bool                    eof;
@@ -501,15 +505,26 @@ ShareEnum(stream_t *access, input_item_node_t *p_node)
     struct vlc_readdir_helper rdh;
     vlc_readdir_helper_init(&rdh, access, p_node);
 
+#ifdef LIBSMB2_SHARE_ENUM_V2
+    struct srvsvc_SHARE_INFO_1_CONTAINER *ctr = &sys->share_enum->ses.ShareInfo.Level1;
+    size_t ctr_count = ctr->EntriesRead;
+#else
     struct srvsvc_netsharectr *ctr = sys->share_enum->ctr;
     size_t ctr_count = ctr->ctr1.count;
+#endif
 
     for (uint32_t iinfo = 0;
          iinfo < ctr_count && ret == VLC_SUCCESS; ++iinfo)
     {
+#ifdef LIBSMB2_SHARE_ENUM_V2
+       struct srvsvc_SHARE_INFO_1 *info = &ctr->Buffer->share_info_1[iinfo];
+       const char *name = info->netname.utf8;
+       uint32_t type = info->type;
+#else
        struct srvsvc_netshareinfo1 *info = &ctr->ctr1.array[iinfo];
        const char *name = info->name;
        uint32_t type = info->type;
+#endif
 
        if (type & SHARE_TYPE_HIDDEN)
            continue;
@@ -608,7 +623,13 @@ vlc_smb2_open_share(stream_t *access, struct smb2_context **smb2p,
 
     int ret;
     if (do_enum)
+    {
+#ifdef LIBSMB2_SHARE_ENUM_V2
+        ret = smb2_share_enum_async(op.smb2, SHARE_INFO_1, smb2_open_cb, &op);
+#else
         ret = smb2_share_enum_async(op.smb2, smb2_open_cb, &op);
+#endif
+    }
     else
     {
         ret = smb2_stat_async(op.smb2, smb2_url->path, &smb2_stat,
-- 
GitLab