The branch, v4-0-test has been updated
       via  925a2066ffa18a86704a8ee1a7a6908e0cd65a2a (commit)
       via  98d3568f079ea143214bcf5271b636313d6491c3 (commit)
      from  e51c0cf62c91f79f703b17bcf37c4a6fa8107ae0 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v4-0-test


- Log -----------------------------------------------------------------
commit 925a2066ffa18a86704a8ee1a7a6908e0cd65a2a
Author: Stefan Metzmacher <[EMAIL PROTECTED]>
Date:   Tue Aug 19 10:29:40 2008 +0200

    ndr_compression: unify the common handling of mszip and xpress compression
    
    metze

commit 98d3568f079ea143214bcf5271b636313d6491c3
Author: Stefan Metzmacher <[EMAIL PROTECTED]>
Date:   Mon Aug 18 17:10:59 2008 +0200

    librpc/ndr: add support for Type Serialization Version 1 to subcontext
    
    We use the header size 0xFFFFFC01 as magic for constructed types.
    
    See [MS-RPCE] 2.2.6 Type Serialization Version 1 for more details.
    
    metze

-----------------------------------------------------------------------

Summary of changes:
 source/librpc/ndr/ndr.c             |  115 ++++++++++++++++++++++++++++-
 source/librpc/ndr/ndr_compression.c |  140 ++++++++--------------------------
 2 files changed, 147 insertions(+), 108 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/librpc/ndr/ndr.c b/source/librpc/ndr/ndr.c
index 4085245..c5e4c44 100644
--- a/source/librpc/ndr/ndr.c
+++ b/source/librpc/ndr/ndr.c
@@ -394,6 +394,8 @@ _PUBLIC_ enum ndr_err_code ndr_pull_subcontext_start(struct 
ndr_pull *ndr,
 {
        struct ndr_pull *subndr;
        uint32_t r_content_size;
+       bool force_le = false;
+       bool force_be = false;
 
        switch (header_size) {
        case 0: {
@@ -426,6 +428,74 @@ _PUBLIC_ enum ndr_err_code 
ndr_pull_subcontext_start(struct ndr_pull *ndr,
                r_content_size = content_size;
                break;
        }
+       case 0xFFFFFC01: {
+               /*
+                * Common Type Header for the Serialization Stream
+                * See [MS-RPCE] 2.2.6 Type Serialization Version 1
+                */
+               uint8_t version;
+               uint8_t drep;
+               uint16_t hdrlen;
+               uint32_t filler;
+               uint32_t content_size;
+               uint32_t reserved;
+
+               /* version */
+               NDR_CHECK(ndr_pull_uint8(ndr, NDR_SCALARS, &version));
+
+               if (version != 1) {
+                       return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT,
+                                             "Bad subcontext (PULL) Common 
Type Header version %d != 1",
+                                             (int)version);
+               }
+
+               /*
+                * 0x10 little endian
+                * 0x00 big endian
+                */
+               NDR_CHECK(ndr_pull_uint8(ndr, NDR_SCALARS, &drep));
+               if (drep == 0x10) {
+                       force_le = true;
+               } else if (drep == 0x00) {
+                       force_be = true;
+               } else {
+                       return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT,
+                                             "Bad subcontext (PULL) Common 
Type Header invalid drep 0x%02X",
+                                             (unsigned int)drep);
+               }
+
+               /* length of the "Private Header for Constructed Type" */
+               NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &hdrlen));
+               if (hdrlen != 8) {
+                       return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT,
+                                             "Bad subcontext (PULL) Common 
Type Header length %d != 8",
+                                             (int)hdrlen);
+               }
+
+               /* filler should be ignored */
+               NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &filler));
+
+               /*
+                * Private Header for Constructed Type
+                */
+               /* length - will be updated latter */
+               NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &content_size));
+               if (size_is >= 0 && size_is != content_size) {
+                       return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad 
subcontext (PULL) size_is(%d) mismatch content_size %d",
+                                             (int)size_is, (int)content_size);
+               }
+               /* the content size must be a multiple of 8 */
+               if ((content_size % 8) != 0) {
+                       return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT,
+                                             "Bad subcontext (PULL) 
size_is(%d) not padded to 8 content_size %d",
+                                             (int)size_is, (int)content_size);
+               }
+               r_content_size = content_size;
+
+               /* reserved */
+               NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &reserved));
+               break;
+       }
        default:
                return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext 
