aboutsummaryrefslogtreecommitdiff
path: root/etc
diff options
context:
space:
mode:
authorXin LI <delphij@FreeBSD.org>2015-04-27 20:21:56 +0000
committerXin LI <delphij@FreeBSD.org>2015-04-27 20:21:56 +0000
commit3f6cf39fb2b3f7089f47ed109ab42e16bae8a46a (patch)
tree94822c8bed57b4261150207f4ec1e7ea3c704d6b /etc
parent26e4122a80bbaa50a4067bd7cc2c1050ef58a318 (diff)
downloadsrc-3f6cf39fb2b3f7089f47ed109ab42e16bae8a46a.tar.gz
src-3f6cf39fb2b3f7089f47ed109ab42e16bae8a46a.zip
Generate new UUID if system UUID is known bad or malformed and add a two
seconds sleep if we found the system UUID be invalid. Obtained from: FreeNAS MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=282114
Diffstat (limited to 'etc')
-rwxr-xr-xetc/rc.d/hostid64
1 files changed, 56 insertions, 8 deletions
diff --git a/etc/rc.d/hostid b/etc/rc.d/hostid
index c4545bd7916a..281b2417c9ea 100755
--- a/etc/rc.d/hostid
+++ b/etc/rc.d/hostid
@@ -1,6 +1,7 @@
#!/bin/sh
#
# Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
+# Copyright (c) 2015 Xin LI <delphij@FreeBSD.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -55,23 +56,66 @@ hostid_set()
${SYSCTL} kern.hostid=${id} >/dev/null
}
-hostid_hardware()
+valid_hostid()
{
- uuid=`kenv -q smbios.system.uuid`
+ uuid=$1
+
x="[0-9a-f]"
y=$x$x$x$x
+
+ # Check against a blacklist before
+ # accepting the UUID.
case "${uuid}" in
+ 00000000-0000-0000-0000-000000000000)
+ ;;
+ 00020003-0004-0005-0006-000700080009)
+ ;;
+ 03000200-0400-0500-0006-000700080009)
+ ;;
+ 07090201-0103-0301-0807-060504030201)
+ ;;
+ 11111111-1111-1111-1111-111111111111)
+ ;;
+ 11111111-2222-3333-4444-555555555555)
+ ;;
+ 4c4c4544-0000-2010-8020-80c04f202020)
+ ;;
+ 58585858-5858-5858-5858-585858585858)
+ ;;
+ 890e2d14-cacd-45d1-ae66-bc80e8bfeb0f)
+ ;;
+ 8e275844-178f-44a8-aceb-a7d7e5178c63)
+ ;;
+ dc698397-fa54-4cf2-82c8-b1b5307a6a7f)
+ ;;
+ fefefefe-fefe-fefe-fefe-fefefefefefe)
+ ;;
+ *-ffff-ffff-ffff-ffffffffffff)
+ ;;
$y$y-$y-$y-$y-$y$y$y)
- echo "${uuid}"
+ return 0
;;
esac
+
+ return 1
+}
+
+hostid_hardware()
+{
+ uuid=`kenv -q smbios.system.uuid`
+
+ if valid_hostid $uuid; then
+ echo "${uuid}"
+ fi
}
hostid_generate()
{
# First look for UUID in hardware.
uuid=`hostid_hardware`
- if [ -z ${uuid} ]; then
+ if [ -z "${uuid}" ]; then
+ warn "hostid: unable to figure out a UUID from DMI data, generating a new one"
+ sleep 2
# If not found, fall back to software-generated UUID.
uuid=`uuidgen`
fi
@@ -92,11 +136,15 @@ hostid_start()
{
# If ${hostid_file} already exists, we take UUID from there.
if [ -r ${hostid_file} ]; then
- hostid_set `cat ${hostid_file}`
- else
- # No hostid file, generate UUID.
- hostid_generate
+ read saved_hostid < ${hostid_file}
+ if valid_hostid ${saved_hostid}; then
+ hostid_set `cat ${hostid_file}`
+ exit 0
+ fi
fi
+
+ # No hostid file, generate UUID.
+ hostid_generate
}
load_rc_config $name