diff --git a/librpc/ndr/ndr_cab.c b/librpc/ndr/ndr_cab.c index 322412fdac3..3efb14fc874 100644 --- a/librpc/ndr/ndr_cab.c +++ b/librpc/ndr/ndr_cab.c @@ -132,7 +132,7 @@ static enum ndr_err_code ndr_push_folder_cfdata(struct ndr_push *ndr, if (cab_ctype == CF_COMPRESS_MSZIP) { ndr_ctype = NDR_COMPRESSION_MSZIP_CAB; - NDR_CHECK(ndr_push_compression_state_init(ndr, ndr_ctype, &ndr->cstate)); + NDR_CHECK(ndr_push_compression_state_init(ndr, ndr_ctype)); } for (i = 0; i < num_cfdata; i++, r++) { @@ -189,11 +189,18 @@ static enum ndr_err_code ndr_push_folder_cfdata(struct ndr_push *ndr, /* compress via subcontext */ NDR_CHECK(ndr_push_subcontext_start(ndr, &push_sub, 0, -1)); + + /* + * This assignment replaces a call to + * ndr_push_compression_state_init(push_sub, ndr_ctype)) + * here. This is instead done outside the loop. + */ push_sub->cstate = ndr->cstate; - NDR_CHECK(ndr_push_compression_start(push_sub, &push_compress, ndr_ctype)); + + NDR_CHECK(ndr_push_compression_start(push_sub, &push_compress)); ndr_set_flags(&push_compress->flags, LIBNDR_FLAG_REMAINING); NDR_CHECK(ndr_push_DATA_BLOB(push_compress, NDR_SCALARS, r->ab)); - NDR_CHECK(ndr_push_compression_end(push_sub, push_compress, ndr_ctype)); + NDR_CHECK(ndr_push_compression_end(push_sub, push_compress)); NDR_CHECK(ndr_push_subcontext_end(ndr, push_sub, 0, -1)); compressed_length = push_sub->offset; diff --git a/librpc/ndr/ndr_compression.c b/librpc/ndr/ndr_compression.c index 54f91f9efbf..4c961f84f4e 100644 --- a/librpc/ndr/ndr_compression.c +++ b/librpc/ndr/ndr_compression.c @@ -898,10 +898,10 @@ enum ndr_err_code ndr_pull_compression_end(struct ndr_pull *subndr, push a compressed subcontext */ enum ndr_err_code ndr_push_compression_start(struct ndr_push *subndr, - struct ndr_push **_uncomndr, - enum ndr_compression_alg compression_alg) + struct ndr_push **_uncomndr) { struct ndr_push *uncomndr; + enum ndr_compression_alg compression_alg = subndr->cstate->type; switch (compression_alg) { case NDR_COMPRESSION_NONE: @@ -928,13 +928,14 @@ enum ndr_err_code ndr_push_compression_start(struct ndr_push *subndr, push a compressed subcontext */ enum ndr_err_code ndr_push_compression_end(struct ndr_push *subndr, - struct ndr_push *uncomndr, - enum ndr_compression_alg compression_alg) + struct ndr_push *uncomndr) { struct ndr_pull *ndrpull; bool last = false; z_stream z; + enum ndr_compression_alg compression_alg = subndr->cstate->type; + ndrpull = talloc_zero(uncomndr, struct ndr_pull); NDR_ERR_HAVE_NO_MEMORY(ndrpull); ndrpull->flags = uncomndr->flags; @@ -1034,12 +1035,17 @@ enum ndr_err_code ndr_pull_compression_state_init(struct ndr_pull *ndr, } enum ndr_err_code ndr_push_compression_state_init(struct ndr_push *ndr, - enum ndr_compression_alg compression_alg, - struct ndr_compression_state **state) + enum ndr_compression_alg compression_alg) { struct ndr_compression_state *s; int z_ret; + /* + * Avoid confusion, NULL out ndr->cstate at the start of the + * compression block + */ + ndr->cstate = NULL; + s = talloc_zero(ndr, struct ndr_compression_state); NDR_ERR_HAVE_NO_MEMORY(s); s->type = compression_alg; @@ -1079,8 +1085,7 @@ enum ndr_err_code ndr_push_compression_state_init(struct ndr_push *ndr, break; } - - *state = s; + ndr->cstate = s; return NDR_ERR_SUCCESS; } diff --git a/librpc/ndr/ndr_compression.h b/librpc/ndr/ndr_compression.h index 7f938523ada..3d335b2befd 100644 --- a/librpc/ndr/ndr_compression.h +++ b/librpc/ndr/ndr_compression.h @@ -42,19 +42,16 @@ enum ndr_err_code ndr_pull_compression_end(struct ndr_pull *subndr, enum ndr_compression_alg compression_alg, ssize_t decompressed_len); enum ndr_err_code ndr_push_compression_start(struct ndr_push *subndr, - struct ndr_push **_uncomndr, - enum ndr_compression_alg compression_alg); + struct ndr_push **_uncomndr); enum ndr_err_code ndr_push_compression_end(struct ndr_push *subndr, - struct ndr_push *uncomndr, - enum ndr_compression_alg compression_alg); + struct ndr_push *uncomndr); enum ndr_err_code ndr_pull_compression_state_init(struct ndr_pull *ndr, enum ndr_compression_alg compression_alg, struct ndr_compression_state **state); void ndr_pull_compression_state_free(struct ndr_compression_state *state); enum ndr_err_code ndr_push_compression_state_init(struct ndr_push *ndr, - enum ndr_compression_alg compression_alg, - struct ndr_compression_state **state); + enum ndr_compression_alg compression_alg); #undef _PRINTF_ATTRIBUTE #define _PRINTF_ATTRIBUTE(a1, a2) diff --git a/librpc/ndr/ndr_drsuapi.c b/librpc/ndr/ndr_drsuapi.c index 0732ee3c6f4..c07ba48ff4b 100644 --- a/librpc/ndr/ndr_drsuapi.c +++ b/librpc/ndr/ndr_drsuapi.c @@ -216,10 +216,11 @@ enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr1(struct ndr_push *ndr, NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1)); { struct ndr_push *_ndr_ts_compressed; - NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP)); + NDR_CHECK(ndr_push_compression_state_init(_ndr_ts, NDR_COMPRESSION_MSZIP)); + NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed)); NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts)); decompressed_length = _ndr_ts_compressed->offset; - NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP)); + NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed)); } compressed_length = _ndr_ts->offset; talloc_free(_ndr_ts); @@ -237,9 +238,10 @@ enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr1(struct ndr_push *ndr, NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1)); { struct ndr_push *_ndr_ts_compressed; - NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP)); + NDR_CHECK(ndr_push_compression_state_init(_ndr_ts, NDR_COMPRESSION_MSZIP)); + NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed)); NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts)); - NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP)); + NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed)); } NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1)); } @@ -259,10 +261,11 @@ enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr6(struct ndr_push *ndr, NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1)); { struct ndr_push *_ndr_ts_compressed; - NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP)); + NDR_CHECK(ndr_push_compression_state_init(_ndr_ts, NDR_COMPRESSION_MSZIP)); + NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed)); NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts)); decompressed_length = _ndr_ts_compressed->offset; - NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP)); + NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed)); } compressed_length = _ndr_ts->offset; talloc_free(_ndr_ts); @@ -280,9 +283,10 @@ enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr6(struct ndr_push *ndr, NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1)); { struct ndr_push *_ndr_ts_compressed; - NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP)); + NDR_CHECK(ndr_push_compression_state_init(_ndr_ts, NDR_COMPRESSION_MSZIP)); + NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed)); NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts)); - NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP)); + NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed)); } NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1)); } @@ -302,10 +306,11 @@ enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesWIN2K3_LZ77_DIRECT2Ctr1(struct NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1)); { struct ndr_push *_ndr_ts_compressed; - NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2)); + NDR_CHECK(ndr_push_compression_state_init(_ndr_ts, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2)); + NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed)); NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts)); decompressed_length = _ndr_ts_compressed->offset; - NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2)); + NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed)); } compressed_length = _ndr_ts->offset; talloc_free(_ndr_ts); @@ -323,9 +328,10 @@ enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesWIN2K3_LZ77_DIRECT2Ctr1(struct NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1)); { struct ndr_push *_ndr_ts_compressed; - NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2)); + NDR_CHECK(ndr_push_compression_state_init(_ndr_ts, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2)); + NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed)); NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts)); - NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2)); + NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed)); } NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1)); } @@ -345,10 +351,11 @@ enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesWIN2K3_LZ77_DIRECT2Ctr6(struct NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1)); { struct ndr_push *_ndr_ts_compressed; - NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2)); + NDR_CHECK(ndr_push_compression_state_init(_ndr_ts, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2)); + NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed)); NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts)); decompressed_length = _ndr_ts_compressed->offset; - NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2)); + NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed)); } compressed_length = _ndr_ts->offset; talloc_free(_ndr_ts); @@ -366,9 +373,10 @@ enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesWIN2K3_LZ77_DIRECT2Ctr6(struct NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1)); { struct ndr_push *_ndr_ts_compressed; - NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2)); + NDR_CHECK(ndr_push_compression_state_init(_ndr_ts, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2)); + NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed)); NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts)); - NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_WIN2K3_LZ77_DIRECT2)); + NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed)); } NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1)); } diff --git a/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm index b21a6e6513e..f468af54eb6 100644 --- a/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm +++ b/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm @@ -514,8 +514,8 @@ sub ParseCompressionPushStart($$$$$) $self->pidl("{"); $self->indent; $self->pidl("struct ndr_push *$comndr;"); - $self->pidl("NDR_CHECK(ndr_push_compression_state_init($ndr, $alg, &$ndr->cstate));"); - $self->pidl("NDR_CHECK(ndr_push_compression_start($ndr, &$comndr, $alg));"); + $self->pidl("NDR_CHECK(ndr_push_compression_state_init($ndr, $alg));"); + $self->pidl("NDR_CHECK(ndr_push_compression_start($ndr, &$comndr));"); return $comndr; } @@ -526,7 +526,7 @@ sub ParseCompressionPushEnd($$$$$) my $comndr = "$ndr\_compressed"; my $alg = compression_alg($e, $l, $env); - $self->pidl("NDR_CHECK(ndr_push_compression_end($ndr, $comndr, $alg));"); + $self->pidl("NDR_CHECK(ndr_push_compression_end($ndr, $comndr));"); $self->pidl("TALLOC_FREE($ndr->cstate);"); $self->deindent; $self->pidl("}");