Apply the right permissions to /etc/hosts
authorGuido Trotter <ultrotter@google.com>
Thu, 12 Feb 2009 09:15:52 +0000 (09:15 +0000)
committerGuido Trotter <ultrotter@google.com>
Thu, 12 Feb 2009 09:15:52 +0000 (09:15 +0000)
commit9b97774028b1a6fb9f3d388ec761af5882cfce4f
tree298f5e1afef2439cfa54c57cd2fc6b5c32b99b76
parent1dff8e07f07ac14ee33d688ea5614904b23ecbb4
Apply the right permissions to /etc/hosts

In the current Ganeti version when modifying /etc/hosts we mistakenly
give it the permissions of the temporary file we create to define its
content, which is by default 0600. This breaks most non-root
applications, and thus must be corrected. This patch forces the mode to
be 0644 (but we might decide to just use the mode of the previous
/etc/hosts, if we want to be more polite against any eventual
administrative choice). We also add a new assertFileMode() method for
unit tests and actually check in the SetEtcHostsEntry and
RemoveEtcHostsEntry tests that the mode is correct, to be sure not to
reintroduce this bug again. Also, a FIXME is added in the original
functions stating that it would be nice to use WriteFile+fn() rather
than reimplementing its functionality again.

Reviewed-by: iustinp
lib/utils.py
test/ganeti.utils_unittest.py
test/testutils.py