From: Andrew Bartlett Date: Sun, 17 Nov 2019 23:02:03 +0000 (+1300) Subject: pidl: Add and use ndr_print_steal_switch_value(), removing ndr_print_get_switch_value() X-Git-Tag: ldb-2.1.0~265 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e08461b2845183224b9775b54be4acaaba705ecd;p=thirdparty%2Fsamba.git pidl: Add and use ndr_print_steal_switch_value(), removing ndr_print_get_switch_value() 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 Reviewed-by: Gary Lockyer --- diff --git a/librpc/ABI/ndr-1.0.0.sigs b/librpc/ABI/ndr-1.0.0.sigs index 144e65fba75..fccf47930c2 100644 --- a/librpc/ABI/ndr-1.0.0.sigs +++ b/librpc/ABI/ndr-1.0.0.sigs @@ -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 *, ...) diff --git a/librpc/ndr/libndr.h b/librpc/ndr/libndr.h index a35283a18b0..0edf8955efb 100644 --- a/librpc/ndr/libndr.h +++ b/librpc/ndr/libndr.h @@ -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); diff --git a/librpc/ndr/ndr.c b/librpc/ndr/ndr.c index 379bc081fd2..6cc53b6e03a 100644 --- a/librpc/ndr/ndr.c +++ b/librpc/ndr/ndr.c @@ -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 */ diff --git a/librpc/ndr/ndr_drsuapi.c b/librpc/ndr/ndr_drsuapi.c index cd550f1f0ee..084057231d0 100644 --- a/librpc/ndr/ndr_drsuapi.c +++ b/librpc/ndr/ndr_drsuapi.c @@ -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: diff --git a/librpc/ndr/ndr_ntlmssp.c b/librpc/ndr/ndr_ntlmssp.c index 7027ac0b13d..021bc402a80 100644 --- a/librpc/ndr/ndr_ntlmssp.c +++ b/librpc/ndr/ndr_ntlmssp.c @@ -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); diff --git a/librpc/ndr/ndr_schannel.c b/librpc/ndr/ndr_schannel.c index 9bbc628a294..6b08a79cab2 100644 --- a/librpc/ndr/ndr_schannel.c +++ b/librpc/ndr/ndr_schannel.c @@ -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); diff --git a/librpc/ndr/ndr_spoolss_buf.c b/librpc/ndr/ndr_spoolss_buf.c index 244d692dca8..a57f578fd45 100644 --- a/librpc/ndr/ndr_spoolss_buf.c +++ b/librpc/ndr/ndr_spoolss_buf.c @@ -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: diff --git a/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm index ee5ba03ab6f..d51063f7216 100644 --- a/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm +++ b/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm @@ -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\");");