summaryrefslogtreecommitdiff
path: root/python/samba/gp_parse
AgeCommit message (Collapse)AuthorFilesLines
2020-10-02python2 reduction: Merge remaining compat code into commonDavid Mulder1-1/+1
The remaining compat code (get_string, get_bytes, cmp) are useful helper routines which we should simply merge into common (especially since there is some duplication here). Signed-off-by: David Mulder <dmulder@suse.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Autobuild-User(master): David Mulder <dmulder@samba.org> Autobuild-Date(master): Fri Oct 2 14:49:36 UTC 2020 on sn-devel-184
2020-08-24python compat: remove ConfigParserDavid Mulder1-4/+7
Signed-off-by: David Mulder <dmulder@suse.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2020-08-11python compat: remove text_typeDouglas Bagnall1-3/+2
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Noel Power <npower@samba.org>
2020-08-11python compat: reduce use of 'if PY3:'Douglas Bagnall1-1/+0
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Noel Power <npower@samba.org>
2020-08-11python compat: remove StringIODouglas Bagnall1-1/+1
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Noel Power <npower@samba.org>
2020-03-19python/samba/gp_parse: Fix test errors with python3.8Noel Power1-1/+1
UNEXPECTED(failure): samba.tests.samba_tool.gpo.samba.tests.samba_tool.gpo.GpoCmdTestCase.test_backup_restore_generalize(ad_dc:local) REASON: Exception: Exception: Traceback (most recent call last): File "/tmp/samba-testbase/b28/samba-ad-dc-1/bin/python/samba/tests/samba_tool/gpo.py", line 434, in test_backup_restore_generalize self.assertIsNone(has_difference(os.path.join(new_path, 'policy', This caused because prior to 3.8 minodom.toprettyxml() was sorting the attribute order, now it preserves the attribute order specified by the user Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2020-02-07python: use raw string for regex with escapeDouglas Bagnall1-1/+1
Python regards 'GPT\.INI$' as a string containing an invalid escape sequence '\.', which is ignored (i.e. treated as the literal sequence of those 2 characters), but only after Python has grumbled to itself, and to you if you enabled DeprecationWarnings. The proper thing to do here is use r-strings, like r'GPT\.INI$', which tell Python that all backslashes are literal. Alternatively (as we do once in this patch), the backslash can itself be escaped ('\\'). There are more problems of this nature in the build scripts. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Noel Power <npower@samba.org>
2019-07-19gp_inf: Read/write files with a UTF-16LE BOM in GptTmpl.infGarming Sam1-3/+6
Regression caused by 16596842a62bec0a9d974c48d64000e3c079254e [MS-GPSB] 2.2 Message Syntax says that you have to write a BOM which I didn't do up until this patch. UTF-16 as input encoding was marked much higher up in the inheritance tree, which got overriden with the Python 3 fixes. I've now marked the encoding much more obviously for this file. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14004 Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz> Autobuild-User(master): Gary Lockyer <gary@samba.org> Autobuild-Date(master): Fri Jul 19 02:20:47 UTC 2019 on sn-devel-184
2019-03-12gpo: Parse GPT.INI with Latin-1Garming Sam1-0/+11
For some reason the French version of RSAT turns accents into ISO-8859-1. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13806 Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-03-12py3: io.open takes a numeric buffering argument at index 2Garming Sam1-1/+1
It's unsure why this doesn't fail generically, but it fails on my machine sometimes... Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-11-05python/samba/gp_parse: PY2/PY3 Decode only when necessaryNoel Power1-3/+6
In python2 we decode str types in load_xml, in python3 these are str class(s) which we cannot decode. Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-11-05python/samba/gp_parse: Fix mulitple encode step with write_sectionNoel Power1-14/+15
In python2 as far as I can see GptTmplInfParser.write_binary more or less works by accident. write_binary creates a writer for the 'utf8' codec, such a writer should consume unicode and emit utf8 encoded bytes. This writer is passed to each of the sections managed by GptTmplInfParser as follows def write_binary(self, filename): with codecs.open(filename, 'wb+', self.encoding) as f: for s in self.sections: self.sections[s].write_section(s, f) And each section type itself is encoding its result to 'utf-16-le' e.g. class UnicodeParam(AbstractParam): def write_section(self, header, fp): fp.write(u'[Unicode]\r\nUnicode=yes\r\n'.encode(self.encoding) But this makes little sense, it seems like sections are encoded to one encoding but the total file is supposed to be encoded as ut8??? Also having an encoding per ParamType doesn't seem correct. Bizarely in PY2 this works and it actually encodes the whole file as utf-16le In PY3 you can't do this as the writer wants to deal with strings not bytes (after the extra encode phase in 'write_section'. So, changes here are to remove the unnecessary encoding in each 'write_section' method, additionally in GptTmplInfParser.write_binary the codecs.open call now uses the correct codec (e.g. 'utf-16-le') to write Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-11-05python/samab/gp_parse: remove unused codeNoel Power1-68/+0
Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-11-05python/samba/gp_parse: Use csv.reader for parsing cvs filesNoel Power1-3/+2
The previous version here was using UnicodeReader which was wrapping the UTF8Recoder class and passing that to csv.reader. It looks like the intention was to read a bytestream in a certain encoding and then reencode it to a different encoding. And then UnicodeReader creates unicode from the newly encoded stream. This is unnecssary, we know the encoding of the bytesstream and codec.getreader will happily consume the bytstream and give back unicode. The unicode can be fed directly into csv.writer. Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-11-05python/samba/gp_parse: PY2/PY3 compat porting for gp_init.pyNoel Power1-1/+1
Fixes 1) use compat versions of ConfigParser and StringIO 2) fix sort list of XML Elements 3) open file needs to be opened in binary mode as write_pretty_xml routing uses BytesIO() object. Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-11-05python/samba/gp_parse: PY3 open file non-binary mode for write_binaryNoel Power1-6/+4
Although this is unintuitive it's because we are writing unicode not bytes (both in PY2 & PY3). using the 'b' mode causes an error in PY3. In PY3 we can define the encoding, but not in PY2. Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-11-05python/samba/gp_parse: PY3 file -> openNoel Power5-7/+7
'file' no longer exists in PY3 replace with 'open' Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-11-05python/samba/gp_parse: PY2/PY3 compat changes for __init__.pyNoel Power1-5/+7
Fixes. 1) sorting of xml.etree.ElementTree.Element, in PY2 sort seems to sort lists of these. In PY3 this no longer works. Choosing tag as the sort key for py3 so at least in python3 there is a consistent sort (probably won't match how it is sorted in PY2 but nothing seems to depend on that) 2) md5 requires bytes 3) tostring returns bytes in PY3, adjust code for that Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-10-25python/gp_parse/gp_inf: remove unused variablesDouglas Bagnall1-2/+0
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Noel Power <npower@samba.org>
2018-10-25python/gp_parse/gp_inf: remove shadowed methodDouglas Bagnall1-9/+0
The 'from_xml()' definition is replaced a few lines down Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Noel Power <npower@samba.org>
2018-10-25python/gp_parse/gp_pol: remove unused importDouglas Bagnall1-1/+0
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Noel Power <npower@samba.org>
2018-10-23python/samba/gp_parse: PY2/PY3 compat porting for gp_init.pyNoel Power1-3/+3
Fixes 1) use compat versions of ConfigParser and StringIO 2) open file needs to be opened in binary mode as write_pretty_xml routine uses BytesIO() object. Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-10-23python/samba/gp_parse: PY3 fdeploy_sids needs to use key method for sortNoel Power1-1/+1
Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-08-16fdeploy_ini: Generalize the share name SIDsGarming Sam2-6/+27
This overrides the custom entity handler defined in the top level parser. Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-08-16gp_parse: Add a generalize XML function to the top level parserGarming Sam1-1/+126
In this function we take XML and using the required metadata, we rewrite it into a generic form using entities. ElementTree unfortunately does not allow us to store unescaped entities, and so we must do a textual replace on the output XML. Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-08-16gp_ini: Add a scripts ini parser for better generalizationGarming Sam1-0/+15
We mark the command path argument as a network path. Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-08-16gp_ini: Add a fdeploy1 parser for better generalizationGarming Sam1-0/+77
We still fail to handle entities in fdeploy.ini (version 0) files. Here we manage to factor out some of the SIDs, but not all of them. This will be completed in a later patch. The overall idea is to split the SID values into individual XML elements and annotate them. We also note down network paths for the redirection folders. Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-08-16gp_ini: Allow better overriding of behaviour in inherited classesGarming Sam1-14/+36
We will need this to parse the parameters or section names as SIDs for fdeploy1.ini Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-08-16gp_csv: Add CSV generalization metadataGarming Sam1-1/+9
There are user identifiers and ACLs which may be stored in the audit CSV. Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-08-16gp_aas: Leave a placeholder for the .aas files for nowGarming Sam1-0/+25
This is to be implemented, but the documentation is somewhat lacking for the .aas files and we so we leave this for now. In particular, the documentation doesn't seem to describe all the possible sections, nor do we understand what happens if we replace certain aspects of the file -- and whether or not it will remain functional. Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-08-16gp_inf: Parse the GptTmpl.inf file which stores security settingsGarming Sam1-0/+385
This is NOT an ini file and CANNOT be parsed by Python ConfigParser without losing information (it would likely eat meaningful whitespace and so should not be done). There are three main types of settings: * Name,Mode,ACL * key = value * registry key and value Note: This appears as key=value, but registry keys in the general case may have = in their names, so we record the entire string in order to be as safe as possible. Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-08-16gp_csv: Parse the audit.csv file which records audit settingsGarming Sam1-0/+164
Based on the setting, the csv will omit certain fields. Using this we can later infer as to how to generalize the ACLs and SIDs. Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-08-16gp_ini: Parse .ini files in SYSVOLGarming Sam1-0/+83
These are fdeploy, scripts + psscripts as well as the GPT.ini at the top level. Note that GPT.ini has a different character encoding and we specify it here. Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-08-16gp_pol: Parse the .pol files (PReg) which stored winreg settingsGarming Sam1-0/+148
Currently, we do not look inside the .pol files for any settings (and do not generalize any so far). Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-08-16gp_parse: Introduce new module for parsing GPO filesGarming Sam1-0/+57
This is the default parser which will cause the file to be restored as-is -- leaving only an effectively blank XML file as a placeholder. Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>