From c8ab71b24b566967fdb39818d071f6548dc056c8 Mon Sep 17 00:00:00 2001 From: Jameson Graef Rollins Date: Sun, 26 Oct 2008 21:50:15 -0400 Subject: [PATCH] Changes to fix bug in authorized_keys file generation in monkeysphere-server update-users. --- debian/changelog | 7 +++ src/monkeysphere-server | 97 ++++++++++++++++++++--------------------- 2 files changed, 54 insertions(+), 50 deletions(-) diff --git a/debian/changelog b/debian/changelog index ad795e7..9aa2b0a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 Sun, 26 Oct 2008 21:49:17 -0400 + monkeysphere (0.16-1) experimental; urgency=low [ Daniel Kahn Gillmor ] diff --git a/src/monkeysphere-server b/src/monkeysphere-server index 0c56279..fb71081 100755 --- a/src/monkeysphere-server +++ b/src/monkeysphere-server @@ -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" -- 2.26.2