libndr: Return enum ndr_err_code from ndr_{pull,push}_steal_switch_value()
authorAndrew Bartlett <abartlet@samba.org>
Tue, 3 Dec 2019 23:45:42 +0000 (12:45 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 12 Dec 2019 03:56:23 +0000 (03:56 +0000)
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=13876

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Thu Dec 12 03:56:23 UTC 2019 on sn-devel-184

librpc/ABI/ndr-1.0.0.sigs
librpc/ndr/libndr.h
librpc/ndr/ndr.c
librpc/ndr/ndr_drsuapi.c
pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm

index 3177f3804d4426ed6b67f490fbad1dedb14fbaa6..bc7c3e88848fc8b69bf14b29b8471c4ce34089fc 100644 (file)
@@ -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)
index 2a4e3fb098a4465d16e2912739dc326f64a43b09..58ef517d3630d06def34c30bae9b3e4f8da91a44 100644 (file)
@@ -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,
index 5616eec211f01e89951b8ec244fcc380112c7464..2259a35b170049fc8750430b595683e73eb4810a 100644 (file)
@@ -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);
 }
 
 /*
index a0a99ef3663aea5227260bb600238441155ac2ac..b03c1ec57b32da700b359741976bcc721579331a 100644 (file)
@@ -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: {
index 31dce4bc2ba98d649948ad8ba18f3379b804814f..0d58cb5f03d5c6a4f048dd215c5770df2e6e1d83 100644 (file)
@@ -1983,7 +1983,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;
@@ -1995,7 +1995,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);
@@ -2171,7 +2171,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("}");
@@ -2182,7 +2182,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);