mirror of
https://github.com/sudo-project/sudo.git
synced 2025-09-01 06:45:10 +00:00
correct error message if mode/owner wrong and not statable by owner
but is statable by root.
This commit is contained in:
21
sudo.c
21
sudo.c
@@ -783,7 +783,7 @@ static void load_cmnd(sudo_mode)
|
|||||||
static int check_sudoers()
|
static int check_sudoers()
|
||||||
{
|
{
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
int fd = -1;
|
int fd = -1, rootstat;
|
||||||
char c;
|
char c;
|
||||||
int rtn = ALL_SYSTEMS_GO;
|
int rtn = ALL_SYSTEMS_GO;
|
||||||
|
|
||||||
@@ -792,8 +792,10 @@ static int check_sudoers()
|
|||||||
* Only works if filesystem is readable/writable by root.
|
* Only works if filesystem is readable/writable by root.
|
||||||
*/
|
*/
|
||||||
set_perms(PERM_ROOT, 0);
|
set_perms(PERM_ROOT, 0);
|
||||||
if (!lstat(_PATH_SUDO_SUDOERS, &statbuf) && SUDOERS_UID == statbuf.st_uid) {
|
if ((rootstat = lstat(_PATH_SUDO_SUDOERS, &statbuf)) == 0 &&
|
||||||
if (SUDOERS_MODE != 0400 && (statbuf.st_mode & 0007777) == 0400) {
|
SUDOERS_UID == statbuf.st_uid && SUDOERS_MODE != 0400 &&
|
||||||
|
(statbuf.st_mode & 0007777) == 0400) {
|
||||||
|
|
||||||
if (chmod(_PATH_SUDO_SUDOERS, SUDOERS_MODE) == 0) {
|
if (chmod(_PATH_SUDO_SUDOERS, SUDOERS_MODE) == 0) {
|
||||||
(void) fprintf(stderr, "%s: fixed mode on %s\n",
|
(void) fprintf(stderr, "%s: fixed mode on %s\n",
|
||||||
Argv[0], _PATH_SUDO_SUDOERS);
|
Argv[0], _PATH_SUDO_SUDOERS);
|
||||||
@@ -814,13 +816,15 @@ static int check_sudoers()
|
|||||||
perror("");
|
perror("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sanity checks on sudoers file. Must be done as sudoers
|
||||||
|
* file owner. We already did a stat as root, so use that
|
||||||
|
* data if we can't stat as sudoers file owner.
|
||||||
|
*/
|
||||||
set_perms(PERM_SUDOERS, 0);
|
set_perms(PERM_SUDOERS, 0);
|
||||||
|
|
||||||
if ((fd = open(_PATH_SUDO_SUDOERS, O_RDONLY)) < 0 || read(fd, &c, 1) == -1)
|
if (lstat(_PATH_SUDO_SUDOERS, &statbuf) != 0 && rootstat != 0)
|
||||||
rtn = NO_SUDOERS_FILE;
|
|
||||||
else if (lstat(_PATH_SUDO_SUDOERS, &statbuf))
|
|
||||||
rtn = NO_SUDOERS_FILE;
|
rtn = NO_SUDOERS_FILE;
|
||||||
else if (!S_ISREG(statbuf.st_mode))
|
else if (!S_ISREG(statbuf.st_mode))
|
||||||
rtn = SUDOERS_NOT_FILE;
|
rtn = SUDOERS_NOT_FILE;
|
||||||
@@ -828,6 +832,9 @@ static int check_sudoers()
|
|||||||
rtn = SUDOERS_WRONG_MODE;
|
rtn = SUDOERS_WRONG_MODE;
|
||||||
else if (statbuf.st_uid != SUDOERS_UID || statbuf.st_gid != SUDOERS_GID)
|
else if (statbuf.st_uid != SUDOERS_UID || statbuf.st_gid != SUDOERS_GID)
|
||||||
rtn = SUDOERS_WRONG_OWNER;
|
rtn = SUDOERS_WRONG_OWNER;
|
||||||
|
else if ((fd = open(_PATH_SUDO_SUDOERS, O_RDONLY)) == -1 ||
|
||||||
|
read(fd, &c, 1) == -1)
|
||||||
|
rtn = NO_SUDOERS_FILE;
|
||||||
|
|
||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
(void) close(fd);
|
(void) close(fd);
|
||||||
|
Reference in New Issue
Block a user