aboutsummaryrefslogtreecommitdiff
path: root/coreutils/install.c
diff options
context:
space:
mode:
authorNero <nero@w1r3.net>2023-09-23 11:50:04 +0000
committerDenys Vlasenko <vda.linux@googlemail.com>2023-10-02 14:26:27 +0200
commit6d22c9abc29d43e919e819ff004fcd84a90de60b (patch)
tree4243be33f0596aa5a70b23067c213de0772b3ee8 /coreutils/install.c
parent791b222dd55d3aa0e8b09be1be571e4829465dd6 (diff)
downloadbusybox-w32-6d22c9abc29d43e919e819ff004fcd84a90de60b.tar.gz
busybox-w32-6d22c9abc29d43e919e819ff004fcd84a90de60b.tar.bz2
busybox-w32-6d22c9abc29d43e919e819ff004fcd84a90de60b.zip
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>
Diffstat (limited to '')
-rw-r--r--coreutils/install.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/coreutils/install.c b/coreutils/install.c
index c0f1c538a..00f8be87e 100644
--- a/coreutils/install.c
+++ b/coreutils/install.c
@@ -244,6 +244,15 @@ int install_main(int argc, char **argv)
244 } 244 }
245 } 245 }
246 246
247 /* Set the user and group id */
248 /* (must be before chmod, or else chown may clear suid/gid bits) */
249 if ((opts & (OPT_OWNER|OPT_GROUP))
250 && lchown(dest, uid, gid) == -1
251 ) {
252 bb_perror_msg("can't change %s of %s", "ownership", dest);
253 ret = EXIT_FAILURE;
254 }
255
247 /* Set the file mode (always, not only with -m). 256 /* Set the file mode (always, not only with -m).
248 * GNU coreutils 6.10 is not affected by umask. */ 257 * GNU coreutils 6.10 is not affected by umask. */
249 if (chmod(dest, mode) == -1) { 258 if (chmod(dest, mode) == -1) {
@@ -254,13 +263,6 @@ int install_main(int argc, char **argv)
254 if (use_default_selinux_context) 263 if (use_default_selinux_context)
255 setdefaultfilecon(dest); 264 setdefaultfilecon(dest);
256#endif 265#endif
257 /* Set the user and group id */
258 if ((opts & (OPT_OWNER|OPT_GROUP))
259 && lchown(dest, uid, gid) == -1
260 ) {
261 bb_perror_msg("can't change %s of %s", "ownership", dest);
262 ret = EXIT_FAILURE;
263 }
264 next: 266 next:
265 if (ENABLE_FEATURE_CLEAN_UP && isdir) 267 if (ENABLE_FEATURE_CLEAN_UP && isdir)
266 free(dest); 268 free(dest);