From bd327f7d7a0d5f3377129ceb7f74e9dcf40587f3 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 25 Mar 2022 14:23:45 +0100 Subject: [PATCH] libcli/security: simplify sddl_encode_sid() We should walk the sid_codes array just once. This makes further changes easier... Signed-off-by: Stefan Metzmacher Reviewed-by: Andrew Bartlett Reviewed-by: Joseph Sutton --- libcli/security/sddl.c | 48 +++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/libcli/security/sddl.c b/libcli/security/sddl.c index 20d5553ad43..85feae305e1 100644 --- a/libcli/security/sddl.c +++ b/libcli/security/sddl.c @@ -556,35 +556,39 @@ failed: static char *sddl_encode_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid, struct sddl_transition_state *state) { + bool in_domain = dom_sid_in_domain(state->domain_sid, sid); + struct dom_sid_buf buf; + const char *sidstr = dom_sid_str_buf(sid, &buf); + uint32_t rid = 0; size_t i; - char *sidstr; - sidstr = dom_sid_string(mem_ctx, sid); - if (sidstr == NULL) return NULL; + if (sid->num_auths > 1) { + rid = sid->sub_auths[sid->num_auths-1]; + } - /* seen if its a well known sid */ - for (i=0;sid_codes[i].sid;i++) { - if (strcmp(sidstr, sid_codes[i].sid) == 0) { - talloc_free(sidstr); + for (i=0;idomain_sid, sid)) { - uint32_t rid = sid->sub_auths[sid->num_auths-1]; - for (;i