Merge branch 'parse_header'

This commit is contained in:
tastytea 2015-09-30 00:26:39 +02:00
commit 165ddbb33c
1 changed files with 16 additions and 13 deletions

View File

@ -16,6 +16,7 @@ HASHER=""
BOOT_MOUNTED=0 BOOT_MOUNTED=0
CONFIG_FILE="/etc/hashboot.cfg" CONFIG_FILE="/etc/hashboot.cfg"
#Umount /boot if we mounted it, exit with given exit code #Umount /boot if we mounted it, exit with given exit code
function die function die
{ {
@ -28,24 +29,12 @@ function die
exit ${1} exit ${1}
} }
#If we're not root: exit #If we're not root: exit
if [ ${UID} -ne 0 ] if [ ${UID} -ne 0 ]
then then
die 4 "You have to be root" die 4 "You have to be root"
fi fi
#Try different hashers, use the most secure
HASHER=$(/usr/bin/which --skip-dot sha512sum 2> /dev/null)
test -z ${HASHER} && HASHER=$(/usr/bin/which --skip-dot sha384sum 2> /dev/null)
test -z ${HASHER} && HASHER=$(/usr/bin/which --skip-dot sha256sum 2> /dev/null)
test -z ${HASHER} && HASHER=$(/usr/bin/which --skip-dot sha224sum 2> /dev/null)
#It gets insecure below here, but better than nothing?
test -z ${HASHER} && HASHER=$(/usr/bin/which --skip-dot sha1sum 2> /dev/null)
test -z ${HASHER} && HASHER=$(/usr/bin/which --skip-dot md5sum 2> /dev/null)
#If we found no hasher: exit
[ -z ${HASHER} ] && die 5 "No hash calculator found"
#If /boot is in fstab but not mounted: mount, mark as mounted #If /boot is in fstab but not mounted: mount, mark as mounted
if grep -q '/boot.*noauto' /etc/fstab && ! grep -q /boot /etc/mtab if grep -q '/boot.*noauto' /etc/fstab && ! grep -q /boot /etc/mtab
then then
@ -53,8 +42,20 @@ then
BOOT_MOUNTED=1 BOOT_MOUNTED=1
fi fi
if [ "${1}" == "index" ] if [ "${1}" == "index" ]
then then
#Try different hashers, use the most secure
HASHER=$(/usr/bin/which --skip-dot sha512sum 2> /dev/null)
test -z ${HASHER} && HASHER=$(/usr/bin/which --skip-dot sha384sum 2> /dev/null)
test -z ${HASHER} && HASHER=$(/usr/bin/which --skip-dot sha256sum 2> /dev/null)
test -z ${HASHER} && HASHER=$(/usr/bin/which --skip-dot sha224sum 2> /dev/null)
#It gets insecure below here, but better than nothing?
test -z ${HASHER} && HASHER=$(/usr/bin/which --skip-dot sha1sum 2> /dev/null)
test -z ${HASHER} && HASHER=$(/usr/bin/which --skip-dot md5sum 2> /dev/null)
#If we found no hasher: exit
[ -z ${HASHER} ] && die 5 "No hash calculator found"
#Look for config file and set ${MBR_DEVICE}. #Look for config file and set ${MBR_DEVICE}.
if [ -f ${CONFIG_FILE} ] if [ -f ${CONFIG_FILE} ]
then then
@ -74,7 +75,7 @@ then
#Write MBR of MBR_DEVICE to ${DIGEST_FILE} #Write MBR of MBR_DEVICE to ${DIGEST_FILE}
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=1M count=1 status=none || die 8 dd if=${MBR_DEVICE} of=${MBR_TMP} bs=1M count=1 status=none || die 8
#Write hashes of all regular files to ${DIGEST_FILE} #Write hashes of all regular files to ${DIGEST_FILE}
${HASHER} ${MBR_TMP} > ${DIGEST_FILE} ${HASHER} ${MBR_TMP} >> ${DIGEST_FILE}
find /boot -type f -exec ${HASHER} --binary {} >> ${DIGEST_FILE} + find /boot -type f -exec ${HASHER} --binary {} >> ${DIGEST_FILE} +
if [ $? == 0 ] if [ $? == 0 ]
then then
@ -94,6 +95,8 @@ then
elif [ "${1}" == "check" ] elif [ "${1}" == "check" ]
then then
COUNTER=0 COUNTER=0
HASHER=$(head -n1 ${DIGEST_FILE} | awk '{print $5}')
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=1M count=1 status=none || die 8 dd if=${MBR_DEVICE} of=${MBR_TMP} bs=1M count=1 status=none || die 8
if $(grep ${MBR_TMP} ${DIGEST_FILE} | ${HASHER} --check --warn --quiet --strict > ${LOG_FILE}) if $(grep ${MBR_TMP} ${DIGEST_FILE} | ${HASHER} --check --warn --quiet --strict > ${LOG_FILE})
then then