diff options
author | David Mulder <dmulder@suse.com> | 2018-03-29 08:25:05 -0600 |
---|---|---|
committer | Douglas Bagnall <dbagnall@samba.org> | 2018-04-12 08:13:34 +0200 |
commit | 10b43aa1c9c1772af1485d93a8bdf53c31de211c (patch) | |
tree | d20f77544f635c0890c5f3892b459a1dbb74fc46 /python/samba/gpclass.py | |
parent | dc4151476923067b7659f42ca1f2c5f809cfef1e (diff) | |
download | samba-10b43aa1c9c1772af1485d93a8bdf53c31de211c.tar.gz |
gpo: Create base class gp_inf_ext
Abstract the process of reading from an ini file,
since other extensions will be reading gpos this
way.
Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'python/samba/gpclass.py')
-rw-r--r-- | python/samba/gpclass.py | 81 |
1 files changed, 47 insertions, 34 deletions
diff --git a/python/samba/gpclass.py b/python/samba/gpclass.py index 7f7392d8092..a4ff22b5e13 100644 --- a/python/samba/gpclass.py +++ b/python/samba/gpclass.py @@ -446,7 +446,53 @@ class inf_to_ldb(gp_ext_setter): return 'System Access' -class gp_sec_ext(gp_ext): +class gp_inf_ext(gp_ext): + @abstractmethod + def list(self, rootpath): + pass + + @abstractmethod + def apply_map(self): + pass + + def read(self, policy): + ret = False + inftable = self.apply_map() + + current_section = None + + # So here we would declare a boolean, + # that would get changed to TRUE. + # + # If at any point in time a GPO was applied, + # then we return that boolean at the end. + + inf_conf = ConfigParser() + inf_conf.optionxform=str + try: + inf_conf.readfp(StringIO(policy)) + except: + inf_conf.readfp(StringIO(policy.decode('utf-16'))) + + for section in inf_conf.sections(): + current_section = inftable.get(section) + if not current_section: + continue + for key, value in inf_conf.items(section): + if current_section.get(key): + (att, setter) = current_section.get(key) + value = value.encode('ascii', 'ignore') + ret = True + setter(self.logger, self.ldb, self.gp_db, self.lp, att, + value).update_samba() + self.gp_db.commit() + return ret + + @abstractmethod + def __str__(self): + pass + +class gp_sec_ext(gp_inf_ext): '''This class does the following two things: 1) Identifies the GPO if it has a certain kind of filepath, 2) Finally parses it. @@ -492,36 +538,3 @@ class gp_sec_ext(gp_ext): } } - def read(self, policy): - ret = False - inftable = self.apply_map() - - current_section = None - - # So here we would declare a boolean, - # that would get changed to TRUE. - # - # If at any point in time a GPO was applied, - # then we return that boolean at the end. - - inf_conf = ConfigParser() - inf_conf.optionxform=str - try: - inf_conf.readfp(StringIO(policy)) - except: - inf_conf.readfp(StringIO(policy.decode('utf-16'))) - - for section in inf_conf.sections(): - current_section = inftable.get(section) - if not current_section: - continue - for key, value in inf_conf.items(section): - if current_section.get(key): - (att, setter) = current_section.get(key) - value = value.encode('ascii', 'ignore') - ret = True - setter(self.logger, self.ldb, self.gp_db, self.lp, att, - value).update_samba() - self.gp_db.commit() - return ret - |