Date: Thu, 12 Jan 2012 08:15:24 GMT From: Dirk-Willem van Gulik <dirkx@webweaving.org> To: freebsd-gnats-submit@FreeBSD.org Subject: conf/164048: /etc/rc.d/hostid is not symlink aware Message-ID: <201201120815.q0C8FONo062154@red.freebsd.org> Resent-Message-ID: <201201120820.q0C8KB4k088320@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 164048
>Category: conf
>Synopsis: /etc/rc.d/hostid is not symlink aware
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Thu Jan 12 08:20:11 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator: Dirk-Willem van Gulik
>Release: FreeBSD 8 & 9
>Organization:
Webweaving
>Environment:
FreeBSD foem.leiden.webweaving.org 8.2-RELEASE-p2 FreeBSD 8.2-RELEASE-p2 #0: Tue Dec 27 15:40:46 CET 2011 root@foem.leiden.webweaving.org:/usr/obj/usr/src/sys/FOEM amd64
>Description:
/sbin/dhclient-script, /etc/rc.d/hostid and /etc/rc.d/sshd are the only three scripts that write in /etc. In some embedded environments, heavily-audited/secure, PXE boots, NFS root's and in, say, virtualbox or Xen, it can be very nice to have a fully-read only / and/or /etc.
dhclient-script and /etc/rc.d/sshd are both aware of the fact that the destination may be a symlink. /etc/rc.d/hostid is not (yet).
Below is a suggestion. Note that this is an alternative to setting the hostid_file to some place.
>How-To-Repeat:
Create a read only /etc; put a symlink for all the writable files:
ln -s /var/run/resolv.conf /etc
ln -s /var/run/hostid /etc
ln -s /var/db/
ln -s /var/db/ssh_host_dsa_key /etc/ssh
ln -s /var/db/ssh_host_key /etc/ssh
ln -s /var/db/ssh_host_rsa_key /etc/ssh
ln -s /var/db/ssh_host_dsa_key.pub /etc/ssh
ln -s /var/db/ssh_host_key.pub /etc/ssh
ln -s /var/db/ssh_host_rsa_key.pub /etc/ssh
reboot - and observe that all works - but that
cat /etc/hostid
shows it to be empty . Apply below - reboot and see that /var/run/hostid now contains the hostid - visible also as /etc/hostid.
>Fix:
--- /etc/rc.d/hostid 2011-02-17 03:19:40.000000000 +0100
+++ /tmp/hostid 2012-01-12 09:10:09.000000000 +0100
@@ -90,12 +90,15 @@
hostid_start()
{
- # If ${hostid_file} already exists, we take UUID from there.
- if [ -r ${hostid_file} ]; then
+ # If ${hostid_file} already exists, we take UUID from there. We use
+ # a -f rather than a -r check as the histid_file may in fact be
+ # a symbolic link.
+ #
+ if [ -f ${hostid_file} ]; then
hostid_set `cat ${hostid_file}`
else
# No hostid file, generate UUID.
- hostid_generate
+ hostid_reset
fi
}
>Release-Note:
>Audit-Trail:
>Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201201120815.q0C8FONo062154>
