Skip to content

Commit

Permalink
Merge pull request #82 from nsacyber/issue/81
Browse files Browse the repository at this point in the history
[#81] Fix empty string handling from SMBIOS
  • Loading branch information
iadgovuser29 committed Oct 9, 2019
2 parents fdac504 + ffcb9f1 commit ab722a5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ ospackage {
os=LINUX
arch=NOARCH
version='1.1.3'
release='2'
release='3'

into '/opt/paccor'
user 'root'
fileMode=0755

requires('dmidecode')
requires('dmidecode', '3.2', GREATER | EQUAL)
requires('jq')
requires('lshw')
requires('vim-common')
Expand Down
12 changes: 6 additions & 6 deletions scripts/allcomponents.sh
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,13 @@ parseNicData () {
optional="$optional"",""$serial"
fi
if ! [[ -z "${revision// }" ]]; then
revision=$(echo "$revision" | sed 's/^[ \t]*//;s/[ \t]*$//')
revision=$(echo "$revision" | sed 's/^[ \t]*//;s/[ \t]*$//' | awk '{ print toupper($0) }')
revision=$(jsonRevision "$revision")
optional="$optional"",""$revision"
fi
bluetoothCap=$(lshwBusItemBluetoothCap)
ethernetCap=$(lshwBusItemEthernetCap)
wirelessCap=$(lshwBusItemWirelessCap)
bluetoothCap=$(lshwBusItemBluetoothCap "$i")
ethernetCap=$(lshwBusItemEthernetCap "$i")
wirelessCap=$(lshwBusItemWirelessCap "$i")

if ([ -n "$bluetoothCap" ] || [ -n "$ethernetCap" ] || [ -n "$wirelessCap" ]) && ! [[ -z "${serialConstant// }" ]]; then
thisAddress=
Expand Down Expand Up @@ -673,7 +673,7 @@ parseHddData () {
optional="$optional"",""$serial"
fi
if ! [[ -z "${revision// }" ]]; then
revision=$(echo "$revision" | sed 's/^[ \t]*//;s/[ \t]*$//')
revision=$(echo "$revision" | sed 's/^[ \t]*//;s/[ \t]*$//' | awk '{ print toupper($0) }')
revision=$(jsonRevision "$revision")
optional="$optional"",""$revision"
fi
Expand Down Expand Up @@ -727,7 +727,7 @@ parseGfxData () {
optional="$optional"",""$serial"
fi
if ! [[ -z "${revision// }" ]]; then
revision=$(echo "$revision" | sed 's/^[ \t]*//;s/[ \t]*$//')
revision=$(echo "$revision" | sed 's/^[ \t]*//;s/[ \t]*$//' | awk '{ print toupper($0) }')
revision=$(jsonRevision "$revision")
optional="$optional"",""$revision"
fi
Expand Down
2 changes: 1 addition & 1 deletion scripts/hw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ lshwGetVersionFromBusItem () {
lshwGetSerialFromBusItem () {
itemnumber="${1}"
result=""
str=$(echo "${busitems[$itemnumber]}" | grep -e "^serial:.*$" | sed 's/^serial: \([0-9A-Za-Z:-]\+\)$/\1/')
str=$(echo "${busitems[$itemnumber]}" | grep -e "^serial:.*$" | sed 's/^serial: \([0-9A-Za-z:-]\+\)$/\1/')
if [ -n "$str" ]; then
result=$str
fi
Expand Down
27 changes: 14 additions & 13 deletions scripts/smbios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dmidecodeData () {
}
dmidecodeStrings () {
handle="${1}"
str=$(dmidecode -H "$handle" -u | awk '/Strings/{f=1;next} /^\w+$/{f=0} f' | sed 's/^[^"]*$//g' | sed 's/.*"\(.*\)".*/\1/g' | sed 's/^\w+//g' | sed '/^[[:space:]]*$/d')
str=$(dmidecode -H "$handle" -u | awk '/Strings/{f=1;next} /^\w+$/{f=0} f' | sed 's/^[^"]*$//g' | sed 's/^\w+//g' | sed '/^[[:space:]]*$/d')
old="$IFS"
IFS=$'\n'
tableStrings=($str)
Expand Down Expand Up @@ -48,13 +48,14 @@ dmidecodeGetString () {
lenDec=$(printf "%d" "0x"${#tableStrings[@]})
if [ $strrefDec -le $lenDec ] && [ $strrefDec -gt 0 ]; then
str="${tableStrings[$strrefDec-1]}"
str=$(printf "$str" | sed 's/^[ \t]*"\?//;s/"\?[ \t]*$//')
fi
printf "$str"
}



#dmidecodeHandles "4"
# Examples:
#dmidecodeHandles "1"
#numHandles=$(dmidecodeNumHandles)
#echo $numHandles
#echo ${tableHandles[*]}
Expand All @@ -65,13 +66,13 @@ dmidecodeGetString () {

#dmidecodeData "${tableHandles[0]}"

#manufacturer=${tableData[4]}

#echo "${tableStrings[$manufacturer]}"
#dmidecodeHandles "2"
#dmidecodeParseHandle "${tableHandles[0]}"
#result=$(dmidecodeGetByte "9")
#result2=$(dmidecodeGetString $result)
#echo $result2
#result3=$(dmidecodeGetString $(dmidecodeGetByte "7"))
#echo $result3
#manufacturer=$(dmidecodeGetString $(dmidecodeGetByte "0x4"))
#model=$(dmidecodeGetByte "0x6")
#model=$(printf "%d" "0x""$model") # Convert to decimal
#model=$(dmidecodeGetString $(dmidecodeGetByte "0x5"))
#serial=$(dmidecodeGetString $(dmidecodeGetByte "0x7"))
#revision=$(dmidecodeGetString $(dmidecodeGetByte "0x6"))
#echo $manufacturer
#echo $model
#echo $serial
#echo $revision

0 comments on commit ab722a5

Please sign in to comment.