summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorDavid Mulder <dmulder@suse.com>2018-07-18 11:34:09 -0600
committerDavid Mulder <dmulder@samba.org>2020-08-27 15:59:34 +0000
commit3303869c4b8659904e490e4ca1bc8bbcd340138d (patch)
tree1248e0276533fc20eb95a16e31e25626ec11b30c /python
parent37661d1aacaa7b761134c3f21a241ee0c1539d21 (diff)
downloadsamba-3303869c4b8659904e490e4ca1bc8bbcd340138d.tar.gz
gpo: Add CSE for applying smb.conf
Add an extension that applies smb.conf params applied via the smb.conf admx files. 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/gp_smb_conf_ext.py66
1 files changed, 65 insertions, 1 deletions
diff --git a/python/samba/gp_smb_conf_ext.py b/python/samba/gp_smb_conf_ext.py
index 1089ec4181e..a67c7ea1278 100644
--- a/python/samba/gp_smb_conf_ext.py
+++ b/python/samba/gp_smb_conf_ext.py
@@ -14,8 +14,72 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import os, re, numbers
from samba.gpclass import gp_pol_ext
+from tempfile import NamedTemporaryFile
+
+def is_number(x):
+ return isinstance(x, numbers.Number) and \
+ type(x) != bool
class gp_smb_conf_ext(gp_pol_ext):
def process_group_policy(self, deleted_gpo_list, changed_gpo_list):
- pass
+
+ pol_file = 'MACHINE/Registry.pol'
+ for guid, settings in deleted_gpo_list:
+ self.gp_db.set_guid(guid)
+ smb_conf = settings.get('smb.conf')
+ if smb_conf is None:
+ continue
+ for key, value in smb_conf.items():
+ self.set_smb_conf(key, value)
+ self.gp_db.delete('smb.conf', key)
+ self.gp_db.commit()
+
+ for gpo in changed_gpo_list:
+ if gpo.file_sys_path:
+ section_name = 'Software\\Policies\\Samba\\smb_conf'
+ self.gp_db.set_guid(gpo.name)
+ path = os.path.join(gpo.file_sys_path, pol_file)
+ pol_conf = self.parse(path)
+ if not pol_conf:
+ continue
+ for e in pol_conf.entries:
+ if not e.keyname.startswith(section_name):
+ continue
+ self.set_smb_conf(e.valuename, e.data)
+ self.gp_db.commit()
+
+ def set_smb_conf(self, attribute, val):
+ old_val = self.lp.get(attribute)
+
+ if type(val) == bytes:
+ val = val.decode()
+ if is_number(val) and is_number(old_val):
+ val = str(val)
+ elif is_number(val) and type(old_val) == bool:
+ val = bool(val)
+ if type(val) == bool:
+ val = 'yes' if val else 'no'
+
+ self.lp.set(attribute, val)
+ with NamedTemporaryFile(delete=False,
+ dir=os.path.dirname(self.lp.configfile)) as f:
+ self.lp.dump(False, f.name)
+ mode = os.stat(self.lp.configfile).st_mode
+ os.chmod(f.name, mode)
+ os.rename(f.name, self.lp.configfile)
+
+ self.logger.info('smb.conf [global] %s was changed from %s to %s' % \
+ (attribute, old_val, str(val)))
+
+ if is_number(old_val):
+ old_val = str(old_val)
+ elif type(old_val) == bool:
+ old_val = 'yes' if old_val else 'no'
+ elif type(old_val) == list:
+ old_val = ' '.join(old_val)
+ self.gp_db.store(str(self), attribute, old_val)
+
+ def __str__(self):
+ return "smb.conf"