]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libcli: Convert security_token_debug_privileges() to talloc_asprintf
authorVolker Lendecke <vl@samba.org>
Wed, 30 Aug 2023 10:39:00 +0000 (12:39 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 10 Oct 2023 23:23:40 +0000 (23:23 +0000)
Reduces the number of DEBUGADD calls which leads to messed debug logs
between processes.

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

index acaf0b0fbc065ce84b90cb73c30b3352ab90972f..33debdc1fed3aeb1dbde15a8926e16671789bdea 100644 (file)
@@ -454,34 +454,45 @@ void security_token_set_right_bit(struct security_token *token, uint32_t right_b
        token->rights_mask |= right_bit;
 }
 
-void security_token_debug_privileges(int dbg_class, int dbg_lev, const struct security_token *token)
+char *security_token_debug_privileges(TALLOC_CTX *mem_ctx,
+                                     const struct security_token *token)
 {
-       DEBUGADDC(dbg_class, dbg_lev, (" Privileges (0x%16llX):\n",
-                                      (unsigned long long) token->privilege_mask));
+       char *s = NULL;
+
+       s = talloc_asprintf(mem_ctx,
+                           " Privileges (0x%16" PRIX64 "):\n",
+                           token->privilege_mask);
 
        if (token->privilege_mask) {
                size_t idx = 0;
-               int i = 0;
+               size_t i = 0;
                for (idx = 0; idx<ARRAY_SIZE(privs); idx++) {
                        if (token->privilege_mask & privs[idx].privilege_mask) {
-                               DEBUGADDC(dbg_class, dbg_lev,
-                                         ("  Privilege[%3lu]: %s\n", (unsigned long)i++,
-                                          privs[idx].name));
+                               talloc_asprintf_addbuf(
+                                       &s,
+                                       "  Privilege[%3zu]: %s\n",
+                                       i++,
+                                       privs[idx].name);
                        }
                }
        }
-       DEBUGADDC(dbg_class, dbg_lev, (" Rights (0x%16lX):\n",
-                                      (unsigned long) token->rights_mask));
+
+       talloc_asprintf_addbuf(&s,
+                              " Rights (0x%16" PRIX32 "):\n",
+                              token->rights_mask);
 
        if (token->rights_mask) {
                size_t idx = 0;
-               int i = 0;
+               size_t i = 0;
                for (idx = 0; idx<ARRAY_SIZE(rights); idx++) {
                        if (token->rights_mask & rights[idx].right_mask) {
-                               DEBUGADDC(dbg_class, dbg_lev,
-                                         ("  Right[%3lu]: %s\n", (unsigned long)i++,
-                                          rights[idx].name));
+                               talloc_asprintf_addbuf(&s,
+                                                      "  Right[%3zu]: %s\n",
+                                                      i++,
+                                                      rights[idx].name);
                        }
                }
        }
+
+       return s;
 }
index 2224543d25a55652c4112ca0fd13a5f1c704d56d..e9dab11371281c2724ac20ac4c3fcbde1096400e 100644 (file)
@@ -110,6 +110,7 @@ void security_token_set_privilege(struct security_token *token, enum sec_privile
 */
 void security_token_set_right_bit(struct security_token *token, uint32_t right_bit);
 
-void security_token_debug_privileges(int dbg_class, int dbg_lev, const struct security_token *token);
+char *security_token_debug_privileges(TALLOC_CTX *mem_ctx,
+                                     const struct security_token *token);
 
 #endif /* PRIVILEGES_H */
index 060c3ee82a0cc7d891a167d15539307ce3d84769..3165249b52745391bde9731ded975b1ba6f45b55 100644 (file)
@@ -30,6 +30,7 @@
 #include "libcli/security/dom_sid.h"
 #include "libcli/security/privileges.h"
 #include "librpc/gen_ndr/ndr_security.h"
+#include "lib/util/talloc_stack.h"
 
 /*
   return a blank security token
@@ -104,6 +105,7 @@ 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)
 {
+       char *privs = NULL;
        uint32_t i;
 
        if (!token) {
@@ -121,7 +123,11 @@ void security_token_debug(int dbg_class, int dbg_lev, const struct security_toke
                           dom_sid_str_buf(&token->sids[i], &sidbuf)));
        }
 
-       security_token_debug_privileges(dbg_class, dbg_lev, token);
+       privs = security_token_debug_privileges(talloc_tos(), token);
+       if (privs != NULL) {
+               DEBUGADDC(dbg_class, dbg_lev, ("%s", privs));
+               TALLOC_FREE(privs);
+       }
 }
 
 /* These really should be cheaper... */