From owner-svn-src-head@FreeBSD.ORG Mon Apr 27 20:21:57 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 10E6367F; Mon, 27 Apr 2015 20:21:57 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D91151858; Mon, 27 Apr 2015 20:21:56 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t3RKLuGR073379; Mon, 27 Apr 2015 20:21:56 GMT (envelope-from delphij@FreeBSD.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t3RKLuLb073378; Mon, 27 Apr 2015 20:21:56 GMT (envelope-from delphij@FreeBSD.org) Message-Id: <201504272021.t3RKLuLb073378@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: delphij set sender to delphij@FreeBSD.org using -f From: Xin LI Date: Mon, 27 Apr 2015 20:21:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r282114 - head/etc/rc.d X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Apr 2015 20:21:57 -0000 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 +# Copyright (c) 2015 Xin LI # 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