[Toybox] [PATCH] new toys groups and whoami

Daniel Walter d.walter at 0x90.at
Fri Feb 24 00:04:04 PST 2012


new toys groups and whoami

 * fixed wrong path for id (should be /usr/bin/id)

--
comments are welcome.

regards,
daniel
--
 toys/id.c |  44 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 42 insertions(+), 2 deletions(-)
--
diff -r 42a322adbd17 toys/id.c
--- a/toys/id.c	Tue Feb 21 21:39:20 2012 -0600
+++ b/toys/id.c	Fri Feb 24 09:03:10 2012 +0100
@@ -2,19 +2,23 @@
  *
  * id.c - print real and effective user and group IDs
  *
+ * Copyright 2012 Daniel Walter <d.walter at 0x90at>
+ *
  * Copyright 2012 Sony Network Entertainment, Inc.
  *
  * by Tim Bird <tim.bird at am.sony.com>
  *
  * See http://www.opengroup.org/onlinepubs/009695399/utilities/id.html
 
-USE_ID(NEWTOY(id, "nGgru", TOYFLAG_BIN))
+USE_ID(NEWTOY(whoami, NULL, TOYFLAG_USR | TOYFLAG_BIN))
+USE_ID(NEWTOY(groups, NULL, TOYFLAG_USR | TOYFLAG_BIN))
+USE_ID(NEWTOY(id, "nGgru", TOYFLAG_USR | TOYFLAG_BIN))
 
 config ID
 	bool "id"
 	default y
 	help
-	  usage: id [-nGgru]
+	  usage: id [-nGgru] [USERNAME] ...
 
 	  Print user and group ID.
 
@@ -23,6 +27,25 @@
 	  -g    Show only the effective group ID
 	  -r	Show real ID instead of effective ID
 	  -u    Show only the effective user ID
+
+config ID_WHOAMI
+	bool
+	default y
+	depends on ID
+	help
+	  usage: whoami
+
+	  Print the user name associated with the current effective user ID
+
+config ID_GROUPS
+	bool
+	default y
+	depends on ID
+	help
+	  usage: groups [USERNAME] ...
+
+	  Print group memberships for each USERNAME or, if no USERNAME is 
+	  specified, for the current process
 */
 
 #include <sys/types.h>
@@ -52,6 +75,23 @@
 	printf("\n");
 }
 
+void whoami_main(void)
+{
+	/* id -un wrapper */
+	toys.optflags = FLAG_u | FLAG_n;
+	*(toys.optargs) = NULL;
+	id_main();
+	return;
+}
+
+void groups_main(void)
+{
+	/* id -Gn wrapper */
+	toys.optflags = FLAG_G | FLAG_n;
+	id_main();
+	return;
+}
+
 void id_main(void)
 {
 	int flags = toys.optflags;

 1330070644.0


More information about the Toybox mailing list