mirror of
https://github.com/samba-team/samba.git
synced 2025-08-03 04:22:09 +03:00
python/samba: PY3 port gpo.apply smbtorture test
1) configparser.set requires string values 2) self.gp_db.store() etc. neex to pass str object for xml.etree.ElementTree.Element text attribute which needs to be text 3) tdb delete method needs bytes key 4) configparser.write needs a file opened in text mode Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
@ -18,6 +18,7 @@
|
||||
import os.path
|
||||
from samba.gpclass import gp_ext_setter, gp_inf_ext
|
||||
from samba.auth import system_session
|
||||
from samba.compat import get_string
|
||||
try:
|
||||
from ldb import LdbError
|
||||
from samba.samdb import SamDB
|
||||
@ -37,8 +38,8 @@ class inf_to_kdc_tdb(gp_ext_setter):
|
||||
self.logger.info('%s was changed from %s to %s' % (self.attribute,
|
||||
old_val, val))
|
||||
if val is not None:
|
||||
self.gp_db.gpostore.store(self.attribute, val)
|
||||
self.gp_db.store(str(self), self.attribute, old_val)
|
||||
self.gp_db.gpostore.store(self.attribute, get_string(val))
|
||||
self.gp_db.store(str(self), self.attribute, get_string(old_val) if old_val else None)
|
||||
else:
|
||||
self.gp_db.gpostore.delete(self.attribute)
|
||||
self.gp_db.delete(str(self), self.attribute)
|
||||
|
@ -23,6 +23,7 @@ sys.path.insert(0, "bin/python")
|
||||
from samba import NTSTATUSError
|
||||
from samba.compat import ConfigParser
|
||||
from samba.compat import StringIO
|
||||
from samba.compat import get_bytes
|
||||
from abc import ABCMeta, abstractmethod
|
||||
import xml.etree.ElementTree as etree
|
||||
import re
|
||||
@ -258,24 +259,24 @@ class GPOStorage:
|
||||
|
||||
def get_int(self, key):
|
||||
try:
|
||||
return int(self.log.get(key))
|
||||
return int(self.log.get(get_bytes(key)))
|
||||
except TypeError:
|
||||
return None
|
||||
|
||||
def get(self, key):
|
||||
return self.log.get(key)
|
||||
return self.log.get(get_bytes(key))
|
||||
|
||||
def get_gplog(self, user):
|
||||
return gp_log(user, self, self.log.get(user))
|
||||
return gp_log(user, self, self.log.get(get_bytes(user)))
|
||||
|
||||
def store(self, key, val):
|
||||
self.log.store(key, val)
|
||||
self.log.store(get_bytes(key), get_bytes(val))
|
||||
|
||||
def cancel(self):
|
||||
self.log.transaction_cancel()
|
||||
|
||||
def delete(self, key):
|
||||
self.log.delete(key)
|
||||
self.log.delete(get_bytes(key))
|
||||
|
||||
def commit(self):
|
||||
self.log.transaction_commit()
|
||||
@ -503,7 +504,7 @@ def parse_gpext_conf(smb_conf):
|
||||
|
||||
def atomic_write_conf(lp, parser):
|
||||
ext_conf = lp.state_path('gpext.conf')
|
||||
with NamedTemporaryFile(delete=False, dir=os.path.dirname(ext_conf)) as f:
|
||||
with NamedTemporaryFile(mode="w+", delete=False, dir=os.path.dirname(ext_conf)) as f:
|
||||
parser.write(f)
|
||||
os.rename(f.name, ext_conf)
|
||||
|
||||
@ -532,8 +533,8 @@ def register_gp_extension(guid, name, path,
|
||||
parser.add_section(guid)
|
||||
parser.set(guid, 'DllName', path)
|
||||
parser.set(guid, 'ProcessGroupPolicy', name)
|
||||
parser.set(guid, 'NoMachinePolicy', 0 if machine else 1)
|
||||
parser.set(guid, 'NoUserPolicy', 0 if user else 1)
|
||||
parser.set(guid, 'NoMachinePolicy', "0" if machine else "1")
|
||||
parser.set(guid, 'NoUserPolicy', "0" if user else "1")
|
||||
|
||||
atomic_write_conf(lp, parser)
|
||||
|
||||
|
@ -27,6 +27,7 @@ from tempfile import NamedTemporaryFile
|
||||
from samba.gp_sec_ext import gp_sec_ext
|
||||
import logging
|
||||
from samba.credentials import Credentials
|
||||
from samba.compat import get_bytes
|
||||
|
||||
poldir = r'\\addom.samba.example.com\sysvol\addom.samba.example.com\Policies'
|
||||
dspath = 'CN=Policies,CN=System,DC=addom,DC=samba,DC=example,DC=com'
|
||||
@ -62,7 +63,7 @@ def stage_file(path, data):
|
||||
if os.path.exists(path):
|
||||
os.rename(path, '%s.bak' % path)
|
||||
with NamedTemporaryFile(delete=False, dir=os.path.dirname(path)) as f:
|
||||
f.write(data)
|
||||
f.write(get_bytes(data))
|
||||
os.rename(f.name, path)
|
||||
os.chmod(path, 0o644)
|
||||
return True
|
||||
|
Reference in New Issue
Block a user