commit db0ea785f0231be4315aa4c5af37e64841ce48f2
parent d3e332c72d415d1c64dcea1ef6928a7c60e3c132
Author: sin <sin@2f30.org>
Date: Wed, 11 Jun 2014 15:42:33 +0100
Implement -g and -u for id(1)
Diffstat:
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/id.1 b/id.1
@@ -2,13 +2,19 @@
.SH NAME
\fBid\fR - Print real and effective user and group IDs
.SH SYNOPSIS
-\fBid\fR [\fB-G\fR] \fR[\fIuser\fR|\fIuid\fR]
+\fBid\fR [\fB-g\fR] [\fB-u\fR] [\fB-G\fR] \fR[\fIuser\fR|\fIuid\fR]
.SH DESCRIPTION
\fBid\fR prints user and group information of the calling process to standard output.
If a login name or uid is specified, the user and group information of that
user is displayed.
.SH OPTIONS
.TP
+\fB-g\fR
+Print only the effective group ID.
+.TP
+\fB-u\fR
+Print only the effective user ID.
+.TP
\fB-G\fR
Display group information as whitespace separated numbers, in no particular order.
.SH SEE ALSO
diff --git a/id.c b/id.c
@@ -18,7 +18,7 @@ static void usernam(const char *nam);
static void
usage(void)
{
- eprintf("usage: %s [-G] [user | uid]\n", argv0);
+ eprintf("usage: %s [-g] [-u] [-G] [user | uid]\n", argv0);
}
static int Gflag = 0;
@@ -27,6 +27,12 @@ int
main(int argc, char *argv[])
{
ARGBEGIN {
+ case 'g':
+ printf("%d\n", getegid());
+ return EXIT_SUCCESS;
+ case 'u':
+ printf("%d\n", geteuid());
+ return EXIT_SUCCESS;
case 'G':
Gflag = 1;
break;