int
parse_args(
int
argc, char
*
*
argv,
int
*
old_optind,
int
*
nargc, char
*
*
*
nargv,
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;
int
mode
=
0
;
/
*
what mode
is
sudo to be run
in
?
*
/
int
flags
=
0
;
/
*
mode flags
*
/
int
valid_flags
=
DEFAULT_VALID_FLAGS;
int
ch, i;
char
*
cp;
debug_decl(parse_args, SUDO_DEBUG_ARGS);
/
*
Is someone trying something funny?
*
/
if
(argc <
=
0
)
usage();
/
*
The plugin API includes the program name (either sudo
or
sudoedit).
*
/
progname
=
getprogname();
sudo_settings[ARG_PROGNAME].value
=
progname;
/
*
First, check to see
if
we were invoked as
"sudoedit"
.
*
/
if
(strcmp(progname,
"sudoedit"
)
=
=
0
) {
mode
=
MODE_EDIT;
sudo_settings[ARG_SUDOEDIT].value
=
"true"
;
valid_flags
=
EDIT_VALID_FLAGS;
short_opts
=
edit_short_opts;
long_opts
=
edit_long_opts;
}
......
if
((ch
=
getopt_long(argc, argv, short_opts, long_opts, NULL)) !
=
-
1
) {
switch (ch) {
......
case
'E'
:
/
*
*
Optional argument
is
a comma
-
separated
list
of
*
environment variables to preserve.
*
If
not
present, preserve everything.
*
/
if
(optarg
=
=
NULL) {
sudo_settings[ARG_PRESERVE_ENVIRONMENT].value
=
"true"
;
SET
(flags, MODE_PRESERVE_ENV);
}
else
{
parse_env_list(&extra_env, optarg);
}
break
;
case
'e'
:
if
(mode && mode !
=
MODE_EDIT)
usage_excl();
mode
=
MODE_EDIT;
sudo_settings[ARG_SUDOEDIT].value
=
"true"
;
valid_flags
=
EDIT_VALID_FLAGS;
break
;
......
case
'l'
:
if
(mode) {
if
(mode
=
=
MODE_LIST)
SET
(flags, MODE_LONG_LIST);
else
usage_excl();
}
mode
=
MODE_LIST;
valid_flags
=
LIST_VALID_FLAGS;
break
;
if
(!mode) {
/
*
Defer
-
k mode setting until we know whether it
is
a flag
or
not
*
/
if
(sudo_settings[ARG_IGNORE_TICKET].value !
=
NULL) {
if
(argc
=
=
0
&& !ISSET(flags, MODE_SHELL|MODE_LOGIN_SHELL)) {
mode
=
MODE_INVALIDATE;
/
*
-
k by itself
*
/
sudo_settings[ARG_IGNORE_TICKET].value
=
NULL;
valid_flags
=
0
;
}
}
if
(!mode)
mode
=
MODE_RUN;
/
*
running a command
*
/
}