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, 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 ########################################################################
20 SYSCONFIGDIR=${MONKEYSPHERE_SYSCONFIGDIR:-"/etc/monkeysphere"}
23 # monkeysphere version
26 ########################################################################
29 # failure function. exits with code 255, unless specified otherwise.
31 [ "$1" ] && echo "$1" >&2
35 # write output to stderr based on specified LOG_LEVEL the first
36 # parameter is the priority of the output, and everything else is what
37 # is echoed to stderr. If there is nothing else, then output comes
38 # from stdin, and is not prefaced by log prefix.
46 # don't include SILENT in alllevels: it's handled separately
47 # list in decreasing verbosity (all caps).
48 # separate with $IFS explicitly, since we do some fancy footwork
50 alllevels="DEBUG${IFS}VERBOSE${IFS}INFO${IFS}ERROR"
52 # translate lowers to uppers in global log level
53 LOG_LEVEL=$(echo "$LOG_LEVEL" | tr "[:lower:]" "[:upper:]")
55 # just go ahead and return if the log level is silent
56 if [ "$LOG_LEVEL" = 'SILENT' ] ; then
60 for level in $alllevels ; do
61 if [ "$LOG_LEVEL" = "$level" ] ; then
65 if [ -z "$found" ] ; then
70 # get priority from first parameter, translating all lower to
72 priority=$(echo "$1" | tr "[:lower:]" "[:upper:]")
75 # scan over available levels
76 for level in $alllevels ; do
77 # output if the log level matches, set output to true
78 # this will output for all subsequent loops as well.
79 if [ "$LOG_LEVEL" = "$level" ] ; then
82 if [ "$priority" = "$level" -a "$output" = 'true' ] ; then
93 # run command as monkeysphere user
94 su_monkeysphere_user() {
95 # our main goal here is to run the given command as the the
96 # monkeysphere user, but without prompting for any sort of
97 # authentication. If this is not possible, we should just fail.
99 # FIXME: our current implementation is overly restrictive, because
100 # there may be some su PAM configurations that would allow su
101 # "$MONKEYSPHERE_USER" -c "$@" to Just Work without prompting,
102 # allowing specific users to invoke commands which make use of
105 # chpst (from runit) would be nice to use, but we don't want to
106 # introduce an extra dependency just for this. This may be a
107 # candidate for re-factoring if we switch implementation languages.
110 # if monkeysphere user, run the command under bash
111 "$MONKEYSPHERE_USER")
115 # if root, su command as monkeysphere user
117 su "$MONKEYSPHERE_USER" -c "$@"
122 log error "non-privileged user."
127 # cut out all comments(#) and blank lines from standard input
129 grep -v -e "^[[:space:]]*#" -e '^$' "$1"
132 # cut a specified line from standard input
134 head --line="$1" "$2" | tail -1
137 # this is a wrapper for doing lock functions.
139 # it lets us depend on either lockfile-progs (preferred) or procmail's
140 # lockfile, and should
142 local use_lockfileprogs=true
146 if ! ( which lockfile-create >/dev/null 2>/dev/null ) ; then
147 if ! ( which lockfile >/dev/null ); then
148 failure "Neither lockfile-create nor lockfile are in the path!"
155 if [ -n "$use_lockfileprogs" ] ; then
156 lockfile-create "$file" || failure "unable to lock '$file'"
158 lockfile -r 20 "${file}.lock" || failure "unable to lock '$file'"
160 log debug "lock created on '$file'."
163 if [ -n "$use_lockfileprogs" ] ; then
164 lockfile-touch --oneshot "$file"
168 log debug "lock touched on '$file'."
171 if [ -n "$use_lockfileprogs" ] ; then
172 lockfile-remove "$file"
176 log debug "lock removed on '$file'."
179 failure "bad argument for lock subfunction '$action'"
184 # for portability, between gnu date and BSD date.
185 # arguments should be: number longunits format
187 # e.g. advance_date 20 seconds +%F
195 # try things the GNU way first
196 if date -d "$number $longunits" "$format" >/dev/null 2>&1; then
197 date -d "$number $longunits" "$format"
199 # otherwise, convert to (a limited version of) BSD date syntax:
223 # this is a longshot, and will likely fail; oh well.
224 shortunits="$longunits"
226 date "-v+${number}${shortunits}" "$format"
231 # check that characters are in a string (in an AND fashion).
232 # used for checking key capability
233 # check_capability capability a [b...]
242 if echo "$usage" | grep -q -v "$capcheck" ; then
251 md5sum "$1" 2> /dev/null
254 # convert escaped characters in pipeline from gpg output back into
256 # FIXME: undo all escape character translation in with-colons gpg
262 # convert nasty chars into gpg-friendly form in pipeline
263 # FIXME: escape everything, not just colons!
268 # prompt for GPG-formatted expiration, and emit result on stdout
269 get_gpg_expiration() {
274 if [ -z "$keyExpire" ]; then
276 Please specify how long the key should be valid.
277 0 = key does not expire
278 <n> = key expires in n days
279 <n>w = key expires in n weeks
280 <n>m = key expires in n months
281 <n>y = key expires in n years
283 while [ -z "$keyExpire" ] ; do
284 read -p "Key is valid for? (0) " keyExpire
285 if ! test_gpg_expire ${keyExpire:=0} ; then
286 echo "invalid value" >&2
290 elif ! test_gpg_expire "$keyExpire" ; then
291 failure "invalid key expiration value '$keyExpire'."
297 passphrase_prompt() {
302 if [ "$DISPLAY" ] && which "${SSH_ASKPASS:-ssh-askpass}" >/dev/null; then
303 "${SSH_ASKPASS:-ssh-askpass}" "$prompt" > "$fifo"
305 read -s -p "$prompt" PASS
306 # Uses the builtin echo, so should not put the passphrase into
307 # the process table. I think. --dkg
308 echo "$PASS" > "$fifo"
312 test_gnu_dummy_s2k_extension() {
314 # this block contains a demonstration private key that has had the
315 # primary key stripped out using the GNU S2K extension known as
316 # "gnu-dummy" (see /usr/share/doc/gnupg/DETAILS.gz). The subkey is
317 # present in cleartext, however.
319 # openpgp2ssh will be able to deal with this based on whether the
320 # local copy of GnuTLS contains read_s2k support that can handle it.
322 # read up on that here:
324 # http://lists.gnu.org/archive/html/gnutls-devel/2008-08/msg00005.html
327 -----BEGIN PGP PRIVATE KEY BLOCK-----
328 Version: GnuPG v1.4.9 (GNU/Linux)
330 lQCVBEO3YdABBACRqqEnucag4+vyZny2M67Pai5+5suIRRvY+Ly8Ms5MvgCi3EVV
331 xT05O/+0ShiRaf+QicCOFrhbU9PZzzU+seEvkeW2UCu4dQfILkmj+HBEIltGnHr3
332 G0yegHj5pnqrcezERURf2e17gGFWX91cXB9Cm721FPXczuKraphKwCA9PwARAQAB
333 /gNlAkdOVQG0OURlbW9uc3RyYXRpb24gS2V5IGZvciBTMksgR05VIGV4dGVuc2lv
334 biAxMDAxIC0tIGdudS1kdW1teYi8BBMBAgAmBQJDt2HQAhsDBQkB4TOABgsJCAcD
335 AgQVAggDBBYCAwECHgECF4AACgkQQZUwSa4UDezTOQP/TMQXUVrWzHYZGopoPZ2+
336 ZS3qddiznBHsgb7MGYg1KlTiVJSroDUBCHIUJvdQKZV9zrzrFl47D07x6hGyUPHV
337 aZXvuITW8t1o5MMHkCy3pmJ2KgfDvdUxrBvLfgPMICA4c6zA0mWquee43syEW9NY
338 g3q61iPlQwD1J1kX1wlimLCdAdgEQ7dh0AEEANAwa63zlQbuy1Meliy8otwiOa+a
339 mH6pxxUgUNggjyjO5qx+rl25mMjvGIRX4/L1QwIBXJBVi3SgvJW1COZxZqBYqj9U
340 8HVT07mWKFEDf0rZLeUE2jTm16cF9fcW4DQhW+sfYm+hi2sY3HeMuwlUBK9KHfW2
341 +bGeDzVZ4pqfUEudABEBAAEAA/0bemib+wxub9IyVFUp7nPobjQC83qxLSNzrGI/
342 RHzgu/5CQi4tfLOnwbcQsLELfker2hYnjsLrT9PURqK4F7udrWEoZ1I1LymOtLG/
343 4tNZ7Mnul3wRC2tCn7FKx8sGJwGh/3li8vZ6ALVJAyOia5TZ/buX0+QZzt6+hPKk
344 7MU1WQIA4bUBjtrsqDwro94DvPj3/jBnMZbXr6WZIItLNeVDUcM8oHL807Am97K1
345 ueO/f6v1sGAHG6lVPTmtekqPSTWBfwIA7CGFvEyvSALfB8NUa6jtk27NCiw0csql
346 kuhCmwXGMVOiryKEfegkIahf2bAd/gnWHPrpWp7bUE20v8YoW22I4wIAhnm5Wr5Q
347 Sy7EHDUxmJm5TzadFp9gq08qNzHBpXSYXXJ3JuWcL1/awUqp3tE1I6zZ0hZ38Ia6
348 SdBMN88idnhDPqPoiKUEGAECAA8FAkO3YdACGyAFCQHhM4AACgkQQZUwSa4UDezm
349 vQP/ZhK+2ly9oI2z7ZcNC/BJRch0/ybQ3haahII8pXXmOThpZohr/LUgoWgCZdXg
350 vP6yiszNk2tIs8KphCAw7Lw/qzDC2hEORjWO4f46qk73RAgSqG/GyzI4ltWiDhqn
351 vnQCFl3+QFSe4zinqykHnLwGPMXv428d/ZjkIc2ju8dRsn4=
353 -----END PGP PRIVATE KEY BLOCK-----
354 " | openpgp2ssh 4129E89D17C1D591 >/dev/null 2>/dev/null
358 # remove all lines with specified string from specified file
367 if [ -z "$file" -o -z "$string" ] ; then
371 if [ ! -e "$file" ] ; then
375 # if the string is in the file...
376 if grep -q -F "$string" "$file" 2> /dev/null ; then
377 tempfile=$(mktemp "${file}.XXXXXXX") || \
378 failure "Unable to make temp file '${file}.XXXXXXX'"
380 # remove the line with the string, and return 0
381 grep -v -F "$string" "$file" >"$tempfile"
382 cat "$tempfile" > "$file"
391 # remove all lines with MonkeySphere strings in file
392 remove_monkeysphere_lines() {
398 if [ -z "$file" ] ; then
402 if [ ! -e "$file" ] ; then
406 tempfile=$(mktemp "${file}.XXXXXXX") || \
407 failure "Could not make temporary file '${file}.XXXXXXX'."
409 egrep -v '^MonkeySphere[[:digit:]]{4}(-[[:digit:]]{2}){2}T[[:digit:]]{2}(:[[:digit:]]{2}){2}$' \
411 cat "$tempfile" > "$file"
415 # translate ssh-style path variables %h and %u
416 translate_ssh_variables() {
423 # get the user's home directory
424 userHome=$(getent passwd "$uname" | cut -d: -f6)
426 # translate '%u' to user name
427 path=${path/\%u/"$uname"}
428 # translate '%h' to user home directory
429 path=${path/\%h/"$userHome"}
434 # test that a string to conforms to GPG's expiration format
436 echo "$1" | egrep -q "^[0-9]+[mwy]?$"
439 # check that a file is properly owned, and that all it's parent
440 # directories are not group/other writable
441 check_key_file_permissions() {
449 # function to check that the given permission corresponds to writability
457 log debug "checking path permission '$path'..."
459 # return 255 if cannot stat file
460 if ! stat=$(ls -ld "$path" 2>/dev/null) ; then
461 log error "could not stat path '$path'."
465 owner=$(echo "$stat" | awk '{ print $3 }')
466 gAccess=$(echo "$stat" | cut -c6)
467 oAccess=$(echo "$stat" | cut -c9)
469 # return 1 if path has invalid owner
470 if [ "$owner" != "$uname" -a "$owner" != 'root' ] ; then
471 log error "improper ownership on path '$path'."
475 # return 2 if path has group or other writability
476 if is_write "$gAccess" || is_write "$oAccess" ; then
477 log error "improper group or other writability on path '$path'."
481 # return zero if all clear, or go to next path
482 if [ "$path" = '/' ] ; then
485 check_key_file_permissions "$uname" $(dirname "$path")
489 ### CONVERSION UTILITIES
491 # output the ssh key for a given key ID
497 gpg --export "$keyID" | openpgp2ssh "$keyID" 2> /dev/null
500 # output known_hosts line from ssh key
509 echo -n "$key" | tr -d '\n'
510 echo " MonkeySphere${DATE}"
513 # output authorized_keys line from ssh key
514 ssh2authorized_keys() {
521 echo -n "$key" | tr -d '\n'
522 echo " MonkeySphere${DATE} ${userID}"
525 # convert key from gpg to ssh known_hosts format
533 # NOTE: it seems that ssh-keygen -R removes all comment fields from
534 # all lines in the known_hosts file. why?
535 # NOTE: just in case, the COMMENT can be matched with the
537 # '^MonkeySphere[[:digit:]]{4}(-[[:digit:]]{2}){2}T[[:digit:]]{2}(:[[:digit:]]{2}){2}$'
539 gpg2ssh "$keyID" | tr -d '\n'
540 echo " MonkeySphere${DATE}"
543 # convert key from gpg to ssh authorized_keys format
544 gpg2authorized_keys() {
551 # NOTE: just in case, the COMMENT can be matched with the
553 # '^MonkeySphere[[:digit:]]{4}(-[[:digit:]]{2}){2}T[[:digit:]]{2}(:[[:digit:]]{2}){2}$'
554 gpg2ssh "$keyID" | tr -d '\n'
555 echo " MonkeySphere${DATE} ${userID}"
560 # retrieve all keys with given user id from keyserver
561 # FIXME: need to figure out how to retrieve all matching keys
562 # (not just first N (5 in this case))
567 if [ "$CHECK_KEYSERVER" != 'true' ] ; then
573 log verbose " checking keyserver $KEYSERVER... "
575 gpg --quiet --batch --with-colons \
576 --command-fd 0 --keyserver "$KEYSERVER" \
577 --search ="$userID" > /dev/null 2>&1
583 ########################################################################
584 ### PROCESSING FUNCTIONS
586 # userid and key policy checking
587 # the following checks policy on the returned keys
588 # - checks that full key has appropriate valididy (u|f)
589 # - checks key has specified capability (REQUIRED_*_KEY_CAPABILITY)
590 # - checks that requested user ID has appropriate validity
591 # (see /usr/share/doc/gnupg/DETAILS.gz)
592 # output is one line for every found key, in the following format:
596 # "flag" is an acceptability flag, 0 = ok, 1 = bad
597 # "sshKey" is the translated gpg key
599 # all log output must go to stderr, as stdout is used to pass the
600 # flag:sshKey to the calling function.
602 # expects global variable: "MODE"
605 local requiredCapability
606 local requiredPubCapability
621 # set the required key capability based on the mode
622 if [ "$MODE" = 'known_hosts' ] ; then
623 requiredCapability="$REQUIRED_HOST_KEY_CAPABILITY"
624 elif [ "$MODE" = 'authorized_keys' ] ; then
625 requiredCapability="$REQUIRED_USER_KEY_CAPABILITY"
627 requiredPubCapability=$(echo "$requiredCapability" | tr "[:lower:]" "[:upper:]")
629 # fetch the user ID if necessary/requested
630 gpg_fetch_userid "$userID"
632 # output gpg info for (exact) userid and store
633 gpgOut=$(gpg --list-key --fixed-list-mode --with-colon \
634 --with-fingerprint --with-fingerprint \
635 ="$userID" 2>/dev/null)
637 # if the gpg query return code is not 0, return 1
638 if [ "$?" -ne 0 ] ; then
639 log verbose " no primary keys found."
643 # loop over all lines in the gpg output and process.
644 echo "$gpgOut" | cut -d: -f1,2,5,10,12 | \
645 while IFS=: read -r type validity keyid uidfpr usage ; do
646 # process based on record type
648 'pub') # primary keys
649 # new key, wipe the slate
656 log verbose " primary key found: $keyid"
658 # if overall key is not valid, skip
659 if [ "$validity" != 'u' -a "$validity" != 'f' ] ; then
660 log debug " - unacceptable primary key validity ($validity)."
663 # if overall key is disabled, skip
664 if check_capability "$usage" 'D' ; then
665 log debug " - key disabled."
668 # if overall key capability is not ok, skip
669 if ! check_capability "$usage" $requiredPubCapability ; then
670 log debug " - unacceptable primary key capability ($usage)."
674 # mark overall key as ok
677 # mark primary key as ok if capability is ok
678 if check_capability "$usage" $requiredCapability ; then
683 if [ "$lastKey" != pub ] ; then
684 log verbose " ! got a user ID after a sub key?! user IDs should only follow primary keys!"
687 # if an acceptable user ID was already found, skip
688 if [ "$uidOK" = 'true' ] ; then
691 # if the user ID does matches...
692 if [ "$(echo "$uidfpr" | gpg_unescape)" = "$userID" ] ; then
693 # and the user ID validity is ok
694 if [ "$validity" = 'u' -o "$validity" = 'f' ] ; then
695 # mark user ID acceptable
698 log debug " - unacceptable user ID validity ($validity)."
704 # output a line for the primary key
706 if [ "$keyOK" -a "$uidOK" -a "$lastKeyOK" ] ; then
707 log verbose " * acceptable primary key."
708 if [ -z "$sshKey" ] ; then
709 log error " ! primary key could not be translated (not RSA or DSA?)."
714 log debug " - unacceptable primary key."
715 if [ -z "$sshKey" ] ; then
716 log debug " ! primary key could not be translated (not RSA or DSA?)."
723 # unset acceptability of last key
728 # don't bother with sub keys if the primary key is not valid
729 if [ "$keyOK" != true ] ; then
733 # don't bother with sub keys if no user ID is acceptable:
734 if [ "$uidOK" != true ] ; then
738 # if sub key validity is not ok, skip
739 if [ "$validity" != 'u' -a "$validity" != 'f' ] ; then
740 log debug " - unacceptable sub key validity ($validity)."
743 # if sub key capability is not ok, skip
744 if ! check_capability "$usage" $requiredCapability ; then
745 log debug " - unacceptable sub key capability ($usage)."
752 'fpr') # key fingerprint
753 fingerprint="$uidfpr"
755 sshKey=$(gpg2ssh "$fingerprint")
757 # if the last key was the pub key, skip
758 if [ "$lastKey" = pub ] ; then
762 # output a line for the sub key
764 if [ "$keyOK" -a "$uidOK" -a "$lastKeyOK" ] ; then
765 log verbose " * acceptable sub key."
766 if [ -z "$sshKey" ] ; then
767 log error " ! sub key could not be translated (not RSA or DSA?)."
772 log debug " - unacceptable sub key."
773 if [ -z "$sshKey" ] ; then
774 log debug " ! sub key could not be translated (not RSA or DSA?)."
781 done | sort -t: -k1 -n -r
782 # NOTE: this last sort is important so that the "good" keys (key
783 # flag '0') come last. This is so that they take precedence when
784 # being processed in the key files over "bad" keys (key flag '1')
787 # process a single host in the known_host file
788 process_host_known_hosts() {
799 userID="ssh://${host}"
801 log verbose "processing: $host"
807 for line in $(process_user_id "${userID}") ; do
808 # note that key was found
811 ok=$(echo "$line" | cut -d: -f1)
812 sshKey=$(echo "$line" | cut -d: -f2)
814 if [ -z "$sshKey" ] ; then
818 # remove any old host key line, and note if removed nothing is
820 remove_line "$KNOWN_HOSTS" "$sshKey" || noKey=true
822 # if key OK, add new host line
823 if [ "$ok" -eq '0' ] ; then
824 # note that key was found ok
825 nKeysOK=$((nKeysOK+1))
828 if [ "$HASH_KNOWN_HOSTS" = 'true' ] ; then
829 # FIXME: this is really hackish cause ssh-keygen won't
830 # hash from stdin to stdout
831 tmpfile=$(mktemp ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX)
832 ssh2known_hosts "$host" "$sshKey" > "$tmpfile"
833 ssh-keygen -H -f "$tmpfile" 2> /dev/null
834 cat "$tmpfile" >> "$KNOWN_HOSTS"
835 rm -f "$tmpfile" "${tmpfile}.old"
837 ssh2known_hosts "$host" "$sshKey" >> "$KNOWN_HOSTS"
840 # log if this is a new key to the known_hosts file
841 if [ "$noKey" ] ; then
842 log info "* new key for $host added to known_hosts file."
847 # if at least one key was found...
848 if [ "$nKeys" -gt 0 ] ; then
849 # if ok keys were found, return 0
850 if [ "$nKeysOK" -gt 0 ] ; then
856 # if no keys were found, return 1
862 # update the known_hosts file for a set of hosts listed on command
864 update_known_hosts() {
871 # the number of hosts specified on command line
877 # create a lockfile on known_hosts:
878 lock create "$KNOWN_HOSTS"
879 # FIXME: we're discarding any pre-existing EXIT trap; is this bad?
880 trap "lock remove $KNOWN_HOSTS" EXIT
882 # note pre update file checksum
883 fileCheck="$(file_hash "$KNOWN_HOSTS")"
887 process_host_known_hosts "$host"
891 nHostsOK=$((nHostsOK+1))
894 nHostsBAD=$((nHostsBAD+1))
898 # touch the lockfile, for good measure.
899 lock touch "$KNOWN_HOSTS"
902 # remove the lockfile and the trap
903 lock remove "$KNOWN_HOSTS"
906 # note if the known_hosts file was updated
907 if [ "$(file_hash "$KNOWN_HOSTS")" != "$fileCheck" ] ; then
908 log debug "known_hosts file updated."
911 # if an acceptable host was found, return 0
912 if [ "$nHostsOK" -gt 0 ] ; then
914 # else if no ok hosts were found...
916 # if no bad host were found then no hosts were found at all,
918 if [ "$nHostsBAD" -eq 0 ] ; then
920 # else if at least one bad host was found, return 2
927 # process hosts from a known_hosts file
928 process_known_hosts() {
931 log debug "processing known_hosts file..."
933 hosts=$(meat "$KNOWN_HOSTS" | cut -d ' ' -f 1 | grep -v '^|.*$' | tr , ' ' | tr '\n' ' ')
935 if [ -z "$hosts" ] ; then
936 log debug "no hosts to process."
940 # take all the hosts from the known_hosts file (first
941 # field), grep out all the hashed hosts (lines starting
943 update_known_hosts $hosts
946 # process uids for the authorized_keys file
947 process_uid_authorized_keys() {
956 log verbose "processing: $userID"
962 for line in $(process_user_id "$userID") ; do
963 # note that key was found
966 ok=$(echo "$line" | cut -d: -f1)
967 sshKey=$(echo "$line" | cut -d: -f2)
969 if [ -z "$sshKey" ] ; then
973 # remove the old host key line
974 remove_line "$AUTHORIZED_KEYS" "$sshKey"
976 # if key OK, add new host line
977 if [ "$ok" -eq '0' ] ; then
978 # note that key was found ok
979 nKeysOK=$((nKeysOK+1))
981 ssh2authorized_keys "$userID" "$sshKey" >> "$AUTHORIZED_KEYS"
985 # if at least one key was found...
986 if [ "$nKeys" -gt 0 ] ; then
987 # if ok keys were found, return 0
988 if [ "$nKeysOK" -gt 0 ] ; then
994 # if no keys were found, return 1
1000 # update the authorized_keys files from a list of user IDs on command
1002 update_authorized_keys() {
1009 # the number of ids specified on command line
1015 # create a lockfile on authorized_keys
1016 lock create "$AUTHORIZED_KEYS"
1017 # FIXME: we're discarding any pre-existing EXIT trap; is this bad?
1018 trap "lock remove $AUTHORIZED_KEYS" EXIT
1020 # note pre update file checksum
1021 fileCheck="$(file_hash "$AUTHORIZED_KEYS")"
1023 # remove any monkeysphere lines from authorized_keys file
1024 remove_monkeysphere_lines "$AUTHORIZED_KEYS"
1027 # process the user ID, change return code if key not found for
1029 process_uid_authorized_keys "$userID"
1034 nIDsOK=$((nIDsOK+1))
1037 nIDsBAD=$((nIDsBAD+1))
1041 # touch the lockfile, for good measure.
1042 lock touch "$AUTHORIZED_KEYS"
1045 # remove the lockfile and the trap
1046 lock remove "$AUTHORIZED_KEYS"
1051 # note if the authorized_keys file was updated
1052 if [ "$(file_hash "$AUTHORIZED_KEYS")" != "$fileCheck" ] ; then
1053 log debug "authorized_keys file updated."
1056 # if an acceptable id was found, return 0
1057 if [ "$nIDsOK" -gt 0 ] ; then
1059 # else if no ok ids were found...
1061 # if no bad ids were found then no ids were found at all, and
1063 if [ "$nIDsBAD" -eq 0 ] ; then
1065 # else if at least one bad id was found, return 2
1072 # process an authorized_user_ids file for authorized_keys
1073 process_authorized_user_ids() {
1078 authorizedUserIDs="$1"
1080 log debug "processing authorized_user_ids file..."
1082 if ! meat "$authorizedUserIDs" > /dev/null ; then
1083 log debug " no user IDs to process."
1089 # extract user IDs from authorized_user_ids file
1091 for line in $(meat "$authorizedUserIDs") ; do
1092 userIDs["$nline"]="$line"
1096 update_authorized_keys "${userIDs[@]}"