1 /* id - return uid and gid Author: John J. Marco */
3 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
5 /* Id - get real and effective user id and group id */
6 /* Author: John J. Marco */
7 /* pa1343@sdcc15.ucsd.edu */
8 /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
10 #include <sys/types.h>
17 int main(int argc
, char *argv
[])
31 gid_t groups
[NGROUPS_MAX
];
34 # define groups (&rgid)
42 get6id(&ruid
, &euid
, &suid
, &rgid
, &egid
, &sgid
);
52 ngroups
= getgroups(NGROUPS_MAX
, groups
);
55 while((c
= getopt(argc
, argv
, "u")) != EOF
) {
61 fprintf(stderr
, "%s: unrecognized option\n", argv
[0]);
71 if ((pwd
= getpwuid(ruid
)) == NULL
)
72 printf("uid=%d", ruid
);
74 printf("uid=%d(%s)", ruid
, pwd
->pw_name
);
76 if ((grp
= getgrgid(rgid
)) == NULL
)
77 printf(" gid=%d", rgid
);
79 printf(" gid=%d(%s)", rgid
, grp
->gr_name
);
82 if ((pwd
= getpwuid(euid
)) != NULL
)
83 printf(" euid=%d(%s)", euid
, pwd
->pw_name
);
85 printf(" euid=%d", euid
);
88 if ((grp
= getgrgid(egid
)) != NULL
)
89 printf(" egid=%d(%s)", egid
, grp
->gr_name
);
91 printf(" egid=%d", egid
);
94 if ((pwd
= getpwuid(suid
)) != NULL
)
95 printf(" suid=%d(%s)", suid
, pwd
->pw_name
);
97 printf(" suid=%d", suid
);
100 if ((grp
= getgrgid(sgid
)) != NULL
)
101 printf(" sgid=%d(%s)", sgid
, grp
->gr_name
);
103 printf(" sgid=%d", sgid
);
106 printf(" issetugid");
111 for (g
= 0; g
< ngroups
; g
++) {
112 if (g
> 0) fputc(',', stdout
);
113 if ((grp
= getgrgid(groups
[g
])) == NULL
)
114 printf("%d", groups
[g
]);
116 printf("%d(%s)", groups
[g
], grp
->gr_name
);