bug-coreutils
[Top][All Lists]
Advanced

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

Patch proposal for id.c and groups.c to fix afs bug


From: Didi
Subject: Patch proposal for id.c and groups.c to fix afs bug
Date: Mon, 3 Mar 2008 15:30:40 +0100

Hey

Sorry for any violation of any mailing list rules, this is my first
patch to coreutils.

On some systems, with AFS, if you call 'id' or 'groups' without a user
name parameter it will return a huge group number:
$ id -G
500 1103556127

The same behavior applies to groups:
$ groups
ribalba id: cannot find name for group ID 1103556127
1103556127

Because of this I propose following patch :

<8----------------

diff --git a/src/groups.c b/src/groups.c
index baac7b9..b24b70a 100644
--- a/src/groups.c
+++ b/src/groups.c
@@ -102,7 +102,7 @@ main (int argc, char **argv)
       egid = getegid ();
       rgid = getgid ();

-      if (!print_group_list (NULL, ruid, rgid, egid, true))
+      if (!print_group_list (getlogin(), ruid, rgid, egid, true))
         ok = false;
       putchar ('\n');
     }
diff --git a/src/id.c b/src/id.c
index e4eda40..d97d809 100644
--- a/src/id.c
+++ b/src/id.c
@@ -196,21 +196,17 @@ of a different user"));
     error (EXIT_FAILURE, 0,
           _("cannot print only names or real IDs in default format"));

-  if (argc - optind == 1)
-    {
-      struct passwd *pwd = getpwnam (argv[optind]);
-      if (pwd == NULL)
-       error (EXIT_FAILURE, 0, _("%s: No such user"), argv[optind]);
-      ruid = euid = pwd->pw_uid;
-      rgid = egid = pwd->pw_gid;
-    }
-  else
-    {
-      euid = geteuid ();
-      ruid = getuid ();
-      egid = getegid ();
-      rgid = getgid ();
-    }
+  struct passwd *pwdg = NULL;
+  if (argc - optind == 1){
+    pwdg = getpwnam (argv[optind]);
+  }else{
+    pwdg = getpwnam (getlogin());
+  }
+  if (pwdg == NULL)
+    error (EXIT_FAILURE, 0, _("%s: No such user"), argv[optind]);
+  ruid = euid = pwdg->pw_uid;
+  rgid = egid = pwdg->pw_gid;
+

   if (just_user)
     {
@@ -223,7 +219,7 @@ of a different user"));
     }
   else if (just_group_list)
     {
-      if (!print_group_list (argv[optind], ruid, rgid, egid, use_name))
+      if (!print_group_list (pwdg->pw_name, ruid, rgid, egid, use_name))
        ok = false;
     }
   else if (just_context)
@@ -232,7 +228,7 @@ of a different user"));
     }
   else
     {
-      print_full_info (argv[optind]);
+      print_full_info (pwdg->pw_name);
     }
   putchar ('\n');


>8----------------

The behavior is due to AFS creating a pseudo group in the kernel that
does not have a name.


Some information to the system I am using:
Linux mypc 2.6.9-67.0.4.EL.cernsmp #1 SMP Mon Feb 4 10:15:50 CET 2008
x86_64 x86_64 x86_64 GNU/Linux

I hope this can help :)

Cheers Didi

----
www.cern.ch/ribalba  /  www.ribalba.de
Email / Jabber: address@hidden
Phone (Work) : +41 22 7679376
Skype : ribalba
Address : CERN / IT-FIO-FS / GENEVE 23/ SCHWEIZ




reply via email to

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