mirror of
https://github.com/samba-team/samba.git
synced 2025-02-02 09:47:23 +03:00
samba-tool: Add a gpo command for removing Sudoers Group Policy
Signed-off-by: David Mulder <dmulder@suse.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
This commit is contained in:
parent
f67a3644f4
commit
f509550f87
@ -1804,6 +1804,11 @@ samba-tool gpo manage sudoers list {31B2F340-016D-11D2-945F-00C04FB984F9}
|
||||
|
||||
class cmd_remove_sudoers(Command):
|
||||
"""Removes a Samba Sudoers Group Policy from the sysvol
|
||||
|
||||
This command removes a sudo rule from the sysvol from applying to winbind clients.
|
||||
|
||||
Example:
|
||||
samba-tool gpo manage sudoers remove {31B2F340-016D-11D2-945F-00C04FB984F9} 'fakeu ALL=(ALL) NOPASSWD: ALL'
|
||||
"""
|
||||
|
||||
synopsis = "%prog <gpo> <entry> [options]"
|
||||
@ -1822,7 +1827,51 @@ class cmd_remove_sudoers(Command):
|
||||
takes_args = ["gpo", "entry"]
|
||||
|
||||
def run(self, gpo, entry, H=None, sambaopts=None, credopts=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')
|
||||
pol_file = '\\'.join([realm.lower(), 'Policies', gpo,
|
||||
'MACHINE\\Registry.pol'])
|
||||
try:
|
||||
pol_data = ndr_unpack(preg.file, conn.loadfile(pol_file))
|
||||
except NTSTATUSError as e:
|
||||
if e.args[0] == 0xC0000033: # STATUS_OBJECT_NAME_INVALID
|
||||
raise CommandError("The specified entry does not exist")
|
||||
elif e.args[0] == 0xC0000022: # STATUS_ACCESS_DENIED
|
||||
raise CommandError("The authenticated user does "
|
||||
"not have sufficient privileges")
|
||||
raise
|
||||
|
||||
if entry not in [e.data for e in pol_data.entries]:
|
||||
raise CommandError("Cannot remove '%s' because it does not exist" %
|
||||
entry)
|
||||
|
||||
entries = [e for e in pol_data.entries if e.data != entry]
|
||||
pol_data.num_entries = len(entries)
|
||||
pol_data.entries = entries
|
||||
|
||||
try:
|
||||
conn.savefile(pol_file, ndr_pack(pol_data))
|
||||
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_sudoers(SuperCommand):
|
||||
"""Manage Sudoers Group Policy Objects"""
|
||||
|
@ -1 +0,0 @@
|
||||
^samba.tests.samba_tool.gpo.samba.tests.samba_tool.gpo.GpoCmdTestCase.test_sudoers_remove
|
Loading…
x
Reference in New Issue
Block a user