From f1bda7ead20c210a28be5decad636e1d95d8c3ec Mon Sep 17 00:00:00 2001 From: Albert Brox Date: Wed, 30 Jun 2021 05:54:15 -0400 Subject: [PATCH] Improve tmpfiles unsafe transition log message (#20048) --- src/basic/fs-util.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 1cfd1700823..8f0834fe46c 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -742,7 +742,8 @@ bool unsafe_transition(const struct stat *a, const struct stat *b) { } static int log_unsafe_transition(int a, int b, const char *path, unsigned flags) { - _cleanup_free_ char *n1 = NULL, *n2 = NULL; + _cleanup_free_ char *n1 = NULL, *n2 = NULL, *user_a = NULL, *user_b = NULL; + struct stat st; if (!FLAGS_SET(flags, CHASE_WARN)) return -ENOLINK; @@ -750,9 +751,14 @@ static int log_unsafe_transition(int a, int b, const char *path, unsigned flags) (void) fd_get_path(a, &n1); (void) fd_get_path(b, &n2); + if (fstat(a, &st) == 0) + user_a = uid_to_name(st.st_uid); + if (fstat(b, &st) == 0) + user_b = uid_to_name(st.st_uid); + return log_warning_errno(SYNTHETIC_ERRNO(ENOLINK), - "Detected unsafe path transition %s %s %s during canonicalization of %s.", - strna(n1), special_glyph(SPECIAL_GLYPH_ARROW), strna(n2), path); + "Detected unsafe path transition %s (owned by %s) %s %s (owned by %s) during canonicalization of %s.", + strna(n1), strna(user_a), special_glyph(SPECIAL_GLYPH_ARROW), strna(n2), strna(user_b), path); } static int log_autofs_mount_point(int fd, const char *path, unsigned flags) { -- 2.47.3