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 # return the primary group of a user
488 get_primary_group() {
489 local uname=${1:-`whoami`}
490 groups "$uname" | sed 's/^..* : //' | awk '{ print $1 }'
493 ### CONVERSION UTILITIES
495 # output the ssh key for a given key ID
501 gpg --export "$keyID" | openpgp2ssh "$keyID" 2>/dev/null
504 # output known_hosts line from ssh key
510 # FIXME this does not properly deal with IPv6 hosts using the
511 # standard port (because it's unclear whether their final
512 # colon-delimited address section is a port number or an address
518 # specify the host and port properly for new ssh known_hosts
520 if [ "$port" != "$host" ] ; then
521 host="[${host}]:${port}"
523 printf "%s %s MonkeySphere%s\n" "$host" "$key" "$DATE"
526 # output authorized_keys line from ssh key
527 ssh2authorized_keys() {
534 printf "%s MonkeySphere%s %s\n" "$key" "$DATE" "$userID"
537 # convert key from gpg to ssh known_hosts format
546 key=$(gpg2ssh "$keyID")
548 # NOTE: it seems that ssh-keygen -R removes all comment fields from
549 # all lines in the known_hosts file. why?
550 # NOTE: just in case, the COMMENT can be matched with the
552 # '^MonkeySphere[[:digit:]]{4}(-[[:digit:]]{2}){2}T[[:digit:]]{2}(:[[:digit:]]{2}){2}$'
553 printf "%s %s MonkeySphere%s\n" "$host" "$key" "$DATE"
556 # convert key from gpg to ssh authorized_keys format
557 gpg2authorized_keys() {
565 key=$(gpg2ssh "$keyID")
567 # NOTE: just in case, the COMMENT can be matched with the
569 # '^MonkeySphere[[:digit:]]{4}(-[[:digit:]]{2}){2}T[[:digit:]]{2}(:[[:digit:]]{2}){2}$'
570 printf "%s MonkeySphere%s %s\n" "$key" "$DATE" "$userID"
575 # retrieve all keys with given user id from keyserver
576 # FIXME: need to figure out how to retrieve all matching keys
577 # (not just first N (5 in this case))
582 if [ "$CHECK_KEYSERVER" != 'true' ] ; then
588 log verbose " checking keyserver $KEYSERVER... "
590 gpg --quiet --batch --with-colons \
591 --command-fd 0 --keyserver "$KEYSERVER" \
592 --search ="$userID" &>/dev/null
598 ########################################################################
599 ### PROCESSING FUNCTIONS
601 # userid and key policy checking
602 # the following checks policy on the returned keys
603 # - checks that full key has appropriate valididy (u|f)
604 # - checks key has specified capability (REQUIRED_*_KEY_CAPABILITY)
605 # - checks that requested user ID has appropriate validity
606 # (see /usr/share/doc/gnupg/DETAILS.gz)
607 # output is one line for every found key, in the following format:
611 # "flag" is an acceptability flag, 0 = ok, 1 = bad
612 # "sshKey" is the translated gpg key
614 # all log output must go to stderr, as stdout is used to pass the
615 # flag:sshKey to the calling function.
617 # expects global variable: "MODE"
621 local requiredCapability
622 local requiredPubCapability
637 # set the required key capability based on the mode
638 if [ "$MODE" = 'known_hosts' ] ; then
639 requiredCapability="$REQUIRED_HOST_KEY_CAPABILITY"
640 elif [ "$MODE" = 'authorized_keys' ] ; then
641 requiredCapability="$REQUIRED_USER_KEY_CAPABILITY"
643 requiredPubCapability=$(echo "$requiredCapability" | tr "[:lower:]" "[:upper:]")
645 # fetch the user ID if necessary/requested
646 gpg_fetch_userid "$userID"
648 # output gpg info for (exact) userid and store
649 gpgOut=$(gpg --list-key --fixed-list-mode --with-colon \
650 --with-fingerprint --with-fingerprint \
651 ="$userID" 2>/dev/null) || returnCode="$?"
653 # if the gpg query return code is not 0, return 1
654 if [ "$returnCode" -ne 0 ] ; then
655 log verbose " no primary keys found."
659 # loop over all lines in the gpg output and process.
660 echo "$gpgOut" | cut -d: -f1,2,5,10,12 | \
661 while IFS=: read -r type validity keyid uidfpr usage ; do
662 # process based on record type
664 'pub') # primary keys
665 # new key, wipe the slate
672 log verbose " primary key found: $keyid"
674 # if overall key is not valid, skip
675 if [ "$validity" != 'u' -a "$validity" != 'f' ] ; then
676 log debug " - unacceptable primary key validity ($validity)."
679 # if overall key is disabled, skip
680 if check_capability "$usage" 'D' ; then
681 log debug " - key disabled."
684 # if overall key capability is not ok, skip
685 if ! check_capability "$usage" $requiredPubCapability ; then
686 log debug " - unacceptable primary key capability ($usage)."
690 # mark overall key as ok
693 # mark primary key as ok if capability is ok
694 if check_capability "$usage" $requiredCapability ; then
699 if [ "$lastKey" != pub ] ; then
700 log verbose " ! got a user ID after a sub key?! user IDs should only follow primary keys!"
703 # if an acceptable user ID was already found, skip
704 if [ "$uidOK" = 'true' ] ; then
707 # if the user ID does matches...
708 if [ "$(echo "$uidfpr" | gpg_unescape)" = "$userID" ] ; then
709 # and the user ID validity is ok
710 if [ "$validity" = 'u' -o "$validity" = 'f' ] ; then
711 # mark user ID acceptable
714 log debug " - unacceptable user ID validity ($validity)."
720 # output a line for the primary key
722 if [ "$keyOK" -a "$uidOK" -a "$lastKeyOK" ] ; then
723 log verbose " * acceptable primary key."
724 if [ -z "$sshKey" ] ; then
725 log error " ! primary key could not be translated (not RSA?)."
730 log debug " - unacceptable primary key."
731 if [ -z "$sshKey" ] ; then
732 log debug " ! primary key could not be translated (not RSA?)."
739 # unset acceptability of last key
744 # don't bother with sub keys if the primary key is not valid
745 if [ "$keyOK" != true ] ; then
749 # don't bother with sub keys if no user ID is acceptable:
750 if [ "$uidOK" != true ] ; then
754 # if sub key validity is not ok, skip
755 if [ "$validity" != 'u' -a "$validity" != 'f' ] ; then
756 log debug " - unacceptable sub key validity ($validity)."
759 # if sub key capability is not ok, skip
760 if ! check_capability "$usage" $requiredCapability ; then
761 log debug " - unacceptable sub key capability ($usage)."
768 'fpr') # key fingerprint
769 fingerprint="$uidfpr"
771 sshKey=$(gpg2ssh "$fingerprint")
773 # if the last key was the pub key, skip
774 if [ "$lastKey" = pub ] ; then
778 # output a line for the sub key
780 if [ "$keyOK" -a "$uidOK" -a "$lastKeyOK" ] ; then
781 log verbose " * acceptable sub key."
782 if [ -z "$sshKey" ] ; then
783 log error " ! sub key could not be translated (not RSA?)."
788 log debug " - unacceptable sub key."
789 if [ -z "$sshKey" ] ; then
790 log debug " ! sub key could not be translated (not RSA?)."
797 done | sort -t: -k1 -n -r
798 # NOTE: this last sort is important so that the "good" keys (key
799 # flag '0') come last. This is so that they take precedence when
800 # being processed in the key files over "bad" keys (key flag '1')
803 # process a single host in the known_host file
804 process_host_known_hosts() {
814 # set the key processing mode
815 export MODE='known_hosts'
818 userID="ssh://${host}"
820 log verbose "processing: $host"
826 for line in $(process_user_id "${userID}") ; do
827 # note that key was found
830 ok=$(echo "$line" | cut -d: -f1)
831 sshKey=$(echo "$line" | cut -d: -f2)
833 if [ -z "$sshKey" ] ; then
837 # remove any old host key line, and note if removed nothing is
839 remove_line "$KNOWN_HOSTS" "$sshKey" || noKey=true
841 # if key OK, add new host line
842 if [ "$ok" -eq '0' ] ; then
843 # note that key was found ok
844 nKeysOK=$((nKeysOK+1))
847 if [ "$HASH_KNOWN_HOSTS" = 'true' ] ; then
848 # FIXME: this is really hackish cause ssh-keygen won't
849 # hash from stdin to stdout
850 tmpfile=$(mktemp ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX)
851 ssh2known_hosts "$host" "$sshKey" > "$tmpfile"
852 ssh-keygen -H -f "$tmpfile" 2>/dev/null
853 cat "$tmpfile" >> "$KNOWN_HOSTS"
854 rm -f "$tmpfile" "${tmpfile}.old"
856 ssh2known_hosts "$host" "$sshKey" >> "$KNOWN_HOSTS"
859 # log if this is a new key to the known_hosts file
860 if [ "$noKey" ] ; then
861 log info "* new key for $host added to known_hosts file."
866 # if at least one key was found...
867 if [ "$nKeys" -gt 0 ] ; then
868 # if ok keys were found, return 0
869 if [ "$nKeysOK" -gt 0 ] ; then
875 # if no keys were found, return 1
881 # update the known_hosts file for a set of hosts listed on command
883 update_known_hosts() {
891 # the number of hosts specified on command line
897 # touch the known_hosts file so that the file permission check
898 # below won't fail upon not finding the file
899 if [ ! -f "$KNOWN_HOSTS" ]; then
900 [ -d $(dirname "$KNOWN_HOSTS") ] || mkdir -m 0700 $(dirname "$KNOWN_HOSTS")
904 # check permissions on the known_hosts file path
905 check_key_file_permissions $(whoami) "$KNOWN_HOSTS" || failure
907 # create a lockfile on known_hosts:
908 lock create "$KNOWN_HOSTS"
909 # FIXME: we're discarding any pre-existing EXIT trap; is this bad?
910 trap "lock remove $KNOWN_HOSTS" EXIT
912 # note pre update file checksum
913 fileCheck="$(file_hash "$KNOWN_HOSTS")"
917 process_host_known_hosts "$host" || returnCode="$?"
919 case "$returnCode" in
921 nHostsOK=$((nHostsOK+1))
924 nHostsBAD=$((nHostsBAD+1))
928 # touch the lockfile, for good measure.
929 lock touch "$KNOWN_HOSTS"
932 # remove the lockfile and the trap
933 lock remove "$KNOWN_HOSTS"
936 # note if the known_hosts file was updated
937 if [ "$(file_hash "$KNOWN_HOSTS")" != "$fileCheck" ] ; then
938 log debug "known_hosts file updated."
941 # if an acceptable host was found, return 0
942 if [ "$nHostsOK" -gt 0 ] ; then
944 # else if no ok hosts were found...
946 # if no bad host were found then no hosts were found at all,
948 if [ "$nHostsBAD" -eq 0 ] ; then
950 # else if at least one bad host was found, return 2
957 # process hosts from a known_hosts file
958 process_known_hosts() {
961 # exit if the known_hosts file does not exist
962 if [ ! -e "$KNOWN_HOSTS" ] ; then
963 failure "known_hosts file '$KNOWN_HOSTS' does not exist."
966 log debug "processing known_hosts file:"
967 log debug " $KNOWN_HOSTS"
969 hosts=$(meat "$KNOWN_HOSTS" | cut -d ' ' -f 1 | grep -v '^|.*$' | tr , ' ' | tr '\n' ' ')
971 if [ -z "$hosts" ] ; then
972 log debug "no hosts to process."
976 # take all the hosts from the known_hosts file (first
977 # field), grep out all the hashed hosts (lines starting
979 update_known_hosts $hosts
982 # process uids for the authorized_keys file
983 process_uid_authorized_keys() {
990 # set the key processing mode
991 export MODE='authorized_keys'
995 log verbose "processing: $userID"
1001 for line in $(process_user_id "$userID") ; do
1002 # note that key was found
1005 ok=$(echo "$line" | cut -d: -f1)
1006 sshKey=$(echo "$line" | cut -d: -f2)
1008 if [ -z "$sshKey" ] ; then
1012 # remove the old host key line
1013 remove_line "$AUTHORIZED_KEYS" "$sshKey"
1015 # if key OK, add new host line
1016 if [ "$ok" -eq '0' ] ; then
1017 # note that key was found ok
1018 nKeysOK=$((nKeysOK+1))
1020 ssh2authorized_keys "$userID" "$sshKey" >> "$AUTHORIZED_KEYS"
1024 # if at least one key was found...
1025 if [ "$nKeys" -gt 0 ] ; then
1026 # if ok keys were found, return 0
1027 if [ "$nKeysOK" -gt 0 ] ; then
1033 # if no keys were found, return 1
1039 # update the authorized_keys files from a list of user IDs on command
1041 update_authorized_keys() {
1049 # the number of ids specified on command line
1055 log debug "updating authorized_keys file:"
1056 log debug " $AUTHORIZED_KEYS"
1058 # check permissions on the authorized_keys file path
1059 check_key_file_permissions $(whoami) "$AUTHORIZED_KEYS" || failure
1061 # create a lockfile on authorized_keys
1062 lock create "$AUTHORIZED_KEYS"
1063 # FIXME: we're discarding any pre-existing EXIT trap; is this bad?
1064 trap "lock remove $AUTHORIZED_KEYS" EXIT
1066 # note pre update file checksum
1067 fileCheck="$(file_hash "$AUTHORIZED_KEYS")"
1069 # remove any monkeysphere lines from authorized_keys file
1070 remove_monkeysphere_lines "$AUTHORIZED_KEYS"
1073 # process the user ID, change return code if key not found for
1075 process_uid_authorized_keys "$userID" || returnCode="$?"
1078 case "$returnCode" in
1080 nIDsOK=$((nIDsOK+1))
1083 nIDsBAD=$((nIDsBAD+1))
1087 # touch the lockfile, for good measure.
1088 lock touch "$AUTHORIZED_KEYS"
1091 # remove the lockfile and the trap
1092 lock remove "$AUTHORIZED_KEYS"
1097 # note if the authorized_keys file was updated
1098 if [ "$(file_hash "$AUTHORIZED_KEYS")" != "$fileCheck" ] ; then
1099 log debug "authorized_keys file updated."
1102 # if an acceptable id was found, return 0
1103 if [ "$nIDsOK" -gt 0 ] ; then
1105 # else if no ok ids were found...
1107 # if no bad ids were found then no ids were found at all, and
1109 if [ "$nIDsBAD" -eq 0 ] ; then
1111 # else if at least one bad id was found, return 2
1118 # process an authorized_user_ids file for authorized_keys
1119 process_authorized_user_ids() {
1124 authorizedUserIDs="$1"
1126 # exit if the authorized_user_ids file is empty
1127 if [ ! -e "$authorizedUserIDs" ] ; then
1128 failure "authorized_user_ids file '$authorizedUserIDs' does not exist."
1131 log debug "processing authorized_user_ids file:"
1132 log debug " $authorizedUserIDs"
1134 # check permissions on the authorized_user_ids file path
1135 check_key_file_permissions $(whoami) "$authorizedUserIDs" || failure
1137 if ! meat "$authorizedUserIDs" >/dev/null ; then
1138 log debug " no user IDs to process."
1144 # extract user IDs from authorized_user_ids file
1146 for line in $(meat "$authorizedUserIDs") ; do
1147 userIDs["$nline"]="$line"
1151 update_authorized_keys "${userIDs[@]}"
1154 # takes a gpg key or keys on stdin, and outputs a list of
1155 # fingerprints, one per line:
1156 list_primary_fingerprints() {
1157 local fake=$(msmktempdir)
1158 GNUPGHOME="$fake" gpg --no-tty --quiet --import
1159 GNUPGHOME="$fake" gpg --with-colons --fingerprint --list-keys | \
1160 awk -F: '/^fpr:/{ print $10 }'
1165 check_cruft_file() {
1169 if [ -e "$loc" ] ; then
1170 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
1174 check_upgrade_dir() {
1178 if [ -d "$loc" ] ; then
1179 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
1183 ## look for cruft from old versions of the monkeysphere, and notice if
1184 ## upgrades have not been run:
1186 check_upgrade_dir "${SYSCONFIGDIR}/gnupg-host" 0.23
1187 check_upgrade_dir "${SYSCONFIGDIR}/gnupg-authentication" 0.23
1189 check_cruft_file "${SYSCONFIGDIR}/gnupg-authentication.conf" 0.23
1190 check_cruft_file "${SYSCONFIGDIR}/gnupg-host.conf" 0.23
1193 for foo in "${SYSDATADIR}/backup-from-"*"-transition" ; do
1194 if [ -d "$foo" ] ; then
1195 printf "! %s\n" "$foo" | log info
1199 if [ "$found" ] ; then
1200 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