From 84a2db7e6234e22c69e3f7f2650d91ccd790b101 Mon Sep 17 00:00:00 2001
From: Tanguy Pruvot <tanguy.pruvot@gmail.com>
Date: Sat, 18 Jun 2011 18:05:57 +0200
Subject: [PATCH] implement groups applet

Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
---
 coreutils/Config.src  |    7 +++++++
 coreutils/Kbuild.src  |    1 +
 coreutils/groups.c    |   34 ++++++++++++++++++++++++++++++++++
 include/applets.src.h |    1 +
 4 files changed, 43 insertions(+), 0 deletions(-)
 create mode 100644 coreutils/groups.c

diff --git a/coreutils/Config.src b/coreutils/Config.src
index 1843e8b..a234b38 100644
--- a/coreutils/Config.src
+++ b/coreutils/Config.src
@@ -269,6 +269,13 @@ config FEATURE_FANCY_HEAD
 	help
 	  This enables the head options (-c, -q, and -v).
 
+config GROUPS
+	bool "groups"
+	default y
+	depends on ID
+	help
+	  Print the group names associated with the current user id
+
 config HOSTID
 	bool "hostid"
 	default y
diff --git a/coreutils/Kbuild.src b/coreutils/Kbuild.src
index 6a41c83..361f3e6 100644
--- a/coreutils/Kbuild.src
+++ b/coreutils/Kbuild.src
@@ -44,6 +44,7 @@ lib-$(CONFIG_LN)        += ln.o
 lib-$(CONFIG_LOGNAME)   += logname.o
 lib-$(CONFIG_LS)        += ls.o
 lib-$(CONFIG_FTPD)      += ls.o
+lib-$(CONFIG_GROUPS)    += groups.o
 lib-$(CONFIG_MD5SUM)    += md5_sha1_sum.o
 lib-$(CONFIG_MKDIR)     += mkdir.o
 lib-$(CONFIG_MKFIFO)    += mkfifo.o
diff --git a/coreutils/groups.c b/coreutils/groups.c
new file mode 100644
index 0000000..c019760
--- /dev/null
+++ b/coreutils/groups.c
@@ -0,0 +1,34 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Mini groups implementation for busybox
+ *
+ * Copyright (C) 2011 Tanguy Pruvot <tanguy.pruvot@gmail.com>.
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
+ */
+
+/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
+
+//usage:#define groups_trivial_usage
+//usage:       ""
+//usage:#define groups_full_usage "\n\n"
+//usage:       "Print the group names associated with the current user id"
+
+#include "libbb.h"
+
+extern int id_main(int argc, char **argv);
+
+int groups_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int groups_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
+{
+	if (argv[1])
+		bb_show_usage();
+
+	char *id_argv[4];
+	id_argv[0] = xstrdup("id");
+	id_argv[1] = xstrdup("-G");
+	id_argv[2] = xstrdup("-n");
+	id_argv[3] = 0;
+
+	return id_main(3, id_argv);
+}
diff --git a/include/applets.src.h b/include/applets.src.h
index 133f376..c3775fb 100644
--- a/include/applets.src.h
+++ b/include/applets.src.h
@@ -170,6 +170,7 @@ IF_GETENFORCE(APPLET(getenforce, BB_DIR_USR_SBIN, BB_SUID_DROP))
 IF_GETOPT(APPLET(getopt, BB_DIR_BIN, BB_SUID_DROP))
 IF_GETSEBOOL(APPLET(getsebool, BB_DIR_USR_SBIN, BB_SUID_DROP))
 IF_GETTY(APPLET(getty, BB_DIR_SBIN, BB_SUID_DROP))
+IF_GROUPS(APPLET_NOEXEC(groups, groups, BB_DIR_USR_BIN, BB_SUID_DROP, groups))
 IF_GUNZIP(APPLET(gunzip, BB_DIR_BIN, BB_SUID_DROP))
 IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP))
 IF_HD(APPLET_NOEXEC(hd, hexdump, BB_DIR_USR_BIN, BB_SUID_DROP, hd))
-- 
1.7.5.3

