install: Fix chown resetting suid/sgid bits from chmod
Since Linux 2.2.13, chown(2) resets the suid/gid bits for all users. This patch changes the ordering so that chmod gets called after chown. This behavior follows GNU coreutils. Signed-off-by: Nero <nero@w1r3.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
791b222dd5
commit
6d22c9abc2
1 changed files with 9 additions and 7 deletions
|
@ -244,6 +244,15 @@ int install_main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set the user and group id */
|
||||||
|
/* (must be before chmod, or else chown may clear suid/gid bits) */
|
||||||
|
if ((opts & (OPT_OWNER|OPT_GROUP))
|
||||||
|
&& lchown(dest, uid, gid) == -1
|
||||||
|
) {
|
||||||
|
bb_perror_msg("can't change %s of %s", "ownership", dest);
|
||||||
|
ret = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set the file mode (always, not only with -m).
|
/* Set the file mode (always, not only with -m).
|
||||||
* GNU coreutils 6.10 is not affected by umask. */
|
* GNU coreutils 6.10 is not affected by umask. */
|
||||||
if (chmod(dest, mode) == -1) {
|
if (chmod(dest, mode) == -1) {
|
||||||
|
@ -254,13 +263,6 @@ int install_main(int argc, char **argv)
|
||||||
if (use_default_selinux_context)
|
if (use_default_selinux_context)
|
||||||
setdefaultfilecon(dest);
|
setdefaultfilecon(dest);
|
||||||
#endif
|
#endif
|
||||||
/* Set the user and group id */
|
|
||||||
if ((opts & (OPT_OWNER|OPT_GROUP))
|
|
||||||
&& lchown(dest, uid, gid) == -1
|
|
||||||
) {
|
|
||||||
bb_perror_msg("can't change %s of %s", "ownership", dest);
|
|
||||||
ret = EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
next:
|
next:
|
||||||
if (ENABLE_FEATURE_CLEAN_UP && isdir)
|
if (ENABLE_FEATURE_CLEAN_UP && isdir)
|
||||||
free(dest);
|
free(dest);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue