mirror of
https://github.com/samba-team/samba.git
synced 2025-08-03 04:22:09 +03:00
gpo: Make the gpclass more easily extensible
Signed-off-by: David Mulder <dmulder@suse.com> Reviewed-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
committed by
Garming Sam
parent
41d1ff7427
commit
8eba3b5d38
@ -29,27 +29,51 @@ import codecs
|
||||
from samba import NTSTATUSError
|
||||
from ConfigParser import ConfigParser
|
||||
from StringIO import StringIO
|
||||
from abc import ABCMeta, abstractmethod
|
||||
|
||||
class gp_ext(object):
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
@abstractmethod
|
||||
def list(self, rootpath):
|
||||
return None
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def parse(self, afile, ldb, conn, attr_log, lp):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def __str__(self):
|
||||
return "default_gp_ext"
|
||||
pass
|
||||
|
||||
|
||||
class inf_to_ldb(object):
|
||||
'''This class takes the .inf file parameter (essentially a GPO file mapped to a GUID),
|
||||
hashmaps it to the Samba parameter, which then uses an ldb object to update the
|
||||
parameter to Samba4. Not registry oriented whatsoever.
|
||||
'''
|
||||
class inf_to():
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
def __init__(self, logger, ldb, dn, attribute, val):
|
||||
def __init__(self, logger, ldb, dn, lp, attribute, val):
|
||||
self.logger = logger
|
||||
self.ldb = ldb
|
||||
self.dn = dn
|
||||
self.attribute = attribute
|
||||
self.val = val
|
||||
self.lp = lp
|
||||
|
||||
def explicit(self):
|
||||
return self.val
|
||||
|
||||
def update_samba(self):
|
||||
(upd_sam, value) = self.mapper().get(self.attribute)
|
||||
upd_sam(value())
|
||||
|
||||
@abstractmethod
|
||||
def mapper(self):
|
||||
pass
|
||||
|
||||
class inf_to_ldb(inf_to):
|
||||
'''This class takes the .inf file parameter (essentially a GPO file mapped to a GUID),
|
||||
hashmaps it to the Samba parameter, which then uses an ldb object to update the
|
||||
parameter to Samba4. Not registry oriented whatsoever.
|
||||
'''
|
||||
|
||||
def ch_minPwdAge(self, val):
|
||||
self.logger.info('KDC Minimum Password age was changed from %s to %s' % (self.ldb.get_minPwdAge(), val))
|
||||
@ -67,9 +91,6 @@ class inf_to_ldb(object):
|
||||
self.logger.info('KDC Password Properties were changed from %s to %s' % (self.ldb.get_pwdProperties(), val))
|
||||
self.ldb.set_pwdProperties(val)
|
||||
|
||||
def explicit(self):
|
||||
return self.val
|
||||
|
||||
def nttime2unix(self):
|
||||
seconds = 60
|
||||
minutes = 60
|
||||
@ -89,10 +110,6 @@ class inf_to_ldb(object):
|
||||
|
||||
}
|
||||
|
||||
def update_samba(self):
|
||||
(upd_sam, value) = self.mapper().get(self.attribute)
|
||||
upd_sam(value()) # or val = value() then update(val)
|
||||
|
||||
|
||||
class gp_sec_ext(gp_ext):
|
||||
'''This class does the following two things:
|
||||
@ -156,11 +173,12 @@ class gp_sec_ext(gp_ext):
|
||||
(att, setter) = current_section.get(key)
|
||||
value = value.encode('ascii', 'ignore')
|
||||
ret = True
|
||||
setter(self.logger, self.ldb, self.dn, att, value).update_samba()
|
||||
setter(self.logger, self.ldb, self.dn, self.lp, att, value).update_samba()
|
||||
return ret
|
||||
|
||||
def parse(self, afile, ldb, conn, attr_log):
|
||||
def parse(self, afile, ldb, conn, attr_log, lp):
|
||||
self.ldb = ldb
|
||||
self.lp = lp
|
||||
self.dn = ldb.get_default_basedn()
|
||||
|
||||
# Fixing the bug where only some Linux Boxes capitalize MACHINE
|
||||
|
@ -49,7 +49,7 @@ def gp_path_list(path):
|
||||
return GPO_LIST
|
||||
|
||||
|
||||
def gpo_parser(GPO_LIST, ldb, conn, attr_log):
|
||||
def gpo_parser(GPO_LIST, ldb, conn, attr_log, lp):
|
||||
'''The API method to parse the GPO
|
||||
:param GPO_LIST:
|
||||
:param ldb: Live instance of an LDB object AKA Samba
|
||||
@ -62,9 +62,9 @@ def gpo_parser(GPO_LIST, ldb, conn, attr_log):
|
||||
for entry in GPO_LIST:
|
||||
(ext, thefile) = entry
|
||||
if ret == False:
|
||||
ret = ext.parse(thefile, ldb, conn, attr_log)
|
||||
ret = ext.parse(thefile, ldb, conn, attr_log, lp)
|
||||
else:
|
||||
temp = ext.parse(thefile, ldb, conn, attr_log)
|
||||
temp = ext.parse(thefile, ldb, conn, attr_log, lp)
|
||||
return ret
|
||||
|
||||
|
||||
@ -243,7 +243,7 @@ for guid_eval in hierarchy_gpos:
|
||||
if (version != 0) and GPO_Changed == True:
|
||||
logger.info('GPO %s has changed' % guid)
|
||||
try:
|
||||
change_backlog = gpo_parser(gpolist, test_ldb, conn, attr_log)
|
||||
change_backlog = gpo_parser(gpolist, test_ldb, conn, attr_log, lp)
|
||||
except:
|
||||
logger.error('Failed to parse gpo %s' % guid)
|
||||
continue
|
||||
|
Reference in New Issue
Block a user