The branch, master has been updated via e14fc159a2f librpc: Simplify find_interface_by_binding() via ecd95fc55eb librpc: Simplify find_interface_by_syntax_id() via 9c1d7632e35 librpc: Convert find_interface_by_uuid to search by syntax_id via 230a89332f5 lib: Fix file_ploadv_send()/_recv() via 7528b7886b9 librpc: Fix a typo via 9d512a099a7 librpc: Simplify dcesrv_check_or_create_context() via 38ebfe2e1f1 epmapper: Simplify endpoints_match() via ce91a899a60 librpc: Simplify dcerpc_binding_string() via 4df6c594c68 librpc: Simplify dcerpc_binding_string() via 895f459b4b2 epmapper: Simplify _epm_Map() via 08757d213ee rpc_server: Introduce "goto nomem;" to dcesrv_endpoint_connect() via c1614edf292 libwbclient: Fix wbcStringToGuid via 2b9ba992b61 lib: Simplify parse_guid_string() and ndr_syntax_id_from_string() via 522ef9e6a57 s4-torture: Add a test for ndr_syntax_id_from_string() via 15934ace717 s4-torture: Add a test for GUID_from_data_blob via 064eab8b257 dsdb: Avoid an unneeded #include via fcf60f155a2 librpc: Simplify dcerpc_binding_set_abstract_syntax() via eed1257268e librpc: Use ndr_syntax_id_buf_string() in dcerpc_binding_set_abstract_syntax() via 243ce602129 librpc: Use ndr_syntax_id_buf_string() in dcerpc_sec_vt_pctx_check() via a35c8a0ec23 librpc: Add ndr_syntax_id_buf_string() via 2e3e297b259 librpc: Add a NULL check to dcerpc_binding_build_tower() via 9374313f033 libndr: Simplify ndr_print_GUID() from c8c2aef0ac6 vfs: restore platform specific POSIX sys_acl_set_file() functions
https://git.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit e14fc159a2fab69612c6922406a9614a7c2d55ee Author: Volker Lendecke <v...@samba.org> Date: Wed Jan 27 14:00:06 2021 +0100 librpc: Simplify find_interface_by_binding() Use find_interface_by_syntax_id() instead of duplicating the loop. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Samuel Cabrero <scabr...@samba.org> Autobuild-User(master): Volker Lendecke <v...@samba.org> Autobuild-Date(master): Thu Jan 28 18:03:53 UTC 2021 on sn-devel-184 commit ecd95fc55eb793cfbbe233bd91664b6d646d430f Author: Volker Lendecke <v...@samba.org> Date: Wed Jan 27 13:54:25 2021 +0100 librpc: Simplify find_interface_by_syntax_id() Directly use ndr_syntax_id_equal() instead of duplicating it with interface_match_by_uuid(). Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Samuel Cabrero <scabr...@samba.org> commit 9c1d7632e35dc28061ff8bce51f162af35bfa4cb Author: Volker Lendecke <v...@samba.org> Date: Wed Jan 27 13:51:33 2021 +0100 librpc: Convert find_interface_by_uuid to search by syntax_id All callers manually dissected the syntax id for this API. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Samuel Cabrero <scabr...@samba.org> commit 230a89332f51b21384d140f5f6d1fb25f593ccb4 Author: Volker Lendecke <v...@samba.org> Date: Tue Jan 26 16:39:29 2021 +0100 lib: Fix file_ploadv_send()/_recv() When reading more than 1024 bytes, don't insert '\0' bytes in between those chunks. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Samuel Cabrero <scabr...@samba.org> commit 7528b7886b9b4fb99816711ad4a21afffb20f3fa Author: Volker Lendecke <v...@samba.org> Date: Tue Jan 26 15:44:47 2021 +0100 librpc: Fix a typo Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Samuel Cabrero <scabr...@samba.org> commit 9d512a099a7f80893ba8fbbff81e83b67dc08301 Author: Volker Lendecke <v...@samba.org> Date: Wed Jan 27 09:49:33 2021 +0100 librpc: Simplify dcesrv_check_or_create_context() Use ndr_syntax_id_buf_string(), avoid a talloc/talloc_free Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Samuel Cabrero <scabr...@samba.org> commit 38ebfe2e1f16909700c60281f28d374448f0b801 Author: Volker Lendecke <v...@samba.org> Date: Sun Jan 24 15:40:11 2021 +0100 epmapper: Simplify endpoints_match() strequal() deals fine with either string being NULL. We only have to take of the case where both are NULL. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Samuel Cabrero <scabr...@samba.org> commit ce91a899a60059c9d495bf37ec5e3a8b4bf6afdc Author: Volker Lendecke <v...@samba.org> Date: Sun Jan 24 15:14:58 2021 +0100 librpc: Simplify dcerpc_binding_string() Make it follow a more conventional memory handling style for reallocs. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Samuel Cabrero <scabr...@samba.org> commit 4df6c594c68dc5c2bfeb8e897f2226304da4848b Author: Volker Lendecke <v...@samba.org> Date: Sun Jan 24 15:07:47 2021 +0100 librpc: Simplify dcerpc_binding_string() Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Samuel Cabrero <scabr...@samba.org> commit 895f459b4b2f347223f5b524d6b79090654cd1f4 Author: Volker Lendecke <v...@samba.org> Date: Sun Jan 24 12:35:07 2021 +0100 epmapper: Simplify _epm_Map() We have a routine to compare ndr_syntax_id, don't do it manually. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Samuel Cabrero <scabr...@samba.org> commit 08757d213ee016dfa958d393ef41d7aa66756132 Author: Volker Lendecke <v...@samba.org> Date: Wed Jan 20 14:30:57 2021 +0100 rpc_server: Introduce "goto nomem;" to dcesrv_endpoint_connect() Avoid the control-flow changing NT_STATUS_HAVE_NO_MEMORY macro. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Samuel Cabrero <scabr...@samba.org> commit c1614edf292ce907b5cecad56ad1643c51256269 Author: Volker Lendecke <v...@samba.org> Date: Sun Jan 24 09:36:15 2021 +0100 libwbclient: Fix wbcStringToGuid The "x" sscanf conversion specifier requires an unsigned int. It is likely that this is actually a uint32_t, don't rely on that. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Samuel Cabrero <scabr...@samba.org> commit 2b9ba992b610ebc600f573d8b3f46568d5347cec Author: Volker Lendecke <v...@samba.org> Date: Sun Jan 24 09:15:29 2021 +0100 lib: Simplify parse_guid_string() and ndr_syntax_id_from_string() Return "bool" instead of NTSTATUS, use hex_byte() instead of read_hex_bytes(). And parse directly into a struct GUID instead of the components. 99 lines less code. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Samuel Cabrero <scabr...@samba.org> commit 522ef9e6a57ba46c6c097c088deb27fe12f3b300 Author: Samuel Cabrero <scabr...@samba.org> Date: Thu Jan 28 13:14:49 2021 +0100 s4-torture: Add a test for ndr_syntax_id_from_string() Signed-off-by: Samuel Cabrero <scabr...@samba.org> Reviewed-by: Volker Lendecke <v...@samba.org> commit 15934ace717a73e270c2e5ac4fb3d306885b195c Author: Samuel Cabrero <scabr...@samba.org> Date: Thu Jan 28 12:37:30 2021 +0100 s4-torture: Add a test for GUID_from_data_blob Signed-off-by: Samuel Cabrero <scabr...@samba.org> Reviewed-by: Volker Lendecke <v...@samba.org> commit 064eab8b2579290c8f363d68727ea4fedf4e6305 Author: Volker Lendecke <v...@samba.org> Date: Sun Jan 24 09:21:23 2021 +0100 dsdb: Avoid an unneeded #include Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Samuel Cabrero <scabr...@samba.org> commit fcf60f155a24bea97395b7ee0200543440782a74 Author: Volker Lendecke <v...@samba.org> Date: Fri Jan 22 20:01:27 2021 +0100 librpc: Simplify dcerpc_binding_set_abstract_syntax() It might be a question of style, but I find it simpler this way. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Samuel Cabrero <scabr...@samba.org> commit eed1257268e96123d9655527071c00d0ab38f803 Author: Volker Lendecke <v...@samba.org> Date: Fri Jan 22 19:59:52 2021 +0100 librpc: Use ndr_syntax_id_buf_string() in dcerpc_binding_set_abstract_syntax() Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Samuel Cabrero <scabr...@samba.org> commit 243ce602129232e50313099f094cf09a848a2ab0 Author: Volker Lendecke <v...@samba.org> Date: Fri Jan 22 19:56:20 2021 +0100 librpc: Use ndr_syntax_id_buf_string() in dcerpc_sec_vt_pctx_check() "mem_ctx" is no longer needed Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Samuel Cabrero <scabr...@samba.org> commit a35c8a0ec233175fd677a40ad72ac707a5c45915 Author: Volker Lendecke <v...@samba.org> Date: Fri Jan 22 19:50:04 2021 +0100 librpc: Add ndr_syntax_id_buf_string() Same pattern as GUID_buf_string() Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Samuel Cabrero <scabr...@samba.org> commit 2e3e297b259ff32094db6fb4114726201f08ca2a Author: Volker Lendecke <v...@samba.org> Date: Fri Jan 22 19:40:37 2021 +0100 librpc: Add a NULL check to dcerpc_binding_build_tower() Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Samuel Cabrero <scabr...@samba.org> commit 9374313f0333a1501d6fb823dbed86fb136f0766 Author: Volker Lendecke <v...@samba.org> Date: Fri Jan 22 19:33:51 2021 +0100 libndr: Simplify ndr_print_GUID() Fix a small memleak of the tmp GUID_string Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Samuel Cabrero <scabr...@samba.org> ----------------------------------------------------------------------- Summary of changes: lib/util/util_str_hex.c | 101 ++++++--------- lib/util/util_str_hex.h | 13 +- librpc/ABI/{ndr-1.0.1.sigs => ndr-1.0.2.sigs} | 1 + librpc/ndr/libndr.h | 5 + librpc/ndr/ndr.c | 2 +- librpc/ndr/ndr_misc.c | 66 ++++------ librpc/ndr/uuid.c | 70 +++-------- librpc/rpc/binding.c | 171 +++++++++++--------------- librpc/rpc/dcerpc_util.c | 29 ++--- librpc/rpc/dcesrv_core.c | 68 ++++------ librpc/rpc/dcesrv_core.h | 6 +- librpc/wscript_build | 2 +- nsswitch/libwbclient/wbc_guid.c | 8 +- source3/lib/util_file.c | 7 ++ source3/rpc_server/epmapper/srv_epmapper.c | 23 +--- source3/rpc_server/rpc_ncacn_np.c | 5 +- source3/winbindd/winbindd_dual_ndr.c | 5 +- source4/dsdb/common/util.c | 1 - source4/rpc_server/epmapper/rpc_epmapper.c | 3 +- source4/torture/ndr/ndr.c | 74 ++++++++++- 20 files changed, 294 insertions(+), 366 deletions(-) copy librpc/ABI/{ndr-1.0.1.sigs => ndr-1.0.2.sigs} (99%) Changeset truncated at 500 lines: diff --git a/lib/util/util_str_hex.c b/lib/util/util_str_hex.c index 792b4e8420b..553fb30681e 100644 --- a/lib/util/util_str_hex.c +++ b/lib/util/util_str_hex.c @@ -1,48 +1,27 @@ #include "replace.h" -#include "libcli/util/ntstatus.h" #include "util_str_hex.h" +#include "lib/util/data_blob.h" +#include "librpc/gen_ndr/misc.h" -NTSTATUS read_hex_bytes(const char *s, uint hexchars, uint64_t *dest) +static bool hex_uint16(const char *in, uint16_t *out) { - uint64_t x = 0; - uint i; - char c; - - if ((hexchars & 1) || hexchars > 16) { - return NT_STATUS_INVALID_PARAMETER; - } - - for (i = 0; i < hexchars; i++) { - x <<= 4; - c = s[i]; - if (c >= '0' && c <= '9') { - x += c - '0'; - } - else if (c >= 'a' && c <= 'f') { - x += c - 'a' + 10; - } - else if (c >= 'A' && c <= 'F') { - x += c - 'A' + 10; - } - else { - /* BAD character (including '\0') */ - return NT_STATUS_INVALID_PARAMETER; - } - } - *dest = x; - return NT_STATUS_OK; + uint8_t hi=0, lo=0; + bool ok = hex_byte(in, &hi) && hex_byte(in+2, &lo); + *out = (((uint16_t)hi)<<8) + lo; + return ok; } +bool hex_uint32(const char *in, uint32_t *out) +{ + uint16_t hi=0, lo=0; + bool ok = hex_uint16(in, &hi) && hex_uint16(in+4, &lo); + *out = (((uint32_t)hi)<<16) + lo; + return ok; +} -NTSTATUS parse_guid_string(const char *s, - uint32_t *time_low, - uint32_t *time_mid, - uint32_t *time_hi_and_version, - uint32_t clock_seq[2], - uint32_t node[6]) +bool parse_guid_string(const char *s, struct GUID *guid) { - uint64_t tmp; - NTSTATUS status; + bool ok; int i; /* "e12b56b6-0a95-11d1-adbb-00c04fd8d5cd" | | | | | @@ -52,49 +31,39 @@ NTSTATUS parse_guid_string(const char *s, | \_______________ time_mid \_____________________ time_low */ - status = read_hex_bytes(s, 8, &tmp); - if (!NT_STATUS_IS_OK(status) || s[8] != '-') { - return NT_STATUS_INVALID_PARAMETER; + + ok = hex_uint32(s, &guid->time_low); + if (!ok || (s[8] != '-')) { + return false; } - *time_low = tmp; s += 9; - status = read_hex_bytes(s, 4, &tmp); - if (!NT_STATUS_IS_OK(status) || s[4] != '-') { - return NT_STATUS_INVALID_PARAMETER; + ok = hex_uint16(s, &guid->time_mid); + if (!ok || (s[4] != '-')) { + return false; } - *time_mid = tmp; s += 5; - status = read_hex_bytes(s, 4, &tmp); - if (!NT_STATUS_IS_OK(status) || s[4] != '-') { - return NT_STATUS_INVALID_PARAMETER; + ok = hex_uint16(s, &guid->time_hi_and_version); + if (!ok || (s[4] != '-')) { + return false; } - *time_hi_and_version = tmp; s += 5; - for (i = 0; i < 2; i++) { - status = read_hex_bytes(s, 2, &tmp); - if (!NT_STATUS_IS_OK(status)) { - return NT_STATUS_INVALID_PARAMETER; - } - clock_seq[i] = tmp; - s += 2; - } - if (s[0] != '-') { - return NT_STATUS_INVALID_PARAMETER; + ok = hex_byte(s, &guid->clock_seq[0]) && + hex_byte(s+2, &guid->clock_seq[1]); + if (!ok || (s[4] != '-')) { + return false; } - - s++; + s += 5; for (i = 0; i < 6; i++) { - status = read_hex_bytes(s, 2, &tmp); - if (!NT_STATUS_IS_OK(status)) { - return NT_STATUS_INVALID_PARAMETER; + ok = hex_byte(s, &guid->node[i]); + if (!ok) { + return false; } - node[i] = tmp; s += 2; } - return NT_STATUS_OK; + return true; } diff --git a/lib/util/util_str_hex.h b/lib/util/util_str_hex.h index d0d53e3ed05..7dd527fcdab 100644 --- a/lib/util/util_str_hex.h +++ b/lib/util/util_str_hex.h @@ -1,10 +1,5 @@ -#include "../libcli/util/ntstatus.h" +#include "replace.h" -NTSTATUS read_hex_bytes(const char *s, uint hexchars, uint64_t *dest); - -NTSTATUS parse_guid_string(const char *s, - uint32_t *time_low, - uint32_t *time_mid, - uint32_t *time_hi_and_version, - uint32_t clock_seq[2], - uint32_t node[6]); +bool hex_uint32(const char *in, uint32_t *out); +struct GUID; +bool parse_guid_string(const char *s, struct GUID *guid); diff --git a/librpc/ABI/ndr-1.0.1.sigs b/librpc/ABI/ndr-1.0.2.sigs similarity index 99% copy from librpc/ABI/ndr-1.0.1.sigs copy to librpc/ABI/ndr-1.0.2.sigs index 84150859c9c..0ec8575906a 100644 --- a/librpc/ABI/ndr-1.0.1.sigs +++ b/librpc/ABI/ndr-1.0.2.sigs @@ -251,6 +251,7 @@ ndr_size_union: size_t (const void *, int, uint32_t, ndr_push_flags_fn_t) ndr_size_winreg_Data_GPO: size_t (const union winreg_Data_GPO *, uint32_t, int) ndr_string_array_size: size_t (struct ndr_push *, const char *) ndr_string_length: uint32_t (const void *, uint32_t) +ndr_syntax_id_buf_string: char *(const struct ndr_syntax_id *, struct ndr_syntax_id_buf *) ndr_syntax_id_equal: bool (const struct ndr_syntax_id *, const struct ndr_syntax_id *) ndr_syntax_id_from_string: bool (const char *, struct ndr_syntax_id *) ndr_syntax_id_null: uuid = {time_low = 0, time_mid = 0, time_hi_and_version = 0, clock_seq = "\000", node = "\000\000\000\000\000"}, if_version = 0 diff --git a/librpc/ndr/libndr.h b/librpc/ndr/libndr.h index 8bb0def40c0..fd772b9b510 100644 --- a/librpc/ndr/libndr.h +++ b/librpc/ndr/libndr.h @@ -556,7 +556,12 @@ void ndr_print_GUID(struct ndr_print *ndr, const char *name, const struct GUID * void ndr_print_sockaddr_storage(struct ndr_print *ndr, const char *name, const struct sockaddr_storage *ss); void ndr_zero_memory(void *ptr, size_t len); bool ndr_syntax_id_equal(const struct ndr_syntax_id *i1, const struct ndr_syntax_id *i2); + +struct ndr_syntax_id_buf { char buf[39 /*GUID*/ + 3 /* "/0x" */ + 8]; }; +char *ndr_syntax_id_buf_string( + const struct ndr_syntax_id *id, struct ndr_syntax_id_buf *buf); char *ndr_syntax_id_to_string(TALLOC_CTX *mem_ctx, const struct ndr_syntax_id *id); + bool ndr_syntax_id_from_string(const char *s, struct ndr_syntax_id *id); enum ndr_err_code ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, const void *p, ndr_push_flags_fn_t fn); enum ndr_err_code ndr_push_struct_into_fixed_blob(DATA_BLOB *blob, diff --git a/librpc/ndr/ndr.c b/librpc/ndr/ndr.c index afe22a28602..024634d0a09 100644 --- a/librpc/ndr/ndr.c +++ b/librpc/ndr/ndr.c @@ -37,7 +37,7 @@ #define NDR_BASE_MARSHALL_SIZE 1024 /* - * This value is arbitary, but designed to reduce the memory a client + * This value is arbitrary, but designed to reduce the memory a client * can allocate and the work the client can force in processing a * malicious packet. * diff --git a/librpc/ndr/ndr_misc.c b/librpc/ndr/ndr_misc.c index 155ab8f21b8..d7ebb066b8a 100644 --- a/librpc/ndr/ndr_misc.c +++ b/librpc/ndr/ndr_misc.c @@ -28,7 +28,8 @@ _PUBLIC_ void ndr_print_GUID(struct ndr_print *ndr, const char *name, const struct GUID *guid) { - ndr->print(ndr, "%-25s: %s", name, GUID_string(ndr, guid)); + struct GUID_txt_buf buf; + ndr->print(ndr, "%-25s: %s", name, GUID_buf_string(guid, &buf)); } bool ndr_syntax_id_equal(const struct ndr_syntax_id *i1, @@ -38,38 +39,32 @@ bool ndr_syntax_id_equal(const struct ndr_syntax_id *i1, && (i1->if_version == i2->if_version); } +char *ndr_syntax_id_buf_string( + const struct ndr_syntax_id *id, struct ndr_syntax_id_buf *dst) +{ + struct GUID_txt_buf guid_buf; + + snprintf(dst->buf, + sizeof(dst->buf), + "%s/0x%08x", + GUID_buf_string(&id->uuid, &guid_buf), + (unsigned int)id->if_version); + + return dst->buf; +} + _PUBLIC_ char *ndr_syntax_id_to_string(TALLOC_CTX *mem_ctx, const struct ndr_syntax_id *id) { - return talloc_asprintf(mem_ctx, - "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x/0x%08x", - id->uuid.time_low, id->uuid.time_mid, - id->uuid.time_hi_and_version, - id->uuid.clock_seq[0], - id->uuid.clock_seq[1], - id->uuid.node[0], id->uuid.node[1], - id->uuid.node[2], id->uuid.node[3], - id->uuid.node[4], id->uuid.node[5], - (unsigned)id->if_version); + struct ndr_syntax_id_buf buf; + return talloc_strdup(mem_ctx, ndr_syntax_id_buf_string(id, &buf)); } _PUBLIC_ bool ndr_syntax_id_from_string(const char *s, struct ndr_syntax_id *id) { - size_t i; - uint32_t time_low; - uint32_t time_mid, time_hi_and_version; - uint32_t clock_seq[2]; - uint32_t node[6]; - uint64_t if_version; - NTSTATUS status; - - status = parse_guid_string(s, - &time_low, - &time_mid, - &time_hi_and_version, - clock_seq, - node); + bool ok; - if (!NT_STATUS_IS_OK(status)) { + ok = parse_guid_string(s, &id->uuid); + if (!ok) { return false; } @@ -77,21 +72,6 @@ _PUBLIC_ bool ndr_syntax_id_from_string(const char *s, struct ndr_syntax_id *id) return false; } - status = read_hex_bytes(s + 39, 8, &if_version); - - if (!NT_STATUS_IS_OK(status)) { - return false; - } - - id->uuid.time_low = time_low; - id->uuid.time_mid = time_mid; - id->uuid.time_hi_and_version = time_hi_and_version; - id->uuid.clock_seq[0] = clock_seq[0]; - id->uuid.clock_seq[1] = clock_seq[1]; - for (i=0; i<6; i++) { - id->uuid.node[i] = node[i]; - } - id->if_version = (uint32_t)if_version; - - return true; + ok = hex_uint32(s+39, &id->if_version); + return ok; } diff --git a/librpc/ndr/uuid.c b/librpc/ndr/uuid.c index ad5c9d37d11..2c16f5ad81c 100644 --- a/librpc/ndr/uuid.c +++ b/librpc/ndr/uuid.c @@ -77,78 +77,42 @@ _PUBLIC_ NTSTATUS GUID_from_ndr_blob(const DATA_BLOB *b, struct GUID *guid) */ _PUBLIC_ NTSTATUS GUID_from_data_blob(const DATA_BLOB *s, struct GUID *guid) { - NTSTATUS status = NT_STATUS_INVALID_PARAMETER; - uint32_t time_low = 0; - uint32_t time_mid = 0; - uint32_t time_hi_and_version = 0; - uint32_t clock_seq[2] = {0}; - uint32_t node[6] = {0}; - uint8_t buf16[16] = {0}; - - DATA_BLOB blob16 = data_blob_const(buf16, sizeof(buf16)); - int i; + bool ok; if (s->data == NULL) { return NT_STATUS_INVALID_PARAMETER; } - switch(s->length) { - case 36: - { - status = parse_guid_string((char *)s->data, - &time_low, - &time_mid, - &time_hi_and_version, - clock_seq, - node); - break; + if (s->length == 36) { + ok = parse_guid_string((char *)s->data, guid); + return ok ? NT_STATUS_OK : NT_STATUS_INVALID_PARAMETER; } - case 38: - { + + if (s->length == 38) { if (s->data[0] != '{' || s->data[37] != '}') { - break; + return NT_STATUS_INVALID_PARAMETER; } - - status = parse_guid_string((char *)s->data + 1, - &time_low, - &time_mid, - &time_hi_and_version, - clock_seq, - node); - break; + ok = parse_guid_string((char *)s->data + 1, guid); + return ok ? NT_STATUS_OK : NT_STATUS_INVALID_PARAMETER; } - case 32: - { + + if (s->length == 32) { + uint8_t buf16[16] = {0}; + DATA_BLOB blob16 = { .data = buf16, .length = sizeof(buf16) }; size_t rlen = strhex_to_str((char *)blob16.data, blob16.length, (const char *)s->data, s->length); if (rlen != blob16.length) { return NT_STATUS_INVALID_PARAMETER; } - s = &blob16; - return GUID_from_ndr_blob(s, guid); - } - case 16: - return GUID_from_ndr_blob(s, guid); - default: - status = NT_STATUS_INVALID_PARAMETER; - break; - } - - if (!NT_STATUS_IS_OK(status)) { - return status; + return GUID_from_ndr_blob(&blob16, guid); } - guid->time_low = time_low; - guid->time_mid = time_mid; - guid->time_hi_and_version = time_hi_and_version; - guid->clock_seq[0] = clock_seq[0]; - guid->clock_seq[1] = clock_seq[1]; - for (i=0;i<6;i++) { - guid->node[i] = node[i]; + if (s->length == 16) { + return GUID_from_ndr_blob(s, guid); } - return NT_STATUS_OK; + return NT_STATUS_INVALID_PARAMETER; } /** diff --git a/librpc/rpc/binding.c b/librpc/rpc/binding.c index 80ab1a45134..817498d8700 100644 --- a/librpc/rpc/binding.c +++ b/librpc/rpc/binding.c @@ -213,49 +213,50 @@ const char *epm_floor_string(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor) */ _PUBLIC_ char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_binding *b) { - char *s = talloc_strdup(mem_ctx, ""); - char *o = s; + char *s = NULL; + char *tmp = NULL; size_t i; const char *t_name = NULL; bool option_section = false; const char *target_hostname = NULL; + s = talloc_strdup(mem_ctx, ""); + if (s == NULL) { + goto nomem; + } + if (b->transport != NCA_UNKNOWN) { t_name = derpc_transport_string_by_transport(b->transport); if (!t_name) { - talloc_free(o); - return NULL; + goto nomem; } } if (!GUID_all_zero(&b->object)) { struct GUID_txt_buf buf; - o = s; - s = talloc_asprintf_append_buffer( + tmp = talloc_asprintf_append_buffer( s, "%s@", GUID_buf_string(&b->object, &buf)); - if (s == NULL) { - talloc_free(o); - return NULL; + if (tmp == NULL) { + goto nomem; } + s = tmp; } if (t_name != NULL) { - o = s; - s = talloc_asprintf_append_buffer(s, "%s:", t_name); - if (s == NULL) { - talloc_free(o); - return NULL; + tmp = talloc_asprintf_append_buffer(s, "%s:", t_name); + if (tmp == NULL) { + goto nomem; } + s = tmp; } if (b->host) { - o = s; - s = talloc_asprintf_append_buffer(s, "%s", b->host); - if (s == NULL) { - talloc_free(o); - return NULL; + tmp = talloc_asprintf_append_buffer(s, "%s", b->host); + if (tmp == NULL) { + goto nomem; } + s = tmp; } target_hostname = b->target_hostname; @@ -265,38 +266,30 @@ _PUBLIC_ char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_bi } } - if (b->endpoint) { - option_section = true; - } else if (target_hostname) { - option_section = true; - } else if (b->target_principal) { - option_section = true; - } else if (b->assoc_group_id != 0) { - option_section = true; - } else if (b->options) { - option_section = true; - } else if (b->flags) { - option_section = true; - } + option_section = + (b->endpoint != NULL) || + (target_hostname != NULL) || + (b->target_principal != NULL) || + (b->assoc_group_id != 0) || + (b->options != NULL) || + (b->flags != 0); if (!option_section) { return s; } -- Samba Shared Repository