]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib: Add "utok_string"
authorVolker Lendecke <vl@samba.org>
Wed, 9 Jan 2019 16:04:34 +0000 (17:04 +0100)
committerJeremy Allison <jra@samba.org>
Wed, 11 Sep 2019 19:59:34 +0000 (19:59 +0000)
A terse, one-line unix token representation for debugging purposes

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/include/proto.h
source3/lib/util.c

index 7bf921f347625a8721e9ed6ab6e4302ae657c936..0d02f38fc8be22977decb21f2f6fc35fa301a520 100644 (file)
@@ -423,6 +423,7 @@ bool map_open_params_to_ntcreate(const char *smb_base_fname,
                                 uint32_t *pprivate_flags);
 struct security_unix_token *copy_unix_token(TALLOC_CTX *ctx, const struct security_unix_token *tok);
 struct security_unix_token *root_unix_token(TALLOC_CTX *mem_ctx);
+char *utok_string(TALLOC_CTX *mem_ctx, const struct security_unix_token *tok);
 bool dir_check_ftype(uint32_t mode, uint32_t dirtype);
 
 /* The following definitions come from lib/util_builtin.c  */
index 7530ea6797301e474e54b496b79dc66640f1b8c6..8bafcbb83d7ec188f938052e04821836a040982e 100644 (file)
@@ -2173,6 +2173,35 @@ struct security_unix_token *root_unix_token(TALLOC_CTX *mem_ctx)
        return t;
 }
 
+char *utok_string(TALLOC_CTX *mem_ctx, const struct security_unix_token *tok)
+{
+       char *str;
+       uint32_t i;
+
+       str = talloc_asprintf(
+               mem_ctx,
+               "uid=%ju, gid=%ju, %"PRIu32" groups:",
+               (uintmax_t)(tok->uid),
+               (uintmax_t)(tok->gid),
+               tok->ngroups);
+       if (str == NULL) {
+               return NULL;
+       }
+
+       for (i=0; i<tok->ngroups; i++) {
+               char *tmp;
+               tmp = talloc_asprintf_append_buffer(
+                       str, " %ju", (uintmax_t)tok->groups[i]);
+               if (tmp == NULL) {
+                       TALLOC_FREE(str);
+                       return NULL;
+               }
+               str = tmp;
+       }
+
+       return str;
+}
+
 /****************************************************************************
  Check that a file matches a particular file type.
 ****************************************************************************/