Remove consent file if owned by root.

As a precaution, remove the consent file if it had at one point been created
by this script (i.e. rather than through the browser).

BUG=chrome-os-partner:3655
TEST=gmerge'd the script and rebooted successfully.  Manually tested the new code.

Change-Id: I79c06b93427687ca948b21bd030d69cadb419c87
Reviewed-on: http://gerrit.chromium.org/gerrit/2696
Reviewed-by: Michael Krebs <mkrebs@chromium.org>
Tested-by: Michael Krebs <mkrebs@chromium.org>
(cherry picked from commit 0d667ec736136a0c67273e44200ab5a9f0142304)
Reviewed-on: http://gerrit.chromium.org/gerrit/2759
diff --git a/session_manager_setup.sh b/session_manager_setup.sh
index f499a47..c6a792a 100755
--- a/session_manager_setup.sh
+++ b/session_manager_setup.sh
@@ -82,6 +82,7 @@
 # Note: If this script is renamed, ChildJob::kWindowManagerSuffix needs to be
 # updated to contain the new name.  See http://crosbug.com/7901 for more info.
 WM_SCRIPT="/sbin/window-manager-session.sh"
+CONSENT_FILE="$DATA_DIR/Consent To Send Stats"
 
 # xdg-open is used to open downloaded files.
 # It runs sensible-browser, which uses $BROWSER.
@@ -122,6 +123,15 @@
     /proc/sys/kernel/core_pattern
 fi
 
+# Remove consent file if it had at one point been created by this script.
+if [ -f "$CONSENT_FILE" ]; then
+  CONSENT_USER_GROUP=$(stat -c %U:%G "$CONSENT_FILE")
+  # normally, the consent file would be owned by "chronos:chronos".
+  if [ "$CONSENT_USER_GROUP" = "root:root" ]; then
+    rm -f "$CONSENT_FILE"
+  fi
+fi
+
 # We need to delete these files as Chrome may have left them around from
 # its prior run (if it crashed).
 rm -f ${DATA_DIR}/SingletonLock