diff options
Diffstat (limited to 'login-utils/newgrp.c')
-rw-r--r-- | login-utils/newgrp.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/login-utils/newgrp.c b/login-utils/newgrp.c index 7016cfa63..d826c541d 100644 --- a/login-utils/newgrp.c +++ b/login-utils/newgrp.c @@ -14,6 +14,7 @@ #include <stdio.h> #include <stdlib.h> #include <errno.h> +#include <getopt.h> #ifdef HAVE_CRYPT_H #include <crypt.h> @@ -87,17 +88,45 @@ allow_setgid(struct passwd *pe, struct group *ge) return FALSE; /* default to denial */ } +static void __attribute__ ((__noreturn__)) usage(FILE * out) +{ + fprintf(out, USAGE_HEADER); + fprintf(out, _(" %s <group>\n"), program_invocation_short_name); + fprintf(out, USAGE_OPTIONS); + fprintf(out, USAGE_HELP); + fprintf(out, USAGE_VERSION); + fprintf(out, USAGE_MAN_TAIL("newgrp(1)")); + exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS); +} + int main(int argc, char *argv[]) { struct passwd *pw_entry; struct group *gr_entry; char *shell; + char ch; + static const struct option longopts[] = { + {"version", no_argument, NULL, 'V'}, + {"help", no_argument, NULL, 'h'}, + {NULL, 0, NULL, 0} + }; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1) + switch (ch) { + case 'V': + printf(UTIL_LINUX_VERSION); + return EXIT_SUCCESS; + case 'h': + usage(stdout); + default: + usage(stderr); + } + if (!(pw_entry = getpwuid(getuid()))) err(EXIT_FAILURE, _("who are you?")); |