mirror of
https://github.com/altlinux/gpupdate.git
synced 2025-03-21 18:50:38 +03:00
gpupdate-setup functions for local policy setup moved to util.util
This commit is contained in:
parent
af1e756037
commit
b5059620a7
@ -22,6 +22,7 @@ import os
|
||||
import pwd
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from .samba import smbopts
|
||||
|
||||
|
||||
def get_machine_name():
|
||||
@ -97,3 +98,82 @@ def runcmd(command_name):
|
||||
except Exception as exc:
|
||||
print(str(exc))
|
||||
|
||||
def get_backends():
|
||||
'''
|
||||
Get the list of backends supported by GPOA
|
||||
'''
|
||||
command = ['/usr/sbin/gpoa', '--list-backends']
|
||||
backends = list()
|
||||
out = list()
|
||||
|
||||
with subprocess.Popen(command, stdout=subprocess.PIPE) as proc:
|
||||
out = proc.stdout.read().decode('utf-8')
|
||||
proc.wait()
|
||||
out = out.split('\n')
|
||||
for line in out:
|
||||
tmpline = line.replace('\n', '')
|
||||
if tmpline != '':
|
||||
backends.append(tmpline)
|
||||
|
||||
return backends
|
||||
|
||||
def get_default_policy_name():
|
||||
'''
|
||||
Determine the preferred Local Policy template name according to
|
||||
ALT distribution type
|
||||
'''
|
||||
localpolicy = 'workstation'
|
||||
dcpolicy = 'ad-domain-controller'
|
||||
|
||||
try:
|
||||
if smbopts().get_server_role() == 'active directory domain controller':
|
||||
return dcpolicy
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
release = '/etc/altlinux-release'
|
||||
if os.path.isfile(release):
|
||||
f = open(release)
|
||||
s = f.readline()
|
||||
if re.search('server', s, re.I):
|
||||
localpolicy = 'server'
|
||||
except:
|
||||
pass
|
||||
|
||||
return localpolicy
|
||||
|
||||
def get_policy_entries(directory):
|
||||
'''
|
||||
Get list of directories representing "Local Policy" templates.
|
||||
'''
|
||||
filtered_entries = list()
|
||||
if os.path.isdir(directory):
|
||||
entries = [os.path.join(directory, entry) for entry in os.listdir(directory)]
|
||||
|
||||
for entry in entries:
|
||||
if os.path.isdir(os.path.join(entry)):
|
||||
if not os.path.islink(os.path.join(entry)):
|
||||
if not entry.rpartition('/')[2] == 'default':
|
||||
filtered_entries.append(entry)
|
||||
|
||||
return filtered_entries
|
||||
|
||||
def get_policy_variants():
|
||||
'''
|
||||
Get the list of local policy variants deployed on this system.
|
||||
Please note that is case overlapping names the names in
|
||||
/etc/local-policy must override names in /usr/share/local-policy
|
||||
'''
|
||||
policy_dir = '/usr/share/local-policy'
|
||||
etc_policy_dir = '/etc/local-policy'
|
||||
|
||||
system_policies = get_policy_entries(policy_dir)
|
||||
user_policies = get_policy_entries(etc_policy_dir)
|
||||
|
||||
general_listing = list()
|
||||
general_listing.extend(system_policies)
|
||||
general_listing.extend(user_policies)
|
||||
|
||||
return general_listing
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user