* src/chgrp.c (main): Don't prohibit -RLh, aka -RL with --no-dereference.
* src/chown.c (main): Likewise.
* src/chown-core.c (change_file_owner): Add to a comment.
* tests/chown/preserve-root: Add tests.
* doc/coreutils.texi (Treating / specially): With --preserve-root,
chgrp and chown will not modify "/", even through a symlink.
2006-12-14 Jim Meyering <jim@meyering.net>
+ * src/chgrp.c (main): Don't prohibit -RLh, aka -RL with --no-dereference.
+ * src/chown.c (main): Likewise.
+ * src/chown-core.c (change_file_owner): Add to a comment.
+ * tests/chown/preserve-root: Add tests.
+
* NEWS: --preserve-root now works with chgrp, chmod, and chown.
* src/chmod.c (process_file): Do honor the --preserve-root option.
* src/chown-core.c (change_file_owner): Likewise, but here, also
2006-12-14 Jim Meyering <jim@meyering.net>
* coreutils.texi: Remove two doubled words.
+ (Treating / specially): With --preserve-root, chgrp and chown
+ will not modify "/", even through a symlink.
2006-11-28 Jim Meyering <jim@meyering.net>
option makes them safer for most purposes. For convenience you can
specify @option{--preserve-root} in an alias or in a shell function.
+Note that the @option{--preserve-root} option also ensures
+that @command{chgrp} and @command{chown} do not modify @file{/}
+even when dereferencing a symlink pointing to @file{/}.
+
@node Special built-in utilities
@section Special built-in utilities
if (dereference == 1)
error (EXIT_FAILURE, 0,
_("-R --dereference requires either -H or -L"));
- chopt.affect_symlink_referent = false;
- }
- else
- {
- if (dereference == 0)
- error (EXIT_FAILURE, 0, _("-R -h requires -P"));
- chopt.affect_symlink_referent = true;
+ dereference = 0;
}
}
else
{
bit_flags = FTS_PHYSICAL;
- chopt.affect_symlink_referent = (dereference != 0);
}
+ chopt.affect_symlink_referent = (dereference != 0);
if (argc - optind < (reference_file ? 1 : 2))
{
{
if (ROOT_DEV_INO_CHECK (chopt->root_dev_ino, ent->fts_statp))
{
- /* This happens e.g., with "chown -R --preserve-root /". */
+ /* This happens e.g., with "chown -R --preserve-root 0 /"
+ and with "chown -RH --preserve-root 0 symlink-to-root". */
ROOT_DEV_INO_WARN (file_full_name);
/* Tell fts not to traverse into this hierarchy. */
fts_set (fts, ent, FTS_SKIP);
if (dereference == 1)
error (EXIT_FAILURE, 0,
_("-R --dereference requires either -H or -L"));
- chopt.affect_symlink_referent = false;
- }
- else
- {
- if (dereference == 0)
- error (EXIT_FAILURE, 0, _("-R -h requires -P"));
- chopt.affect_symlink_referent = true;
+ dereference = 0;
}
}
else
{
bit_flags = FTS_PHYSICAL;
- chopt.affect_symlink_referent = (dereference != 0);
}
+ chopt.affect_symlink_referent = (dereference != 0);
if (argc - optind < (reference_file ? 1 : 2))
{
# and then, only to make them readable by owner.
chmod -R --preserve-root u+r / >> out 2>&1 && fail=1
+# With -RHh, --preserve-root should trigger nothing,
+# since the symlink in question is not a command line argument.
+# Contrary to the above commands, these two should succeed.
+echo '==== test -RHh' >> out
+chown -RHh --preserve-root `id -u` d >> out 2>&1 || fail=1
+chgrp -RHh --preserve-root `id -g` d >> out 2>&1 || fail=1
+
+# These must fail.
+echo '==== test -RLh' >> out
+chown -RLh --preserve-root `id -u` d >> out 2>&1 && fail=1
+chgrp -RLh --preserve-root `id -g` d >> out 2>&1 && fail=1
+
cat <<\EOF > exp || fail=1
chown: it is dangerous to operate recursively on `/'
chown: use --no-preserve-root to override this failsafe
chgrp: use --no-preserve-root to override this failsafe
chmod: it is dangerous to operate recursively on `/'
chmod: use --no-preserve-root to override this failsafe
+==== test -RHh
+==== test -RLh
+chown: it is dangerous to operate recursively on `d/slink-to-root' (same as `/')
+chown: use --no-preserve-root to override this failsafe
+chgrp: it is dangerous to operate recursively on `d/slink-to-root' (same as `/')
+chgrp: use --no-preserve-root to override this failsafe
EOF
cmp out exp || fail=1