installer: Fix the /mnt/stateful_partition/unencrypted permission.

This patch introduces a postinstall fix (read as hack) to change the
permission of /mnt/stateful_partition/unencrypted (if it exists) to
0755 owned by root:root. This solves some issues with devices coming
out of the factory with these permission wrong, not being able to
read the files pre-populated there.

The patch introces three syscall calls: stat, chmod and chown, that
only log a message to stdout or stderr when they succeed or fail
respectively. All errors are non-fatal.

BUG=chromium:432774
TEST=Manual local test.

Procedure executed in the chroot after commenting out some code that
requires cgpt working on a real device (just to get to run this patch).
Setup:
 $ emerge-link chromeos-install
 $ mkdir /tmp/foo3
 $ cp /build/link/usr/bin/cros_installer /tmp/foo3/
 $ mkdir -p /tmp/foo3/proc && echo cros_legacy > /tmp/foo3/proc/cmdline
 $ mkdir -p /tmp/foo3/etc
 $ echo "CHROMEOS_RELEASE_VERSION=1.2.3.4" > /tmp/foo3/etc/lsb-release
 $ touch /tmp/foo3/foo2 && touch /tmp/foo3/foo3
 $ cp /build/link/usr/bin/cros_installer /tmp/foo3/

Tests the four cases:
 $ sudo chroot /tmp/foo3 /cros_installer postinst / /foo3
...
Couldn't check the current permission, ignored: No such file or directory
...

 $ sudo mkdir -p /tmp/foo3//mnt/stateful_partition/unencrypted/foo
 $ sudo chroot /tmp/foo3 /cros_installer postinst / /foo3
...
Checking /mnt/stateful_partition/unencrypted permission.
Permission is ok.
...

 $ sudo chown 1234:5678 /tmp/foo3/mnt/stateful_partition/unencrypted
 $ sudo chroot /tmp/foo3 /cros_installer postinst / /foo3
...
Checking /mnt/stateful_partition/unencrypted permission.
Permission changed successfully.
...

 $ ls -la /tmp/foo3/mnt/stateful_partition/unencrypted
drwxr-xr-x 3 root root 4096 Nov 14 23:30 .
...

 $ sudo chmod 766 /tmp/foo3/mnt/stateful_partition/unencrypted
 $ sudo chroot /tmp/foo3 /cros_installer postinst / /foo3
...
Checking /mnt/stateful_partition/unencrypted permission.
Permission changed successfully.
...

 $ ls -la /tmp/foo3/mnt/stateful_partition/unencrypted
drwxr-xr-x 3 root root 4096 Nov 14 23:30 .
...

Change-Id: Ib8a3d70e281c1abc5ae80b72f60bdc7f6bc3d2d8
Previous-Reviewed-on: https://chromium-review.googlesource.com/229983
(cherry picked from commit 21489894e6983d197f19b711d918980fa0632238)
Previous-Reviewed-on: https://chromium-review.googlesource.com/230764
(cherry picked from commit 721bc2a15d64f3a2b6175a2768f811e7928b4483)
Reviewed-on: https://chromium-review.googlesource.com/232951
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
1 file changed