1
0
mirror of https://github.com/altlinux/gpupdate.git synced 2025-03-21 18:50:38 +03:00

Merge pull request #188 from altlinux/addition_mapped_drive

Create symlinks in user home directory for mapped network drives
This commit is contained in:
Evgeny Sinelnikov 2022-12-29 05:33:55 +04:00 committed by GitHub
commit 11768248e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 88 additions and 4 deletions

View File

@ -139,16 +139,27 @@ class cifs_applier_user(applier_frontend):
__template_auto = 'autofs_auto.j2'
__template_mountpoints_hide = 'autofs_mountpoints_hide.j2'
__template_auto_hide = 'autofs_auto_hide.j2'
__enable_home_link = 'Software\\BaseALT\\Policies\\GPUpdate\\DriveMapsHome'
__enable_home_link_user = 'Software\\BaseALT\\Policies\\GPUpdate\\DriveMapsHomeUser'
__target_mountpoint = '/media/gpupdate'
__target_mountpoint_user = '/run/media'
__mountpoint_dirname = 'drives.system'
__mountpoint_dirname_user = 'drives'
def __init__(self, storage, sid, username):
self.storage = storage
self.sid = sid
self.username = username
self.state_home_link = False
self.state_home_link_user = False
if username:
self.home = '/run/media/' + username
self.home = self.__target_mountpoint_user + '/' + username
self.state_home_link = self.check_enable_home_link(self.__enable_home_link)
self.state_home_link_user = self.check_enable_home_link(self.__enable_home_link_user)
else:
self.home = '/media/gpupdate'
self.home = self.__target_mountpoint
conf_file = '{}.conf'.format(sid)
conf_hide_file = '{}_hide.conf'.format(sid)
autofs_file = '{}.autofs'.format(sid)
@ -172,9 +183,9 @@ class cifs_applier_user(applier_frontend):
self.user_creds = self.auto_master_d / cred_file
if username:
self.mntTarget = 'UserDrive'
self.mntTarget = self.__mountpoint_dirname_user
else:
self.mntTarget = 'Drive'
self.mntTarget = self.__mountpoint_dirname
self.mount_dir = Path(os.path.join(self.home))
self.drives = storage_get_drives(self.storage, self.sid)
@ -195,6 +206,12 @@ class cifs_applier_user(applier_frontend):
, self.__module_experimental
)
def check_enable_home_link(self, enable_home_link):
if self.storage.get_hkcu_entry(self.sid, enable_home_link):
data = self.storage.get_hkcu_entry(self.sid, enable_home_link).data
return bool(int(data))
else:
return False
def user_context_apply(self):
'''
@ -264,8 +281,59 @@ class cifs_applier_user(applier_frontend):
f.write(autofs_text)
f.flush()
if self.username:
self.update_drivemaps_home_links()
subprocess.check_call(['/bin/systemctl', 'restart', 'autofs'])
def update_drivemaps_home_links():
dUser = Path(get_homedir(self.username)+'/net.' + self.__mountpoint_dirname_user)
dUserHide = Path(get_homedir(self.username)+'/.net.' + self.__mountpoint_dirname_user)
if self.state_home_link_user:
dUserMountpoint = Path(self.home).joinpath(self.__mountpoint_dirname_user)
dUserMountpointHide = Path(self.home).joinpath('.' + self.__mountpoint_dirname_user)
if not dUser.exists():
try:
os.symlink(dUserMountpoint, dUser, True)
except Exception as exc:
log('D194', {'exc': exc})
if not dUserHide.exists():
try:
os.symlink(dUserMountpointHide, dUserHide, True)
except Exception as exc:
log('D196', {'exc': exc})
else:
if dUser.is_symlink() and dUser.owner() == 'root':
dUser.unlink()
if dUserHide.is_symlink() and dUserHide.owner() == 'root':
dUserHide.unlink()
dMachine = Path(get_homedir(self.username)+'/net.' + self.__mountpoint_dirname)
dMachineHide = Path(get_homedir(self.username)+'/.net.' + self.__mountpoint_dirname)
if self.state_home_link:
dMachineMountpoint = Path(self.__target_mountpoint).joinpath(self.__mountpoint_dirname)
dMachineMountpointHide = Path(self.__target_mountpoint).joinpath('.' + self.__mountpoint_dirname)
if not dMachine.exists():
try:
os.symlink(dMachineMountpoint, dMachine, True)
except Exception as exc:
log('D195', {'exc': exc})
if not dMachineHide.exists():
try:
os.symlink(dMachineMountpointHide, dMachineHide, True)
except Exception as exc:
log('D197', {'exc': exc})
else:
if dMachine.is_symlink() and dMachine.owner() == 'root':
dMachine.unlink()
if dMachineHide.is_symlink() and dMachineHide.owner() == 'root':
dMachineHide.unlink()
def admin_context_apply(self):
if self.__module_enabled:

View File

@ -795,6 +795,18 @@ msgstr "Процесс GPOA запущен для компьютера"
msgid "Running networkshare applier for machine will not be started"
msgstr "Применение настроек сетевых каталогов для машины не будет запущено"
msgid "Failed to create a symlink to the network drives mountpoint"
msgstr "Не удалось создать ссылку на точку монтирования сетевых дисков пользователя"
msgid "Failed to create a symlink to the system network drives mountpoint"
msgstr "Не удалось создать ссылку на точку монтирования системных сетевых дисков"
msgid "Failed to create a symlink to the hidden network drives mountpoint"
msgstr "Не удалось создать ссылку на точку монтирования скрытых сетевых дисков пользователя"
msgid "Failed to create a symlink to the hidden system network drives mountpoint"
msgstr "Не удалось создать ссылку на точку монтирования скрытых системных сетевых дисков"
# Debug_end
# Warning

View File

@ -298,6 +298,10 @@ def debug_code(code):
debug_ids[191] = 'File copy'
debug_ids[192] = 'File update'
debug_ids[193] = 'Deleting a file'
debug_ids[194] = 'Failed to create a symlink to the network drives mountpoint'
debug_ids[195] = 'Failed to create a symlink to the system network drives mountpoint'
debug_ids[196] = 'Failed to create a symlink to the hidden network drives mountpoint'
debug_ids[197] = 'Failed to create a symlink to the hidden system network drives mountpoint'
return debug_ids.get(code, 'Unknown debug code')