Subject: chown: warn when encountering deprecated dot separator

From: Paul Eggert <[email-masked]>
Date: Thu, 24 Feb 2022 18:23:38 -0800

Thanks for the suggestion. I installed the attached patches to do that.

From 320b3f8c96fc69670475c7a39d5818c5b4755912 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Thu, 24 Feb 2022 18:05:03 -0800
Subject: [PATCH 1/2] build: update gnulib submodule to latest

---
 gnulib | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gnulib b/gnulib
index 06b2e943b..23cca8268 160000
--- a/gnulib
+++ b/gnulib
@@ -1 +1 @@
-Subproject commit 06b2e943be39284783ff81ac6c9503200f41dba3
+Subproject commit 23cca8268d21f5d58ed0209002d5673d0518c426
-- 
2.35.1

From aac2a3cff4f94df899483da7963f4fc983c7c6b0 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Thu, 24 Feb 2022 18:17:23 -0800
Subject: [PATCH 2/2] 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.
---
 NEWS               |  5 +++++
 doc/coreutils.texi |  3 ++-
 src/chown.c        | 17 ++++++++++-------
 src/chroot.c       |  9 +++++----
 4 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/NEWS b/NEWS
index eec705b2f..af6596b06 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 641680e11..e9be0993a 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 329b0f4dc..07cc907a4 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 1cd04300c..be9601304 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.
-- 
2.35.1