mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-28 21:07:55 +00:00
Use separate getopt config for sudoedit.
Avoids a problem where the user gets an exclusive usage error message when using a sudo-specific option. GitHub issue #95
This commit is contained in:
parent
a4c710ccfd
commit
a40e4b3867
@ -129,41 +129,47 @@ struct environment {
|
|||||||
* Available command line options, both short and long.
|
* Available command line options, both short and long.
|
||||||
* Note that we must disable arg permutation to support setting environment
|
* Note that we must disable arg permutation to support setting environment
|
||||||
* variables and to better support the optional arg of the -h flag.
|
* variables and to better support the optional arg of the -h flag.
|
||||||
|
* There is a more limited set of options for sudoedit (the sudo-specific
|
||||||
|
* long options are listed first).
|
||||||
*/
|
*/
|
||||||
static const char short_opts[] = "+Aa:BbC:c:D:Eeg:Hh::iKklnPp:R:r:SsT:t:U:u:Vv";
|
static const char sudo_short_opts[] = "+Aa:BbC:c:D:Eeg:Hh::iKklnPp:R:r:SsT:t:U:u:Vv";
|
||||||
static struct option long_opts[] = {
|
static const char edit_short_opts[] = "+Aa:BC:c:D:g:h::knp:R:r:ST:t:u:V";
|
||||||
|
static struct option sudo_long_opts[] = {
|
||||||
|
/* sudo-specific long options */
|
||||||
|
{ "background", no_argument, NULL, 'b' },
|
||||||
|
{ "preserve-env", optional_argument, NULL, 'E' },
|
||||||
|
{ "edit", no_argument, NULL, 'e' },
|
||||||
|
{ "set-home", no_argument, NULL, 'H' },
|
||||||
|
{ "login", no_argument, NULL, 'i' },
|
||||||
|
{ "remove-timestamp", no_argument, NULL, 'K' },
|
||||||
|
{ "list", no_argument, NULL, 'l' },
|
||||||
|
{ "preserve-groups", no_argument, NULL, 'P' },
|
||||||
|
{ "shell", no_argument, NULL, 's' },
|
||||||
|
{ "other-user", required_argument, NULL, 'U' },
|
||||||
|
{ "validate", no_argument, NULL, 'v' },
|
||||||
|
/* common long options */
|
||||||
{ "askpass", no_argument, NULL, 'A' },
|
{ "askpass", no_argument, NULL, 'A' },
|
||||||
{ "auth-type", required_argument, NULL, 'a' },
|
{ "auth-type", required_argument, NULL, 'a' },
|
||||||
{ "background", no_argument, NULL, 'b' },
|
|
||||||
{ "bell", no_argument, NULL, 'B' },
|
{ "bell", no_argument, NULL, 'B' },
|
||||||
{ "close-from", required_argument, NULL, 'C' },
|
{ "close-from", required_argument, NULL, 'C' },
|
||||||
{ "login-class", required_argument, NULL, 'c' },
|
{ "login-class", required_argument, NULL, 'c' },
|
||||||
{ "chdir", required_argument, NULL, 'D' },
|
{ "chdir", required_argument, NULL, 'D' },
|
||||||
{ "preserve-env", optional_argument, NULL, 'E' },
|
|
||||||
{ "edit", no_argument, NULL, 'e' },
|
|
||||||
{ "group", required_argument, NULL, 'g' },
|
{ "group", required_argument, NULL, 'g' },
|
||||||
{ "set-home", no_argument, NULL, 'H' },
|
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "help", no_argument, NULL, 'h' },
|
||||||
{ "host", required_argument, NULL, OPT_HOSTNAME },
|
{ "host", required_argument, NULL, OPT_HOSTNAME },
|
||||||
{ "login", no_argument, NULL, 'i' },
|
|
||||||
{ "remove-timestamp", no_argument, NULL, 'K' },
|
|
||||||
{ "reset-timestamp", no_argument, NULL, 'k' },
|
{ "reset-timestamp", no_argument, NULL, 'k' },
|
||||||
{ "list", no_argument, NULL, 'l' },
|
|
||||||
{ "non-interactive", no_argument, NULL, 'n' },
|
{ "non-interactive", no_argument, NULL, 'n' },
|
||||||
{ "preserve-groups", no_argument, NULL, 'P' },
|
|
||||||
{ "prompt", required_argument, NULL, 'p' },
|
{ "prompt", required_argument, NULL, 'p' },
|
||||||
{ "chroot", required_argument, NULL, 'R' },
|
{ "chroot", required_argument, NULL, 'R' },
|
||||||
{ "role", required_argument, NULL, 'r' },
|
{ "role", required_argument, NULL, 'r' },
|
||||||
{ "stdin", no_argument, NULL, 'S' },
|
{ "stdin", no_argument, NULL, 'S' },
|
||||||
{ "shell", no_argument, NULL, 's' },
|
|
||||||
{ "type", required_argument, NULL, 't' },
|
|
||||||
{ "command-timeout",required_argument, NULL, 'T' },
|
{ "command-timeout",required_argument, NULL, 'T' },
|
||||||
{ "other-user", required_argument, NULL, 'U' },
|
{ "type", required_argument, NULL, 't' },
|
||||||
{ "user", required_argument, NULL, 'u' },
|
{ "user", required_argument, NULL, 'u' },
|
||||||
{ "version", no_argument, NULL, 'V' },
|
{ "version", no_argument, NULL, 'V' },
|
||||||
{ "validate", no_argument, NULL, 'v' },
|
|
||||||
{ NULL, no_argument, NULL, '\0' },
|
{ NULL, no_argument, NULL, '\0' },
|
||||||
};
|
};
|
||||||
|
static struct option *edit_long_opts = &sudo_long_opts[11];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Insert a key=value pair into the specified environment.
|
* Insert a key=value pair into the specified environment.
|
||||||
@ -241,13 +247,14 @@ int
|
|||||||
parse_args(int argc, char **argv, int *old_optind, int *nargc, char ***nargv,
|
parse_args(int argc, char **argv, int *old_optind, int *nargc, char ***nargv,
|
||||||
struct sudo_settings **settingsp, char ***env_addp)
|
struct sudo_settings **settingsp, char ***env_addp)
|
||||||
{
|
{
|
||||||
|
const char *progname, *short_opts = sudo_short_opts;
|
||||||
|
struct option *long_opts = sudo_long_opts;
|
||||||
struct environment extra_env;
|
struct environment extra_env;
|
||||||
int mode = 0; /* what mode is sudo to be run in? */
|
int mode = 0; /* what mode is sudo to be run in? */
|
||||||
int flags = 0; /* mode flags */
|
int flags = 0; /* mode flags */
|
||||||
int valid_flags = DEFAULT_VALID_FLAGS;
|
int valid_flags = DEFAULT_VALID_FLAGS;
|
||||||
int ch, i;
|
int ch, i;
|
||||||
char *cp;
|
char *cp;
|
||||||
const char *progname;
|
|
||||||
debug_decl(parse_args, SUDO_DEBUG_ARGS);
|
debug_decl(parse_args, SUDO_DEBUG_ARGS);
|
||||||
|
|
||||||
/* Is someone trying something funny? */
|
/* Is someone trying something funny? */
|
||||||
@ -263,6 +270,8 @@ parse_args(int argc, char **argv, int *old_optind, int *nargc, char ***nargv,
|
|||||||
mode = MODE_EDIT;
|
mode = MODE_EDIT;
|
||||||
sudo_settings[ARG_SUDOEDIT].value = "true";
|
sudo_settings[ARG_SUDOEDIT].value = "true";
|
||||||
valid_flags = EDIT_VALID_FLAGS;
|
valid_flags = EDIT_VALID_FLAGS;
|
||||||
|
short_opts = edit_short_opts;
|
||||||
|
long_opts = edit_long_opts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load local IP addresses and masks. */
|
/* Load local IP addresses and masks. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user