From: Paul Eggert Date: Fri, 25 Feb 2022 02:17:23 +0000 (-0800) Subject: chown: warn about USER.GROUP X-Git-Tag: v9.1~38 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8f31074cb4c9b023ef0aa47a0ce34c92745169b6;p=thirdparty%2Fcoreutils.git chown: warn about USER.GROUP Suggested by Dan Jacobson (Bug#44770). * src/chown.c, src/chroot.c (main): Issue warnings if obsolete USER.GROUP notation is present. --- diff --git a/NEWS b/NEWS index eec705b2f4..af6596b062 100644 --- a/NEWS +++ b/NEWS @@ -51,6 +51,11 @@ GNU coreutils NEWS -*- outline -*- simple copies between regular files. This may be more efficient, by avoiding user space copies, and possibly employing copy offloading or reflinking. + chown and chroot now warn about usages like "chown root.root f", + which have the nonstandard and long-obsolete "." separator that + causes problems on platforms where user names contain ".". + Applications should use ":" instead of ".". + cksum no longer allows abbreviated algorithm names, so that forward compatibility and robustness is improved. diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 641680e110..e9be0993ac 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -11318,7 +11318,8 @@ or group ID, then you may specify it with a leading @samp{+}. Some older scripts may still use @samp{.} in place of the @samp{:} separator. POSIX 1003.1-2001 (@pxref{Standards conformance}) does not require support for that, but for backward compatibility GNU -@command{chown} supports @samp{.} so long as no ambiguity results. +@command{chown} supports @samp{.} so long as no ambiguity results, +although it issues a warning and support may be removed in future versions. New scripts should avoid the use of @samp{.} because it is not portable, and because it has undesirable results if the entire @var{owner@samp{.}group} happens to identify a user whose name diff --git a/src/chown.c b/src/chown.c index 329b0f4dca..07cc907a42 100644 --- a/src/chown.c +++ b/src/chown.c @@ -227,11 +227,12 @@ main (int argc, char **argv) case FROM_OPTION: { - char const *e = parse_user_spec (optarg, - &required_uid, &required_gid, - NULL, NULL); + bool warn; + char const *e = parse_user_spec_warn (optarg, + &required_uid, &required_gid, + NULL, NULL, &warn); if (e) - die (EXIT_FAILURE, 0, "%s: %s", e, quote (optarg)); + error (warn ? 0 : EXIT_FAILURE, 0, "%s: %s", e, quote (optarg)); break; } @@ -297,10 +298,12 @@ main (int argc, char **argv) } else { - char const *e = parse_user_spec (argv[optind], &uid, &gid, - &chopt.user_name, &chopt.group_name); + bool warn; + char const *e = parse_user_spec_warn (argv[optind], &uid, &gid, + &chopt.user_name, + &chopt.group_name, &warn); if (e) - die (EXIT_FAILURE, 0, "%s: %s", e, quote (argv[optind])); + error (warn ? 0 : EXIT_FAILURE, 0, "%s: %s", e, quote (argv[optind])); /* If a group is specified but no user, set the user name to the empty string so that diagnostics say "ownership :GROUP" diff --git a/src/chroot.c b/src/chroot.c index 1cd04300c8..be96013042 100644 --- a/src/chroot.c +++ b/src/chroot.c @@ -354,10 +354,11 @@ main (int argc, char **argv) Diagnose any failures. If any have failed, exit before execvp. */ if (userspec) { - char const *err = parse_user_spec (userspec, &uid, &gid, NULL, NULL); - - if (err && uid_unset (uid) && gid_unset (gid)) - die (EXIT_CANCELED, errno, "%s", (err)); + bool warn; + char const *err = parse_user_spec_warn (userspec, &uid, &gid, + NULL, NULL, &warn); + if (err) + error (warn ? 0 : EXIT_CANCELED, 0, "%s", err); } /* If no gid is supplied or looked up, do so now.