Changes to fix bug in authorized_keys file generation in
authorJameson Graef Rollins <jrollins@phys.columbia.edu>
Mon, 27 Oct 2008 01:50:15 +0000 (21:50 -0400)
committerJameson Graef Rollins <jrollins@phys.columbia.edu>
Mon, 27 Oct 2008 01:50:15 +0000 (21:50 -0400)
monkeysphere-server update-users.

debian/changelog
src/monkeysphere-server

index ad795e7f851fbc3570d1f561cd39eab26989ffae..9aa2b0ad0a38999e2cb900283051e0a48dfdf1d2 100644 (file)
@@ -1,3 +1,10 @@
+monkeysphere (0.17-1) experimental; urgency=low
+
+  * Fix some bugs in, and cleanup, authorized_keys file creation in
+    monkeysphere-server update-users.
+
+ -- Jameson Graef Rollins <jrollins@phys.columbia.edu>  Sun, 26 Oct 2008 21:49:17 -0400
+
 monkeysphere (0.16-1) experimental; urgency=low
 
   [ Daniel Kahn Gillmor ]
index 0c562799a3355a09207c7023e0d1044a7eea5451..fb710812ade86378798f9d3b137d44157f251404 100755 (executable)
@@ -170,32 +170,8 @@ update_users() {
            continue
        fi
 
-       # set authorized_user_ids and raw authorized_keys variables,
-       # translating ssh-style path variables
-       authorizedUserIDs=$(translate_ssh_variables "$uname" "$AUTHORIZED_USER_IDS")
-       rawAuthorizedKeys=$(translate_ssh_variables "$uname" "$RAW_AUTHORIZED_KEYS")
-
-       # if neither is found, skip user
-       if [ ! -s "$authorizedUserIDs" ] ; then
-           if [ "$rawAuthorizedKeys" = '-' -o ! -s "$rawAuthorizedKeys" ] ; then
-               continue
-           fi
-       fi
-
        log verbose "----- user: $uname -----"
 
-        # exit if the authorized_user_ids file is empty
-       if ! check_key_file_permissions "$uname" "$AUTHORIZED_USER_IDS" ; then
-           log error "Improper permissions on path '$AUTHORIZED_USER_IDS'."
-           continue
-       fi
-
-       # check permissions on the authorized_keys file path
-       if ! check_key_file_permissions "$uname" "$RAW_AUTHORIZED_KEYS" ; then
-           log error "Improper permissions on path '$RAW_AUTHORIZED_KEYS'."
-           continue
-       fi
-
         # make temporary directory
         TMPLOC=$(mktemp -d ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX)
 
@@ -217,39 +193,60 @@ update_users() {
         chmod 0600 "$TMP_AUTHORIZED_USER_IDS"
         chown -R "$MONKEYSPHERE_USER" "$TMPLOC"
 
-       # if the authorized_user_ids file exists...
+       # process authorized_user_ids file
+       # translating ssh-style path variables
+       authorizedUserIDs=$(translate_ssh_variables "$uname" "$AUTHORIZED_USER_IDS")
        if [ -s "$authorizedUserIDs" ] ; then
-            # copy user authorized_user_ids file to temporary
-            # location
-           cat "$authorizedUserIDs" > "$TMP_AUTHORIZED_USER_IDS"
-
-           # export needed variables
-           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="$?"
+           # 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
+                # location
+               cat "$authorizedUserIDs" > "$TMP_AUTHORIZED_USER_IDS"
+
+               # export needed variables
+               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="$?"
+           else
+               log error "Improper permissions on path '$AUTHORIZED_USER_IDS'."
+           fi
        fi
 
-       # add user-controlled authorized_keys file path if specified
+       # add user-controlled authorized_keys file if specified
+       # translate ssh-style path variables
+       rawAuthorizedKeys=$(translate_ssh_variables "$uname" "$RAW_AUTHORIZED_KEYS")
        if [ "$rawAuthorizedKeys" != '-' -a -s "$rawAuthorizedKeys" ] ; then
-           log verbose "adding raw authorized_keys file... "
-           cat "$rawAuthorizedKeys" >> "$AUTHORIZED_KEYS"
+           # check permissions on the authorized_keys file path
+           if check_key_file_permissions "$uname" "$rawAuthorizedKeys" ; then
+               log verbose "adding raw authorized_keys file... "
+               cat "$rawAuthorizedKeys" >> "$AUTHORIZED_KEYS"
+           else
+               log error "Improper permissions on path '$RAW_AUTHORIZED_KEYS'.  Not added to authorized_keys file."
+           fi
        fi
 
-       # openssh appears to check the contents of the
-        # authorized_keys file as the user in question, so the
-        # file must be readable by that user at least.
-       # FIXME: is there a better way to do this?
-       chown root "$AUTHORIZED_KEYS"
-       chgrp $(getent passwd "$uname" | cut -f4 -d:) "$AUTHORIZED_KEYS"
-       chmod g+r "$AUTHORIZED_KEYS"
+       # move the new authorized_keys file into place
+       if [ -s "$AUTHORIZED_KEYS" ] ; then
+           # openssh appears to check the contents of the
+           # authorized_keys file as the user in question, so the
+           # file must be readable by that user at least.
+           # FIXME: is there a better way to do this?
+           chown root "$AUTHORIZED_KEYS"
+           chgrp $(getent passwd "$uname" | cut -f4 -d:) "$AUTHORIZED_KEYS"
+           chmod g+r "$AUTHORIZED_KEYS"
+
+           mv -f "$AUTHORIZED_KEYS" "${SYSDATADIR}/authorized_keys/${uname}"
+       else
+           rm -f "${SYSDATADIR}/authorized_keys/${uname}"
+       fi
 
-       # move the resulting authorized_keys file into place
-       mv -f "$AUTHORIZED_KEYS" "${SYSDATADIR}/authorized_keys/${uname}"
+       # unset the trap
+       trap - EXIT
 
        # destroy temporary directory
        rm -rf "$TMPLOC"