summaryrefslogtreecommitdiff
path: root/librpc
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2009-10-06 20:47:09 +1100
committerAndrew Tridgell <tridge@samba.org>2009-10-07 09:56:22 +1100
commit2bf8a7485cf0733c808bc97a399a1c73bb988414 (patch)
treece07335e4304dfbe973b1da46ddeaecb19da53ac /librpc
parenta4aa38f8b927d6713c4cdd921a0a27cded041e94 (diff)
downloadsamba-2bf8a7485cf0733c808bc97a399a1c73bb988414.tar.gz
pidl: get the alignment right for uint1632 enums (NDR64)
The default enum in NDR63 is 32 bits, not 16 bits. We need a uint1632 type to get the alignment right.
Diffstat (limited to 'librpc')
-rw-r--r--librpc/ndr/libndr.h3
-rw-r--r--librpc/ndr/ndr_basic.c78
2 files changed, 66 insertions, 15 deletions
diff --git a/librpc/ndr/libndr.h b/librpc/ndr/libndr.h
index f4c649c4152..45cb24405f3 100644
--- a/librpc/ndr/libndr.h
+++ b/librpc/ndr/libndr.h
@@ -467,6 +467,7 @@ NDR_SCALAR_PROTO(uint8, uint8_t)
NDR_SCALAR_PROTO(int8, int8_t)
NDR_SCALAR_PROTO(uint16, uint16_t)
NDR_SCALAR_PROTO(int16, int16_t)
+NDR_SCALAR_PROTO(uint1632, uint16_t)
NDR_SCALAR_PROTO(uint32, uint32_t)
NDR_SCALAR_PROTO(uint3264, uint32_t)
NDR_SCALAR_PROTO(int32, int32_t)
@@ -549,8 +550,10 @@ 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_pull_enum_uint1632(struct ndr_pull *ndr, int ndr_flags, uint16_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);
+_PUBLIC_ enum ndr_err_code ndr_push_enum_uint1632(struct ndr_push *ndr, int ndr_flags, uint16_t v);
#endif /* __LIBNDR_H__ */
diff --git a/librpc/ndr/ndr_basic.c b/librpc/ndr/ndr_basic.c
index 1a19cc9327e..64fa5a62998 100644
--- a/librpc/ndr/ndr_basic.c
+++ b/librpc/ndr/ndr_basic.c
@@ -102,6 +102,24 @@ _PUBLIC_ enum ndr_err_code ndr_pull_uint16(struct ndr_pull *ndr, int ndr_flags,
}
/*
+ parse a uint1632_t
+*/
+_PUBLIC_ enum ndr_err_code ndr_pull_uint1632(struct ndr_pull *ndr, int ndr_flags, uint16_t *v)
+{
+ if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) {
+ uint32_t v32 = 0;
+ enum ndr_err_code err = ndr_pull_uint32(ndr, ndr_flags, &v32);
+ *v = v32;
+ if (unlikely(v32 != *v)) {
+ DEBUG(0,(__location__ ": non-zero upper 16 bits 0x%08x\n", (unsigned)v32));
+ return NDR_ERR_NDR64;
+ }
+ return err;
+ }
+ return ndr_pull_uint16(ndr, ndr_flags, v);
+}
+
+/*
parse a int32_t
*/
_PUBLIC_ enum ndr_err_code ndr_pull_int32(struct ndr_pull *ndr, int ndr_flags, int32_t *v)
@@ -282,10 +300,18 @@ _PUBLIC_ enum ndr_err_code ndr_pull_enum_uint8(struct ndr_pull *ndr, int ndr_fla
}
/*
- parse a uint16_t enum (uint32_t on NDR64)
+ parse a uint16_t enum
*/
_PUBLIC_ enum ndr_err_code ndr_pull_enum_uint16(struct ndr_pull *ndr, int ndr_flags, uint16_t *v)
{
+ return ndr_pull_uint16(ndr, ndr_flags, v);
+}
+
+/*
+ parse a uint1632_t enum (uint32_t on NDR64)
+*/
+_PUBLIC_ enum ndr_err_code ndr_pull_enum_uint1632(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));
@@ -296,11 +322,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_enum_uint16(struct ndr_pull *ndr, int ndr_fl
}
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;
+ return ndr_pull_uint16(ndr, ndr_flags, v);
}
/*
@@ -320,13 +342,10 @@ _PUBLIC_ enum ndr_err_code ndr_push_enum_uint8(struct ndr_push *ndr, int ndr_fla
}
/*
- push a uint16_t enum (uint32_t on NDR64)
+ push a uint16_t enum
*/
_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);
}
@@ -338,6 +357,16 @@ _PUBLIC_ enum ndr_err_code ndr_push_enum_uint32(struct ndr_push *ndr, int ndr_fl
return ndr_push_uint32(ndr, ndr_flags, v);
}
+/*
+ push a uint1632_t enum
+*/
+_PUBLIC_ enum ndr_err_code ndr_push_enum_uint1632(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 WERROR
@@ -421,6 +450,17 @@ _PUBLIC_ enum ndr_err_code ndr_push_uint16(struct ndr_push *ndr, int ndr_flags,
}
/*
+ push a uint1632
+*/
+_PUBLIC_ enum ndr_err_code ndr_push_uint1632(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 int32_t
*/
_PUBLIC_ enum ndr_err_code ndr_push_int32(struct ndr_push *ndr, int ndr_flags, int32_t v)
@@ -452,11 +492,7 @@ _PUBLIC_ enum ndr_err_code ndr_push_uint3264(struct ndr_push *ndr, int ndr_flags
if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) {
return ndr_push_hyper(ndr, ndr_flags, v);
}
- NDR_PUSH_ALIGN(ndr, 4);
- NDR_PUSH_NEED_BYTES(ndr, 4);
- NDR_SIVAL(ndr, ndr->offset, v);
- ndr->offset += 4;
- return NDR_ERR_SUCCESS;
+ return ndr_push_uint32(ndr, ndr_flags, v);
}
/*
@@ -536,6 +572,12 @@ _PUBLIC_ enum ndr_err_code ndr_push_align(struct ndr_push *ndr, size_t size)
} else {
size = 4;
}
+ } else if (size == 3) {
+ if (ndr->flags & LIBNDR_FLAG_NDR64) {
+ size = 4;
+ } else {
+ size = 2;
+ }
}
NDR_PUSH_ALIGN(ndr, size);
return NDR_ERR_SUCCESS;
@@ -550,6 +592,12 @@ _PUBLIC_ enum ndr_err_code ndr_pull_align(struct ndr_pull *ndr, size_t size)
} else {
size = 4;
}
+ } else if (size == 3) {
+ if (ndr->flags & LIBNDR_FLAG_NDR64) {
+ size = 4;
+ } else {
+ size = 2;
+ }
}
NDR_PULL_ALIGN(ndr, size);
return NDR_ERR_SUCCESS;