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