Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- src/pacman/check.c | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/src/pacman/check.c b/src/pacman/check.c index 0fe74e8..2c2d4b2 100644 --- a/src/pacman/check.c +++ b/src/pacman/check.c @@ -20,6 +20,8 @@ #include <limits.h> #include <string.h> #include <errno.h> +#include <grp.h> +#include <pwd.h> /* pacman */ #include "check.h" @@ -74,22 +76,46 @@ static int check_file_permissions(const char *pkgname, const char *filepath, { int errors = 0; mode_t fsmode; + const char *uname = archive_entry_uname(entry); + const char *gname = archive_entry_gname(entry); /* uid */ - if(st->st_uid != archive_entry_uid(entry)) { - errors++; - if(!config->quiet) { - pm_printf(ALPM_LOG_WARNING, _("%s: %s (UID mismatch)\n"), - pkgname, filepath); + if(uname) { + struct passwd *pw = getpwuid(st->st_uid); + if(!pw || strcmp(uname, pw->pw_name) != 0) { + errors++; + if(!config->quiet) { + pm_printf(ALPM_LOG_WARNING, _("%s: %s (Owner mismatch)\n"), + pkgname, filepath); + } + } + } else { + if(st->st_uid != archive_entry_uid(entry)) { + errors++; + if(!config->quiet) { + pm_printf(ALPM_LOG_WARNING, _("%s: %s (UID mismatch)\n"), + pkgname, filepath); + } } } /* gid */ - if(st->st_gid != archive_entry_gid(entry)) { - errors++; - if(!config->quiet) { - pm_printf(ALPM_LOG_WARNING, _("%s: %s (GID mismatch)\n"), - pkgname, filepath); + if(gname) { + struct group *gr = getgrgid(st->st_gid); + if(!gr || strcmp(gname, gr->gr_name) != 0) { + errors++; + if(!config->quiet) { + pm_printf(ALPM_LOG_WARNING, _("%s: %s (Group mismatch)\n"), + pkgname, filepath); + } + } + } else { + if(st->st_gid != archive_entry_gid(entry)) { + errors++; + if(!config->quiet) { + pm_printf(ALPM_LOG_WARNING, _("%s: %s (GID mismatch)\n"), + pkgname, filepath); + } } } -- 2.7.2