aboutsummaryrefslogtreecommitdiffstats
path: root/toolbox/id.c
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-10-21 07:00:00 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2008-10-21 07:00:00 -0700
commit4f6e8d7a00cbeda1e70cc15be9c4af1018bdad53 (patch)
tree54fd1b2695a591d2306d41264df67c53077b752c /toolbox/id.c
downloadsystem_core-4f6e8d7a00cbeda1e70cc15be9c4af1018bdad53.tar.gz
system_core-4f6e8d7a00cbeda1e70cc15be9c4af1018bdad53.tar.bz2
system_core-4f6e8d7a00cbeda1e70cc15be9c4af1018bdad53.zip
Initial Contribution
Diffstat (limited to 'toolbox/id.c')
-rw-r--r--toolbox/id.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/toolbox/id.c b/toolbox/id.c
new file mode 100644
index 00000000..bb03cad2
--- /dev/null
+++ b/toolbox/id.c
@@ -0,0 +1,51 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include <grp.h>
+
+static void print_uid(uid_t uid)
+{
+ struct passwd *pw = getpwuid(uid);
+
+ if (pw) {
+ printf("%d(%s)", uid, pw->pw_name);
+ } else {
+ printf("%d",uid);
+ }
+}
+
+static void print_gid(gid_t gid)
+{
+ struct group *gr = getgrgid(gid);
+ if (gr) {
+ printf("%d(%s)", gid, gr->gr_name);
+ } else {
+ printf("%d",gid);
+ }
+}
+
+int id_main(int argc, char **argv)
+{
+ gid_t list[64];
+ int n, max;
+
+ max = getgroups(64, list);
+ if (max < 0) max = 0;
+
+ printf("uid=");
+ print_uid(getuid());
+ printf(" gid=");
+ print_gid(getgid());
+ if (max) {
+ printf(" groups=");
+ print_gid(list[0]);
+ for(n = 1; n < max; n++) {
+ printf(",");
+ print_gid(list[n]);
+ }
+ }
+ printf("\n");
+ return 0;
+}