diff --git a/modules/access/smb2.c b/modules/access/smb2.c index b1bebf0b6bd4bb73665fd639389199b4ddbfcd6b..6cdd37eb63cce614b8cdf81248a8c4d2f34bd6b5 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; @@ -161,7 +165,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 +183,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 +198,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) @@ -501,17 +505,33 @@ 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->ctr1.count && ret == VLC_SUCCESS; ++iinfo) + 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]; - if (info->type & SHARE_TYPE_HIDDEN) + const char *name = info->name; + uint32_t type = info->type; +#endif + + 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; } } @@ -603,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,