From d935fa6bc7b92781c0d031327a9551224aab8909 Mon Sep 17 00:00:00 2001 From: Alexey Tikhonov Date: Tue, 29 Aug 2023 18:29:54 +0200 Subject: [PATCH] UTILS: include name of the file that failed perform_checks() in the debug log MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Alejandro López Reviewed-by: Tomáš Halman (cherry picked from commit 7d14e529c6ec4d059ae9b3bf9f0576d6d561ca18) --- src/util/check_file.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/util/check_file.c b/src/util/check_file.c index 27edcfa8b2a..2203a41c328 100644 --- a/src/util/check_file.c +++ b/src/util/check_file.c @@ -28,7 +28,8 @@ #include "util/util.h" -static errno_t perform_checks(struct stat *stat_buf, +static errno_t perform_checks(const char *filename, + struct stat *stat_buf, uid_t uid, gid_t gid, mode_t mode, mode_t mask); @@ -53,15 +54,16 @@ errno_t check_file(const char *filename, } if (ret == -1) { ret = errno; - DEBUG(SSSDBG_TRACE_FUNC, "lstat for [%s] failed: [%d][%s].\n", + DEBUG(SSSDBG_TRACE_FUNC, "lstat for '%s' failed: [%d][%s].\n", filename, ret, strerror(ret)); return ret; } - return perform_checks(stat_buf, uid, gid, mode, mask); + return perform_checks(filename, stat_buf, uid, gid, mode, mask); } -static errno_t perform_checks(struct stat *stat_buf, +static errno_t perform_checks(const char *filename, + struct stat *stat_buf, uid_t uid, gid_t gid, mode_t mode, mode_t mask) { @@ -74,25 +76,28 @@ static errno_t perform_checks(struct stat *stat_buf, } if ((mode & S_IFMT) != (st_mode & S_IFMT)) { - DEBUG(SSSDBG_TRACE_LIBS, "File is not the right type.\n"); + DEBUG(SSSDBG_TRACE_LIBS, "File '%s' is not of the right type.\n", + filename); return EINVAL; } if ((st_mode & ALLPERMS) != (mode & ALLPERMS)) { DEBUG(SSSDBG_TRACE_LIBS, - "File has the wrong (bit masked) mode [%.7o], " - "expected [%.7o].\n", + "File '%s' has the wrong (bit masked) mode [%.7o], " + "expected [%.7o].\n", filename, (st_mode & ALLPERMS), (mode & ALLPERMS)); return EINVAL; } if (uid != (uid_t)(-1) && stat_buf->st_uid != uid) { - DEBUG(SSSDBG_TRACE_LIBS, "File must be owned by uid [%d].\n", uid); + DEBUG(SSSDBG_TRACE_LIBS, "File '%s' must be owned by uid [%d].\n", + filename, uid); return EINVAL; } if (gid != (gid_t)(-1) && stat_buf->st_gid != gid) { - DEBUG(SSSDBG_TRACE_LIBS, "File must be owned by gid [%d].\n", gid); + DEBUG(SSSDBG_TRACE_LIBS, "File '%s' must be owned by gid [%d].\n", + filename, gid); return EINVAL; }