The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <unistd.h> |
| 4 | #include <sys/types.h> |
| 5 | #include <pwd.h> |
| 6 | #include <grp.h> |
Stephen Smalley | 8290d10 | 2012-01-13 08:53:56 -0500 | [diff] [blame] | 7 | #include <selinux/selinux.h> |
Stephen Smalley | 8290d10 | 2012-01-13 08:53:56 -0500 | [diff] [blame] | 8 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 9 | static void print_uid(uid_t uid) |
| 10 | { |
| 11 | struct passwd *pw = getpwuid(uid); |
| 12 | |
| 13 | if (pw) { |
| 14 | printf("%d(%s)", uid, pw->pw_name); |
| 15 | } else { |
| 16 | printf("%d",uid); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | static void print_gid(gid_t gid) |
| 21 | { |
| 22 | struct group *gr = getgrgid(gid); |
| 23 | if (gr) { |
| 24 | printf("%d(%s)", gid, gr->gr_name); |
| 25 | } else { |
| 26 | printf("%d",gid); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | int id_main(int argc, char **argv) |
| 31 | { |
| 32 | gid_t list[64]; |
| 33 | int n, max; |
Stephen Smalley | 8290d10 | 2012-01-13 08:53:56 -0500 | [diff] [blame] | 34 | char *secctx; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 35 | |
| 36 | max = getgroups(64, list); |
| 37 | if (max < 0) max = 0; |
| 38 | |
| 39 | printf("uid="); |
| 40 | print_uid(getuid()); |
| 41 | printf(" gid="); |
| 42 | print_gid(getgid()); |
| 43 | if (max) { |
| 44 | printf(" groups="); |
| 45 | print_gid(list[0]); |
| 46 | for(n = 1; n < max; n++) { |
| 47 | printf(","); |
| 48 | print_gid(list[n]); |
| 49 | } |
| 50 | } |
Stephen Smalley | 8290d10 | 2012-01-13 08:53:56 -0500 | [diff] [blame] | 51 | if (getcon(&secctx) == 0) { |
| 52 | printf(" context=%s", secctx); |
| 53 | free(secctx); |
| 54 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 55 | printf("\n"); |
| 56 | return 0; |
| 57 | } |