diff options
author | Elliott Hughes <enh@google.com> | 2015-03-26 17:09:41 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-03-26 17:09:41 -0700 |
commit | 499ba7d3be449a031955d3a77193ed506b7b7317 (patch) | |
tree | c45334194edae436db96547fa728c01601ea86ff /su | |
parent | d56e76f04b1f2ec89c52f68941591c54b8da21b3 (diff) | |
download | extras-499ba7d3be449a031955d3a77193ed506b7b7317.tar.gz |
Special-case "su --help".
Rather than force people to move from "su system echo -n hello", where
the -n gets interpreted by getopt_long(3), to "su system -- echo -n hello",
just hard-code the recognition of --help. This seems easier than moving
people over to the more traditional "su -c 'echo -n hello'" style.
Bug: 19948740
Change-Id: I248269343b452a381effb7b8926ac7f2522b941b
Diffstat (limited to 'su')
-rw-r--r-- | su/su.c | 35 |
1 files changed, 11 insertions, 24 deletions
@@ -85,31 +85,18 @@ int main(int argc, char** argv) { if (current_uid != AID_ROOT && current_uid != AID_SHELL) error(1, 0, "not allowed"); // Handle -h and --help. - while (true) { - int option_index = 0; - static struct option long_options[] = { - { "help", no_argument, 0, 'h' }, - { 0, 0, 0, 0 }, - }; - - int c = getopt_long(argc, argv, "h", long_options, &option_index); - if (c == -1) break; - switch (c) { - case 'h': - default: - fprintf(stderr, - "usage: su [UID[,GID[,GID2]...]] [COMMAND [ARG...]]\n" - "\n" - "Switch to WHO (default 'root') and run the given command (default sh).\n" - "\n" - "where WHO is a comma-separated list of user, group,\n" - "and supplementary groups in that order.\n" - "\n"); - return 0; - } + ++argv; + if (*argv && (strcmp(*argv, "--help") == 0 || strcmp(*argv, "-h") == 0)) { + fprintf(stderr, + "usage: su [UID[,GID[,GID2]...]] [COMMAND [ARG...]]\n" + "\n" + "Switch to WHO (default 'root') and run the given command (default sh).\n" + "\n" + "where WHO is a comma-separated list of user, group,\n" + "and supplementary groups in that order.\n" + "\n"); + return 0; } - // Bump argv to the first non-option argument. - argv += optind; // The default user is root. uid_t uid = 0; |