From 4eaf35f250ab6eec036b7ab21a482a76289f8303 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Ond=C5=99ej=20Va=C5=A1=C3=ADk?= Date: Fri, 24 Oct 2008 17:24:09 +0200 Subject: [PATCH] chmod: inform in verbose if used mode for chmod was different than requested * chmod (process_file): Display a message when SUID, SGID or sticky bit change was requested but not performed. Suggested by Aaron Toponce * NEWS: Mention that change. --- NEWS | 3 +++ src/chmod.c | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 3fc0349..86f415b 100644 --- a/NEWS +++ b/NEWS @@ -23,6 +23,9 @@ GNU coreutils NEWS -*- outline -*- Rm was improved directly, while the others inherit the improvement from the newer version of fts in gnulib. + chmod now displays a message when SUID, SGID or sticky bit change was + requested, but not performed. + comm now verifies that the inputs are in sorted order. This check can be turned off with the --nocheck-order option. diff --git a/src/chmod.c b/src/chmod.c index 80fc363..87f8199 100644 --- a/src/chmod.c +++ b/src/chmod.c @@ -259,8 +259,41 @@ process_file (FTS *fts, FTSENT *ent) if (verbosity != V_off) { - bool changed = (chmod_succeeded - && mode_changed (file, old_mode, new_mode)); + bool mode_change = mode_changed (file, old_mode, new_mode); + bool changed = (chmod_succeeded && mode change); + + if (chmod_succeeded && ((old_mode ^ new_mode) & CHMOD_MODE_BITS)) + { + + /* Changed to another mode than requested */ + struct stat new_stats; + char perms_requested[12]; + char perms_actual[12]; + + if (stat (file, &new_stats) != 0) + { + if (!force_silent) + error (0, errno, _("getting new attributes of %s"), + quote (file)); + ok = false; + } + + strmode (new_mode, perms_requested); + perms_requested[10] = '\0'; + strmode (new_stats.st_mode, perms_actual); + perms_actual[10] = '\0'; + printf( + _("can't change mode of %s to %04lo (%s), using %04lo (%s)\n"), + quote (file), + (unsigned long int) (new_mode & CHMOD_MODE_BITS), + &perms_requested[1], + (unsigned long int) (new_stats.st_mode & CHMOD_MODE_BITS), + &perms_actual[1]); + + /* Change mode to actual mode after change for verbose output */ + new_mode = new_stats.st_mode; + } + if (changed || verbosity == V_high) { -- 1.5.6.1.156.ge903b