(PULL) header_size %d", 
                                      (int)header_size);
@@ -443,6 +513,12 @@ _PUBLIC_ enum ndr_err_code 
ndr_pull_subcontext_start(struct ndr_pull *ndr,
        subndr->data_size = r_content_size;
        subndr->iconv_convenience = talloc_reference(subndr, 
ndr->iconv_convenience);
 
+       if (force_le) {
+               ndr_set_flags(&ndr->flags, LIBNDR_FLAG_LITTLE_ENDIAN);
+       } else if (force_be) {
+               ndr_set_flags(&ndr->flags, LIBNDR_FLAG_BIGENDIAN);
+       }
+
        *_subndr = subndr;
        return NDR_ERR_SUCCESS;
 }
@@ -487,8 +563,10 @@ _PUBLIC_ enum ndr_err_code ndr_push_subcontext_end(struct 
ndr_push *ndr,
                                 size_t header_size,
                                 ssize_t size_is)
 {
+       ssize_t padding_len;
+
        if (size_is >= 0) {
-               ssize_t padding_len = size_is - subndr->offset;
+               padding_len = size_is - subndr->offset;
                if (padding_len > 0) {
                        NDR_CHECK(ndr_push_zero(subndr, padding_len));
                } else if (padding_len < 0) {
@@ -509,6 +587,41 @@ _PUBLIC_ enum ndr_err_code ndr_push_subcontext_end(struct 
ndr_push *ndr,
                NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, subndr->offset));
                break;
 
+       case 0xFFFFFC01:
+               /*
+                * Common Type Header for the Serialization Stream
+                * See [MS-RPCE] 2.2.6 Type Serialization Version 1
+                */
+               padding_len = NDR_ROUND(subndr->offset, 8) - subndr->offset;
+               if (padding_len > 0) {
+                       NDR_CHECK(ndr_push_zero(subndr, padding_len));
+               }
+
+               /* version */
+               NDR_CHECK(ndr_push_uint8(ndr, NDR_SCALARS, 1));
+
+               /*
+                * 0x10 little endian
+                * 0x00 big endian
+                */
+               NDR_CHECK(ndr_push_uint8(ndr, NDR_SCALARS, 
NDR_BE(ndr)?0x00:0x10));
+
+               /* length of the "Private Header for Constructed Type" */
+               NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, 8));
+
+               /* filler */
+               NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0xCCCCCCCC));
+
+               /*
+                * Private Header for Constructed Type
+                */
+               /* length - will be updated latter */
+               NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, subndr->offset));
+
+               /* reserved */
+               NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));
+               break;
+
        default:
                return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext 
header size %d", 
                                      (int)header_size);
diff --git a/source/librpc/ndr/ndr_compression.c 
b/source/librpc/ndr/ndr_compression.c
index 7c2aca7..ad8dda1 100644
--- a/source/librpc/ndr/ndr_compression.c
+++ b/source/librpc/ndr/ndr_compression.c
@@ -145,80 +145,6 @@ static enum ndr_err_code 
ndr_pull_compression_mszip_chunk(struct ndr_pull *ndrpu
        return NDR_ERR_SUCCESS;
 }
 
