samba: fixes and improvements

Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Veiko Aasa 2019-11-23 12:41:25 +03:00 committed by James Valleroy
parent 598bcb6fbb
commit dbdd482e61
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
7 changed files with 137 additions and 27 deletions

View File

@ -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)

7
debian/copyright vendored
View File

@ -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:

View File

@ -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 '

View File

@ -35,11 +35,11 @@
{{ block.super }}
{% if is_enabled %}
<h3>{% trans "Select devices for sharing:" %}</h3>
<h3>{% trans "Select disks for sharing" %}</h3>
<p>
{% 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 %}
</p>
<table class="table table-bordered table-condensed table-striped">
@ -71,7 +71,10 @@
<input type="hidden" value="{{ disk.filesystem_type }}"
name="filesystem_type">
<input type="checkbox" value="{{ disk.mount_point }}"
name="mount_point" autocomplete="off"/>
name="mount_point" autocomplete="off"
{% if disk.filesystem_type == 'vfat' %}
title='{% trans "vfat partitions are not supported" %}' disabled
{% endif %}/>
</form>
{% endif %}
</td>
@ -102,11 +105,9 @@
</table>
{% if unavailable_shares %}
<h3>Shares configured but the disk is not available:</h3>
<h3>{% trans "Shares configured but the disk is not available" %}</h3>
<p>
{% 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." %}
</p>
<table class="table table-bordered table-condensed table-striped">
<thead>

View File

@ -36,6 +36,7 @@ class SambaAppView(views.AppView):
"""Samba sharing basic configuration."""
name = samba.name
description = samba.description
diagnostics_module_name = 'samba'
app_id = 'samba'
template_name = 'samba.html'

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
width="512"
height="512"
style="font-size:158px;font-family:DesignSystemC-700;fill:url(#linearGradient8)"
id="svg2"
sodipodi:docname="samba.svg"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)">
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1020"
id="namedview13"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:zoom="2"
inkscape:cx="211.38382"
inkscape:cy="310.44925"
inkscape:window-x="0"
inkscape:window-y="31"
inkscape:window-maximized="1"
inkscape:current-layer="svg2" />
<metadata
id="metadata4">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs6">
<linearGradient
x1="331.94678"
y1="12"
x2="331.94678"
y2="123"
gradientUnits="userSpaceOnUse"
id="linearGradient8">
<stop
style="stop-color:#99a29b;stop-opacity:1"
offset="0"
id="stop10" />
<stop
style="stop-color:#738777;stop-opacity:1"
offset="1"
id="stop12" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient8"
id="linearGradient27"
gradientUnits="userSpaceOnUse"
x1="331.94678"
y1="12"
x2="331.94678"
y2="123"
gradientTransform="matrix(3.5127656,0,0,3.1903866,-2.0368349,35.78584)" />
</defs>
<path
d="M 454.62268,39.375 V 69.88308 H 101.86774 c -19.240578,0 -33.397888,4.37836 -42.51178,13.0681 -9.113951,8.69024 -13.641139,22.03378 -13.641139,40.13778 v 148.28697 c 0,5.56095 1.371946,9.71908 4.17141,12.46243 2.799448,2.66927 7.15311,3.98801 13.063095,3.98798 H 377.12229 c 9.3551,0 15.90694,1.91725 19.64953,5.78257 4.05375,3.86557 6.03729,10.42331 6.03759,19.64082 v 21.03662 c 0,9.19035 -1.99594,15.68718 -6.03759,19.54111 -3.73139,3.85404 -10.32213,5.78258 -19.64953,5.78258 H 56.03357 V 328.50378 L -0.5,395.50188 56.03357,462.5 v -31.10627 h 356.65547 c 24.34224,0 42.36791,-5.456 53.899,-16.45042 11.53034,-10.99435 17.23411,-27.9418 17.2345,-50.84679 v -87.23713 c -3.5e-4,-21.08287 -5.30405,-36.73884 -15.91722,-46.85881 -10.61385,-10.40078 -27.10211,-15.55312 -49.50803,-15.55312 H 152.41508 c -9.01732,0 -15.60745,-1.92821 -19.64954,-5.78257 -4.04229,-3.85399 -6.03757,-10.35034 -6.03757,-19.54113 v -20.93693 c 0,-9.19046 1.99528,-15.78635 6.03757,-19.64079 4.04209,-3.85392 10.63222,-5.78234 19.64954,-5.78257 h 302.2076 v 30.50805 l 56.53357,-66.8984 z"
id="path14"
inkscape:connector-curvature="0"
style="fill:url(#linearGradient27);stroke-width:3.34769773" />
</svg>

After

Width:  |  Height:  |  Size: 3.5 KiB