Blame contrib/aide-attributes.sh

Packit 762fc5
#!/bin/bash
Packit 762fc5
Packit 762fc5
# Copyright © 2010 Hannes von Haugwitz <hannes@vonhaugwitz.com>
Packit 762fc5
Packit 762fc5
# This program is free software; you can redistribute it and/or modify
Packit 762fc5
# it under the terms of the GNU General Public License as published by
Packit 762fc5
# the Free Software Foundation; either version 2 of the License, or
Packit 762fc5
# (at your option) any later version.
Packit 762fc5
Packit 762fc5
# This program is distributed in the hope that it will be useful,
Packit 762fc5
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 762fc5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 762fc5
# GNU General Public License for more details.
Packit 762fc5
Packit 762fc5
# You should have received a copy of the GNU General Public License
Packit 762fc5
# along with this program; if not, write to the Free Software
Packit 762fc5
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
Packit 762fc5
Packit 762fc5
set -e
Packit 762fc5
set -u
Packit 762fc5
Packit 762fc5
attributes=( "filename" "linkname" "perm" "uid" "gid" "size" "atime" \
Packit 762fc5
    "ctime" "mtime" "inode" "bcount" "lnkcount" "md5" "sha1" \
Packit 762fc5
    "rmd160" "tiger" "crc32" "haval" "gost" "crc32b" "attr" \
Packit 762fc5
    "acl" "bsize" "rdev" "dev" "checkmask" "growingsize" "checkinode" \
Packit 762fc5
    "allownewfile" "allowrmfile" "sha256" "sha512"  "selinux" \
Packit 762fc5
    "xattrs" "whirlpool" "ftype" "e2fsattrs" )
Packit 762fc5
Packit 762fc5
NAME="aide-attributes"
Packit 762fc5
Packit 762fc5
err() {
Packit 762fc5
    echo "$NAME: $1!" >&2
Packit 762fc5
    echo "usage: $NAME HEX_NUMBER [HEX_NUMBER]"
Packit 762fc5
    exit $2
Packit 762fc5
}
Packit 762fc5
Packit 762fc5
dec2hex() {
Packit 762fc5
    let hex=0x$1 2> /dev/null || err "argument '$1' is no valid hex number" 2
Packit 762fc5
    if [ "$hex" -lt "0" ] || [ "$hex" -gt "$((2**${#attributes[@]}))" ] ; then
Packit 762fc5
        err "argument '$1' too large (> 2^${#attributes[@]})" 3
Packit 762fc5
    fi
Packit 762fc5
    echo "$hex"
Packit 762fc5
}
Packit 762fc5
Packit 762fc5
COMPARE=false
Packit 762fc5
Packit 762fc5
if [ -n "${1:-}" ] ; then
Packit 762fc5
    a=$(dec2hex $1)
Packit 762fc5
    if [ -n "${2:-}" ] ; then
Packit 762fc5
        COMPARE=true
Packit 762fc5
        b=$(dec2hex $2)
Packit 762fc5
        [ -n "${3:-}" ] && err "Too much arguments provided" 4
Packit 762fc5
    fi
Packit 762fc5
else
Packit 762fc5
    err "Not enough arguments provided" 1;
Packit 762fc5
fi
Packit 762fc5
Packit 762fc5
for (( i=0; i<${#attributes[@]}; i++ )) ; do
Packit 762fc5
    if $COMPARE ; then
Packit 762fc5
        if (( 2**$i & $a )) && ! (( 2**$i & $b )) ; then
Packit 762fc5
            echo "-"${attributes[$i]}
Packit 762fc5
        elif ! (( 2**$i & $a )) && (( 2**$i & $b )) ; then
Packit 762fc5
            echo "+"${attributes[$i]}
Packit 762fc5
        fi
Packit 762fc5
    else
Packit 762fc5
        if (( 2**$i & $a )) ; then
Packit 762fc5
            echo "${attributes[$i]}"
Packit 762fc5
        fi
Packit 762fc5
    fi
Packit 762fc5
done
Packit 762fc5
Packit 762fc5
exit 0