From 5ae1aed7e7f05f7e46da93207c2d4a3046f0e47f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 14 Oct 2024 13:29:21 +0200 Subject: [PATCH 1/2] libcli: avoid work in security token debug no-op When the debug level is too low to print, we don't need to allocate the strings. Bug: https://bugzilla.samba.org/show_bug.cgi?id=15737 Signed-off-by: Volker Lendecke Signed-off-by: Douglas Bagnall Pair-programmed-with: Douglas Bagnall --- libcli/security/security_token.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libcli/security/security_token.c b/libcli/security/security_token.c index 0218eed1722..a79f5925ea2 100644 --- a/libcli/security/security_token.c +++ b/libcli/security/security_token.c @@ -80,17 +80,22 @@ struct security_token *security_token_duplicate(TALLOC_CTX *mem_ctx, const struc ****************************************************************************/ void security_token_debug(int dbg_class, int dbg_lev, const struct security_token *token) { - TALLOC_CTX *frame = talloc_stackframe(); + TALLOC_CTX *frame = NULL; char *sids = NULL; char *privs = NULL; uint32_t i; - if (!token) { - DEBUGC(dbg_class, dbg_lev, ("Security token: (NULL)\n")); - TALLOC_FREE(frame); + if (!CHECK_DEBUGLVLC(dbg_class, dbg_lev)) { return; } + if (!token) { + DEBUGC(dbg_class, dbg_lev, ("Security token: (NULL)\n")); + return; + } + + frame = talloc_stackframe(); + sids = talloc_asprintf(frame, "Security token SIDs (%" PRIu32 "):\n", token->num_sids); -- 2.43.0 From 16b48cd828247ef8c61c8647eed92b8c4ddd7939 Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Fri, 21 Feb 2025 10:51:33 +1300 Subject: [PATCH 2/2] smbd: avoid work in unix token debug no-op When the debug level is too low to print, we don't need to allocate the strings. Bug: https://bugzilla.samba.org/show_bug.cgi?id=15737 Signed-off-by: Volker Lendecke Signed-off-by: Douglas Bagnall Pair-programmed-with: Volker Lendecke --- source3/auth/token_util.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/source3/auth/token_util.c b/source3/auth/token_util.c index 023ad7cbb02..4dd8036616b 100644 --- a/source3/auth/token_util.c +++ b/source3/auth/token_util.c @@ -888,10 +888,16 @@ NTSTATUS finalize_local_nt_token(struct security_token *result, void debug_unix_user_token(int dbg_class, int dbg_lev, uid_t uid, gid_t gid, int n_groups, gid_t *groups) { - TALLOC_CTX *frame = talloc_stackframe(); + TALLOC_CTX *frame = NULL; char *s = NULL; int i; + if (!CHECK_DEBUGLVLC(dbg_class, dbg_lev)) { + return; + } + + frame = talloc_stackframe(); + s = talloc_asprintf(frame, "UNIX token of user %ld\n", (long int)uid); -- 2.43.0