diff options
author | Andrew Tridgell <tridge@samba.org> | 2009-09-17 15:14:31 -0700 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2009-09-17 21:52:26 -0700 |
commit | ae91cff2597caba2f8f033f69c8bf6a3706da409 (patch) | |
tree | 9a7caf91a65ae66d3cddafa14dd12008620967a1 /librpc | |
parent | c2523d2e2bb84c38741ea88c0c67ff692fd82b1c (diff) | |
download | samba-ae91cff2597caba2f8f033f69c8bf6a3706da409.tar.gz samba-ae91cff2597caba2f8f033f69c8bf6a3706da409.tar.bz2 samba-ae91cff2597caba2f8f033f69c8bf6a3706da409.zip |
ndr: split out ndr enum functions
This allows for easier implementation of the NDR32/NDR64 split
Diffstat (limited to 'librpc')
-rw-r--r-- | librpc/ndr/libndr.h | 7 | ||||
-rw-r--r-- | librpc/ndr/ndr.c | 8 | ||||
-rw-r--r-- | librpc/ndr/ndr_basic.c | 67 |
3 files changed, 78 insertions, 4 deletions
diff --git a/librpc/ndr/libndr.h b/librpc/ndr/libndr.h index 16a1ff65d0..03b4362b37 100644 --- a/librpc/ndr/libndr.h +++ b/librpc/ndr/libndr.h @@ -541,4 +541,11 @@ char *GUID_hexstring(TALLOC_CTX *mem_ctx, const struct GUID *guid); char *NS_GUID_string(TALLOC_CTX *mem_ctx, const struct GUID *guid); struct GUID GUID_random(void); +_PUBLIC_ enum ndr_err_code ndr_pull_enum_uint8(struct ndr_pull *ndr, int ndr_flags, uint8_t *v); +_PUBLIC_ enum ndr_err_code ndr_pull_enum_uint16(struct ndr_pull *ndr, int ndr_flags, uint16_t *v); +_PUBLIC_ enum ndr_err_code ndr_pull_enum_uint32(struct ndr_pull *ndr, int ndr_flags, uint32_t *v); +_PUBLIC_ enum ndr_err_code ndr_push_enum_uint8(struct ndr_push *ndr, int ndr_flags, uint8_t v); +_PUBLIC_ enum ndr_err_code ndr_push_enum_uint16(struct ndr_push *ndr, int ndr_flags, uint16_t v); +_PUBLIC_ enum ndr_err_code ndr_push_enum_uint32(struct ndr_push *ndr, int ndr_flags, uint32_t v); + #endif /* __LIBNDR_H__ */ diff --git a/librpc/ndr/ndr.c b/librpc/ndr/ndr.c index d629d852e8..cb47ca1d60 100644 --- a/librpc/ndr/ndr.c +++ b/librpc/ndr/ndr.c @@ -459,7 +459,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_subcontext_start(struct ndr_pull *ndr, case 4: { uint32_t content_size; - NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &content_size)); + NDR_CHECK(ndr_pull_uint3264(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); @@ -544,7 +544,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_subcontext_start(struct ndr_pull *ndr, subndr = talloc_zero(ndr, struct ndr_pull); NDR_ERR_HAVE_NO_MEMORY(subndr); - subndr->flags = ndr->flags; + subndr->flags = ndr->flags & ~LIBNDR_FLAG_NDR64; subndr->current_mem_ctx = ndr->current_mem_ctx; subndr->data = ndr->data + ndr->offset; @@ -588,7 +588,7 @@ _PUBLIC_ enum ndr_err_code ndr_push_subcontext_start(struct ndr_push *ndr, subndr = ndr_push_init_ctx(ndr, ndr->iconv_convenience); NDR_ERR_HAVE_NO_MEMORY(subndr); - subndr->flags = ndr->flags; + subndr->flags = ndr->flags & ~LIBNDR_FLAG_NDR64; *_subndr = subndr; return NDR_ERR_SUCCESS; @@ -623,7 +623,7 @@ _PUBLIC_ enum ndr_err_code ndr_push_subcontext_end(struct ndr_push *ndr, break; case 4: - NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, subndr->offset)); + NDR_CHECK(ndr_push_uint3264(ndr, NDR_SCALARS, subndr->offset)); break; case 0xFFFFFC01: diff --git a/librpc/ndr/ndr_basic.c b/librpc/ndr/ndr_basic.c index efadb1e95e..00e33ad9d0 100644 --- a/librpc/ndr/ndr_basic.c +++ b/librpc/ndr/ndr_basic.c @@ -272,6 +272,73 @@ _PUBLIC_ enum ndr_err_code ndr_pull_WERROR(struct ndr_pull *ndr, int ndr_flags, return NDR_ERR_SUCCESS; } + +/* + parse a uint8_t enum +*/ +_PUBLIC_ enum ndr_err_code ndr_pull_enum_uint8(struct ndr_pull *ndr, int ndr_flags, uint8_t *v) +{ + return ndr_pull_uint8(ndr, ndr_flags, v); +} + +/* + parse a uint16_t enum (uint32_t on NDR64) +*/ +_PUBLIC_ enum ndr_err_code ndr_pull_enum_uint16(struct ndr_pull *ndr, int ndr_flags, uint16_t *v) +{ + if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) { + uint32_t v32; + NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &v32)); + *v = v32; + if (v32 != *v) { + DEBUG(0,(__location__ ": non-zero upper 16 bits 0x%08x\n", (unsigned)v32)); + return NDR_ERR_NDR64; + } + return NDR_ERR_SUCCESS; + } + NDR_PULL_ALIGN(ndr, 2); + NDR_PULL_NEED_BYTES(ndr, 2); + *v = NDR_SVAL(ndr, ndr->offset); + ndr->offset += 2; + return NDR_ERR_SUCCESS; +} + +/* + parse a uint32_t enum +*/ +_PUBLIC_ enum ndr_err_code ndr_pull_enum_uint32(struct ndr_pull *ndr, int ndr_flags, uint32_t *v) +{ + return ndr_pull_uint32(ndr, ndr_flags, v); +} + +/* + push a uint8_t enum +*/ +_PUBLIC_ enum ndr_err_code ndr_push_enum_uint8(struct ndr_push *ndr, int ndr_flags, uint8_t v) +{ + return ndr_push_uint8(ndr, ndr_flags, v); +} + +/* + push a uint16_t enum (uint32_t on NDR64) +*/ +_PUBLIC_ enum ndr_err_code ndr_push_enum_uint16(struct ndr_push *ndr, int ndr_flags, uint16_t v) +{ + if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) { + return ndr_push_uint32(ndr, ndr_flags, v); + } + return ndr_push_uint16(ndr, ndr_flags, v); +} + +/* + push a uint32_t enum +*/ +_PUBLIC_ enum ndr_err_code ndr_push_enum_uint32(struct ndr_push *ndr, int ndr_flags, uint32_t v) +{ + return ndr_push_uint32(ndr, ndr_flags, v); +} + + /* push a WERROR */ |