]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libcli: Make security_token_debug() use just one DEBUG statement
authorVolker Lendecke <vl@samba.org>
Wed, 30 Aug 2023 10:46:18 +0000 (12:46 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 10 Oct 2023 23:23:40 +0000 (23:23 +0000)
This avoids messing up the debug logs when multiple processes are
writing into the same file.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
libcli/security/security_token.c

index 3165249b52745391bde9731ded975b1ba6f45b55..79de6e3b31b884dbe59940cd6c33d4aada17da8d 100644 (file)
@@ -105,29 +105,36 @@ 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();
+       char *sids = NULL;
        char *privs = NULL;
        uint32_t i;
 
        if (!token) {
                DEBUGC(dbg_class, dbg_lev, ("Security token: (NULL)\n"));
+               TALLOC_FREE(frame);
                return;
        }
 
-       DEBUGC(dbg_class, dbg_lev, ("Security token SIDs (%"PRIu32"):\n",
-                                      token->num_sids));
+       sids = talloc_asprintf(frame,
+                              "Security token SIDs (%" PRIu32 "):\n",
+                              token->num_sids);
        for (i = 0; i < token->num_sids; i++) {
                struct dom_sid_buf sidbuf;
-               DEBUGADDC(dbg_class,
-                         dbg_lev,
-                         ("  SID[%3"PRIu32"]: %s\n", i,
-                          dom_sid_str_buf(&token->sids[i], &sidbuf)));
+               talloc_asprintf_addbuf(
+                       &sids,
+                       "  SID[%3" PRIu32 "]: %s\n",
+                       i,
+                       dom_sid_str_buf(&token->sids[i], &sidbuf));
        }
 
-       privs = security_token_debug_privileges(talloc_tos(), token);
-       if (privs != NULL) {
-               DEBUGADDC(dbg_class, dbg_lev, ("%s", privs));
-               TALLOC_FREE(privs);
-       }
+       privs = security_token_debug_privileges(frame, token);
+
+       DEBUGC(dbg_class,
+              dbg_lev,
+              ("%s%s", sids ? sids : "(NULL)", privs ? privs : "(NULL)"));
+
+       TALLOC_FREE(frame);
 }
 
 /* These really should be cheaper... */