]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pidl: Add and use ndr_print_steal_switch_value(), removing ndr_print_get_switch_value()
authorAndrew Bartlett <abartlet@samba.org>
Sun, 17 Nov 2019 23:02:03 +0000 (12:02 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 12 Dec 2019 02:30:40 +0000 (02:30 +0000)
This avoids really long token lists for switch values
that will not be needed past this point.

The function name is changed to clarify what exactly is being
done here, and the old function is removed to ensure it is
not being used anywhere else.

Merge the removal of ndr_print_get_switch_value into
just-tagged librpc/ABI/ndr-1.0.0.sigs as this
has not been put into any release yet.

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>
librpc/ABI/ndr-1.0.0.sigs
librpc/ndr/libndr.h
librpc/ndr/ndr.c
librpc/ndr/ndr_drsuapi.c
librpc/ndr/ndr_ntlmssp.c
librpc/ndr/ndr_schannel.c
librpc/ndr/ndr_spoolss_buf.c
pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm

index 144e65fba759be96fd679e5c202467166530d6d4..fccf47930c2cce0e3380320a9fc1a046af7dd51a 100644 (file)
@@ -49,7 +49,6 @@ ndr_print_double: void (struct ndr_print *, const char *, double)
 ndr_print_enum: void (struct ndr_print *, const char *, const char *, const char *, uint32_t)
 ndr_print_function_debug: void (ndr_print_function_t, const char *, int, void *)
 ndr_print_function_string: char *(TALLOC_CTX *, ndr_print_function_t, const char *, int, void *)
-ndr_print_get_switch_value: uint32_t (struct ndr_print *, const void *)
 ndr_print_gid_t: void (struct ndr_print *, const char *, gid_t)
 ndr_print_hyper: void (struct ndr_print *, const char *, uint64_t)
 ndr_print_int16: void (struct ndr_print *, const char *, int16_t)
@@ -68,6 +67,7 @@ ndr_print_printf_helper: void (struct ndr_print *, const char *, ...)
 ndr_print_ptr: void (struct ndr_print *, const char *, const void *)
 ndr_print_set_switch_value: enum ndr_err_code (struct ndr_print *, const void *, uint32_t)
 ndr_print_sockaddr_storage: void (struct ndr_print *, const char *, const struct sockaddr_storage *)
+ndr_print_steal_switch_value: uint32_t (struct ndr_print *, const void *)
 ndr_print_string: void (struct ndr_print *, const char *, const char *)
 ndr_print_string_array: void (struct ndr_print *, const char *, const char **)
 ndr_print_string_helper: void (struct ndr_print *, const char *, ...)
index a35283a18b019fbe6a4767665e8d66f3e1ca20e2..0edf8955efbceffc9b4e9f7d3417a623c137de9c 100644 (file)
@@ -619,7 +619,7 @@ enum ndr_err_code ndr_print_set_switch_value(struct ndr_print *ndr, const void *
 uint32_t ndr_push_get_switch_value(struct ndr_push *ndr, const void *p);
 uint32_t ndr_push_steal_switch_value(struct ndr_push *ndr, const void *p);
 uint32_t ndr_pull_get_switch_value(struct ndr_pull *ndr, const void *p);
-uint32_t ndr_print_get_switch_value(struct ndr_print *ndr, const void *p);
+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);
 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);
index 379bc081fd2f5d3e0bd2e3a7b2f10a383f233244..6cc53b6e03a954f346aba91c715af3d467530acd 100644 (file)
@@ -1257,9 +1257,18 @@ _PUBLIC_ uint32_t ndr_pull_get_switch_value(struct ndr_pull *ndr, const void *p)
        return ndr_token_peek(&ndr->switch_list, p);
 }
 
-_PUBLIC_ uint32_t ndr_print_get_switch_value(struct ndr_print *ndr, const void *p)
+/* retrieve a switch value and remove it from the list */
+_PUBLIC_ uint32_t ndr_print_steal_switch_value(struct ndr_print *ndr, const void *p)
 {
-       return ndr_token_peek(&ndr->switch_list, p);
+       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;
 }
 
 /* retrieve a switch value and remove it from the list */
