1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-24 21:34:56 +03:00
samba-mirror/source4
Douglas Bagnall 41249302a3 lib/compression: add simple python bindings
There are four functions, allowing compression and decompression in
the two formats we support so far. The functions will accept bytes or
unicode strings which are treated as utf-8.

The LZ77+Huffman decompression algorithm requires an exact target
length to decompress, so this is mandatory.

The plain decompression algorithm does not need an exact length, but
you can provide one to help it know how much space to allocate. As
currently written, you can provide a short length and it will often
succeed in decompressing to a different shorter string.

These bindings are intended to make ad-hoc investigation easier, not
for production use. This is reflected in the guesses about output size
that plain_decompress() makes if you don't supply one -- either they
are stupidly wasteful or ridiculously insufficient, depending on
whether or not you were trying to decompress a 20MB string.

>>> a = '12345678'
>>> import compression
>>> b = compression.huffman_compress(a)
>>> b
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00  #....
>>> len(b)
262
>>> c = compression.huffman_decompress(b, len(a))
>>> c
b'12345678'                                   # note, c is bytes, a is str
>>> a
'12345678'
>>> d = compression.plain_compress(a)
>>> d
b'\xff\xff\xff\x0012345678'
>>> compression.plain_decompress(d)           # no size specified, guesses
b'12345678'
>>> compression.plain_decompress(d,5)
b'12345'
>>> compression.plain_decompress(d,0)         # 0 for auto
b'12345678'
>>> compression.plain_decompress(d,1)
b'1'
>>> compression.plain_decompress(a,444)
Traceback (most recent call last):
   compression.CompressionError: unable to decompress data into a buffer of 444 bytes.
>>> compression.plain_decompress(b,444)
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 #...

That last one decompresses the Huffman compressed file with the plain
compressor; pretty much any string is valid for plain decompression.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
2022-12-22 19:50:33 +00:00
..
auth s4-auth: fix sam test binary ntstatus include path 2022-12-16 21:35:45 +00:00
cldap_server cldap_server: Align integer types 2022-12-12 21:16:33 +00:00
client s4:client: Fix shellcheck errors in test_smbclient.sh 2022-08-22 14:20:36 +00:00
cluster dbwrap: Remove calls to loadparm 2018-04-24 01:53:19 +02:00
dns_server dns_server: Use talloc_asprintf_addbuf() in b9_format() 2022-12-14 04:32:34 +00:00
dsdb CVE-2022-37966 s4:pydsdb: add ENC_HMAC_SHA1_96_AES256_SK 2022-12-13 13:07:30 +00:00
echo_server s4: rename source4/smbd/ to source4/samba/ 2020-11-27 10:07:18 +00:00
include lib: Remove smb_threads from includes.h 2022-04-26 21:41:29 +00:00
kdc CVE-2022-37966 s4:kdc: apply restrictions of "kdc supported enctypes" 2022-12-13 13:07:30 +00:00
ldap_server s4:ldap_server: let ldapsrv_call_writev_start use conn_idle_time to limit the time 2022-10-19 17:13:39 +00:00
lib s4:messaging: add irpc_bh_do_ndr_print() in order to debug irpc calls 2022-11-24 11:01:37 +00:00
libcli s3-librpc: add ads.idl and convert ads_struct to talloc. 2022-12-16 20:38:32 +00:00
libnet s4:libnet: correctly handle gnutls_pbkdf2() errors 2022-12-14 13:35:20 +00:00
librpc s3-librpc: add ads.idl and convert ads_struct to talloc. 2022-12-16 20:38:32 +00:00
nbt_server CVE-2022-32746 ldb: Make use of functions for appending to an ldb_message 2022-07-27 10:52:36 +00:00
ntp_signd s4: rename source4/smbd/ to source4/samba/ 2020-11-27 10:07:18 +00:00
ntvfs ntvfs: Remove orphans from 2006 2022-10-27 18:18:36 +00:00
param python: whitespace fixes 2022-10-03 20:03:32 +00:00
rpc_server CVE-2022-38023 s4:rpc_server/netlogon: implement "server schannel require seal[:COMPUTERACCOUNT]" 2022-12-13 13:07:29 +00:00
samba s4/samba: use process_set_title() 2022-12-14 01:38:29 +00:00
script s4:script: Fix shellcheck errors in find_unused_options.sh 2022-08-22 14:20:36 +00:00
scripting samba-tool: binary uses samba_tool function 2022-09-08 22:34:36 +00:00
selftest lib/compression: add simple python bindings 2022-12-22 19:50:33 +00:00
setup python:tests: Allocate OID range for testing to avoid collisions 2022-08-25 13:55:47 +00:00
smb_server s4:smb_server: don't set mapped_state explicitly in auth_usersupplied_info 2022-03-10 03:16:35 +00:00
torture s4:torture: Fix stack variable used out of scope in test_devicemode_full() 2022-12-20 06:55:45 +00:00
utils s4:utils: Fix shellcheck errors in test_samba_tool.sh 2022-08-22 20:35:36 +00:00
winbind CVE-2022-32746 ldb: Make use of functions for appending to an ldb_message 2022-07-27 10:52:36 +00:00
wrepl_server s4: rename source4/smbd/ to source4/samba/ 2020-11-27 10:07:18 +00:00
.clang_complete
.valgrind_suppressions
wscript_build s4:client: Migrate cifsdd to new cmdline option parser 2021-06-16 00:34:38 +00:00