From db0ea785f0231be4315aa4c5af37e64841ce48f2 Mon Sep 17 00:00:00 2001 From: sin Date: Wed, 11 Jun 2014 15:42:33 +0100 Subject: [PATCH] Implement -g and -u for id(1) --- id.1 | 8 +++++++- id.c | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/id.1 b/id.1 index 9dca2d3..cd83326 100644 --- 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 index 225c254..1efadbc 100644 --- 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;