diff options
author | Jeremy Allison <jra@samba.org> | 2009-10-17 10:36:33 -0700 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2009-10-17 10:36:33 -0700 |
commit | 7c51fa6d699a653cafa90df8e44911b576118ebd (patch) | |
tree | 543bf9ca698e03eff81104898b33e77f1abed319 /librpc/ndr | |
parent | cc3a6770c77ec8fe1cd63bf4c682853c56201f0c (diff) | |
parent | 3e3214fd91471bca5b6c4d3782e922d252d588fb (diff) | |
download | samba-7c51fa6d699a653cafa90df8e44911b576118ebd.tar.gz samba-7c51fa6d699a653cafa90df8e44911b576118ebd.tar.bz2 samba-7c51fa6d699a653cafa90df8e44911b576118ebd.zip |
Merge branch 'master' of ssh://jra@git.samba.org/data/git/samba
Diffstat (limited to 'librpc/ndr')
-rw-r--r-- | librpc/ndr/libndr.h | 8 | ||||
-rw-r--r-- | librpc/ndr/ndr_basic.c | 124 | ||||
-rw-r--r-- | librpc/ndr/ndr_drsuapi.c | 110 | ||||
-rw-r--r-- | librpc/ndr/ndr_drsuapi.h | 3 |
4 files changed, 133 insertions, 112 deletions
diff --git a/librpc/ndr/libndr.h b/librpc/ndr/libndr.h index 03b4362b37..45cb24405f 100644 --- a/librpc/ndr/libndr.h +++ b/librpc/ndr/libndr.h @@ -467,9 +467,11 @@ 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) +NDR_SCALAR_PROTO(int3264, int32_t) NDR_SCALAR_PROTO(udlong, uint64_t) NDR_SCALAR_PROTO(udlongr, uint64_t) NDR_SCALAR_PROTO(dlong, int64_t) @@ -498,6 +500,10 @@ enum ndr_err_code ndr_pull_bytes(struct ndr_pull *ndr, uint8_t *data, uint32_t n enum ndr_err_code ndr_pull_array_uint8(struct ndr_pull *ndr, int ndr_flags, uint8_t *data, uint32_t n); enum ndr_err_code ndr_push_align(struct ndr_push *ndr, size_t size); enum ndr_err_code ndr_pull_align(struct ndr_pull *ndr, size_t size); +enum ndr_err_code ndr_push_union_align(struct ndr_push *ndr, size_t size); +enum ndr_err_code ndr_pull_union_align(struct ndr_pull *ndr, size_t size); +enum ndr_err_code ndr_push_trailer_align(struct ndr_push *ndr, size_t size); +enum ndr_err_code ndr_pull_trailer_align(struct ndr_pull *ndr, size_t size); enum ndr_err_code ndr_push_bytes(struct ndr_push *ndr, const uint8_t *data, uint32_t n); enum ndr_err_code ndr_push_zero(struct ndr_push *ndr, uint32_t n); enum ndr_err_code ndr_push_array_uint8(struct ndr_push *ndr, int ndr_flags, const uint8_t *data, uint32_t n); @@ -544,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 00e33ad9d0..64fa5a6299 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,11 +592,53 @@ _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; } +_PUBLIC_ enum ndr_err_code ndr_push_union_align(struct ndr_push *ndr, size_t size) +{ + /* MS-RPCE section 2.2.5.3.4.4 */ + if (ndr->flags & LIBNDR_FLAG_NDR64) { + return ndr_push_align(ndr, size); + } + return NDR_ERR_SUCCESS; +} + +_PUBLIC_ enum ndr_err_code ndr_pull_union_align(struct ndr_pull *ndr, size_t size) +{ + /* MS-RPCE section 2.2.5.3.4.4 */ + if (ndr->flags & LIBNDR_FLAG_NDR64) { + return ndr_pull_align(ndr, size); + } + return NDR_ERR_SUCCESS; +} + +_PUBLIC_ enum ndr_err_code ndr_push_trailer_align(struct ndr_push *ndr, size_t size) +{ + /* MS-RPCE section 2.2.5.3.4.1 */ + if (ndr->flags & LIBNDR_FLAG_NDR64) { + return ndr_push_align(ndr, size); + } + return NDR_ERR_SUCCESS; +} + +_PUBLIC_ enum ndr_err_code ndr_pull_trailer_align(struct ndr_pull *ndr, size_t size) +{ + /* MS-RPCE section 2.2.5.3.4.1 */ + if (ndr->flags & LIBNDR_FLAG_NDR64) { + return ndr_pull_align(ndr, size); + } + return NDR_ERR_SUCCESS; +} + /* push some bytes */ @@ -806,6 +890,16 @@ _PUBLIC_ void ndr_print_uint32(struct ndr_print *ndr, const char *name, uint32_t ndr->print(ndr, "%-25s: 0x%08x (%u)", name, v, v); } +_PUBLIC_ void ndr_print_int3264(struct ndr_print *ndr, const char *name, int32_t v) +{ + ndr->print(ndr, "%-25s: %d", name, v); +} + +_PUBLIC_ void ndr_print_uint3264(struct ndr_print *ndr, const char *name, uint32_t v) +{ + ndr->print(ndr, "%-25s: 0x%08x (%u)", name, v, v); +} + _PUBLIC_ void ndr_print_udlong(struct ndr_print *ndr, const char *name, uint64_t v) { ndr->print(ndr, "%-25s: 0x%016llx (%llu)", name, (unsigned long long)v, (unsigned long long)v); diff --git a/librpc/ndr/ndr_drsuapi.c b/librpc/ndr/ndr_drsuapi.c index 0c790e52ca..bfc3c75b4e 100644 --- a/librpc/ndr/ndr_drsuapi.c +++ b/librpc/ndr/ndr_drsuapi.c @@ -82,102 +82,24 @@ void ndr_print_drsuapi_DsReplicaObjectListItemEx(struct ndr_print *ndr, const ch } \ } while (0) -enum ndr_err_code ndr_push_drsuapi_DsReplicaOID(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsReplicaOID *r) +_PUBLIC_ void ndr_print_drsuapi_DsReplicaOID(struct ndr_print *ndr, const char *name, const struct drsuapi_DsReplicaOID *r) { - if (ndr_flags & NDR_SCALARS) { - NDR_CHECK(ndr_push_align(ndr, 4)); - NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_size_drsuapi_DsReplicaOID_oid(r->oid, 0))); - NDR_CHECK(ndr_push_unique_ptr(ndr, r->oid)); - } - if (ndr_flags & NDR_BUFFERS) { - if (r->oid) { - DATA_BLOB blob; - - if (strncasecmp("ff", r->oid, 2) == 0) { - blob = strhex_to_data_blob(ndr, r->oid); - if (!blob.data) { - return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, - "HEX String Conversion Error: %s\n", - __location__); - } - } else { - _OID_PUSH_CHECK(ber_write_OID_String(&blob, r->oid)); - talloc_steal(ndr, blob.data); - } - - NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, blob.length)); - NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, blob.data, blob.length)); - } - } - return NDR_ERR_SUCCESS; -} - -enum ndr_err_code ndr_pull_drsuapi_DsReplicaOID(struct ndr_pull *ndr, int ndr_flags, struct drsuapi_DsReplicaOID *r) -{ - uint32_t _ptr_oid; - TALLOC_CTX *_mem_save_oid_0; - if (ndr_flags & NDR_SCALARS) { - NDR_CHECK(ndr_pull_align(ndr, 4)); - NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->__ndr_size)); - if (r->__ndr_size < 0 || r->__ndr_size > 10000) { - return ndr_pull_error(ndr, NDR_ERR_RANGE, "value out of range"); - } - NDR_CHECK(ndr_pull_generic_ptr(ndr, &_ptr_oid)); - if (_ptr_oid) { - NDR_PULL_ALLOC(ndr, r->oid); - } else { - r->oid = NULL; - } - } - if (ndr_flags & NDR_BUFFERS) { - if (r->oid) { - DATA_BLOB _oid_array; - const char *_oid; - - _mem_save_oid_0 = NDR_PULL_GET_MEM_CTX(ndr); - NDR_PULL_SET_MEM_CTX(ndr, ndr, 0); - NDR_CHECK(ndr_pull_array_size(ndr, &r->oid)); - _oid_array.length = ndr_get_array_size(ndr, &r->oid); - NDR_PULL_ALLOC_N(ndr, _oid_array.data, _oid_array.length); - NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, _oid_array.data, _oid_array.length)); - NDR_PULL_SET_MEM_CTX(ndr, _mem_save_oid_0, 0); - - if (_oid_array.length && _oid_array.data[0] == 0xFF) { - _oid = data_blob_hex_string(ndr, &_oid_array); - NDR_ERR_HAVE_NO_MEMORY(_oid); - } else { - _OID_PULL_CHECK(ber_read_OID_String(ndr, _oid_array, &_oid)); - } - data_blob_free(&_oid_array); - talloc_steal(r->oid, _oid); - r->oid = _oid; - } - if (r->oid) { - NDR_CHECK(ndr_check_array_size(ndr, (void*)&r->oid, r->__ndr_size)); - } - } - return NDR_ERR_SUCCESS; -} - -size_t ndr_size_drsuapi_DsReplicaOID_oid(const char *oid, int flags) -{ - DATA_BLOB _blob; - size_t ret = 0; - - if (!oid) return 0; - - if (strncasecmp("ff", oid, 2) == 0) { - _blob = strhex_to_data_blob(NULL, oid); - if (_blob.data) { - ret = _blob.length; - } - } else { - if (ber_write_OID_String(&_blob, oid)) { - ret = _blob.length; - } + ndr_print_struct(ndr, name, "drsuapi_DsReplicaOID"); + ndr->depth++; + ndr_print_uint32(ndr, "length", r->length); + ndr->print(ndr, "%-25s: length=%u", "oid", r->length); + if (r->binary_oid) { + char *partial_oid = NULL; + DATA_BLOB oid_blob = data_blob_const(r->binary_oid, r->length); + char *hex_str = data_blob_hex_string(ndr, &oid_blob); + ber_read_partial_OID_String(ndr, oid_blob, (const char **)&partial_oid); + ndr->depth++; + ndr->print(ndr, "%-25s: 0x%s (%s)", "binary_oid", hex_str, partial_oid); + ndr->depth--; + talloc_free(hex_str); + talloc_free(partial_oid); } - data_blob_free(&_blob); - return ret; + ndr->depth--; } enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr1(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesMSZIPCtr1 *r) diff --git a/librpc/ndr/ndr_drsuapi.h b/librpc/ndr/ndr_drsuapi.h index 12c2c78bde..179879a3b7 100644 --- a/librpc/ndr/ndr_drsuapi.h +++ b/librpc/ndr/ndr_drsuapi.h @@ -28,8 +28,5 @@ void ndr_print_drsuapi_DsReplicaObjectListItem(struct ndr_print *ndr, const char void ndr_print_drsuapi_DsReplicaObjectListItemEx(struct ndr_print *ndr, const char *name, const struct drsuapi_DsReplicaObjectListItemEx *r); -enum ndr_err_code ndr_push_drsuapi_DsReplicaOID(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsReplicaOID *r); -enum ndr_err_code ndr_pull_drsuapi_DsReplicaOID(struct ndr_pull *ndr, int ndr_flags, struct drsuapi_DsReplicaOID *r); -size_t ndr_size_drsuapi_DsReplicaOID_oid(const char *oid, int flags); #endif /* _LIBRPC_NDR_NDR_DRSUAPI_H */ |