[sudo-workers] [PATCH] Add bell option to sudo prompt

Michael Spradling mike at mspradling.com
Fri May 24 11:35:02 MDT 2019


I was wondering if you would entertain the idea of adding a bell when
sudo prompts the user for a password.  This is a nice thing to have when
their are long scripts that run and have a sudo prompt at the end.
Before this change,  the sudo ends up timing out since I don't catch it
in before the timeout occurs.

Thanks,
Michael
-------------- next part --------------
# HG changeset patch
# User Michael Spradling <mike at mspradling.com>
# Date 1558718158 14400
#      Fri May 24 13:15:58 2019 -0400
# Node ID b8a810555274acefd14bf580bd33e0269309e9bf
# Parent  8a3db9d71297934aa7f7b60caeea2bf4c6e4c207
Add bell option to sudo prompt

Sometimes it would be nice to have sudo perform a bell indication when it
prompts the user.  For example, this is nice when their is a long running
process that does a sudo prompt at the end of the script.

diff -r 8a3db9d71297 -r b8a810555274 src/parse_args.c
--- a/src/parse_args.c	Mon May 06 10:04:07 2019 -0600
+++ b/src/parse_args.c	Fri May 24 13:15:58 2019 -0400
@@ -1,6 +1,4 @@
 /*
- * SPDX-License-Identifier: ISC
- *
  * Copyright (c) 1993-1996, 1998-2017 Todd C. Miller <Todd.Miller at sudo.ws>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -133,11 +131,12 @@
  * Note that we must disable arg permutation to support setting environment
  * variables and to better support the optional arg of the -h flag.
  */
-static const char short_opts[] =  "+Aa:bC:c:D:Eeg:Hh::iKklnPp:r:SsT:t:U:u:Vv";
+static const char short_opts[] =  "+Aa:bBC:c:D:Eeg:Hh::iKklnPp:r:SsT:t:U:u:Vv";
 static struct option long_opts[] = {
     { "askpass",	no_argument,		NULL,	'A' },
     { "auth-type",	required_argument,	NULL,	'a' },
     { "background",	no_argument,		NULL,	'b' },
+    { "bell",	        no_argument,		NULL,	'B' },
     { "close-from",	required_argument,	NULL,	'C' },
     { "login-class",	required_argument,	NULL,	'c' },
     { "preserve-env",	optional_argument,	NULL,	'E' },
@@ -317,6 +316,9 @@
 		case 'b':
 		    SET(flags, MODE_BACKGROUND);
 		    break;
+		case 'B':
+		    SET(tgetpass_flags, TGP_BELL);
+		    break;
 		case 'C':
 		    if (strtonum(optarg, 3, INT_MAX, NULL) == 0) {
 			sudo_warnx(U_("the argument to -C must be a number greater than or equal to 3"));
@@ -711,6 +713,8 @@
 #endif
     sudo_lbuf_append(&lbuf, "  -b, --background              %s\n",
 	_("run command in the background"));
+    sudo_lbuf_append(&lbuf, "  -B, --bell                    %s\n",
+	_("Bell prompt when prompting"));
     sudo_lbuf_append(&lbuf, "  -C, --close-from=num          %s\n",
 	_("close all file descriptors >= num"));
 #ifdef HAVE_LOGIN_CAP_H
diff -r 8a3db9d71297 -r b8a810555274 src/sudo.h
--- a/src/sudo.h	Mon May 06 10:04:07 2019 -0600
+++ b/src/sudo.h	Fri May 24 13:15:58 2019 -0400
@@ -1,6 +1,4 @@
 /*
- * SPDX-License-Identifier: ISC
- *
  * Copyright (c) 1993-1996, 1998-2005, 2007-2016
  *	Todd C. Miller <Todd.Miller at sudo.ws>
  *
@@ -38,7 +36,6 @@
 #include "sudo_fatal.h"
 #include "sudo_conf.h"
 #include "sudo_debug.h"
-#include "sudo_queue.h"
 #include "sudo_util.h"
 
 #ifdef HAVE_PRIV_SET
@@ -86,6 +83,7 @@
 #define TGP_ASKPASS	0x04		/* read from askpass helper program */
 #define TGP_MASK	0x08		/* mask user input when reading */
 #define TGP_NOECHO_TRY	0x10		/* turn off echo if possible */
+#define TGP_BELL    0x20 		/* bell on password prompt */
 
 /* name/value pairs for command line settings. */
 struct sudo_settings {
diff -r 8a3db9d71297 -r b8a810555274 src/tgetpass.c
--- a/src/tgetpass.c	Mon May 06 10:04:07 2019 -0600
+++ b/src/tgetpass.c	Fri May 24 13:15:58 2019 -0400
@@ -1,6 +1,4 @@
 /*
- * SPDX-License-Identifier: ISC
- *
  * Copyright (c) 1996, 1998-2005, 2007-2018
  *	Todd C. Miller <Todd.Miller at sudo.ws>
  *
@@ -128,6 +126,9 @@
     enum tgetpass_errval errval;
     debug_decl(tgetpass, SUDO_DEBUG_CONV)
 
+    if (ISSET(flags, TGP_BELL))
+	printf("\a");
+
     (void) fflush(stdout);
 
     if (askpass == NULL) {


More information about the sudo-workers mailing list