X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=src%2Fcommon;h=2b05c3c992c5eb6a10e5c07a6c6a14324b4110d5;hb=d076f454cf6c576681749ae7f31dec1bc2b52833;hp=f93793e65958768ab7e7dc3d3848339803d41ba3;hpb=bb2427c28bf40179c4881b22c23f23f9bea78f55;p=monkeysphere.git diff --git a/src/common b/src/common index f93793e..2b05c3c 100644 --- a/src/common +++ b/src/common @@ -4,6 +4,8 @@ # # Written by # Jameson Rollins +# Jamie McClelland +# Daniel Kahn Gillmor # # Copyright 2008, released under the GPL, version 3 or later @@ -33,6 +35,14 @@ log() { local priority local level local output + local alllevels + local found= + + # don't include SILENT in alllevels: it's handled separately + # list in decreasing verbosity (all caps). + # separate with $IFS explicitly, since we do some fancy footwork + # elsewhere. + alllevels="DEBUG${IFS}VERBOSE${IFS}INFO${IFS}ERROR" # translate lowers to uppers in global log level LOG_LEVEL=$(echo "$LOG_LEVEL" | tr "[:lower:]" "[:upper:]") @@ -42,16 +52,25 @@ log() { return fi + for level in $alllevels ; do + if [ "$LOG_LEVEL" = "$level" ] ; then + found=true + fi + done + if [ -z "$found" ] ; then + # default to INFO: + LOG_LEVEL=INFO + fi + # get priority from first parameter, translating all lower to # uppers priority=$(echo "$1" | tr "[:lower:]" "[:upper:]") shift # scan over available levels - # list in decreasing verbosity (all caps) - for level in DEBUG INFO ERROR ; do + for level in $alllevels ; do # output if the log level matches, set output to true - # this will output for all subsequenty loops as well. + # this will output for all subsequent loops as well. if [ "$LOG_LEVEL" = "$level" ] ; then output=true fi @@ -203,6 +222,7 @@ vnQCFl3+QFSe4zinqykHnLwGPMXv428d/ZjkIc2ju8dRsn4= remove_line() { local file local string + local tempfile file="$1" string="$2" @@ -217,8 +237,13 @@ remove_line() { # if the string is in the file... if grep -q -F "$string" "$file" 2> /dev/null ; then + tempfile=$(mktemp "${file}.XXXXXXX") || \ + failure "Unable to make temp file '${file}.XXXXXXX'" + # remove the line with the string, and return 0 - grep -v -F "$string" "$file" | sponge "$file" + grep -v -F "$string" "$file" >"$tempfile" + cat "$tempfile" > "$file" + rm "$tempfile" return 0 # otherwise return 1 else @@ -229,6 +254,7 @@ remove_line() { # remove all lines with MonkeySphere strings in file remove_monkeysphere_lines() { local file + local tempfile file="$1" @@ -240,8 +266,13 @@ remove_monkeysphere_lines() { return 1 fi + tempfile=$(mktemp "${file}.XXXXXXX") || \ + failure "Could not make temporary file '${file}.XXXXXXX'." + egrep -v '^MonkeySphere[[:digit:]]{4}(-[[:digit:]]{2}){2}T[[:digit:]]{2}(:[[:digit:]]{2}){2}$' \ - "$file" | sponge "$file" + "$file" >"$tempfile" + cat "$tempfile" > "$file" + rm "$tempfile" } # translate ssh-style path variables %h and %u @@ -466,7 +497,7 @@ process_user_id() { # if the gpg query return code is not 0, return 1 if [ "$?" -ne 0 ] ; then - log error " no primary keys found." + log verbose " no primary keys found." return 1 fi @@ -483,7 +514,7 @@ process_user_id() { lastKeyOK= fingerprint= - log error " primary key found: $keyid" + log verbose " primary key found: $keyid" # if overall key is not valid, skip if [ "$validity" != 'u' -a "$validity" != 'f' ] ; then @@ -532,7 +563,7 @@ process_user_id() { # output a line for the primary key # 0 = ok, 1 = bad if [ "$keyOK" -a "$uidOK" -a "$lastKeyOK" ] ; then - log error " * acceptable primary key." + log verbose " * acceptable primary key." if [ -z "$sshKey" ] ; then log error " ! primary key could not be translated (not RSA or DSA?)." else @@ -588,7 +619,7 @@ process_user_id() { # output a line for the sub key # 0 = ok, 1 = bad if [ "$keyOK" -a "$uidOK" -a "$lastKeyOK" ] ; then - log error " * acceptable sub key." + log verbose " * acceptable sub key." if [ -z "$sshKey" ] ; then log error " ! sub key could not be translated (not RSA or DSA?)." else @@ -623,7 +654,7 @@ process_host_known_hosts() { host="$1" userID="ssh://${host}" - log info "processing: $host" + log verbose "processing: $host" nKeys=0 nKeysOK=0 @@ -724,7 +755,7 @@ update_known_hosts() { # note if the known_hosts file was updated if [ "$(file_hash "$KNOWN_HOSTS")" != "$fileCheck" ] ; then - log info "known_hosts file updated." + log verbose "known_hosts file updated." fi # if an acceptable host was found, return 0 @@ -747,7 +778,7 @@ update_known_hosts() { process_known_hosts() { local hosts - log info "processing known_hosts file..." + log verbose "processing known_hosts file..." hosts=$(meat "$KNOWN_HOSTS" | cut -d ' ' -f 1 | grep -v '^|.*$' | tr , ' ' | tr '\n' ' ') @@ -772,7 +803,7 @@ process_uid_authorized_keys() { userID="$1" - log info "processing: $userID" + log verbose "processing: $userID" nKeys=0 nKeysOK=0 @@ -867,7 +898,7 @@ update_authorized_keys() { # note if the authorized_keys file was updated if [ "$(file_hash "$AUTHORIZED_KEYS")" != "$fileCheck" ] ; then - log info "authorized_keys file updated." + log verbose "authorized_keys file updated." fi # if an acceptable id was found, return 0 @@ -894,7 +925,7 @@ process_authorized_user_ids() { authorizedUserIDs="$1" - log info "processing authorized_user_ids file..." + log verbose "processing authorized_user_ids file..." if ! meat "$authorizedUserIDs" > /dev/null ; then log error "no user IDs to process."