index cd550f1f0ee39d337d79145375c1b7119131932d..084057231d0f94b1c6d60ee25d985d0bbf9e5464 100644 (file)
@@ -577,7 +577,7 @@ enum ndr_err_code ndr_pull_drsuapi_DsBindInfo(struct ndr_pull *ndr, int ndr_flag
 _PUBLIC_ void ndr_print_drsuapi_DsBindInfo(struct ndr_print *ndr, const char *name, const union drsuapi_DsBindInfo *r)
 {
        uint32_t level;
-       level = ndr_print_get_switch_value(ndr, r);
+       level = ndr_print_steal_switch_value(ndr, r);
        ndr_print_union(ndr, name, level, "drsuapi_DsBindInfo");
        switch (level) {
                case 24:
index 7027ac0b13d836c0fb02d03b7b48c8fb0dcc5ae0..021bc402a80cda007d8bd95b4f63e66d41d7e95e 100644 (file)
@@ -164,7 +164,7 @@ _PUBLIC_ void ndr_print_ntlmssp_lm_response(TALLOC_CTX *mem_ctx,
 _PUBLIC_ void ndr_print_ntlmssp_Version(struct ndr_print *ndr, const char *name, const union ntlmssp_Version *r)
 {
        int level;
-       level = ndr_print_get_switch_value(ndr, r);
+       level = ndr_print_steal_switch_value(ndr, r);
        switch (level) {
                case NTLMSSP_NEGOTIATE_VERSION:
                        ndr_print_ntlmssp_VERSION(ndr, name, &r->version);
index 9bbc628a29436cc58a43f94e5d244dfac339353c..6b08a79cab2cfafe5c38c72b2466cd03b21eb5ae 100644 (file)
@@ -27,7 +27,7 @@
 _PUBLIC_ void ndr_print_NL_AUTH_MESSAGE_BUFFER(struct ndr_print *ndr, const char *name, const union NL_AUTH_MESSAGE_BUFFER *r)
 {
        int level;
-       level = ndr_print_get_switch_value(ndr, r);
+       level = ndr_print_steal_switch_value(ndr, r);
        switch (level) {
                case NL_FLAG_OEM_NETBIOS_DOMAIN_NAME:
                        ndr_print_string(ndr, name, r->a);
@@ -58,7 +58,7 @@ _PUBLIC_ void ndr_print_NL_AUTH_MESSAGE_BUFFER(struct ndr_print *ndr, const char
 _PUBLIC_ void ndr_print_NL_AUTH_MESSAGE_BUFFER_REPLY(struct ndr_print *ndr, const char *name, const union NL_AUTH_MESSAGE_BUFFER_REPLY *r)
 {
        int level;
-       level = ndr_print_get_switch_value(ndr, r);
+       level = ndr_print_steal_switch_value(ndr, r);
        switch (level) {
                case NL_NEGOTIATE_RESPONSE:
                        ndr_print_uint32(ndr, name, r->dummy);
index 244d692dca8bc1c210886276d5aa6a1215029219..a57f578fd455b40e40749114626332f7b9f3bb5a 100644 (file)
@@ -1096,7 +1096,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_spoolss_DriverInfo101(struct ndr_pull *ndr,
 void ndr_print_spoolss_Field(struct ndr_print *ndr, const char *name, const union spoolss_Field *r)
 {
        int level;
-       level = ndr_print_get_switch_value(ndr, r);
+       level = ndr_print_steal_switch_value(ndr, r);
        ndr_print_union(ndr, name, level, "spoolss_Field");
        switch (level) {
                case PRINTER_NOTIFY_TYPE:
index ee5ba03ab6f2e1e6c8b7b9409f203b4579264dcf..d51063f72168f3c2f0b897061cbea66755dbb89e 100644 (file)
@@ -2019,7 +2019,7 @@ sub ParseUnionPrint($$$$$)
 
        $self->start_flags($e, $ndr);
 
-       $self->pidl("level = ndr_print_get_switch_value($ndr, $varname);");
+       $self->pidl("level = ndr_print_steal_switch_value($ndr, $varname);");
 
        $self->pidl("ndr_print_union($ndr, name, level, \"$name\");");