mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-29 21:38:05 +00:00
o Add -f option (alternate sudoers file)
o Convert to use getopt(3)
This commit is contained in:
parent
4073b477f2
commit
3c4691a1d0
35
visudo.c
35
visudo.c
@ -106,6 +106,10 @@ extern int errorlineno;
|
|||||||
extern int pedantic;
|
extern int pedantic;
|
||||||
extern int quiet;
|
extern int quiet;
|
||||||
|
|
||||||
|
/* For getopt(3) */
|
||||||
|
extern char *optarg;
|
||||||
|
extern int optind;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Globals
|
* Globals
|
||||||
*/
|
*/
|
||||||
@ -115,7 +119,6 @@ char *stmp = _PATH_SUDOERS_TMP;
|
|||||||
struct sudo_user sudo_user;
|
struct sudo_user sudo_user;
|
||||||
int parse_error = FALSE;
|
int parse_error = FALSE;
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(argc, argv)
|
main(argc, argv)
|
||||||
int argc;
|
int argc;
|
||||||
@ -130,6 +133,7 @@ main(argc, argv)
|
|||||||
int sudoers_fd; /* sudoers file descriptor */
|
int sudoers_fd; /* sudoers file descriptor */
|
||||||
int stmp_fd; /* stmp file descriptor */
|
int stmp_fd; /* stmp file descriptor */
|
||||||
int n; /* length parameter */
|
int n; /* length parameter */
|
||||||
|
int ch; /* getopt char */
|
||||||
time_t now; /* time now */
|
time_t now; /* time now */
|
||||||
struct stat stmp_sb, sudoers_sb; /* to check for changes */
|
struct stat stmp_sb, sudoers_sb; /* to check for changes */
|
||||||
|
|
||||||
@ -145,20 +149,32 @@ main(argc, argv)
|
|||||||
* Arg handling.
|
* Arg handling.
|
||||||
*/
|
*/
|
||||||
checkonly = 0;
|
checkonly = 0;
|
||||||
while (--argc) {
|
while ((ch = getopt(argc, argv, "Vcf:sq")) != -1) {
|
||||||
if (!strcmp(argv[argc], "-V")) {
|
switch (ch) {
|
||||||
|
case 'V':
|
||||||
(void) printf("visudo version %s\n", version);
|
(void) printf("visudo version %s\n", version);
|
||||||
exit(0);
|
exit(0);
|
||||||
} else if (!strcmp(argv[argc], "-s")) {
|
case 'c':
|
||||||
pedantic++; /* strict mode */
|
|
||||||
} else if (!strcmp(argv[argc], "-c")) {
|
|
||||||
checkonly++; /* check mode */
|
checkonly++; /* check mode */
|
||||||
} else if (!strcmp(argv[argc], "-q")) {
|
break;
|
||||||
|
case 'f':
|
||||||
|
sudoers = optarg; /* sudoers file path */
|
||||||
|
easprintf(&stmp, "%s.tmp", optarg);
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
pedantic++; /* strict mode */
|
||||||
|
break;
|
||||||
|
case 'q':
|
||||||
quiet++; /* quiet mode */
|
quiet++; /* quiet mode */
|
||||||
} else {
|
break;
|
||||||
|
default:
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc)
|
||||||
|
usage();
|
||||||
|
|
||||||
/* Mock up a fake sudo_user struct. */
|
/* Mock up a fake sudo_user struct. */
|
||||||
user_host = user_shost = user_cmnd = "";
|
user_host = user_shost = user_cmnd = "";
|
||||||
@ -694,6 +710,7 @@ Exit(sig)
|
|||||||
static void
|
static void
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
(void) fprintf(stderr, "usage: %s [-s] [-V]\n", Argv[0]);
|
(void) fprintf(stderr, "usage: %s [-c] [-f sudoers] [-q] [-s] [-V]\n",
|
||||||
|
Argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user