switch (sudo_secure_file(sudoers, sudoers_uid, sudoers_gid, &sb)) {
case SUDO_PATH_SECURE:
/*
- * If we are expecting sudoers to be group readable but
- * it is not, we must open the file as root, not uid 1.
+ * If we are expecting sudoers to be group readable by
+ * SUDOERS_GID but it is not, we must open the file as root,
+ * not uid 1.
*/
- if (sudoers_uid == ROOT_UID && (sudoers_mode & S_IRGRP)) {
- if ((sb.st_mode & S_IRGRP) == 0) {
+ if (sudoers_uid == ROOT_UID && ISSET(sudoers_mode, S_IRGRP)) {
+ if (!ISSET(sb.st_mode, S_IRGRP) || sb.st_gid != SUDOERS_GID) {
restore_perms();
set_perms(PERM_ROOT);
}