Skip to content
Snippets Groups Projects

smartstatus - harden sudo command execution

Merged Hahn Axel (hahn) requested to merge 6723-sudo into master
1 file
+ 10
4
Compare changes
  • Side-by-side
  • Inline
+ 10
4
@@ -37,15 +37,15 @@
@@ -37,15 +37,15 @@
# 2021-04-07 v1.2 <axel.hahn@iml.unibe.ch> update message if sudo smartctl -H fails
# 2021-04-07 v1.2 <axel.hahn@iml.unibe.ch> update message if sudo smartctl -H fails
# 2021-10-28 v1.3 <axel.hahn@iml.unibe.ch> detect -d param for smartctl
# 2021-10-28 v1.3 <axel.hahn@iml.unibe.ch> detect -d param for smartctl
# 2022-07-08 v1.4 <axel.hahn@iml.unibe.ch> remove pipe in status line
# 2022-07-08 v1.4 <axel.hahn@iml.unibe.ch> remove pipe in status line
 
# 2023-10-20 v1.5 <axel.hahn@unibe.ch> harden sudo command execution
# ======================================================================
# ======================================================================
. `dirname $0`/inc_pluginfunctions
. $(dirname $0)/inc_pluginfunctions
typeset -i iFound=0
typeset -i iFound=0
typeset -i iErrors=0
typeset -i iErrors=0
sOut=
sOut=
sDetails=
tmpDetailsfile=/tmp/smartstatus-all.log
tmpDetailsfile=/tmp/smartstatus-all.log
# fix for v0.5
# fix for v0.5
@@ -61,7 +61,7 @@ function detectParam(){
@@ -61,7 +61,7 @@ function detectParam(){
local _moreparam
local _moreparam
grep '^# PARAM' $0 | cut -f 2- -d ':' | while read _moreparam
grep '^# PARAM' $0 | cut -f 2- -d ':' | while read _moreparam
do
do
sudo smartctl -H $_mydevice $_moreparam >/dev/null 2>&1 && echo "$_moreparam"
sudo -n smartctl -H $_mydevice $_moreparam >/dev/null 2>&1 && echo "$_moreparam"
done
done
echo "$_moreparam"
echo "$_moreparam"
}
}
@@ -132,7 +132,13 @@ ph.require smartctl
@@ -132,7 +132,13 @@ ph.require smartctl
rm -f $tmpDetailsfile 2>/dev/null
rm -f $tmpDetailsfile 2>/dev/null
for mydevice in `ls -1 /dev/sd* | grep -v "[0-9]"`
# --- pre check for sudo permissions on smartctl
 
if ! sudo -n smartctl -h >/dev/null 2>&1; then
 
ph.abort "UNKNOWN: No sudo permissions to execute smartctl."
 
fi
 
 
# --- loop over sd devices
 
for mydevice in $(ls -1 /dev/sd* | grep -v "[0-9]")
do
do
iFound=$iFound+1
iFound=$iFound+1
Loading