bin/mocksetup: /var/cache/mock: -u: Fix.
[nethome.git] / bin / lsexec
1 #!/bin/bash
2 # Copyright (C) 2003, 2004 Red Hat, Inc.
3 # Written by Ingo Molnar and Ulrich Drepper
4 if [ "$#" != "1" ]; then
5   echo "usage: lsexec [ <PID> | process name | --all ]"
6   exit 1
7 fi
8 if ! test -f /etc/redhat-release; then
9   echo "this script is written for RHEL or Fedora Core"
10   exit 1
11 fi
12
13 cd /proc
14
15 printit() {
16     if [ -r $1/maps ]; then
17      echo -n $(basename $(readlink $1/exe))
18      printf ", PID %6d: " $1
19      if [ -r $1/exe ]; then
20        if eu-readelf -h $1/exe|egrep -q 'Type:[[:space:]]*EXEC'; then
21          echo -n -e '\033[31mno PIE\033[m, '
22        else
23          if eu-readelf -d $1/exe|egrep -q '  DEBUG[[:space:]]*$'; then
24            echo -n -e '\033[32mPIE\033[m, '
25            if eu-readelf -d $1/exe|fgrep -q TEXTREL; then
26              echo -n -e '\033[31mTEXTREL\033[m, '
27            fi
28           else
29            echo -n -e '\033[33mDSO\033[m, '
30           fi
31        fi
32        if eu-readelf -l $1/exe|fgrep -q 'GNU_RELRO'; then
33          if eu-readelf -d $1/exe|fgrep -q 'BIND_NOW'; then
34            if eu-readelf -l $1/exe|fgrep -q ' .got] .data .bss'; then
35              echo -n -e '\033[32mfull RELRO\033[m, '
36            else
37              echo -n -e '\033[31mincorrect RELRO\033[m, '
38            fi
39          else
40            echo -n -e '\033[33mpartial RELRO\033[m, '
41          fi
42        else
43          echo -n -e '\033[31mno RELRO\033[m, '
44        fi
45      fi
46      lastpg=$(sed -n '/^[[:xdigit:]]*-[[:xdigit:]]* rw.. \([[:xdigit:]]*\) 00:00 0$/p' $1/maps|
47               tail -n 1)
48      if echo "$lastpg" | egrep -v -q ' rwx. '; then
49        lastpg=""
50      fi
51      if [ -z "$lastpg" ] || [ -z "$(echo $lastpg||cut -d ' ' -f3|tr -d 0)" ]; then
52        echo -e '\033[32mExec-Shield enabled\033[m'
53      else
54       echo -e '\033[31mExec-Shield disabled\033[m'
55       for N in `awk '{print $6}' $1/maps  | egrep '\.so|bin/' | grep '^/' | sort -u`; do
56         NE=$(eu-readelf -l $N | fgrep STACK | fgrep 'RW ')
57         if [ "$NE" = "" ]; then
58           echo " => $N disables Exec-Shield!"
59         fi
60       done
61      fi
62     fi
63 }
64
65 if [ -d $1 ]; then
66   printit $1
67   exit 0
68 fi
69
70 if [ "$1" = "--all" ]; then
71    for N in [1-9]*; do
72      if [ $N != $$ ] && readlink -q $N/exe > /dev/null; then
73        printit $N
74      fi
75    done
76    exit 0
77 fi
78
79 for N in `/sbin/pidof $1`; do
80  if [ -d $N ]; then
81   printit $N
82  fi
83 done