bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug#10021: [PATCH id] Add error-checking on GNU


From: Ludovic Courtès
Subject: Re: bug#10021: [PATCH id] Add error-checking on GNU
Date: Sat, 12 Nov 2011 22:48:58 +0100
User-agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.90 (gnu/linux)

Hi Jim,

Thanks for the quick review!

Jim Meyering <address@hidden> skribis:

> However, wouldn't that fail unnecessarily for a process without
> one ID even though id is being asked to print some other(s)?
> E.g., it'd fail for a process with no EUID even when id
> is being asked to print only the real UID or GIDs.

Indeed.

> Also, if you send another version, please indent only with spaces
> and change each diagnostic to start with lower case letter.

Sure.  (There’s one just above that doesn’t follow the rule.)

> You may want to run "make syntax-check" to check for things like that.

OK.

Here’s an updated patch with a test case.

I don’t have a copyright assignment on file for Coreutils but I guess
it’s OK for this change?

Thanks,
Ludo’.

From b1e9324ea83a2df604256d7d41d25440e21dd2d8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <address@hidden>
Date: Sat, 12 Nov 2011 01:25:45 +0100
Subject: [PATCH] id: error out for zero UIDs/GIDs on GNU/Hurd

* src/id.c (main)[__GNU__]: Check for EUID, RUID, EGID, or RGID = -1;
  raise an error when appropriate.

* tests/Makefile.am (TESTS): Add `id/gnu-zero-uids'.
* tests/id/gnu-zero-uids: New file.
* tests/init.cfg (require_gnu_): New function.
---
 src/id.c               |   21 +++++++++++++++++++++
 tests/Makefile.am      |    1 +
 tests/id/gnu-zero-uids |   31 +++++++++++++++++++++++++++++++
 tests/init.cfg         |    8 ++++++++
 4 files changed, 61 insertions(+), 0 deletions(-)
 create mode 100644 tests/id/gnu-zero-uids

diff --git a/src/id.c b/src/id.c
index f80fcd1..9325282 100644
--- a/src/id.c
+++ b/src/id.c
@@ -202,9 +202,30 @@ main (int argc, char **argv)
   else
     {
       euid = geteuid ();
+#ifdef __GNU__
+      if (euid == -1 && !use_real
+          && !just_group && !just_group_list && !just_context)
+        error (EXIT_FAILURE, errno, _("cannot get effective UID"));
+#endif
+
       ruid = getuid ();
+#ifdef __GNU__
+      if (ruid == -1 && use_real
+          && !just_group && !just_group_list && !just_context)
+        error (EXIT_FAILURE, errno, _("cannot get real UID"));
+#endif
+
       egid = getegid ();
+#ifdef __GNU__
+      if (egid == -1 && !use_real && !just_user)
+        error (EXIT_FAILURE, errno, _("cannot get effective GID"));
+#endif
+
       rgid = getgid ();
+#ifdef __GNU__
+      if (rgid == -1 && use_real && !just_user)
+        error (EXIT_FAILURE, errno, _("cannot get real GID"));
+#endif
     }
 
   if (just_user)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5021c18..80f95b1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -399,6 +399,7 @@ TESTS =                                             \
   du/slink                                     \
   du/trailing-slash                            \
   du/two-args                                  \
+  id/gnu-zero-uids                             \
   id/no-context                                        \
   install/basic-1                              \
   install/create-leading                       \
diff --git a/tests/id/gnu-zero-uids b/tests/id/gnu-zero-uids
new file mode 100644
index 0000000..b4a7d5a
--- /dev/null
+++ b/tests/id/gnu-zero-uids
@@ -0,0 +1,31 @@
+#!/bin/sh
+# On GNU, `id' must fail for processes with zero UIDs.
+
+# Copyright (C) 2011 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+print_ver_ id
+
+require_gnu_
+
+if sush - true; then
+    # Run `id' with zero UIDs.  It should exit with a non-zero status.
+    sush - id > out && fail=1
+else
+    skip_ "the \`sush' command does not work"
+fi
+
+Exit $fail
diff --git a/tests/init.cfg b/tests/init.cfg
index 915f38a..f5f27dd 100644
--- a/tests/init.cfg
+++ b/tests/init.cfg
@@ -499,4 +499,12 @@ print_ver_()
   fi
 }
 
+# Are we running on GNU/Hurd?
+require_gnu_()
+{
+  if test "`uname`" != GNU; then
+     skip_ 'not running on GNU/Hurd'
+  fi
+}
+
 sanitize_path_
-- 
1.7.6

Attachment: pgp78U0GCX_6M.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]