Author: delphij
Date: Mon Apr 27 20:21:56 2015
New Revision: 282114
URL: https://svnweb.freebsd.org/changeset/base/282114

Log:
  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

Modified:
  head/etc/rc.d/hostid

Modified: head/etc/rc.d/hostid
==============================================================================
--- head/etc/rc.d/hostid        Mon Apr 27 19:52:18 2015        (r282113)
+++ head/etc/rc.d/hostid        Mon Apr 27 20:21:56 2015        (r282114)
@@ -1,6 +1,7 @@
 #!/bin/sh
 #
 # Copyright (c) 2007 Pawel Jakub Dawidek <p...@freebsd.org>
+# Copyright (c) 2015 Xin LI <delp...@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
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to