shill: login: Allow guest login

Modify shill login script to allow an empty "user" parameter, since
this is how guest login works.  In this situation, create a temporary
directory for the user profile which will be removed at logout.

BUG=chromium-os:36181
TEST=Rerun unit tests.  Login as guest and make sure profile is pushed,
temporary directory exists.  On logout ensure profile directory has
been removed.

Change-Id: Ice8299e83cebe00b7c560cc00455d6228a09c9e2
Reviewed-on: https://gerrit.chromium.org/gerrit/37779
Reviewed-by: Richard Barnette <jrbarnette@chromium.org>
Commit-Ready: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/bin/shill_login_user b/bin/shill_login_user
index 18521bc..705380a 100755
--- a/bin/shill_login_user
+++ b/bin/shill_login_user
@@ -27,10 +27,6 @@
 # user whose profile is being loaded.
 user=$1
 script_name=$(basename $0)
-if [ -z "$user" ] ; then
-  echo "Usage: $0 <user>"
-  exit 1
-fi
 
 # Reference to older connection manager profile.
 flimflam_profile_dir=~chronos/flimflam
@@ -45,15 +41,23 @@
 old_profile_dir=~chronos/shill
 old_profile="$old_profile_dir/shill.profile"
 
-cryptohome_dir=$(cryptohome-path system ${user})
+if [ -n "$user" ] ; then
+  cryptohome_dir=$(cryptohome-path system ${user})
+  if [ ! -d "$cryptohome_dir" ] ; then
+    logger -t "$script_name" \
+      "User cryptohome dir $cryptohome_dir does not exist"
+    exit 1
+  fi
+else
+  # If no user is given, create a temporary profile directory which will
+  # be erased on logout.
+  cryptohome_dir="/var/run/shill/guest_user_profile"
+  rm -rf "$cryptohome_dir"
+fi
+
 cryptohome_profile_dir="$cryptohome_dir/shill"
 cryptohome_profile="$cryptohome_profile_dir/shill.profile"
 
-if [ ! -d "$cryptohome_dir" ] ; then
-  logger -t "$script_name" "User cryptohome dir $cryptohome_dir does not exist"
-  exit 1
-fi
-
 if [ ! -d "$cryptohome_profile_dir" ]; then
   if ! mkdir -p --mode=700 $cryptohome_profile_dir ; then
     logger -t "$script_name" \
diff --git a/bin/shill_logout_user b/bin/shill_logout_user
index 0fdd7c0..bc7980b 100755
--- a/bin/shill_logout_user
+++ b/bin/shill_logout_user
@@ -11,5 +11,5 @@
 dbus-send --system --dest=org.chromium.flimflam --print-reply / \
   org.chromium.flimflam.Manager.PopProfile string:$profile_name ||
     logger -t "$script_name"  "Failed to pop shill profile $profile_name"
-rm -rf /var/run/shill/user_profiles
+rm -rf /var/run/shill/user_profiles /var/run/shill/guest_user_profile