diff --git a/modules/access/Makefile.am b/modules/access/Makefile.am index b73fda5f4c3b0e1756f63686b2b1a9732bacbbdc..b6b3af2266e673c38ebd746ebc3f870ae233c428 100644 --- a/modules/access/Makefile.am +++ b/modules/access/Makefile.am @@ -242,7 +242,7 @@ endif EXTRA_LTLIBRARIES += libvcd_plugin.la access_LTLIBRARIES += $(LTLIBvcd) -libdvdnav_plugin_la_SOURCES = access/dvdnav.c demux/mpeg/ps.h demux/mpeg/pes.h +libdvdnav_plugin_la_SOURCES = access/disc_helper.h access/dvdnav.c demux/mpeg/ps.h demux/mpeg/pes.h libdvdnav_plugin_la_CFLAGS = $(AM_CFLAGS) $(DVDNAV_CFLAGS) libdvdnav_plugin_la_LIBADD = $(DVDNAV_LIBS) libdvdnav_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(accessdir)' diff --git a/modules/access/disc_helper.h b/modules/access/disc_helper.h new file mode 100644 index 0000000000000000000000000000000000000000..8d5a4ef8b44ffd8295b61a2ba091ade2be54126f --- /dev/null +++ b/modules/access/disc_helper.h @@ -0,0 +1,70 @@ +/***************************************************************************** + * disc_helper.h: disc helper functions + ***************************************************************************** + * Copyright (C) 2020 VLC authors and VideoLAN + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#include <errno.h> +#include <sys/stat.h> +#include <unistd.h> + +#include <vlc_dialog.h> +#include <vlc_fs.h> + + +inline static int DiscProbeMacOSPermission( vlc_object_t *p_this, const char *psz_file ) +{ +#ifdef __APPLE__ + /* Check is only relevant starting macOS Catalina */ + if( __builtin_available( macOS 10.15, * ) ) + { + /* Continue. The check above cannot be negated. */ + } + else + { + return VLC_SUCCESS; + } + + msg_Dbg( p_this, "Checking access permission for path %s", psz_file ); + + struct stat stat_buf; + if( vlc_stat( psz_file, &stat_buf ) != 0 ) + return VLC_SUCCESS; // Continue with probing to be on the safe side + + if( !S_ISBLK( stat_buf.st_mode ) && !S_ISCHR( stat_buf.st_mode ) ) + return VLC_SUCCESS; + + /* Check that device access in fact fails with EPERM error */ + int retVal = access( psz_file, R_OK ); + if( retVal == -1 && errno == EPERM ) + { + msg_Err( p_this, "Path %s cannot be opened due to unsufficient permissions", psz_file ); + vlc_dialog_display_error( p_this, _("Problem accessing a system resource"), + _("Potentially, macOS blocks access to your disc. " + "Please open \"System Preferences\" -> \"Security & Privacy\" " + "and allow VLC to access your external media in \"Files and Folders\" section.")); + + return VLC_EGENERIC; + } + + return VLC_SUCCESS; +#else + VLC_UNUSED( p_this ); + VLC_UNUSED( psz_file ); + return VLC_SUCCESS; +#endif +} diff --git a/modules/access/dvdnav.c b/modules/access/dvdnav.c index 0200871bdfefe22da716b622337a48e05d9db8f8..2b199f76c896d646ee23d518cde8b9b9035e75c6 100644 --- a/modules/access/dvdnav.c +++ b/modules/access/dvdnav.c @@ -65,6 +65,8 @@ dvdnav_status_t dvdnav_jump_to_sector_by_time(dvdnav_t *, uint64_t, int32_t); #include "../demux/mpeg/ps.h" #include "../demux/timestamps_filter.h" +#include "disc_helper.h" + /***************************************************************************** * Module descriptor *****************************************************************************/ @@ -414,6 +416,9 @@ static int AccessDemuxOpen ( vlc_object_t *p_this ) if( !forced && ProbeDVD( psz_file ) != VLC_SUCCESS ) goto bailout; + if( forced && DiscProbeMacOSPermission( p_this, psz_file ) != VLC_SUCCESS ) + goto bailout; + /* Open dvdnav */ psz_path = ToLocale( psz_file ); #if DVDNAV_VERSION >= 60100 @@ -425,13 +430,6 @@ static int AccessDemuxOpen ( vlc_object_t *p_this ) #endif { msg_Warn( p_demux, "cannot open DVD (%s)", psz_file); - -#ifdef __APPLE__ - vlc_dialog_display_error( p_demux, _("Problem accessing a system resource"), - _("Potentially, macOS blocks access to your disc. " - "Please open \"System Preferences\" -> \"Security & Privacy\" " - "and allow VLC to access your external media in \"Files and Folders\" section.")); -#endif goto bailout; } diff --git a/po/POTFILES.in b/po/POTFILES.in index b65bf541c5edf85f99542160afaccc8bbec2fedc..ae2d9379cb9ec662c359ae112d9622bc637c0a92 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -159,6 +159,7 @@ modules/access/concat.c modules/access/dc1394.c modules/access/dcp/dcp.cpp modules/access/decklink.cpp +modules/access/disc_helper.h modules/access/dshow/dshow.cpp modules/access/dsm/access.c modules/access/dsm/sd.c