mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
samba: private shares
- new share types - group and home shares - users: when creating, deleting or changing user password, update also Samba tdbsam backend database - users: new managed packages - samba-common-bin, tdb-tools - module page: show current samba users who are in freedombox-share group - module page: show users who should re-enter their password in the password change page - fix: use os.path.ismount() from Python standard library to validate a mount point - fix: samba share permissions, fixes #1729 - fix: delete a share - do not raise an exception if the share doesn't exist - storage: show samba share type in the directory selection form Closes #1727 Signed-off-by: Veiko Aasa <veiko17@disroot.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
1 parent
851d1c7c28
commit
83cb305026
10 files changed
+360
-172
No files matched your search
+66
-3
@@ -27,7 +27,6 @@ import subprocess
|
||||
import sys
|
||||
|
||||
import augeas
|
||||
|
||||
from plinth import action_utils
|
||||
|
||||
ACCESS_CONF = '/etc/security/access.conf'
|
||||
@@ -80,6 +79,12 @@ def parse_arguments():
|
||||
subparser.add_argument('username', help='LDAP user to add to group')
|
||||
subparser.add_argument('groupname', help='LDAP group to add the user to')
|
||||
|
||||
subparser = subparsers.add_parser('set-user-status',
|
||||
help='Set user as active or inactive')
|
||||
subparser.add_argument('username', help='User to change status')
|
||||
subparser.add_argument('status', choices=['active', 'inactive'],
|
||||
help='New status of the user')
|
||||
|
||||
subparser = subparsers.add_parser(
|
||||
'remove-user-from-group',
|
||||
help='Remove an LDAP user from an LDAP group')
|
||||
@@ -227,6 +232,23 @@ def configure_ldapscripts():
|
||||
aug.save()
|
||||
|
||||
|
||||
def get_samba_users():
|
||||
"""Get users from the Samba user database."""
|
||||
# 'pdbedit -L' is better for listing users but is installed only with samba
|
||||
stdout = subprocess.check_output(
|
||||
['tdbdump', '/var/lib/samba/private/passdb.tdb']).decode()
|
||||
return re.findall(r'USER_(.*)\\0', stdout)
|
||||
|
||||
|
||||
def disconnect_samba_user(username):
|
||||
"""Disconnect a Samba user."""
|
||||
try:
|
||||
subprocess.check_call(['pkill', '-U', username, 'smbd'])
|
||||
except subprocess.CalledProcessError as error:
|
||||
if error.returncode != 1:
|
||||
raise
|
||||
|
||||
|
||||
def read_password():
|
||||
"""Read the password from stdin."""
|
||||
return ''.join(sys.stdin)
|
||||
@@ -235,8 +257,10 @@ def read_password():
|
||||
def subcommand_create_user(arguments):
|
||||
"""Create an LDAP user, set password and flush cache."""
|
||||
_run(['ldapadduser', arguments.username, 'users'])
|
||||
set_user_password(arguments.username, read_password())
|
||||
password = read_password()
|
||||
set_user_password(arguments.username, password)
|
||||
flush_cache()
|
||||
set_samba_user(arguments.username, password)
|
||||
|
||||
|
||||
def subcommand_remove_user(arguments):
|
||||
@@ -244,10 +268,15 @@ def subcommand_remove_user(arguments):
|
||||
username = arguments.username
|
||||
groups = get_user_groups(username)
|
||||
|
||||
if username in get_samba_users():
|
||||
subprocess.check_call(['smbpasswd', '-x', username])
|
||||
disconnect_samba_user(username)
|
||||
|
||||
for group in groups:
|
||||
remove_user_from_group(username, group)
|
||||
|
||||
_run(['ldapdeleteuser', username])
|
||||
|
||||
flush_cache()
|
||||
|
||||
|
||||
@@ -275,9 +304,25 @@ def set_user_password(username, password):
|
||||
_run(['ldapsetpasswd', username, password])
|
||||
|
||||
|
||||
def set_samba_user(username, password):
|
||||
"""Insert a user to the Samba database.
|
||||
|
||||
If a user already exists, update password.
|
||||
"""
|
||||
proc = subprocess.Popen(['smbpasswd', '-a', '-s', username],
|
||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
_, stderr = proc.communicate(input='{0}\n{0}\n'.format(password).encode(),
|
||||
timeout=10)
|
||||
if proc.returncode != 0:
|
||||
raise RuntimeError('Unable to add Samba user: ', stderr)
|
||||
|
||||
|
||||
def subcommand_set_user_password(arguments):
|
||||
"""Set a user's password."""
|
||||
set_user_password(arguments.username, read_password())
|
||||
password = read_password()
|
||||
set_user_password(arguments.username, password)
|
||||
set_samba_user(arguments.username, password)
|
||||
|
||||
|
||||
def get_user_groups(username):
|
||||
@@ -352,6 +397,8 @@ def subcommand_remove_user_from_group(arguments):
|
||||
"""Remove an LDAP user from an LDAP group."""
|
||||
remove_user_from_group(arguments.username, arguments.groupname)
|
||||
flush_cache()
|
||||
if arguments.groupname == 'freedombox-share':
|
||||
disconnect_samba_user(arguments.username)
|
||||
|
||||
|
||||
def subcommand_get_group_users(arguments):
|
||||
@@ -369,6 +416,22 @@ def subcommand_get_group_users(arguments):
|
||||
print(user)
|
||||
|
||||
|
||||
def subcommand_set_user_status(arguments):
|
||||
"""Set the status of the user."""
|
||||
username = arguments.username
|
||||
status = arguments.status
|
||||
|
||||
if status == 'active':
|
||||
flag = '-e'
|
||||
else:
|
||||
flag = '-d'
|
||||
|
||||
if username in get_samba_users():
|
||||
subprocess.check_call(['smbpasswd', flag, username])
|
||||
if status == 'inactive':
|
||||
disconnect_samba_user(username)
|
||||
|
||||
|
||||
def flush_cache():
|
||||
"""Flush nscd and apache2 cache."""
|
||||
_run(['nscd', '--invalidate=passwd'])
|
||||
|
||||
Reference in new issue
Block a user