summaryrefslogtreecommitdiff
path: root/src/share/ma/keys_for_user
blob: f48d5d33e6c9ef4317080cede626479a8f3d8942 (plain)
  1. # -*-shell-script-*-
  2. # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
  3. # Monkeysphere authentication keys-for-user subcommand
  4. #
  5. # The monkeysphere scripts are written by:
  6. # Jameson Rollins <jrollins@finestructure.net>
  7. # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
  8. #
  9. # They are Copyright 2008-2010, and are all released under the GPL,
  10. # version 3 or later.
  11. # This command could be run as an sshd AuthorizedKeysCommand to
  12. # provide the authorized keys for a user, based on OpenPGP user id's
  13. # listed in the user's authorized_user_ids file.
  14. keys_for_user() {
  15. local uname
  16. local authorizedUserIDs
  17. local line
  18. local userIDs
  19. # get users from command line
  20. uname="$1"
  21. # path to authorized_user_ids file, translating ssh-style path
  22. # variables
  23. authorizedUserIDs=$(translate_ssh_variables "$uname" "$AUTHORIZED_USER_IDS")
  24. # exit if the authorized_user_ids file is empty
  25. if [ ! -s "$authorizedUserIDs" ] ; then
  26. failure "authorized_user_ids file '$authorizedUserIDs' is empty or does not exist."
  27. fi
  28. log debug "authorized_user_ids file: $authorizedUserIDs"
  29. # check permissions on the authorized_user_ids file path
  30. check_key_file_permissions "$uname" "$authorizedUserIDs" || failure
  31. GNUPGHOME="$GNUPGHOME_SPHERE"
  32. export GNUPGHOME
  33. # extract user IDs from authorized_user_ids file
  34. IFS=$'\n'
  35. for line in $(meat "$authorizedUserIDs") ; do
  36. su_monkeysphere_user ". ${SYSSHAREDIR}/common; keys_for_userid '$line'"
  37. done
  38. }