From: Volker Lendecke Date: Wed, 9 Jan 2019 16:04:34 +0000 (+0100) Subject: lib: Add "utok_string" X-Git-Tag: talloc-2.3.1~867 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=219a189c9993893149c9beef90a9d626ee0f3fa7;p=thirdparty%2Fsamba.git lib: Add "utok_string" A terse, one-line unix token representation for debugging purposes Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/include/proto.h b/source3/include/proto.h index 7bf921f3476..0d02f38fc8b 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -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 */ diff --git a/source3/lib/util.c b/source3/lib/util.c index 7530ea67973..8bafcbb83d7 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -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; ingroups; 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. ****************************************************************************/