date -d "$number $longunits" "$format"
else
# otherwise, convert to (a limited version of) BSD date syntax:
date -d "$number $longunits" "$format"
else
# otherwise, convert to (a limited version of) BSD date syntax:
# check that a file is properly owned, and that all it's parent
# directories are not group/other writable
check_key_file_permissions() {
# check that a file is properly owned, and that all it's parent
# directories are not group/other writable
check_key_file_permissions() {
- # return 0 is path does not exist
- [ -e "$path" ] || return 0
+ # return 255 if cannot stat file
+ if ! stat=$(ls -ld "$path" 2>/dev/null) ; then
+ log error "could not stat path '$path'."
+ return 255
+ fi
- owner=$(ls -l "$path" | awk '{ print $3 }')
- gAccess=$(ls -l "$path" | cut -c6)
- oAccess=$(ls -l "$path" | cut -c9)
+ owner=$(echo "$stat" | awk '{ print $3 }')
+ gAccess=$(echo "$stat" | cut -c6)
+ oAccess=$(echo "$stat" | cut -c9)
- # check owner
- if [ "$owner" != "$user" -a "$owner" != 'root' ] ; then
+ # return 1 if path has invalid owner
+ if [ "$owner" != "$uname" -a "$owner" != 'root' ] ; then
+ log error "improper ownership on path '$path'."
# if overall key is not valid, skip
if [ "$validity" != 'u' -a "$validity" != 'f' ] ; then
# if overall key is not valid, skip
if [ "$validity" != 'u' -a "$validity" != 'f' ] ; then
continue
fi
# if overall key is disabled, skip
if check_capability "$usage" 'D' ; then
continue
fi
# if overall key is disabled, skip
if check_capability "$usage" 'D' ; then
continue
fi
# if overall key capability is not ok, skip
if ! check_capability "$usage" $requiredPubCapability ; then
continue
fi
# if overall key capability is not ok, skip
if ! check_capability "$usage" $requiredPubCapability ; then
# if sub key validity is not ok, skip
if [ "$validity" != 'u' -a "$validity" != 'f' ] ; then
# if sub key validity is not ok, skip
if [ "$validity" != 'u' -a "$validity" != 'f' ] ; then
continue
fi
# if sub key capability is not ok, skip
if ! check_capability "$usage" $requiredCapability ; then
continue
fi
# if sub key capability is not ok, skip
if ! check_capability "$usage" $requiredCapability ; then
- # 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
# if key OK, add new host line
if [ "$ok" -eq '0' ] ; then
# note if the known_hosts file was updated
if [ "$(file_hash "$KNOWN_HOSTS")" != "$fileCheck" ] ; then
# note if the known_hosts file was updated
if [ "$(file_hash "$KNOWN_HOSTS")" != "$fileCheck" ] ; then
hosts=$(meat "$KNOWN_HOSTS" | cut -d ' ' -f 1 | grep -v '^|.*$' | tr , ' ' | tr '\n' ' ')
if [ -z "$hosts" ] ; then
hosts=$(meat "$KNOWN_HOSTS" | cut -d ' ' -f 1 | grep -v '^|.*$' | tr , ' ' | tr '\n' ' ')
if [ -z "$hosts" ] ; then
# note if the authorized_keys file was updated
if [ "$(file_hash "$AUTHORIZED_KEYS")" != "$fileCheck" ] ; then
# note if the authorized_keys file was updated
if [ "$(file_hash "$AUTHORIZED_KEYS")" != "$fileCheck" ] ; then