Merge commit 'micah/master'
[monkeysphere.git] / src / common
index 297e7f344c9d39686c94c1097ee587a142e51455..ef931ca4bc7a20282be621bfa533830c9cfef8bb 100644 (file)
@@ -1,9 +1,10 @@
 # -*-shell-script-*-
+# This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
 
 # Shared sh functions for the monkeysphere
 #
 # Written by
-# Jameson Rollins <jrollins@fifthhorseman.net>
+# Jameson Rollins <jrollins@finestructure.net>
 # Jamie McClelland <jm@mayfirst.org>
 # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
 #
@@ -19,6 +20,9 @@
 SYSCONFIGDIR=${MONKEYSPHERE_SYSCONFIGDIR:-"/etc/monkeysphere"}
 export SYSCONFIGDIR
 
+# monkeysphere version
+VERSION=__VERSION__
+
 ########################################################################
 ### UTILITY FUNCTIONS
 
@@ -147,7 +151,7 @@ advance_date() {
     local shortunits
 
     # try things the GNU way first 
-    if date -d "$number $longunits" "$format" >&/dev/null ; then
+    if date -d "$number $longunits" "$format" >/dev/null 2>&1; then
        date -d "$number $longunits" "$format"
     else
        # otherwise, convert to (a limited version of) BSD date syntax:
@@ -639,7 +643,7 @@ process_user_id() {
                ;;
            'uid') # user ids
                if [ "$lastKey" != pub ] ; then
-                   log verbose " - got a user ID after a sub key?!  user IDs should only follow primary keys!"
+                   log verbose " ! got a user ID after a sub key?!  user IDs should only follow primary keys!"
                    continue
                fi
                # if an acceptable user ID was already found, skip
@@ -652,6 +656,8 @@ process_user_id() {
                    if [ "$validity" = 'u' -o "$validity" = 'f' ] ; then
                        # mark user ID acceptable
                        uidOK=true
+                   else
+                       log debug "  - unacceptable user ID validity ($validity)."
                    fi
                else
                    continue
@@ -669,7 +675,7 @@ process_user_id() {
                else
                    log debug "  - unacceptable primary key."
                    if [ -z "$sshKey" ] ; then
-                       log error "    ! primary key could not be translated (not RSA or DSA?)."
+                       log debug "    ! primary key could not be translated (not RSA or DSA?)."
                    else
                        echo "1:${sshKey}"
                    fi
@@ -693,10 +699,12 @@ process_user_id() {
                
                # if sub key validity is not ok, skip
                if [ "$validity" != 'u' -a "$validity" != 'f' ] ; then
+                   log debug "  - unacceptable sub key validity ($validity)."
                    continue
                fi
                # if sub key capability is not ok, skip
                if ! check_capability "$usage" $requiredCapability ; then
+                   log debug "  - unacceptable sub key capability ($usage)."
                    continue
                fi
 
@@ -725,7 +733,7 @@ process_user_id() {
                else
                    log debug "  - unacceptable sub key."
                    if [ -z "$sshKey" ] ; then
-                       log error "    ! sub key could not be translated (not RSA or DSA?)."
+                       log debug "    ! sub key could not be translated (not RSA or DSA?)."
                    else
                        echo "1:${sshKey}"
                    fi
@@ -742,6 +750,7 @@ process_user_id() {
 process_host_known_hosts() {
     local host
     local userID
+    local noKey=
     local nKeys
     local nKeysOK
     local ok
@@ -768,8 +777,9 @@ process_host_known_hosts() {
             continue
         fi
 
-       # remove the old host key line, and note if removed
-       remove_line "$KNOWN_HOSTS" "$sshKey"
+       # remove any old host key line, and note if removed nothing is
+       # removed
+       remove_line "$KNOWN_HOSTS" "$sshKey" || noKey=true
 
        # if key OK, add new host line
        if [ "$ok" -eq '0' ] ; then
@@ -788,6 +798,11 @@ process_host_known_hosts() {
            else
                ssh2known_hosts "$host" "$sshKey" >> "$KNOWN_HOSTS"
            fi
+
+           # log if this is a new key to the known_hosts file
+           if [ "$noKey" ] ; then
+               log info "* new key for $host added to known_hosts file."
+           fi
        fi
     done