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
This commit is contained in:
parent
26e4122a80
commit
3f6cf39fb2
@ -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
|
||||
}
|
||||
|
||||
valid_hostid()
|
||||
{
|
||||
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)
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
hostid_hardware()
|
||||
{
|
||||
uuid=`kenv -q smbios.system.uuid`
|
||||
x="[0-9a-f]"
|
||||
y=$x$x$x$x
|
||||
case "${uuid}" in
|
||||
$y$y-$y-$y-$y-$y$y$y)
|
||||
|
||||
if valid_hostid $uuid; then
|
||||
echo "${uuid}"
|
||||
;;
|
||||
esac
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user