~ubuntu-branches/ubuntu/vivid/ctdb/vivid-proposed

« back to all changes in this revision

Viewing changes to tests/eventscripts/stubs/nmap

  • Committer: Package Import Robot
  • Author(s): Mathieu Parent
  • Date: 2011-11-06 15:18:59 UTC
  • mfrom: (1.2.14)
  • Revision ID: package-import@ubuntu.com-20111106151859-41lblk8ml4es7ra3
Tags: 1.11+git20111102-1
* New upstream release
  - removed 92-apache-service-enable.diff: integrated 
  - removed 99-fix-broken-readdir-test.diff: integrated
* d/rules, d/control, d/compat:
  - converted to dh (% target and dh_auto_*)
  - moved to compat level 9 (buildeps upgraded)
  - dh9 enabled hardening build flags
  - added hardening=+bindnow
  - dh9 enabled multiarch
    + Don't use /use/lib64 on ppc64 (Closes: #644907)
    + libctdb-dev is Multi-Arch: same
    + removed 10_no-lib64.diff: not needed with multiarch
* ctdb.init:
  - removed gettext support
  - synced with upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
prog="nmap"
 
4
 
 
5
# Pretty that we're the shell and that this command could not be
 
6
# found.
 
7
if [ "$FAKE_NMAP_NOT_FOUND" = "yes" ] ; then
 
8
    echo "sh: ${prog}: command not found" >&2
 
9
    exit 127
 
10
fi
 
11
 
 
12
usage ()
 
13
{
 
14
    cat >&2 <<EOF
 
15
Usage: $prog -n -oG - -PS 127.0.0.1 -p <port>[,<port> ...]
 
16
 
 
17
A fake nmap stub that prints items depending on the variable
 
18
FAKE_TCP_LISTEN and the ports specified.
 
19
 
 
20
Note that all options apart from -p are ignored.
 
21
 
 
22
EOF
 
23
    exit 1
 
24
}
 
25
 
 
26
ports=""
 
27
 
 
28
parse_options ()
 
29
{
 
30
    _temp=$(getopt -n "$prog" -a -o "np:" -l help -l PS: -l oG: -- "$@")
 
31
 
 
32
    [ $? != 0 ] && usage
 
33
 
 
34
    eval set -- "$_temp"
 
35
 
 
36
    while true ; do
 
37
        case "$1" in
 
38
            -n) shift ;;
 
39
            --oG|--PS) shift 2 ;;
 
40
            -p) ports="${ports}${ports:+ }${2//,/ }" ; shift 2 ;;
 
41
            --) shift ; break ;;
 
42
            -h|--help|*) usage ;; # * shouldn't happen, so this is reasonable.
 
43
        esac
 
44
    done
 
45
 
 
46
    [ $# -gt 0 ] && usage
 
47
 
 
48
    [ -n "$ports" ] || usage
 
49
}
 
50
 
 
51
# For printing out...
 
52
args="$*"
 
53
 
 
54
parse_options "$@"
 
55
 
 
56
port_states=""
 
57
 
 
58
for p in $ports ; do
 
59
    pn=$(getent services "$p" | sed -e 's@[[:space:]].*@@')
 
60
    for i in $FAKE_TCP_LISTEN ; do
 
61
        lp="${i##*:}"
 
62
        if [ "$p" = "$lp" ] ; then
 
63
            port_states="${port_states}${port_states:+, }${p}/open/tcp//${pn}///"
 
64
            continue 2
 
65
        fi
 
66
    done
 
67
    port_states="${port_states}${port_states:+, }${p}/closed/tcp//${pn}///"
 
68
done
 
69
 
 
70
cat <<EOF
 
71
# Nmap 5.21 scan initiated $(date) as: nmap $args
 
72
Host: 127.0.0.1 ()      Status: Up
 
73
Host: 127.0.0.1 ()      Ports: $port_states
 
74
# Nmap done at $(date) -- 1 IP address (1 host up) scanned in 0.04 seconds
 
75
EOF