-static enum ndr_err_code ndr_pull_compression_mszip(struct ndr_pull *subndr,
-                                          struct ndr_pull **_comndr,
-                                          ssize_t decompressed_len)
-{
-       struct ndr_push *ndrpush;
-       struct ndr_pull *comndr;
-       DATA_BLOB uncompressed;
-       uint32_t payload_header[4];
-       uint32_t payload_size;
-       uint32_t payload_offset;
-       uint8_t *payload;
-       z_stream z;
-       bool last = false;
-
-       ndrpush = ndr_push_init_ctx(subndr, subndr->iconv_convenience);
-       NDR_ERR_HAVE_NO_MEMORY(ndrpush);
-
-       ZERO_STRUCT(z);
-
-       while (!last) {
-               NDR_CHECK(ndr_pull_compression_mszip_chunk(subndr, ndrpush, &z, 
&last));
-       }
-
-       uncompressed = ndr_push_blob(ndrpush);
-
-       if (uncompressed.length != decompressed_len) {
-               return ndr_pull_error(subndr, NDR_ERR_COMPRESSION, "Bad MSZIP 
uncompressed_len [%u] != [%d] (PULL)",
-                                     (int)uncompressed.length, 
(int)decompressed_len);
-       }
-
-       comndr = talloc_zero(subndr, struct ndr_pull);
-       NDR_ERR_HAVE_NO_MEMORY(comndr);
-       comndr->flags           = subndr->flags;
-       comndr->current_mem_ctx = subndr->current_mem_ctx;
-
-       comndr->data            = uncompressed.data;
-       comndr->data_size       = uncompressed.length;
-       comndr->offset          = 0;
-
-       comndr->iconv_convenience = talloc_reference(comndr, 
subndr->iconv_convenience);
-
-       NDR_CHECK(ndr_pull_uint32(comndr, NDR_SCALARS, &payload_header[0]));
-       NDR_CHECK(ndr_pull_uint32(comndr, NDR_SCALARS, &payload_header[1]));
-       NDR_CHECK(ndr_pull_uint32(comndr, NDR_SCALARS, &payload_header[2]));
-       NDR_CHECK(ndr_pull_uint32(comndr, NDR_SCALARS, &payload_header[3]));
-
-       if (payload_header[0] != 0x00081001) {
-               return ndr_pull_error(subndr, NDR_ERR_COMPRESSION, "Bad MSZIP 
payload_header[0] [0x%08X] != [0x00081001] (PULL)",
-                                     payload_header[0]);
-       }
-       if (payload_header[1] != 0xCCCCCCCC) {
-               return ndr_pull_error(subndr, NDR_ERR_COMPRESSION, "Bad MSZIP 
payload_header[1] [0x%08X] != [0xCCCCCCCC] (PULL)",
-                                     payload_header[1]);
-       }
-
-       payload_size = payload_header[2];
-
-       if (payload_header[3] != 0x00000000) {
-               return ndr_pull_error(subndr, NDR_ERR_COMPRESSION, "Bad MSZIP 
payload_header[3] [0x%08X] != [0x00000000] (PULL)",
-                                     payload_header[3]);
-       }
-
-       payload_offset = comndr->offset;
-       NDR_CHECK(ndr_pull_advance(comndr, payload_size));
-       payload = comndr->data + payload_offset;
-
-       comndr->data            = payload;
-       comndr->data_size       = payload_size;
-       comndr->offset          = 0;
-
-       *_comndr = comndr;
-       return NDR_ERR_SUCCESS;
-}
-
 static enum ndr_err_code ndr_push_compression_mszip(struct ndr_push *subndr,
                                           struct ndr_push *comndr)
 {
@@ -268,9 +194,20 @@ static enum ndr_err_code 
ndr_pull_compression_xpress_chunk(struct ndr_pull *ndrp
        return NDR_ERR_SUCCESS;
 }
 
-static enum ndr_err_code ndr_pull_compression_xpress(struct ndr_pull *subndr,
-                                           struct ndr_pull **_comndr,
-                                           ssize_t decompressed_len)
+static enum ndr_err_code ndr_push_compression_xpress(struct ndr_push *subndr,
+                                           struct ndr_push *comndr)
+{
+       return ndr_push_error(subndr, NDR_ERR_COMPRESSION, "XPRESS compression 
is not supported yet (PUSH)");
+}
+
+/*
+  handle compressed subcontext buffers, which in midl land are 
user-marshalled, but
+  we use magic in pidl to make them easier to cope with
+*/
+enum ndr_err_code ndr_pull_compression_start(struct ndr_pull *subndr,
+                                   struct ndr_pull **_comndr,
+                                   enum ndr_compression_alg compression_alg,
+                                   ssize_t decompressed_len)
 {
        struct ndr_push *ndrpush;
        struct ndr_pull *comndr;
@@ -280,18 +217,34 @@ static enum ndr_err_code 
ndr_pull_compression_xpress(struct ndr_pull *subndr,
        uint32_t payload_offset;
        uint8_t *payload;
        bool last = false;
+       z_stream z;
 
        ndrpush = ndr_push_init_ctx(subndr, subndr->iconv_convenience);
        NDR_ERR_HAVE_NO_MEMORY(ndrpush);
 
-       while (!last) {
-               NDR_CHECK(ndr_pull_compression_xpress_chunk(subndr, ndrpush, 
&last));
+       switch (compression_alg) {
+       case NDR_COMPRESSION_MSZIP:
+               ZERO_STRUCT(z);
+               while (!last) {
+                       NDR_CHECK(ndr_pull_compression_mszip_chunk(subndr, 
ndrpush, &z, &last));
+               }
+               break;
+
+       case NDR_COMPRESSION_XPRESS:
+               while (!last) {
+                       NDR_CHECK(ndr_pull_compression_xpress_chunk(subndr, 
ndrpush, &last));
+               }
+               break;
+
+       default:
+               return ndr_pull_error(subndr, NDR_ERR_COMPRESSION, "Bad 
compression algorithm %d (PULL)",
+                                     compression_alg);
        }
 
        uncompressed = ndr_push_blob(ndrpush);
        if (uncompressed.length != decompressed_len) {
                return ndr_pull_error(subndr, NDR_ERR_COMPRESSION,
-                                     "Bad XPRESS uncompressed_len [%u] != 
[%u](0x%08X) (PULL)",
+                                     "Bad uncompressed_len [%u] != 
[%u](0x%08X) (PULL)",
                                      (int)uncompressed.length,
                                      (int)decompressed_len,
                                      (int)decompressed_len);
@@ -344,33 +297,6 @@ static enum ndr_err_code 
ndr_pull_compression_xpress(struct ndr_pull *subndr,
        return NDR_ERR_SUCCESS;
 }
 
-static enum ndr_err_code ndr_push_compression_xpress(struct ndr_push *subndr,
-                                           struct ndr_push *comndr)
-{
-       return ndr_push_error(subndr, NDR_ERR_COMPRESSION, "XPRESS compression 
is not supported yet (PUSH)");
-}
-
-/*
-  handle compressed subcontext buffers, which in midl land are 
user-marshalled, but
-  we use magic in pidl to make them easier to cope with
-*/
-enum ndr_err_code ndr_pull_compression_start(struct ndr_pull *subndr,
-                                   struct ndr_pull **_comndr,
-                                   enum ndr_compression_alg compression_alg,
-                                   ssize_t decompressed_len)
-{
-       switch (compression_alg) {
-       case NDR_COMPRESSION_MSZIP:
-               return ndr_pull_compression_mszip(subndr, _comndr, 
decompressed_len);
-       case NDR_COMPRESSION_XPRESS:
-               return ndr_pull_compression_xpress(subndr, _comndr, 
decompressed_len);
-       default:
-               return ndr_pull_error(subndr, NDR_ERR_COMPRESSION, "Bad 
compression algorithm %d (PULL)", 
-                                     compression_alg);
-       }
-       return NDR_ERR_SUCCESS;
-}
-
 enum ndr_err_code ndr_pull_compression_end(struct ndr_pull *subndr,
                                  struct ndr_pull *comndr,
                                  enum ndr_compression_alg compression_alg,


-- 
Samba Shared Repository

Reply via email to