X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=src%2Fcommon;h=5d92b26f0a283d6cc1ea4d113eb54f9a3fd5696b;hb=1732c334d09f2c4de4d16f10dba1daa971b67fbc;hp=c8a7db65425523a59d84ec7aab094e384db96100;hpb=5c3ec72ee2c2f5a0d6d942b0998ba8cc3369f608;p=monkeysphere.git diff --git a/src/common b/src/common index c8a7db6..5d92b26 100644 --- a/src/common +++ b/src/common @@ -16,8 +16,8 @@ ### COMMON VARIABLES # managed directories -ETC="/etc/monkeysphere" -export ETC +SYSCONFIGDIR=${MONKEYSPHERE_SYSCONFIGDIR:-"/etc/monkeysphere"} +export SYSCONFIGDIR ######################################################################## ### UTILITY FUNCTIONS @@ -134,6 +134,54 @@ lock() { esac } + +# for portability, between gnu date and BSD date. +# arguments should be: number longunits format + +# e.g. advance_date 20 seconds +%F +advance_date() { + local gnutry + local number="$1" + local longunits="$2" + local format="$3" + local shortunits + + # try things the GNU way first + if date -d "$number $longunits" "$format" >&/dev/null ; then + date -d "$number $longunits" "$format" + else + # otherwise, convert to (a limited version of) BSD date syntax: + case "$longunits" in + years) + shortunits=y + ;; + months) + shortunits=m + ;; + weeks) + shortunits=w + ;; + days) + shortunits=d + ;; + hours) + shortunits=H + ;; + minutes) + shortunits=M + ;; + seconds) + shortunits=S + ;; + *) + # this is a longshot, and will likely fail; oh well. + shortunits="$longunits" + esac + date "-v+${number}${shortunits}" "$format" + fi +} + + # check that characters are in a string (in an AND fashion). # used for checking key capability # check_capability capability a [b...] @@ -351,9 +399,9 @@ check_key_file_permissions() { local gAccess local oAccess - # function to check that an octal corresponds to writability + # function to check that the given permission corresponds to writability is_write() { - [ "$1" -eq 2 -o "$1" -eq 3 -o "$1" -eq 6 -o "$1" -eq 7 ] + [ "$1" = "w" ] } user="$1" @@ -362,10 +410,9 @@ check_key_file_permissions() { # return 0 is path does not exist [ -e "$path" ] || return 0 - owner=$(stat --format '%U' "$path") - access=$(stat --format '%a' "$path") - gAccess=$(echo "$access" | cut -c2) - oAccess=$(echo "$access" | cut -c3) + owner=$(ls -l "$path" | awk '{ print $3 }') + gAccess=$(ls -l "$path" | cut -c6) + oAccess=$(ls -l "$path" | cut -c9) # check owner if [ "$owner" != "$user" -a "$owner" != 'root' ] ; then @@ -468,7 +515,7 @@ gpg_fetch_userid() { userID="$1" - log info " checking keyserver $KEYSERVER... " + log verbose " checking keyserver $KEYSERVER... " echo 1,2,3,4,5 | \ gpg --quiet --batch --with-colons \ --command-fd 0 --keyserver "$KEYSERVER" \ @@ -561,17 +608,17 @@ process_user_id() { # if overall key is not valid, skip if [ "$validity" != 'u' -a "$validity" != 'f' ] ; then - log error " - unacceptable primary key validity ($validity)." + log debug " - unacceptable primary key validity ($validity)." continue fi # if overall key is disabled, skip if check_capability "$usage" 'D' ; then - log error " - key disabled." + log debug " - key disabled." continue fi # if overall key capability is not ok, skip if ! check_capability "$usage" $requiredPubCapability ; then - log error " - unacceptable primary key capability ($usage)." + log debug " - unacceptable primary key capability ($usage)." continue fi @@ -585,7 +632,7 @@ process_user_id() { ;; 'uid') # user ids if [ "$lastKey" != pub ] ; then - log error " - 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 @@ -613,7 +660,7 @@ process_user_id() { echo "0:${sshKey}" fi else - log error " - unacceptable primary key." + log debug " - unacceptable primary key." if [ -z "$sshKey" ] ; then log error " ! primary key could not be translated (not RSA or DSA?)." else @@ -669,7 +716,7 @@ process_user_id() { echo "0:${sshKey}" fi else - log error " - unacceptable sub key." + log debug " - unacceptable sub key." if [ -z "$sshKey" ] ; then log error " ! sub key could not be translated (not RSA or DSA?)." else @@ -798,7 +845,7 @@ update_known_hosts() { # note if the known_hosts file was updated if [ "$(file_hash "$KNOWN_HOSTS")" != "$fileCheck" ] ; then - log verbose "known_hosts file updated." + log debug "known_hosts file updated." fi # if an acceptable host was found, return 0 @@ -821,12 +868,12 @@ update_known_hosts() { process_known_hosts() { local hosts - log verbose "processing known_hosts file..." + log debug "processing known_hosts file..." hosts=$(meat "$KNOWN_HOSTS" | cut -d ' ' -f 1 | grep -v '^|.*$' | tr , ' ' | tr '\n' ' ') if [ -z "$hosts" ] ; then - log error "no hosts to process." + log debug "no hosts to process." return fi @@ -941,7 +988,7 @@ update_authorized_keys() { # note if the authorized_keys file was updated if [ "$(file_hash "$AUTHORIZED_KEYS")" != "$fileCheck" ] ; then - log verbose "authorized_keys file updated." + log debug "authorized_keys file updated." fi # if an acceptable id was found, return 0 @@ -968,10 +1015,10 @@ process_authorized_user_ids() { authorizedUserIDs="$1" - log verbose "processing authorized_user_ids file..." + log debug "processing authorized_user_ids file..." if ! meat "$authorizedUserIDs" > /dev/null ; then - log error "no user IDs to process." + log debug "no user IDs to process." return fi