Commit 263269ba authored by Andrew Bartlett's avatar Andrew Bartlett

libndr: Return enum ndr_err_code from ndr_{pull,push}_steal_switch_value()

This breaks the ABI so we merge this into the unreleased libndr-1.0.0.

The advantage of the new functions is there (except for print, which
is unchanged) is an error raised when the token is not found, so
we can be confident in the changes to the token behaviour.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13876Signed-off-by: Andrew Bartlett's avatarAndrew Bartlett <[email protected]>
parent 9018c7f1
......@@ -138,7 +138,7 @@ ndr_pull_restore_relative_base_offset: void (struct ndr_pull *, uint32_t)
ndr_pull_set_switch_value: enum ndr_err_code (struct ndr_pull *, const void *, uint32_t)
ndr_pull_setup_relative_base_offset1: enum ndr_err_code (struct ndr_pull *, const void *, uint32_t)
ndr_pull_setup_relative_base_offset2: enum ndr_err_code (struct ndr_pull *, const void *)
ndr_pull_steal_switch_value: uint32_t (struct ndr_pull *, const void *)
ndr_pull_steal_switch_value: enum ndr_err_code (struct ndr_pull *, const void *, uint32_t *)
ndr_pull_string: enum ndr_err_code (struct ndr_pull *, int, const char **)
ndr_pull_string_array: enum ndr_err_code (struct ndr_pull *, int, const char ***)
ndr_pull_struct_blob: enum ndr_err_code (const DATA_BLOB *, TALLOC_CTX *, void *, ndr_pull_flags_fn_t)
......@@ -213,7 +213,7 @@ ndr_push_setup_relative_base_offset1: enum ndr_err_code (struct ndr_push *, cons
ndr_push_setup_relative_base_offset2: enum ndr_err_code (struct ndr_push *, const void *)
ndr_push_short_relative_ptr1: enum ndr_err_code (struct ndr_push *, const void *)
ndr_push_short_relative_ptr2: enum ndr_err_code (struct ndr_push *, const void *)
ndr_push_steal_switch_value: uint32_t (struct ndr_push *, const void *)
ndr_push_steal_switch_value: enum ndr_err_code (struct ndr_push *, const void *, uint32_t *)
ndr_push_string: enum ndr_err_code (struct ndr_push *, int, const char *)
ndr_push_string_array: enum ndr_err_code (struct ndr_push *, int, const char **)
ndr_push_struct_blob: enum ndr_err_code (DATA_BLOB *, TALLOC_CTX *, const void *, ndr_push_flags_fn_t)
......
......@@ -616,9 +616,16 @@ enum ndr_err_code ndr_check_pipe_chunk_trailer(struct ndr_pull *ndr, int ndr_fla
enum ndr_err_code ndr_push_set_switch_value(struct ndr_push *ndr, const void *p, uint32_t val);
enum ndr_err_code ndr_pull_set_switch_value(struct ndr_pull *ndr, const void *p, uint32_t val);
enum ndr_err_code ndr_print_set_switch_value(struct ndr_print *ndr, const void *p, uint32_t val);
uint32_t ndr_push_steal_switch_value(struct ndr_push *ndr, const void *p);
/* retrieve a switch value (for push) and remove it from the list */
enum ndr_err_code ndr_push_steal_switch_value(struct ndr_push *ndr,
const void *p,
uint32_t *v);
/* retrieve a switch value and remove it from the list */
uint32_t ndr_print_steal_switch_value(struct ndr_print *ndr, const void *p);
uint32_t ndr_pull_steal_switch_value(struct ndr_pull *ndr, const void *p);
/* retrieve a switch value and remove it from the list */
enum ndr_err_code ndr_pull_steal_switch_value(struct ndr_pull *ndr,
const void *p,
uint32_t *v);
enum ndr_err_code ndr_pull_struct_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p, ndr_pull_flags_fn_t fn);
enum ndr_err_code ndr_pull_struct_blob_all(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p, ndr_pull_flags_fn_t fn);
enum ndr_err_code ndr_pull_struct_blob_all_noalloc(const DATA_BLOB *blob,
......
......@@ -1231,17 +1231,11 @@ _PUBLIC_ enum ndr_err_code ndr_print_set_switch_value(struct ndr_print *ndr, con
}
/* retrieve a switch value (for push) and remove it from the list */
_PUBLIC_ uint32_t ndr_push_steal_switch_value(struct ndr_push *ndr, const void *p)
_PUBLIC_ enum ndr_err_code ndr_push_steal_switch_value(struct ndr_push *ndr,
const void *p,
uint32_t *v)
{
enum ndr_err_code status;
uint32_t v;
status = ndr_token_retrieve(&ndr->switch_list, p, &v);
if (!NDR_ERR_CODE_IS_SUCCESS(status)) {
return 0;
}
return v;
return ndr_token_retrieve(&ndr->switch_list, p, v);
}
/* retrieve a switch value and remove it from the list */
......@@ -1259,17 +1253,11 @@ _PUBLIC_ uint32_t ndr_print_steal_switch_value(struct ndr_print *ndr, const void
}
/* retrieve a switch value and remove it from the list */
_PUBLIC_ uint32_t ndr_pull_steal_switch_value(struct ndr_pull *ndr, const void *p)
_PUBLIC_ enum ndr_err_code ndr_pull_steal_switch_value(struct ndr_pull *ndr,
const void *p,
uint32_t *v)
{
enum ndr_err_code status;
uint32_t v;
status = ndr_token_retrieve(&ndr->switch_list, p, &v);
if (!NDR_ERR_CODE_IS_SUCCESS(status)) {
return 0;
}
return v;
return ndr_token_retrieve(&ndr->switch_list, p, v);
}
/*
......
......@@ -420,7 +420,8 @@ enum ndr_err_code ndr_push_drsuapi_DsBindInfo(struct ndr_push *ndr, int ndr_flag
ndr->flags = ndr->flags & ~LIBNDR_FLAG_NDR64;
NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
if (ndr_flags & NDR_SCALARS) {
uint32_t level = ndr_push_steal_switch_value(ndr, r);
uint32_t level;
NDR_CHECK(ndr_push_steal_switch_value(ndr, r, &level));
NDR_CHECK(ndr_push_union_align(ndr, 4));
switch (level) {
case 24: {
......@@ -480,7 +481,8 @@ enum ndr_err_code ndr_pull_drsuapi_DsBindInfo(struct ndr_pull *ndr, int ndr_flag
ndr->flags = ndr->flags & ~LIBNDR_FLAG_NDR64;
NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
if (ndr_flags & NDR_SCALARS) {
uint32_t level = ndr_pull_steal_switch_value(ndr, r);
uint32_t level;
NDR_CHECK(ndr_pull_steal_switch_value(ndr, r, &level));
NDR_CHECK(ndr_pull_union_align(ndr, 4));
switch (level) {
case 24: {
......
......@@ -1971,7 +1971,7 @@ sub ParseUnionPush($$$$)
$self->pidl("if (ndr_flags & NDR_SCALARS) {");
$self->indent;
$self->pidl("/* This token is not used again (except perhaps below in the NDR_BUFFERS case) */");
$self->pidl("level = ndr_push_steal_switch_value($ndr, $varname);");
$self->pidl("NDR_CHECK(ndr_push_steal_switch_value($ndr, $varname, &level));");
$self->ParseUnionPushPrimitives($e, $ndr, $varname);
$self->deindent;
......@@ -1983,7 +1983,7 @@ sub ParseUnionPush($$$$)
$self->pidl("if (!(ndr_flags & NDR_SCALARS)) {");
$self->indent;
$self->pidl("/* We didn't get it above, and the token is not needed after this. */");
$self->pidl("level = ndr_push_steal_switch_value($ndr, $varname);");
$self->pidl("NDR_CHECK(ndr_push_steal_switch_value($ndr, $varname, &level));");
$self->deindent;
$self->pidl("}");
$self->ParseUnionPushDeferred($e, $ndr, $varname);
......@@ -2159,7 +2159,7 @@ sub ParseUnionPull($$$$)
$self->pidl("if (ndr_flags & NDR_SCALARS) {");
$self->indent;
$self->pidl("/* This token is not used again (except perhaps below in the NDR_BUFFERS case) */");
$self->pidl("level = ndr_pull_steal_switch_value($ndr, $varname);");
$self->pidl("NDR_CHECK(ndr_pull_steal_switch_value($ndr, $varname, &level));");
$self->ParseUnionPullPrimitives($e,$ndr,$varname,$switch_type);
$self->deindent;
$self->pidl("}");
......@@ -2170,7 +2170,7 @@ sub ParseUnionPull($$$$)
$self->pidl("if (!(ndr_flags & NDR_SCALARS)) {");
$self->indent;
$self->pidl("/* We didn't get it above, and the token is not needed after this. */");
$self->pidl("level = ndr_pull_steal_switch_value($ndr, $varname);");
$self->pidl("NDR_CHECK(ndr_pull_steal_switch_value($ndr, $varname, &level));");
$self->deindent;
$self->pidl("}");
$self->ParseUnionPullDeferred($e,$ndr,$varname);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment