[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH]: chmod - do inform about using different mode than requested
From: |
Paul Eggert |
Subject: |
Re: [PATCH]: chmod - do inform about using different mode than requested with SGID/SUID/sticky bits without permissions to change them |
Date: |
Fri, 24 Oct 2008 13:21:53 -0700 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.3 (gnu/linux) |
Ondřej Vašík <address@hidden> writes:
> - 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 */
This doesn't look right to me. First, surely there's no need to invoke
mode_changed if chmod_succeeded is false. Second, ((old_mode ^
new_mode) & CHMOD_MODE_BITS) doesn't tell us whether we changed to
another mode than requested; mode_change tells us that.
> + struct stat new_stats;
> + char perms_requested[12];
> + char perms_actual[12];
> +
> + if (stat (file, &new_stats) != 0)
Third, this means we've invoked 'stat' twice on the file afterwards,
once here, and once in mode_changed. We should invoke 'stat' only in
mode_changed.