| OLD | NEW | 
|   1 #!/bin/bash |   1 #!/bin/bash | 
|   2 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |   2 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 
|   3 # Use of this source code is governed by a BSD-style license that can be |   3 # Use of this source code is governed by a BSD-style license that can be | 
|   4 # found in the LICENSE file. |   4 # found in the LICENSE file. | 
|   5  |   5  | 
|   6 set -e  # exit on failure |   6 set -e  # exit on failure | 
|   7 set -E  # share the error handler |   7 set -E  # share the error handler | 
|   8 set -u  # require all variables to be defined |   8 set -u  # require all variables to be defined | 
|   9 USERID="" |   9 USERID="" | 
|  10 PASSWORD="" |  10 PASSWORD="" | 
|  11  |  11  | 
|  12 function error_handler() { |  12 function error_handler() { | 
|  13   if ! typeset -F cryptohome::log; then |  13   if ! typeset -F cryptohome::log; then | 
|  14     echo "An error occurred before/in cryptohome." 1>&2 |  14     echo "An error occurred before/in cryptohome." 1>&2 | 
|  15     # Assume common is ok. |  15     # Assume common is ok. | 
|  16     /bin/mount -t tmpfs tmpfs /home/$DEFAULT_USER |  16     /bin/mount -t tmpfs tmpfs $DEFAULT_MOUNT_POINT | 
|  17     /bin/chown $DEFAULT_USER /home/$DEFAULT_USER |  17     /bin/chown $DEFAULT_USER $DEFAULT_MOUNT_POINT | 
|  18     exit 1 |  18     exit 1 | 
|  19   fi |  19   fi | 
|  20  |  20  | 
|  21   local image="$IMAGE_DIR/${USERID}/image" |  21   local image="$IMAGE_DIR/${USERID}/image" | 
|  22   cryptohome::log "entering the mount error_handler ($image)" |  22   cryptohome::log "entering the mount error_handler ($image)" | 
|  23   # We don't want to error out again if close fails |  23   # We don't want to error out again if close fails | 
|  24   cryptohome::close || $true |  24   cryptohome::close || $true | 
|  25   # Same goes for detach |  25   # Same goes for detach | 
|  26   cryptohome::detach || $true |  26   cryptohome::detach || $true | 
|  27   if [[ -n "$image" ]]; then |  27   if [[ -n "$image" ]]; then | 
|  28     cryptohome::log "removing the failed image: $image" |  28     cryptohome::log "removing the failed image: $image" | 
|  29     $rm -f $image |  29     $rm -f $image | 
|  30   fi |  30   fi | 
|  31   cryptohome::log "attempting to create a new image..." |  31   cryptohome::log "attempting to create a new image..." | 
|  32   # Let's try a new image. If that fails, use the exit trap. |  32   # Let's try a new image. If that fails, use the exit trap. | 
|  33   trap second_chance EXIT |  33   trap second_chance EXIT | 
|  34   cryptohome::mount_or_create "$USERID" "$PASSWORD" |  34   cryptohome::mount_or_create "$USERID" "$PASSWORD" | 
|  35   trap - EXIT |  35   trap - EXIT | 
|  36   cryptohome::log "new image created and mounted successfully" |  36   cryptohome::log "new image created and mounted successfully" | 
|  37   cryptohome::log "mount completed" |  37   cryptohome::log "mount completed" | 
|  38   $exit 0 |  38   $exit 0 | 
|  39 } |  39 } | 
|  40 # TODO: move traps into a single call |  40 # TODO: move traps into a single call | 
|  41 trap error_handler ERR; |  41 trap error_handler ERR; | 
|  42  |  42  | 
|  43 function second_chance() { |  43 function second_chance() { | 
|  44   cryptohome::log "new image creation failed (again)" |  44   cryptohome::log "new image creation failed (again)" | 
|  45   cryptohome::log "mounting tmpfs" |  45   cryptohome::log "mounting tmpfs" | 
|  46   $mount -t tmpfs tmpfs /home/$DEFAULT_USER |  46   $mount -t tmpfs tmpfs $DEFAULT_MOUNT_POINT | 
|  47   $chown $DEFAULT_USER /home/$DEFAULT_USER |  47   $chown $DEFAULT_USER $DEFAULT_MOUNT_POINT | 
|  48   cryptohome::log "mount completed" |  48   cryptohome::log "mount completed" | 
|  49   $exit 0 |  49   $exit 0 | 
|  50 } |  50 } | 
|  51  |  51  | 
|  52 function mount_main() { |  52 function mount_main() { | 
|  53   if ! typeset -p CHROMEOS_USER &>/dev/null  ; then |  53   if ! typeset -p CHROMEOS_USER &>/dev/null  ; then | 
|  54     cryptohome::log "CHROMEOS_USER not exported." |  54     cryptohome::log "CHROMEOS_USER not exported." | 
|  55     cryptohome::log "Assuming we aren't coming via pam_google..." |  55     cryptohome::log "Assuming we aren't coming via pam_google..." | 
|  56     return 0 |  56     return 0 | 
|  57   fi |  57   fi | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
|  76 } |  76 } | 
|  77  |  77  | 
|  78 # Invoke main. |  78 # Invoke main. | 
|  79 if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then |  79 if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then | 
|  80   source "$(dirname "$0")/../lib/chromeos-cryptohome/common" |  80   source "$(dirname "$0")/../lib/chromeos-cryptohome/common" | 
|  81   utils::declare_commands exit |  81   utils::declare_commands exit | 
|  82   # Everything is done by default at present. |  82   # Everything is done by default at present. | 
|  83   mount_main |  83   mount_main | 
|  84 fi |  84 fi | 
|  85  |  85  | 
| OLD | NEW |