[sudo-workers] [PATCH] Print "This incident will be reported" message *if* mail will be sent.

10maurycy10 at gmail.com 10maurycy10 at gmail.com
Fri Feb 18 21:29:12 MST 2022


>From 2e5e9e192480de47a34a3f215a53c73de21720f6 Mon Sep 17 00:00:00 2001
From: 10maurycy10 <10maurycy10 at gmail.com>
Date: Fri, 18 Feb 2022 10:58:53 -0800
Subject: [PATCH] Print "This incident will be reported" message *if* mail will
 be sent.

Removing the message will ruin the classic meme, as show in
https://xkcd.com/838/

The message was inaccurate if sudo was configured not to mail incident
reports, However a few if statements can solve the problem.

signed off by 10maurycy10 at gmail.com

---
 plugins/sudoers/logging.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/plugins/sudoers/logging.c b/plugins/sudoers/logging.c
index 12a516ebb..1ed99ec9b 100644
--- a/plugins/sudoers/logging.c
+++ b/plugins/sudoers/logging.c
@@ -312,14 +312,26 @@ log_denial(int status, bool inform_user)
 	sudoers_setlocale(SUDOERS_LOCALE_USER, &oldlocale);
 
 	if (ISSET(status, FLAG_NO_USER)) {
-	    sudo_printf(SUDO_CONV_ERROR_MSG, _("%s is not in the sudoers "
-		"file.\n"), user_name);
+		if (mailit)
+	    		sudo_printf(SUDO_CONV_ERROR_MSG, _("%s is not in the sudoers "
+			"file. This incident will be reported.\n"), user_name);
+		else
+			sudo_printf(SUDO_CONV_ERROR_MSG, _("%s is not in the sudoers "
+			"file.\n"), user_name);
 	} else if (ISSET(status, FLAG_NO_HOST)) {
-	    sudo_printf(SUDO_CONV_ERROR_MSG, _("%s is not allowed to run sudo "
-		"on %s.\n"), user_name, user_srunhost);
+		if (mailit)
+	    		sudo_printf(SUDO_CONV_ERROR_MSG, _("%s is not allowed to run sudo "
+			"on %s.  This incident will be reported/\n"), user_name, user_srunhost);
+		else 
+			sudo_printf(SUDO_CONV_ERROR_MSG, _("%s is not allowed to run sudo "
+			"on %s.\n"), user_name, user_srunhost);
 	} else if (ISSET(status, FLAG_NO_CHECK)) {
-	    sudo_printf(SUDO_CONV_ERROR_MSG, _("Sorry, user %s may not run "
-		"sudo on %s.\n"), user_name, user_srunhost);
+	    if (mailit)
+		    	sudo_printf(SUDO_CONV_ERROR_MSG, _("Sorry, user %s may not run "
+			"sudo on %s.  This incident will be reported.\n"), user_name, user_srunhost);
+		else
+			sudo_printf(SUDO_CONV_ERROR_MSG, _("Sorry, user %s may not run "
+			"sudo on %s.\n"), user_name, user_srunhost);
 	} else {
 	    sudo_printf(SUDO_CONV_ERROR_MSG, _("Sorry, user %s is not allowed "
 		"to execute '%s%s%s' as %s%s%s on %s.\n"),
-- 
2.35.1



More information about the sudo-workers mailing list