I have a script that runs an utility every two days. This utility does some stuff on my system. It is a very known, widely used piece of open source software.
#!/usr/bin/env bash
#...do stuff here
utility
Sometimes, but not always, utility
will need me to enter my password so it can do its thing. I'm not watching utility
run, and I'm not looking at any output either, 1>/dev/null
. So I'd like for any attempt utility
makes to sudo
to automatically fail. Later I can run it manually and see what it needs superuser access for.
The problem is that it's not my script sudoing, it's utility
. utility
updates regularly so I don't want to edit it. Setting SUDO_ASKPASS to something useless looked promising but it requires sudo
to have been caled with -A
from utility
. utility
man page and online docs also don't have a way to "prevent sudo", neither did I have any luck googling "prevent system wide sudo."
I'm thinking of using this fake-sudo-test.bash
:
#!/usr/bin/env bash
FAKE_SUDO="/usr/local/bin/sudo"
echo "echo 'no sudo for you $0' && exit 1" > $FAKE_SUDO
chmod u+x $FAKE_SUDO
sudo echo "I got superuser access"
\rm $FAKE_SUDO
This works because my $PATH has /usr/local/bin
in front of /usr/bin
.
Do you know a better way to do it?
PS: utility
is brew
, from the homebrew package manager for macOS, and I'm using brew upgrade
in question. I thought making the question more generic would make it more useful.
$ sudo -V
Sudo version 1.8.17p1
Sudoers policy plugin version 1.8.17p1
Sudoers file grammar version 45
Sudoers I/O plugin version 1.8.17p1
sudo
that exits if called – Jesse_b Jul 4 '18 at 16:04utility
. – Kusalananda♦ Jul 4 '18 at 16:45brew
practically never callssudo
(and if it does it calls/usr/bin/sudo
so your false sudo won't work), maybe one of the formulae does? Anyway, can't you allowsudo brew
in/etc/sudoers
for the user in question? And then run the wholebrew update
withsudo
? – nohillside Jul 4 '18 at 17:32