From: Todd C. Miller Date: Fri, 31 Aug 2018 14:08:45 +0000 (-0600) Subject: If sudo_lock_file() fails for a reason other than the file already X-Git-Tag: SUDO_1_8_25^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=470a7830dcb20a23f915aa11474eabb8939b594a;p=sudo If sudo_lock_file() fails for a reason other than the file already being locked, give the user a chance to edit anyway. --- diff --git a/plugins/sudoers/visudo.c b/plugins/sudoers/visudo.c index 304846995..7082ec812 100644 --- a/plugins/sudoers/visudo.c +++ b/plugins/sudoers/visudo.c @@ -960,6 +960,26 @@ done: debug_return_bool(ok); } +static bool +lock_sudoers(struct sudoersfile *entry) +{ + int ch; + debug_decl(lock_sudoers, SUDOERS_DEBUG_UTIL) + + if (!sudo_lock_file(entry->fd, SUDO_TLOCK)) { + if (errno == EAGAIN || errno == EWOULDBLOCK) { + sudo_warnx(U_("%s busy, try again later"), entry->path); + debug_return_bool(false); + } + sudo_warn(U_("unable to lock %s"), entry->path); + (void) fputs(_("Edit anyway? [y/N]"), stdout); + ch = getchar(); + if (tolower(ch) != 'y') + debug_return_bool(false); + } + debug_return_bool(true); +} + /* * Used to open (and lock) the initial sudoers file and to also open * any subsequent files #included via a callback from the parser. @@ -995,8 +1015,8 @@ open_sudoers(const char *path, bool doedit, bool *keepopen) free(entry); debug_return_ptr(NULL); } - if (!checkonly && !sudo_lock_file(entry->fd, SUDO_TLOCK)) - sudo_fatalx(U_("%s busy, try again later"), entry->path); + if (!checkonly && !lock_sudoers(entry)) + debug_return_ptr(NULL); if ((fp = fdopen(entry->fd, "r")) == NULL) sudo_fatal("%s", entry->path); TAILQ_INSERT_TAIL(&sudoerslist, entry, entries);