explicity set the USER variable, since it's needed for checking file permissions...
[monkeysphere.git] / src / share / ma / update_users
index e9e3cc60387f899469c1361ae12d56c4bde3d0cc..195e9828f8c49a937647963b9a4dbab567a86559 100644 (file)
@@ -13,6 +13,7 @@
 
 update_users() {
 
+local returnCode=0
 local unames
 local uname
 local authorizedKeysDir
@@ -26,8 +27,6 @@ else
     unames=$(getent passwd | cut -d: -f1)
 fi
 
-RETURN=0
-
 # set mode
 MODE="authorized_keys"
 
@@ -35,7 +34,7 @@ MODE="authorized_keys"
 GNUPGHOME="$GNUPGHOME_SPHERE"
 
 # the authorized_keys directory
-authorizedKeysDir="${MADATADIR}/authorized_keys"
+authorizedKeysDir="${SYSDATADIR}/authorized_keys"
 
 # check to see if the gpg trust database has been initialized
 if [ ! -s "${GNUPGHOME}/trustdb.gpg" ] ; then
@@ -81,6 +80,7 @@ for uname in $unames ; do
     # translating ssh-style path variables
     authorizedUserIDs=$(translate_ssh_variables "$uname" "$AUTHORIZED_USER_IDS")
     if [ -s "$authorizedUserIDs" ] ; then
+       log debug "authorized_user_ids file found."
        # check permissions on the authorized_user_ids file path
        if check_key_file_permissions "$uname" "$authorizedUserIDs" ; then
             # copy user authorized_user_ids file to temporary
@@ -88,13 +88,14 @@ for uname in $unames ; do
            cat "$authorizedUserIDs" > "$TMP_AUTHORIZED_USER_IDS"
 
            # export needed variables
+           export USER="$uname"
            export AUTHORIZED_KEYS
            export TMP_AUTHORIZED_USER_IDS
 
            # process authorized_user_ids file, as monkeysphere user
            su_monkeysphere_user \
-               ". ${SYSSHAREDIR}/common; process_authorized_user_ids $TMP_AUTHORIZED_USER_IDS"
-           RETURN="$?"
+               ". ${SYSSHAREDIR}/common; process_authorized_user_ids $TMP_AUTHORIZED_USER_IDS" \
+               || returnCode="$?"
        else
            log debug "not processing authorized_user_ids."
        fi
@@ -141,7 +142,7 @@ for uname in $unames ; do
            log error "Failed to install authorized_keys for '$uname'!"
            rm -f "${authorizedKeysDir}/${uname}"
            # indicate that there has been a failure:
-           RETURN=1
+           returnCode=1
        }
     else
        rm -f "${authorizedKeysDir}/${uname}"
@@ -154,4 +155,5 @@ for uname in $unames ; do
     rm -rf "$TMPLOC"
 done
 
+return $returnCode
 }