2 # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
4 # Shared sh functions for the monkeysphere
7 # Jameson Rollins <jrollins@finestructure.net>
8 # Jamie McClelland <jm@mayfirst.org>
9 # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
11 # Copyright 2008-2009, released under the GPL, version 3 or later
13 # all-caps variables are meant to be user supplied (ie. from config
14 # file) and are considered global
16 ########################################################################
21 cat "${SYSSHAREDIR}/VERSION"
24 # failure function. exits with code 255, unless specified otherwise.
26 [ "$1" ] && echo "$1" >&2
30 # write output to stderr based on specified LOG_LEVEL the first
31 # parameter is the priority of the output, and everything else is what
32 # is echoed to stderr. If there is nothing else, then output comes
33 # from stdin, and is not prefaced by log prefix.
41 # don't include SILENT in alllevels: it's handled separately
42 # list in decreasing verbosity (all caps).
43 # separate with $IFS explicitly, since we do some fancy footwork
45 alllevels="DEBUG${IFS}VERBOSE${IFS}INFO${IFS}ERROR"
47 # translate lowers to uppers in global log level
48 LOG_LEVEL=$(echo "$LOG_LEVEL" | tr "[:lower:]" "[:upper:]")
50 # just go ahead and return if the log level is silent
51 if [ "$LOG_LEVEL" = 'SILENT' ] ; then
55 for level in $alllevels ; do
56 if [ "$LOG_LEVEL" = "$level" ] ; then
60 if [ -z "$found" ] ; then
65 # get priority from first parameter, translating all lower to
67 priority=$(echo "$1" | tr "[:lower:]" "[:upper:]")
70 # scan over available levels
71 for level in $alllevels ; do
72 # output if the log level matches, set output to true
73 # this will output for all subsequent loops as well.
74 if [ "$LOG_LEVEL" = "$level" ] ; then
77 if [ "$priority" = "$level" -a "$output" = 'true' ] ; then
82 fi | sed 's/^/'"${LOG_PREFIX}"'/' >&2
87 # run command as monkeysphere user
88 su_monkeysphere_user() {
89 # our main goal here is to run the given command as the the
90 # monkeysphere user, but without prompting for any sort of
91 # authentication. If this is not possible, we should just fail.
93 # FIXME: our current implementation is overly restrictive, because
94 # there may be some su PAM configurations that would allow su
95 # "$MONKEYSPHERE_USER" -c "$@" to Just Work without prompting,
96 # allowing specific users to invoke commands which make use of
99 # chpst (from runit) would be nice to use, but we don't want to
100 # introduce an extra dependency just for this. This may be a
101 # candidate for re-factoring if we switch implementation languages.
104 # if monkeysphere user, run the command under bash
105 "$MONKEYSPHERE_USER")
109 # if root, su command as monkeysphere user
111 su "$MONKEYSPHERE_USER" -c "$@"
116 log error "non-privileged user."
121 # cut out all comments(#) and blank lines from standard input
123 grep -v -e "^[[:space:]]*#" -e '^$' "$1"
126 # cut a specified line from standard input
128 head --line="$1" "$2" | tail -1
131 # make a temporary directory
133 mktemp -d ${TMPDIR:-/tmp}/monkeysphere.XXXXXXXXXX
136 # make a temporary file
138 mktemp ${TMPDIR:-/tmp}/monkeysphere.XXXXXXXXXX
141 # this is a wrapper for doing lock functions.
143 # it lets us depend on either lockfile-progs (preferred) or procmail's
144 # lockfile, and should
146 local use_lockfileprogs=true
150 if ! ( type lockfile-create &>/dev/null ) ; then
151 if ! ( type lockfile &>/dev/null ); then
152 failure "Neither lockfile-create nor lockfile are in the path!"
159 if [ -n "$use_lockfileprogs" ] ; then
160 lockfile-create "$file" || failure "unable to lock '$file'"
162 lockfile -r 20 "${file}.lock" || failure "unable to lock '$file'"
164 log debug "lock created on '$file'."
167 if [ -n "$use_lockfileprogs" ] ; then
168 lockfile-touch --oneshot "$file"
172 log debug "lock touched on '$file'."
175 if [ -n "$use_lockfileprogs" ] ; then
176 lockfile-remove "$file"
180 log debug "lock removed on '$file'."
183 failure "bad argument for lock subfunction '$action'"
188 # for portability, between gnu date and BSD date.
189 # arguments should be: number longunits format
191 # e.g. advance_date 20 seconds +%F
199 # try things the GNU way first
200 if date -d "$number $longunits" "$format" &>/dev/null; then
201 date -d "$number $longunits" "$format"
203 # otherwise, convert to (a limited version of) BSD date syntax:
227 # this is a longshot, and will likely fail; oh well.
228 shortunits="$longunits"
230 date "-v+${number}${shortunits}" "$format"
235 # check that characters are in a string (in an AND fashion).
236 # used for checking key capability
237 # check_capability capability a [b...]
246 if echo "$usage" | grep -q -v "$capcheck" ; then
255 if type md5sum &>/dev/null ; then
257 elif type md5 &>/dev/null ; then
260 failure "Neither md5sum nor md5 are in the path!"
264 # convert escaped characters in pipeline from gpg output back into
266 # FIXME: undo all escape character translation in with-colons gpg
272 # convert nasty chars into gpg-friendly form in pipeline
273 # FIXME: escape everything, not just colons!
278 # prompt for GPG-formatted expiration, and emit result on stdout
279 get_gpg_expiration() {
284 if [ -z "$keyExpire" -a "$PROMPT" = 'true' ]; then
286 Please specify how long the key should be valid.
287 0 = key does not expire
288 <n> = key expires in n days
289 <n>w = key expires in n weeks
290 <n>m = key expires in n months
291 <n>y = key expires in n years
293 while [ -z "$keyExpire" ] ; do
294 printf "Key is valid for? (0) " >&2
296 if ! test_gpg_expire ${keyExpire:=0} ; then
297 echo "invalid value" >&2
301 elif ! test_gpg_expire "$keyExpire" ; then
302 failure "invalid key expiration value '$keyExpire'."
308 passphrase_prompt() {
313 if [ "$DISPLAY" ] && type "${SSH_ASKPASS:-ssh-askpass}" >/dev/null; then
314 printf 'Launching "%s"\n' "${SSH_ASKPASS:-ssh-askpass}" | log info
315 printf '(with prompt "%s")\n' "$prompt" | log debug
316 "${SSH_ASKPASS:-ssh-askpass}" "$prompt" > "$fifo"
318 read -s -p "$prompt" PASS
319 # Uses the builtin echo, so should not put the passphrase into
320 # the process table. I think. --dkg
321 echo "$PASS" > "$fifo"
325 # remove all lines with specified string from specified file
334 if [ -z "$file" -o -z "$string" ] ; then
338 if [ ! -e "$file" ] ; then
342 # if the string is in the file...
343 if grep -q -F "$string" "$file" 2>/dev/null ; then
344 tempfile=$(mktemp "${file}.XXXXXXX") || \
345 failure "Unable to make temp file '${file}.XXXXXXX'"
347 # remove the line with the string, and return 0
348 grep -v -F "$string" "$file" >"$tempfile"
349 cat "$tempfile" > "$file"
358 # remove all lines with MonkeySphere strings in file
359 remove_monkeysphere_lines() {
365 # return error if file does not exist
366 if [ ! -e "$file" ] ; then
370 # just return ok if the file is empty, since there aren't any
372 if [ ! -s "$file" ] ; then
376 tempfile=$(mktemp "${file}.XXXXXXX") || \
377 failure "Could not make temporary file '${file}.XXXXXXX'."
379 egrep -v '^MonkeySphere[[:digit:]]{4}(-[[:digit:]]{2}){2}T[[:digit:]]{2}(:[[:digit:]]{2}){2}$' \
381 cat "$tempfile" > "$file"
385 # translate ssh-style path variables %h and %u
386 translate_ssh_variables() {
393 # get the user's home directory
394 userHome=$(get_homedir "$uname")
396 # translate '%u' to user name
397 path=${path/\%u/"$uname"}
398 # translate '%h' to user home directory
399 path=${path/\%h/"$userHome"}
404 # test that a string to conforms to GPG's expiration format
406 echo "$1" | egrep -q "^[0-9]+[mwy]?$"
409 # check that a file is properly owned, and that all it's parent
410 # directories are not group/other writable
411 check_key_file_permissions() {
419 # function to check that the given permission corresponds to writability
427 log debug "checking path permission '$path'..."
429 # rewrite path if it points to a symlink
430 if [ -h "$path" ] ; then
431 path=$(readlink -f "$path")
432 log debug "checking path symlink '$path'..."
435 # return 255 if cannot stat file
436 if ! stat=$(ls -ld "$path" 2>/dev/null) ; then
437 log error "could not stat path '$path'."
441 owner=$(echo "$stat" | awk '{ print $3 }')
442 gAccess=$(echo "$stat" | cut -c6)
443 oAccess=$(echo "$stat" | cut -c9)
445 # return 1 if path has invalid owner
446 if [ "$owner" != "$uname" -a "$owner" != 'root' ] ; then
447 log error "improper ownership on path '$path':"
448 log error " $owner != ($uname|root)"
452 # return 2 if path has group or other writability
453 if is_write "$gAccess" || is_write "$oAccess" ; then
454 log error "improper group or other writability on path '$path':"
455 log error " group: $gAccess, other: $oAccess"
459 # return zero if all clear, or go to next path
460 if [ "$path" = '/' ] ; then
464 check_key_file_permissions "$uname" $(dirname "$path")
468 # return a list of all users on the system
470 if type getent &>/dev/null ; then
471 # for linux and FreeBSD systems
472 getent passwd | cut -d: -f1
473 elif type dscl &>/dev/null ; then
475 dscl localhost -list /Search/Users
477 failure "Neither getent or dscl is in the path! Could not determine list of users."
481 # return the path to the home directory of a user
483 local uname=${1:-`whoami`}
484 eval "echo ~${uname}"
487 ### CONVERSION UTILITIES
489 # output the ssh key for a given key ID
495 gpg --export "$keyID" | openpgp2ssh "$keyID" 2>/dev/null
498 # output known_hosts line from ssh key
504 # FIXME this does not properly deal with IPv6 hosts using the
505 # standard port (because it's unclear whether their final
506 # colon-delimited address section is a port number or an address
512 # specify the host and port properly for new ssh known_hosts
514 if [ "$port" != "$host" ] ; then
515 host="[${host}]:${port}"
517 printf "%s %s MonkeySphere%s\n" "$host" "$key" "$DATE"
520 # output authorized_keys line from ssh key
521 ssh2authorized_keys() {
528 printf "%s MonkeySphere%s %s\n" "$key" "$DATE" "$userID"
531 # convert key from gpg to ssh known_hosts format
540 key=$(gpg2ssh "$keyID")
542 # NOTE: it seems that ssh-keygen -R removes all comment fields from
543 # all lines in the known_hosts file. why?
544 # NOTE: just in case, the COMMENT can be matched with the
546 # '^MonkeySphere[[:digit:]]{4}(-[[:digit:]]{2}){2}T[[:digit:]]{2}(:[[:digit:]]{2}){2}$'
547 printf "%s %s MonkeySphere%s\n" "$host" "$key" "$DATE"
550 # convert key from gpg to ssh authorized_keys format
551 gpg2authorized_keys() {
559 key=$(gpg2ssh "$keyID")
561 # NOTE: just in case, the COMMENT can be matched with the
563 # '^MonkeySphere[[:digit:]]{4}(-[[:digit:]]{2}){2}T[[:digit:]]{2}(:[[:digit:]]{2}){2}$'
564 printf "%s MonkeySphere%s %s\n" "$key" "$DATE" "$userID"
569 # retrieve all keys with given user id from keyserver
570 # FIXME: need to figure out how to retrieve all matching keys
571 # (not just first N (5 in this case))
576 if [ "$CHECK_KEYSERVER" != 'true' ] ; then
582 log verbose " checking keyserver $KEYSERVER... "
584 gpg --quiet --batch --with-colons \
585 --command-fd 0 --keyserver "$KEYSERVER" \
586 --search ="$userID" &>/dev/null
592 ########################################################################
593 ### PROCESSING FUNCTIONS
595 # userid and key policy checking
596 # the following checks policy on the returned keys
597 # - checks that full key has appropriate valididy (u|f)
598 # - checks key has specified capability (REQUIRED_*_KEY_CAPABILITY)
599 # - checks that requested user ID has appropriate validity
600 # (see /usr/share/doc/gnupg/DETAILS.gz)
601 # output is one line for every found key, in the following format:
605 # "flag" is an acceptability flag, 0 = ok, 1 = bad
606 # "sshKey" is the translated gpg key
608 # all log output must go to stderr, as stdout is used to pass the
609 # flag:sshKey to the calling function.
611 # expects global variable: "MODE"
615 local requiredCapability
616 local requiredPubCapability
631 # set the required key capability based on the mode
632 if [ "$MODE" = 'known_hosts' ] ; then
633 requiredCapability="$REQUIRED_HOST_KEY_CAPABILITY"
634 elif [ "$MODE" = 'authorized_keys' ] ; then
635 requiredCapability="$REQUIRED_USER_KEY_CAPABILITY"
637 requiredPubCapability=$(echo "$requiredCapability" | tr "[:lower:]" "[:upper:]")
639 # fetch the user ID if necessary/requested
640 gpg_fetch_userid "$userID"
642 # output gpg info for (exact) userid and store
643 gpgOut=$(gpg --list-key --fixed-list-mode --with-colon \
644 --with-fingerprint --with-fingerprint \
645 ="$userID" 2>/dev/null) || returnCode="$?"
647 # if the gpg query return code is not 0, return 1
648 if [ "$returnCode" -ne 0 ] ; then
649 log verbose " no primary keys found."
653 # loop over all lines in the gpg output and process.
654 echo "$gpgOut" | cut -d: -f1,2,5,10,12 | \
655 while IFS=: read -r type validity keyid uidfpr usage ; do
656 # process based on record type
658 'pub') # primary keys
659 # new key, wipe the slate
666 log verbose " primary key found: $keyid"
668 # if overall key is not valid, skip
669 if [ "$validity" != 'u' -a "$validity" != 'f' ] ; then
670 log debug " - unacceptable primary key validity ($validity)."
673 # if overall key is disabled, skip
674 if check_capability "$usage" 'D' ; then
675 log debug " - key disabled."
678 # if overall key capability is not ok, skip
679 if ! check_capability "$usage" $requiredPubCapability ; then
680 log debug " - unacceptable primary key capability ($usage)."
684 # mark overall key as ok
687 # mark primary key as ok if capability is ok
688 if check_capability "$usage" $requiredCapability ; then
693 if [ "$lastKey" != pub ] ; then
694 log verbose " ! got a user ID after a sub key?! user IDs should only follow primary keys!"
697 # if an acceptable user ID was already found, skip
698 if [ "$uidOK" = 'true' ] ; then
701 # if the user ID does matches...
702 if [ "$(echo "$uidfpr" | gpg_unescape)" = "$userID" ] ; then
703 # and the user ID validity is ok
704 if [ "$validity" = 'u' -o "$validity" = 'f' ] ; then
705 # mark user ID acceptable
708 log debug " - unacceptable user ID validity ($validity)."
714 # output a line for the primary key
716 if [ "$keyOK" -a "$uidOK" -a "$lastKeyOK" ] ; then
717 log verbose " * acceptable primary key."
718 if [ -z "$sshKey" ] ; then
719 log error " ! primary key could not be translated (not RSA?)."
724 log debug " - unacceptable primary key."
725 if [ -z "$sshKey" ] ; then
726 log debug " ! primary key could not be translated (not RSA?)."
733 # unset acceptability of last key
738 # don't bother with sub keys if the primary key is not valid
739 if [ "$keyOK" != true ] ; then
743 # don't bother with sub keys if no user ID is acceptable:
744 if [ "$uidOK" != true ] ; then
748 # if sub key validity is not ok, skip
749 if [ "$validity" != 'u' -a "$validity" != 'f' ] ; then
750 log debug " - unacceptable sub key validity ($validity)."
753 # if sub key capability is not ok, skip
754 if ! check_capability "$usage" $requiredCapability ; then
755 log debug " - unacceptable sub key capability ($usage)."
762 'fpr') # key fingerprint
763 fingerprint="$uidfpr"
765 sshKey=$(gpg2ssh "$fingerprint")
767 # if the last key was the pub key, skip
768 if [ "$lastKey" = pub ] ; then
772 # output a line for the sub key
774 if [ "$keyOK" -a "$uidOK" -a "$lastKeyOK" ] ; then
775 log verbose " * acceptable sub key."
776 if [ -z "$sshKey" ] ; then
777 log error " ! sub key could not be translated (not RSA?)."
782 log debug " - unacceptable sub key."
783 if [ -z "$sshKey" ] ; then
784 log debug " ! sub key could not be translated (not RSA?)."
791 done | sort -t: -k1 -n -r
792 # NOTE: this last sort is important so that the "good" keys (key
793 # flag '0') come last. This is so that they take precedence when
794 # being processed in the key files over "bad" keys (key flag '1')
797 # process a single host in the known_host file
798 process_host_known_hosts() {
808 # set the key processing mode
809 export MODE='known_hosts'
812 userID="ssh://${host}"
814 log verbose "processing: $host"
820 for line in $(process_user_id "${userID}") ; do
821 # note that key was found
824 ok=$(echo "$line" | cut -d: -f1)
825 sshKey=$(echo "$line" | cut -d: -f2)
827 if [ -z "$sshKey" ] ; then
831 # remove any old host key line, and note if removed nothing is
833 remove_line "$KNOWN_HOSTS" "$sshKey" || noKey=true
835 # if key OK, add new host line
836 if [ "$ok" -eq '0' ] ; then
837 # note that key was found ok
838 nKeysOK=$((nKeysOK+1))
841 if [ "$HASH_KNOWN_HOSTS" = 'true' ] ; then
842 # FIXME: this is really hackish cause ssh-keygen won't
843 # hash from stdin to stdout
844 tmpfile=$(mktemp ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX)
845 ssh2known_hosts "$host" "$sshKey" > "$tmpfile"
846 ssh-keygen -H -f "$tmpfile" 2>/dev/null
847 cat "$tmpfile" >> "$KNOWN_HOSTS"
848 rm -f "$tmpfile" "${tmpfile}.old"
850 ssh2known_hosts "$host" "$sshKey" >> "$KNOWN_HOSTS"
853 # log if this is a new key to the known_hosts file
854 if [ "$noKey" ] ; then
855 log info "* new key for $host added to known_hosts file."
860 # if at least one key was found...
861 if [ "$nKeys" -gt 0 ] ; then
862 # if ok keys were found, return 0
863 if [ "$nKeysOK" -gt 0 ] ; then
869 # if no keys were found, return 1
875 # update the known_hosts file for a set of hosts listed on command
877 update_known_hosts() {
885 # the number of hosts specified on command line
891 # touch the known_hosts file so that the file permission check
892 # below won't fail upon not finding the file
893 (umask 0022 && touch "$KNOWN_HOSTS")
895 # check permissions on the known_hosts file path
896 check_key_file_permissions $(whoami) "$KNOWN_HOSTS" || failure
898 # create a lockfile on known_hosts:
899 lock create "$KNOWN_HOSTS"
900 # FIXME: we're discarding any pre-existing EXIT trap; is this bad?
901 trap "lock remove $KNOWN_HOSTS" EXIT
903 # note pre update file checksum
904 fileCheck="$(file_hash "$KNOWN_HOSTS")"
908 process_host_known_hosts "$host" || returnCode="$?"
910 case "$returnCode" in
912 nHostsOK=$((nHostsOK+1))
915 nHostsBAD=$((nHostsBAD+1))
919 # touch the lockfile, for good measure.
920 lock touch "$KNOWN_HOSTS"
923 # remove the lockfile and the trap
924 lock remove "$KNOWN_HOSTS"
927 # note if the known_hosts file was updated
928 if [ "$(file_hash "$KNOWN_HOSTS")" != "$fileCheck" ] ; then
929 log debug "known_hosts file updated."
932 # if an acceptable host was found, return 0
933 if [ "$nHostsOK" -gt 0 ] ; then
935 # else if no ok hosts were found...
937 # if no bad host were found then no hosts were found at all,
939 if [ "$nHostsBAD" -eq 0 ] ; then
941 # else if at least one bad host was found, return 2
948 # process hosts from a known_hosts file
949 process_known_hosts() {
952 # exit if the known_hosts file does not exist
953 if [ ! -e "$KNOWN_HOSTS" ] ; then
954 failure "known_hosts file '$KNOWN_HOSTS' does not exist."
957 log debug "processing known_hosts file:"
958 log debug " $KNOWN_HOSTS"
960 hosts=$(meat "$KNOWN_HOSTS" | cut -d ' ' -f 1 | grep -v '^|.*$' | tr , ' ' | tr '\n' ' ')
962 if [ -z "$hosts" ] ; then
963 log debug "no hosts to process."
967 # take all the hosts from the known_hosts file (first
968 # field), grep out all the hashed hosts (lines starting
970 update_known_hosts $hosts
973 # process uids for the authorized_keys file
974 process_uid_authorized_keys() {
981 # set the key processing mode
982 export MODE='authorized_keys'
986 log verbose "processing: $userID"
992 for line in $(process_user_id "$userID") ; do
993 # note that key was found
996 ok=$(echo "$line" | cut -d: -f1)
997 sshKey=$(echo "$line" | cut -d: -f2)
999 if [ -z "$sshKey" ] ; then
1003 # remove the old host key line
1004 remove_line "$AUTHORIZED_KEYS" "$sshKey"
1006 # if key OK, add new host line
1007 if [ "$ok" -eq '0' ] ; then
1008 # note that key was found ok
1009 nKeysOK=$((nKeysOK+1))
1011 ssh2authorized_keys "$userID" "$sshKey" >> "$AUTHORIZED_KEYS"
1015 # if at least one key was found...
1016 if [ "$nKeys" -gt 0 ] ; then
1017 # if ok keys were found, return 0
1018 if [ "$nKeysOK" -gt 0 ] ; then
1024 # if no keys were found, return 1
1030 # update the authorized_keys files from a list of user IDs on command
1032 update_authorized_keys() {
1040 # the number of ids specified on command line
1046 log debug "updating authorized_keys file:"
1047 log debug " $AUTHORIZED_KEYS"
1049 # check permissions on the authorized_keys file path
1050 check_key_file_permissions $(whoami) "$AUTHORIZED_KEYS" || failure
1052 # create a lockfile on authorized_keys
1053 lock create "$AUTHORIZED_KEYS"
1054 # FIXME: we're discarding any pre-existing EXIT trap; is this bad?
1055 trap "lock remove $AUTHORIZED_KEYS" EXIT
1057 # note pre update file checksum
1058 fileCheck="$(file_hash "$AUTHORIZED_KEYS")"
1060 # remove any monkeysphere lines from authorized_keys file
1061 remove_monkeysphere_lines "$AUTHORIZED_KEYS"
1064 # process the user ID, change return code if key not found for
1066 process_uid_authorized_keys "$userID" || returnCode="$?"
1069 case "$returnCode" in
1071 nIDsOK=$((nIDsOK+1))
1074 nIDsBAD=$((nIDsBAD+1))
1078 # touch the lockfile, for good measure.
1079 lock touch "$AUTHORIZED_KEYS"
1082 # remove the lockfile and the trap
1083 lock remove "$AUTHORIZED_KEYS"
1088 # note if the authorized_keys file was updated
1089 if [ "$(file_hash "$AUTHORIZED_KEYS")" != "$fileCheck" ] ; then
1090 log debug "authorized_keys file updated."
1093 # if an acceptable id was found, return 0
1094 if [ "$nIDsOK" -gt 0 ] ; then
1096 # else if no ok ids were found...
1098 # if no bad ids were found then no ids were found at all, and
1100 if [ "$nIDsBAD" -eq 0 ] ; then
1102 # else if at least one bad id was found, return 2
1109 # process an authorized_user_ids file for authorized_keys
1110 process_authorized_user_ids() {
1115 authorizedUserIDs="$1"
1117 # exit if the authorized_user_ids file is empty
1118 if [ ! -e "$authorizedUserIDs" ] ; then
1119 failure "authorized_user_ids file '$authorizedUserIDs' does not exist."
1122 log debug "processing authorized_user_ids file:"
1123 log debug " $authorizedUserIDs"
1125 # check permissions on the authorized_user_ids file path
1126 check_key_file_permissions $(whoami) "$authorizedUserIDs" || failure
1128 if ! meat "$authorizedUserIDs" >/dev/null ; then
1129 log debug " no user IDs to process."
1135 # extract user IDs from authorized_user_ids file
1137 for line in $(meat "$authorizedUserIDs") ; do
1138 userIDs["$nline"]="$line"
1142 update_authorized_keys "${userIDs[@]}"
1145 # takes a gpg key or keys on stdin, and outputs a list of
1146 # fingerprints, one per line:
1147 list_primary_fingerprints() {
1148 local fake=$(msmktempdir)
1149 GNUPGHOME="$fake" gpg --no-tty --quiet --import
1150 GNUPGHOME="$fake" gpg --with-colons --fingerprint --list-keys | \
1151 awk -F: '/^fpr:/{ print $10 }'
1156 check_cruft_file() {
1160 if [ -e "$loc" ] ; then
1161 printf "! The file '%s' is no longer used by\n monkeysphere (as of version %s), and can be removed.\n\n" "$loc" "$version" | log info
1165 check_upgrade_dir() {
1169 if [ -d "$loc" ] ; then
1170 printf "The presence of directory '%s' indicates that you have\nnot yet completed a monkeysphere upgrade.\nYou should probably run the following script:\n %s/transitions/%s\n\n" "$loc" "$SYSSHAREDIR" "$version" | log info
1174 ## look for cruft from old versions of the monkeysphere, and notice if
1175 ## upgrades have not been run:
1177 check_upgrade_dir "${SYSCONFIGDIR}/gnupg-host" 0.23
1178 check_upgrade_dir "${SYSCONFIGDIR}/gnupg-authentication" 0.23
1180 check_cruft_file "${SYSCONFIGDIR}/gnupg-authentication.conf" 0.23
1181 check_cruft_file "${SYSCONFIGDIR}/gnupg-host.conf" 0.23
1184 for foo in "${SYSDATADIR}/backup-from-"*"-transition" ; do
1185 if [ -d "$foo" ] ; then
1186 printf "! %s\n" "$foo" | log info
1190 if [ "$found" ] ; then
1191 printf "The directories above are backups left over from a monkeysphere transition.\nThey may contain copies of sensitive data (host keys, certifier lists), but\nthey are no longer needed by monkeysphere.\nYou may remove them at any time.\n\n" | log info