diff --git a/actions/samba b/actions/samba index 3cadf7444..419bc7900 100755 --- a/actions/samba +++ b/actions/samba @@ -24,6 +24,7 @@ import configparser import json import os import shutil +import stat import subprocess import augeas @@ -93,6 +94,11 @@ def parse_arguments(): return parser.parse_args() +def _close_share(share_name): + """Disconnect all samba users who are connected to the share.""" + subprocess.check_call(['smbcontrol', 'smbd', 'close-share', share_name]) + + def _conf_command(parameters, **kwargs): """Run samba configuration registry command.""" subprocess.check_call(['net', 'conf'] + parameters, **kwargs) @@ -103,6 +109,8 @@ def _create_share(mount_point, windows_filesystem=False): open_share_path = os.path.join(mount_point, SHARES_PATH, 'open_share') os.makedirs(open_share_path, exist_ok=True) + _make_mounts_readable_by_others(mount_point) + # FAT and NTFS partitions don't support chown and chmod if not windows_filesystem: shutil.chown(open_share_path, group='sambashare') @@ -112,6 +120,15 @@ def _create_share(mount_point, windows_filesystem=False): _define_open_share(share_name, open_share_path, windows_filesystem) +def _create_share_name(mount_point): + """Create a share name.""" + share_name = os.path.basename(mount_point) + if not share_name: + share_name = 'disk' + + return share_name + + def _define_open_share(name, path, windows_filesystem=False): """Define an open samba share.""" try: @@ -124,20 +141,10 @@ def _define_open_share(name, path, windows_filesystem=False): _conf_command(['setparm', name, 'inherit permissions', 'yes']) -def _create_share_name(mount_point): - """Create a share name.""" - share_name = os.path.basename(mount_point) - if not share_name: - share_name = "disk" - - return share_name - - def _get_shares(): - """Get shares""" + """Get shares.""" shares = [] - command = ['net', 'conf', 'list'] - output = subprocess.check_output(command) + output = subprocess.check_output(['net', 'conf', 'list']) config = configparser.ConfigParser() config.read_string(output.decode()) for name in config.sections(): @@ -148,6 +155,13 @@ def _get_shares(): return 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 _use_config_file(conf_file): """Set samba configuration file location.""" aug = augeas.Augeas( @@ -182,13 +196,12 @@ def subcommand_delete_share(arguments): shares = _get_shares() for share in shares: if share['mount_point'] == mount_point: + _close_share(share['name']) _conf_command(['delshare', share['name']]) - # restart samba to disconnect all users - action_utils.service_restart('smbd') break else: raise RuntimeError( - 'Mount path "{0}" is not shared.'.format(mount_point)) + 'Mount point "{0}" is not shared.'.format(mount_point)) def subcommand_get_shares(_): @@ -197,7 +210,7 @@ def subcommand_get_shares(_): def subcommand_setup(_): - """Configure samba. Use custom samba config file.""" + """Configure samba, use custom samba config file.""" with open(CONF_PATH, 'w') as file_handle: file_handle.write(CONF) _use_config_file(CONF_PATH) diff --git a/debian/copyright b/debian/copyright index a2bca8c0b..9c5eb3ca7 100644 --- a/debian/copyright +++ b/debian/copyright @@ -172,6 +172,13 @@ Copyright: Thomas B. (https://github.com/thomascube) Comment: https://raw.githubusercontent.com/roundcube/roundcubemail/master/skins/elastic/images/logo.svg License: CC-BY-SA-3.0 +Files: static/themes/default/icons/samba.png + static/themes/default/icons/samba.svg +Copyright: None +Comment: 2010 Samba Team + https://commons.wikimedia.org/wiki/File:Samba_logo_2010.svg +License: public-domain + Files: static/themes/default/icons/searx.png static/themes/default/icons/searx.svg Copyright: diff --git a/plinth/modules/samba/__init__.py b/plinth/modules/samba/__init__.py index f18d946a4..c52b1bf2f 100644 --- a/plinth/modules/samba/__init__.py +++ b/plinth/modules/samba/__init__.py @@ -41,11 +41,11 @@ managed_packages = ['samba'] name = _('Samba') -short_description = _('Samba File Sharing') +short_description = _('File Sharing') description = [ - _('Samba allows to share files and folders between computers in your ' - 'local network.'), + _('Samba allows to share files and folders between FreedomBox and ' + 'other computers in your local network.'), format_lazy( _('After installation, you can choose which disks to use for sharing. ' 'Enabled {hostname} shares are open to everyone in your local ' diff --git a/plinth/modules/samba/templates/samba.html b/plinth/modules/samba/templates/samba.html index 2e849d70c..d6760eaa3 100644 --- a/plinth/modules/samba/templates/samba.html +++ b/plinth/modules/samba/templates/samba.html @@ -35,11 +35,11 @@ {{ block.super }} {% if is_enabled %} -
{% blocktrans trimmed %} - NB! Selecting device does not share the whole disk, only the folder - FreedomBox/shares/open_share will be shared on that disk. + NB! Only the directory FreedomBox/shares/open_share will be shared on + selected disks. The directory will be created if it doesn't exist. {% endblocktrans %}
- {% blocktrans trimmed %} - If the disk is plugged back in, sharing will be automatically enabled. - {% endblocktrans %} + {% trans "If the disk is plugged back in, sharing will be automatically enabled." %}