mirror of
https://github.com/samba-team/samba.git
synced 2025-08-02 00:22:11 +03:00
samba-tool: Add a gpo command for adding VGP Symbolic Link Group Policy
Signed-off-by: David Mulder <dmulder@suse.com> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
committed by
Jeremy Allison
parent
7b2ecefd55
commit
3fc89829a9
@ -889,6 +889,11 @@
|
|||||||
<para>List VGP Symbolic Link Group Policy from the sysvol</para>
|
<para>List VGP Symbolic Link Group Policy from the sysvol</para>
|
||||||
</refsect3>
|
</refsect3>
|
||||||
|
|
||||||
|
<refsect3>
|
||||||
|
<title>gpo manage symlink add</title>
|
||||||
|
<para>Adds a VGP Symbolic Link Group Policy to the sysvol</para>
|
||||||
|
</refsect3>
|
||||||
|
|
||||||
<refsect2>
|
<refsect2>
|
||||||
<title>group</title>
|
<title>group</title>
|
||||||
<para>Manage groups.</para>
|
<para>Manage groups.</para>
|
||||||
|
@ -67,7 +67,7 @@ from samba.credentials import SMB_SIGNING_REQUIRED
|
|||||||
from samba.netcmd.common import attr_default
|
from samba.netcmd.common import attr_default
|
||||||
from samba.common import get_bytes, get_string
|
from samba.common import get_bytes, get_string
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
from io import StringIO
|
from io import StringIO, BytesIO
|
||||||
|
|
||||||
|
|
||||||
def gpo_flags_string(value):
|
def gpo_flags_string(value):
|
||||||
@ -2331,7 +2331,69 @@ samba-tool gpo manage symlink add {31B2F340-016D-11D2-945F-00C04FB984F9} /tmp/so
|
|||||||
|
|
||||||
def run(self, gpo, source, target, H=None, sambaopts=None, credopts=None,
|
def run(self, gpo, source, target, H=None, sambaopts=None, credopts=None,
|
||||||
versionopts=None):
|
versionopts=None):
|
||||||
pass
|
self.lp = sambaopts.get_loadparm()
|
||||||
|
self.creds = credopts.get_credentials(self.lp, fallback_machine=True)
|
||||||
|
|
||||||
|
# We need to know writable DC to setup SMB connection
|
||||||
|
if H and H.startswith('ldap://'):
|
||||||
|
dc_hostname = H[7:]
|
||||||
|
self.url = H
|
||||||
|
else:
|
||||||
|
dc_hostname = netcmd_finddc(self.lp, self.creds)
|
||||||
|
self.url = dc_url(self.lp, self.creds, dc=dc_hostname)
|
||||||
|
|
||||||
|
# SMB connect to DC
|
||||||
|
conn = smb_connection(dc_hostname,
|
||||||
|
'sysvol',
|
||||||
|
lp=self.lp,
|
||||||
|
creds=self.creds)
|
||||||
|
|
||||||
|
realm = self.lp.get('realm')
|
||||||
|
vgp_dir = '\\'.join([realm.lower(), 'Policies', gpo,
|
||||||
|
'MACHINE\\VGP\\VTLA\\Unix\\Symlink'])
|
||||||
|
vgp_xml = '\\'.join([vgp_dir, 'manifest.xml'])
|
||||||
|
try:
|
||||||
|
xml_data = ET.ElementTree(ET.fromstring(conn.loadfile(vgp_xml)))
|
||||||
|
policy = xml_data.getroot().find('policysetting')
|
||||||
|
data = policy.find('data')
|
||||||
|
except NTSTATUSError as e:
|
||||||
|
# STATUS_OBJECT_NAME_INVALID, STATUS_OBJECT_NAME_NOT_FOUND,
|
||||||
|
# STATUS_OBJECT_PATH_NOT_FOUND
|
||||||
|
if e.args[0] in [0xC0000033, 0xC0000034, 0xC000003A]:
|
||||||
|
# The file doesn't exist, so create the xml structure
|
||||||
|
xml_data = ET.ElementTree(ET.Element('vgppolicy'))
|
||||||
|
policysetting = ET.SubElement(xml_data.getroot(),
|
||||||
|
'policysetting')
|
||||||
|
pv = ET.SubElement(policysetting, 'version')
|
||||||
|
pv.text = '1'
|
||||||
|
name = ET.SubElement(policysetting, 'name')
|
||||||
|
name.text = 'Symlink Policy'
|
||||||
|
description = ET.SubElement(policysetting, 'description')
|
||||||
|
description.text = 'Specifies symbolic link data'
|
||||||
|
data = ET.SubElement(policysetting, 'data')
|
||||||
|
elif e.args[0] == 0xC0000022: # STATUS_ACCESS_DENIED
|
||||||
|
raise CommandError("The authenticated user does "
|
||||||
|
"not have sufficient privileges")
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
|
file_properties = ET.SubElement(data, 'file_properties')
|
||||||
|
source_elm = ET.SubElement(file_properties, 'source')
|
||||||
|
source_elm.text = source
|
||||||
|
target_elm = ET.SubElement(file_properties, 'target')
|
||||||
|
target_elm.text = target
|
||||||
|
|
||||||
|
out = BytesIO()
|
||||||
|
xml_data.write(out, encoding='UTF-8', xml_declaration=True)
|
||||||
|
out.seek(0)
|
||||||
|
try:
|
||||||
|
create_directory_hier(conn, vgp_dir)
|
||||||
|
conn.savefile(vgp_xml, out.read())
|
||||||
|
except NTSTATUSError as e:
|
||||||
|
if e.args[0] == 0xC0000022: # STATUS_ACCESS_DENIED
|
||||||
|
raise CommandError("The authenticated user does "
|
||||||
|
"not have sufficient privileges")
|
||||||
|
raise
|
||||||
|
|
||||||
class cmd_symlink(SuperCommand):
|
class cmd_symlink(SuperCommand):
|
||||||
"""Manage symlink Group Policy Objects"""
|
"""Manage symlink Group Policy Objects"""
|
||||||
|
@ -1 +0,0 @@
|
|||||||
^samba.tests.samba_tool.gpo.samba.tests.samba_tool.gpo.GpoCmdTestCase.test_symlink_add
|
|
Reference in New Issue
Block a user