Skip to content
Snippets Groups Projects
Commit 8cd3f7b0 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch '6723-sudo' into 'master'

smartstatus - harden sudo command execution

See merge request !198
parents 9a4d05bb 840a770a
No related branches found
No related tags found
1 merge request!198smartstatus - harden sudo command execution
...@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment