~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to utils/aa-decode

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2011-04-27 10:38:07 UTC
  • mfrom: (5.1.118 natty)
  • Revision ID: james.westby@ubuntu.com-20110427103807-ym3rhwys6o84ith0
Tags: 2.6.1-2
debian/copyright: clarify for some full organization names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
#    Copyright (C) 2009-2010 Canonical Ltd.
 
4
#
 
5
#    This program is free software; you can redistribute it and/or
 
6
#    modify it under the terms of version 2 of the GNU General Public
 
7
#    License as published by the Free Software Foundation.
 
8
#
 
9
#    This program is distributed in the hope that it will be useful,
 
10
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
#    GNU General Public License for more details.
 
13
#
 
14
#    You should have received a copy of the GNU General Public License
 
15
#    along with this program; if not, contact Canonical, Ltd.
 
16
#
 
17
 
 
18
set -e
 
19
 
 
20
help() {
 
21
    cat <<EOM
 
22
USAGE: aa-decode [OPTIONS] <encoded string>
 
23
Decode a hex-encoded string to ASCII. It will also take an audit log on
 
24
standard input and convert any hex-encoded AppArmor log entries and display
 
25
them on standard output.
 
26
 
 
27
OPTIONS:
 
28
  --help        display this help
 
29
 
 
30
EXAMPLES:
 
31
$ aa-decode 2F746D702F666F6F20626172
 
32
Decoded: /tmp/foo bar
 
33
$ cat /var/log/kern.log | aa-decode
 
34
... denied_mask="r::" fsuid=1000 ouid=1000 name=/tmp/foo bar
 
35
EOM
 
36
}
 
37
 
 
38
decode() {
 
39
    decoded=`perl -le "\\$s = '$1' ; print pack 'H*', \\$s"`
 
40
    echo "$decoded"
 
41
}
 
42
 
 
43
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
 
44
    help
 
45
    exit
 
46
fi
 
47
 
 
48
# if have an argument, then use it, otherwise process stdin
 
49
if [ -n "$1" ]; then
 
50
    e=`echo "$1" | tr -s '[:lower:]' '[:upper:]'`
 
51
    if ! echo "$e" | egrep -q "^[0-9A-F]+$" ; then
 
52
        echo "String should only contain hex characters (0-9, a-f, A-F)"
 
53
        return
 
54
    fi
 
55
 
 
56
    d=`decode $e`
 
57
    if [ -z "$d" ]; then
 
58
        echo "Could not decode string"
 
59
        exit 1
 
60
    fi
 
61
 
 
62
    echo "Decoded: $d"
 
63
    exit 0
 
64
fi
 
65
 
 
66
# For now just look at 'name=...' which is usually the last in the log entry,
 
67
# so validate input against this and output based on it.
 
68
# TODO: better handle other cases too
 
69
egrep ' name=2[fF][0-9a-fA-F]*$' | while read line ; do
 
70
    e=`echo "$line" | sed 's/.* name=\(.*\)/\\1/g' | tr -s '[:lower:]' '[:upper:]'`
 
71
    d=`decode $e`
 
72
    echo -n "$line" | sed "s/\(.*\) name=.*/\1 name=/g"
 
73
    echo "'$d'"
 
74
done
 
75