Add log output for keyserver checking.
[monkeysphere.git] / src / common
index 471e75a6143aa23138602c1d2ef85d65802d80fb..d1554a62c23ae9f44746d1e1114c0178d1d68f6a 100644 (file)
@@ -47,17 +47,17 @@ gpg_fetch_userid() {
 
     userID="$1"
 
-    # if CHECK_KEYSERVER variable set, check the keyserver
-    # for the user ID
-    if [ "CHECK_KEYSERVER" ] ; then
-       echo 1,2,3,4,5 | \
-           gpg --quiet --batch --command-fd 0 --with-colons \
-           --keyserver "$KEYSERVER" \
-           --search ="$userID" >/dev/null 2>&1
-
-    # otherwise just return true
+    log "checking keyserver $KEYSERVER..."
+    echo 1,2,3,4,5 | \
+       gpg --quiet --batch --command-fd 0 --with-colons \
+       --keyserver "$KEYSERVER" \
+       --search ="$userID" >/dev/null 2>&1
+    if [ "$?" = 0 ] ; then
+       log "  user ID found on keyserver."
+       return 0
     else
-       return
+       log "  user ID not found on keyserver."
+       return 1
     fi
 }
 
@@ -167,8 +167,11 @@ process_user_id() {
     fi
     requiredPubCapability=$(echo "$requiredCapability" | tr "[:lower:]" "[:upper:]")
 
-    # fetch keys from keyserver, return 1 if none found
-    gpg_fetch_userid "$userID" || return 1
+    # if CHECK_KEYSERVER variable set, check the keyserver
+    # for the user ID
+    if [ "$CHECK_KEYSERVER" = "true" ] ; then
+       gpg_fetch_userid "$userID"
+    fi
 
     # output gpg info for (exact) userid and store
     gpgOut=$(gpg --fixed-list-mode --list-key --with-colons \
@@ -176,7 +179,7 @@ process_user_id() {
 
     # return 1 if there only "tru" lines are output from gpg
     if [ -z "$(echo "$gpgOut" | grep -v '^tru:')" ] ; then
-       log "  key not found."
+       log "  key not found in keychain."
        return 1
     fi
 
@@ -268,14 +271,14 @@ process_user_id() {
     # key cache file
     if [ "$keyOK" -a "$uidOK" -a "${keyIDs[*]}" ] ; then
        for keyID in ${keyIDs[@]} ; do
-           log "  acceptable key/uid found."
+           log "  acceptable key/userID found."
 
            if [ "$MODE" = 'known_hosts' ] ; then
                # export the key
                gpg2known_hosts "$keyID" "$userID" >> \
                    "$cacheDir"/"$userIDHash"."$pubKeyID"
                # hash the cache file if specified
-               if [ "$HASH_KNOWN_HOSTS" ] ; then
+               if [ "$HASH_KNOWN_HOSTS" = "true" ] ; then
                    ssh-keygen -H -f "$cacheDir"/"$userIDHash"."$pubKeyID" > /dev/null 2>&1
                    rm "$cacheDir"/"$userIDHash"."$pubKeyID".old
                fi
@@ -408,7 +411,7 @@ update_authorized_keys() {
     else
        log "no gpg keys to add."
     fi
-    if [ "$userAuthorizedKeys" -a -s "$userAuthorizedKeys" ] ; then
+    if [ "$userAuthorizedKeys" != "-" -a -s "$userAuthorizedKeys" ] ; then
        log -n "adding user authorized_keys file... "
        cat "$userAuthorizedKeys" >> "$msAuthorizedKeys"
        echo "done."