From 9d653d87eccafee083e8bcbea80b63aa5fdb480e Mon Sep 17 00:00:00 2001 From: Veiko Aasa Date: Mon, 13 Jan 2020 12:03:25 +0200 Subject: [PATCH] storage: Make external disk mounts accessible by other users - samba app doesn't need anymore to change mount permissions Fixes #1692 (in a different way) Signed-off-by: Veiko Aasa Reviewed-by: James Valleroy --- actions/samba | 10 ---------- actions/storage | 17 +++++++++++++++++ plinth/modules/storage/__init__.py | 3 ++- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/actions/samba b/actions/samba index c7d79cdd5..f225aea3c 100755 --- a/actions/samba +++ b/actions/samba @@ -24,7 +24,6 @@ import configparser import json import os import shutil -import stat import subprocess SHARES_CONF_BACKUP_FILE = '/var/lib/plinth/backups-data/samba-shares-dump.conf' @@ -120,8 +119,6 @@ def _create_share(mount_point, share_type, windows_filesystem=False): share_path = os.path.join(mount_point, shares_path, subdir) os.makedirs(share_path, exist_ok=True) - _make_mounts_readable_by_others(mount_point) - # FAT and NTFS partitions don't support setting permissions if not windows_filesystem: if share_type in ['open', 'group']: @@ -235,13 +232,6 @@ def _get_shares_path(mount_point): return 'FreedomBox/shares/' -def _make_mounts_readable_by_others(mount_point): - """Make mounted devices readable/traversible by others.""" - dirname = os.path.dirname(mount_point) - stats = os.stat(dirname) - os.chmod(dirname, stats.st_mode | stat.S_IROTH | stat.S_IXOTH) - - def _set_open_share_permissions(directory): """Set file and directory permissions for open share.""" shutil.chown(directory, group='freedombox-share') diff --git a/actions/storage b/actions/storage index 181f431f7..f645a0e1b 100755 --- a/actions/storage +++ b/actions/storage @@ -23,6 +23,7 @@ import argparse import json import os import re +import stat import subprocess import sys @@ -34,6 +35,8 @@ def parse_arguments(): parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(dest='subcommand', help='Sub command') + subparsers.add_parser('setup', help='Configure storage after install') + subparser = subparsers.add_parser( 'is-partition-expandable', help='Return whether a given partition can be expanded') @@ -320,6 +323,20 @@ def umount_all_filesystems_of_drive(drive_object_path): umount_filesystem(obj.get_filesystem()) +def subcommand_setup(_): + """Configure storage.""" + # create udisks2 default mount directory + mounts_directory = '/media/root' + try: + os.mkdir(mounts_directory) + except FileExistsError: + pass + + # make the directory readable and traversible by other users + stats = os.stat(mounts_directory) + os.chmod(mounts_directory, stats.st_mode | stat.S_IROTH | stat.S_IXOTH) + + def subcommand_usage_info(_): """Get information about disk space usage.""" command = [ diff --git a/plinth/modules/storage/__init__.py b/plinth/modules/storage/__init__.py index a162d3b35..adbc66971 100644 --- a/plinth/modules/storage/__init__.py +++ b/plinth/modules/storage/__init__.py @@ -32,7 +32,7 @@ from plinth.utils import format_lazy, import_from_gi from .manifest import backup # noqa, pylint: disable=unused-import -version = 3 +version = 4 name = _('Storage') @@ -277,6 +277,7 @@ def get_error_message(error): def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages, skip_recommends=True) + helper.call('post', actions.superuser_run, 'storage', ['setup']) helper.call('post', app.enable) disks = get_disks() root_device = get_root_device(disks)