diff options
author | David Mulder <dmulder@suse.com> | 2020-11-12 11:19:37 -0700 |
---|---|---|
committer | David Mulder <dmulder@samba.org> | 2020-12-09 17:38:28 +0000 |
commit | fff3e0eb6afe4ef2d6b74bf80413c74b176bc441 (patch) | |
tree | e0a9c4cbc86bf5b5c46b53a15de844e11a2dd107 /python | |
parent | f74dea08be48dcb194570d9ff0ef2a30c2cf878e (diff) | |
download | samba-fff3e0eb6afe4ef2d6b74bf80413c74b176bc441.tar.gz |
samba-tool: Add a gpo command for listing smb.conf Group Policies
Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Diffstat (limited to 'python')
-rw-r--r-- | python/samba/netcmd/gpo.py | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/python/samba/netcmd/gpo.py b/python/samba/netcmd/gpo.py index 6ad45e5ca8c..b9c50c82797 100644 --- a/python/samba/netcmd/gpo.py +++ b/python/samba/netcmd/gpo.py @@ -2074,6 +2074,11 @@ class cmd_security(SuperCommand): class cmd_list_smb_conf(Command): """List Samba smb.conf Group Policy from the sysvol + +This command lists smb.conf settings from the sysvol that will be applied to winbind clients. + +Example: +samba-tool gpo manage smb_conf list {31B2F340-016D-11D2-945F-00C04FB984F9} """ synopsis = "%prog <gpo> [options]" @@ -2092,7 +2097,43 @@ class cmd_list_smb_conf(Command): takes_args = ["gpo"] def run(self, gpo, 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 + return # The file doesn't exist, so there is nothing to list + if e.args[0] == 0xC0000022: # STATUS_ACCESS_DENIED + raise CommandError("The authenticated user does " + "not have sufficient privileges") + raise + + keyname = b'Software\\Policies\\Samba\\smb_conf' + lp = param.LoadParm() + for entry in pol_data.entries: + if get_bytes(entry.keyname) == keyname: + lp.set(entry.valuename, str(entry.data)) + val = lp.get(entry.valuename) + self.outf.write('%s = %s\n' % (entry.valuename, val)) class cmd_smb_conf(SuperCommand): """Manage smb.conf Group Policy Objects""" |