ProgrammersOfVilnius / pov-check-health

Debian package that runs basic system health monitoring checks hourly from cron
https://launchpad.net/~pov/+archive/ppa
2 stars 0 forks source link

Wishlist: check_ownership #6

Closed mgedmin closed 5 years ago

mgedmin commented 9 years ago

I want to check for incorrect file permissions. Scifi:

check_ownership root:root /some/directory
check_ownership user /path
check_ownership :group /path
mgedmin commented 9 years ago

Here's a working implementation

check_ownership() {
    info_check check_ownership "$@"
    user=${1%:*}
    group=${1#*:}
    filename=$2
    if [ -n "$user" ]; then
        actual_user=$(stat -c %U $filename)
        [ "$user" = "$actual_user" ] || warn "$filename: bad ownership ($actual_user instead of $user)"
    fi
    if [ -n "$group" ]; then
        actual_group=$(stat -c %G $filename)
        [ "$group" = "$actual_group" ] || warn "$filename: bad group ownership ($actual_user instead of $user)"
    fi
}

It lacks some error handling perhaps.

mgedmin commented 5 years ago

I don't currently need this.