| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
. ../support/simple_eval_tools.sh |
| 4 |
|
| 5 |
HEADER com2sec directive |
| 6 |
|
| 7 |
SKIPIFNOT NETSNMP_TRANSPORT_UDP_DOMAIN |
| 8 |
SKIPIF NETSNMP_NO_DEBUGGING |
| 9 |
|
| 10 |
# |
| 11 |
# Begin test |
| 12 |
# |
| 13 |
|
| 14 |
# 401a Test missing CONTEXT |
| 15 |
CONFIGAGENT 'com2sec -Cn' |
| 16 |
# 401b Test empty CONTEXT |
| 17 |
CONFIGAGENT 'com2sec -Cn ""' |
| 18 |
# 401c Test overlong CONTEXT (33 chars) |
| 19 |
CONFIGAGENT 'com2sec -Cn 123456789012345678901234567890123 secname default com' |
| 20 |
|
| 21 |
# 402a Test missing secName |
| 22 |
CONFIGAGENT 'com2sec' |
| 23 |
# 402b Test empty secName |
| 24 |
CONFIGAGENT 'com2sec ""' |
| 25 |
# 402c Test overlong secName (33 chars) |
| 26 |
CONFIGAGENT 'com2sec 123456789012345678901234567890123 default com' |
| 27 |
# 402d Test valid context and missing secName |
| 28 |
CONFIGAGENT 'com2sec -Cn 12345678901234567890123456789012' |
| 29 |
# 402e Test valid context and empty secName |
| 30 |
CONFIGAGENT 'com2sec -Cn 12345678901234567890123456789012 ""' |
| 31 |
|
| 32 |
# 403a Test missing network address |
| 33 |
CONFIGAGENT 'com2sec t403a' |
| 34 |
# 403b Test empty network address |
| 35 |
CONFIGAGENT 'com2sec t403b ""' |
| 36 |
# 403c Test forbidden value (now why it is forbidden...) |
| 37 |
CONFIGAGENT 'com2sec t403c NETWORK' |
| 38 |
|
| 39 |
# 404a Test missing community |
| 40 |
CONFIGAGENT 'com2sec t404a default' |
| 41 |
# 404b Test empty community |
| 42 |
CONFIGAGENT 'com2sec t404b default ""' |
| 43 |
# 404c Test forbidden value (now why it is forbidden...) |
| 44 |
CONFIGAGENT 'com2sec t404c default COMMUNITY' |
| 45 |
# 404d Test overlong community (255 chars) |
| 46 |
CONFIGAGENT 'com2sec t404d default 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567' |
| 47 |
# 404e Test valid community |
| 48 |
CONFIGAGENT 'com2sec t404e default 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456' |
| 49 |
|
| 50 |
# 405a Test 'default' configuration |
| 51 |
CONFIGAGENT 'com2sec t405a default c405a' |
| 52 |
# 405b Test ip address configuration |
| 53 |
CONFIGAGENT 'com2sec t405b 10.0.0.0 c405b' |
| 54 |
# 405c Test valid numeric mask |
| 55 |
CONFIGAGENT 'com2sec t405c 10.0.0.0/8 c405c' |
| 56 |
# 405d Test invalid numeric mask (too big) |
| 57 |
CONFIGAGENT 'com2sec t405d 10.0.0.0/33 c405d' |
| 58 |
# 405e Test invalid numeric mask (negative) |
| 59 |
CONFIGAGENT 'com2sec t405e 10.0.0.0/-1 c405e' |
| 60 |
# 405f Test valid ip address mask |
| 61 |
CONFIGAGENT 'com2sec t405f 10.0.0.0/255.0.0.0 c405f' |
| 62 |
# 405g Test invalid ip address mask |
| 63 |
CONFIGAGENT 'com2sec t405g 10.0.0.0/512.0.0.0 c405g' |
| 64 |
# 405h Test invalid ip address mask |
| 65 |
CONFIGAGENT 'com2sec t405h 10.0.0.0/hh c405h' |
| 66 |
# 405i Test address with 1 bits not covered by the mask |
| 67 |
CONFIGAGENT 'com2sec t405i 10.0.0.0/3.192.0.0 c405i' |
| 68 |
# 405j Test that 0.0.0.0 works (alias for default) |
| 69 |
CONFIGAGENT 'com2sec t405j 0.0.0.0 c405j' |
| 70 |
# 405k Test that 0.0.0.0/0 works (alias for default) |
| 71 |
CONFIGAGENT 'com2sec t405k 0.0.0.0/0 c405k' |
| 72 |
# 405l Test that 0.0.0.0/0.0.0.0 works (alias for default) |
| 73 |
CONFIGAGENT 'com2sec t405l 0.0.0.0/0.0.0.0 c405l' |
| 74 |
|
| 75 |
# 406a Test maximally long address/mask |
| 76 |
CONFIGAGENT 'com2sec t406a 255.255.255.255/255.255.255.255 c406a' |
| 77 |
|
| 78 |
# 407a Test non existant host name |
| 79 |
CONFIGAGENT 'com2sec t407a no.such.address. c407a' |
| 80 |
# 407b Test maximally long host name/mask |
| 81 |
CONFIGAGENT 'com2sec t407b a23456789012345678901234567890123456789012345678901234567890123.a23456789012345678901234567890123456789012345678901234567890123.a23456789012345678901234567890123456789012345678901234567890123.a234567890123456789012345678901234567890123456789012345678901./255.255.255.255 c407b' |
| 82 |
|
| 83 |
# 408 Lookup tests, require network access |
| 84 |
# 408a Test lookup returning a single host |
| 85 |
CONFIGAGENT 'com2sec t408a onea.net-snmp.org c408a' |
| 86 |
# 408a Test lookup returning multiple hosts |
| 87 |
CONFIGAGENT 'com2sec t408b twoa.net-snmp.org c408b' |
| 88 |
|
| 89 |
# Default agent setup |
| 90 |
CONFIGAGENT "[snmp] persistentdir $SNMP_TMP_PERSISTENTDIR" |
| 91 |
# Dummy config to prevent the basic_setup warning |
| 92 |
CONFIGAGENT 'rocommunity public 127.0.0.0/8' |
| 93 |
|
| 94 |
AGENT_FLAGS='-Dnetsnmp_udp_parse_security,netsnmp_udp6_parse_security,netsnmp_unix_parse_security' |
| 95 |
|
| 96 |
STARTAGENT |
| 97 |
|
| 98 |
SAVECHECKAGENT() { |
| 99 |
CHECKAGENT "$@" |
| 100 |
if [ "x$return_value" != "x0" ] ; then |
| 101 |
FINISHED |
| 102 |
fi |
| 103 |
} |
| 104 |
|
| 105 |
SAVECHECKAGENT 'line 1: Error: missing CONTEXT_NAME parameter' |
| 106 |
SAVECHECKAGENT 'line 2: Error: missing NAME parameter' |
| 107 |
SAVECHECKAGENT 'line 3: Error: context name too long' |
| 108 |
CHECKAGENTCOUNT atleastone 'line 4: Error: Blank line following com2sec token.' |
| 109 |
SAVECHECKAGENT 'line 5: Error: empty NAME parameter' |
| 110 |
SAVECHECKAGENT 'line 6: Error: security name too long' |
| 111 |
SAVECHECKAGENT 'line 7: Error: missing NAME parameter' |
| 112 |
SAVECHECKAGENT 'line 8: Error: empty NAME parameter' |
| 113 |
SAVECHECKAGENT 'line 9: Error: missing SOURCE parameter' |
| 114 |
SAVECHECKAGENT 'line 10: Error: empty SOURCE parameter' |
| 115 |
SAVECHECKAGENT 'line 11: Error: example config NETWORK not properly configured' |
| 116 |
SAVECHECKAGENT 'line 12: Error: missing COMMUNITY parameter' |
| 117 |
SAVECHECKAGENT 'line 13: Error: empty COMMUNITY parameter' |
| 118 |
SAVECHECKAGENT 'line 14: Error: example config COMMUNITY not properly configured' |
| 119 |
SAVECHECKAGENT 'line 15: Error: community name too long' |
| 120 |
SAVECHECKAGENT '<"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456", 0.0.0.0/0.0.0.0> => "t404e"' |
| 121 |
SAVECHECKAGENT '<"c405a", 0.0.0.0/0.0.0.0> => "t405a"' |
| 122 |
SAVECHECKAGENT '<"c405b", 10.0.0.0/255.255.255.255> => "t405b"' |
| 123 |
SAVECHECKAGENT '<"c405c", 10.0.0.0/255.0.0.0> => "t405c"' |
| 124 |
SAVECHECKAGENT 'line 20: Error: bad mask length' |
| 125 |
SAVECHECKAGENT 'line 21: Error: bad mask length' |
| 126 |
SAVECHECKAGENT '<"c405f", 10.0.0.0/255.0.0.0> => "t405f"' |
| 127 |
SAVECHECKAGENT 'line 23: Error: bad mask' |
| 128 |
SAVECHECKAGENT 'line 24: Error: bad mask' |
| 129 |
SAVECHECKAGENT 'line 25: Error: source/mask mismatch' |
| 130 |
SAVECHECKAGENT '<"c405j", 0.0.0.0/255.255.255.255> => "t405j"' |
| 131 |
SAVECHECKAGENT '<"c405k", 0.0.0.0/0.0.0.0> => "t405k"' |
| 132 |
SAVECHECKAGENT '<"c405l", 0.0.0.0/0.0.0.0> => "t405l"' |
| 133 |
SAVECHECKAGENT '<"c406a", 255.255.255.255/255.255.255.255> => "t406a"' |
| 134 |
SAVECHECKAGENT 'line 30: Error:' # msg from h_strerror so it varies |
| 135 |
SAVECHECKAGENT 'line 31: Error:' # msg from h_strerror so it varies |
| 136 |
|
| 137 |
if false; then |
| 138 |
# The two tests below have been disabled because these rely on resolving a |
| 139 |
# domain name into a local IP address. Such DNS replies are filtered out by |
| 140 |
# many security devices because to avoid DNS rebinding attacks. See also |
| 141 |
# https://en.wikipedia.org/wiki/DNS_rebinding. |
| 142 |
|
| 143 |
CHECKAGENT '<"c408a"' |
| 144 |
if [ "$snmp_last_test_result" -eq 0 ] ; then |
| 145 |
CHECKAGENT 'line 32: Error:' |
| 146 |
if [ "$snmp_last_test_result" -ne 1 ] ; then |
| 147 |
return_value=1 |
| 148 |
FINISHED |
| 149 |
fi |
| 150 |
elif [ "$snmp_last_test_result" -ne 1 ] ; then |
| 151 |
return_value=1 |
| 152 |
FINISHED |
| 153 |
fi |
| 154 |
|
| 155 |
CHECKAGENT '<"c408b"' |
| 156 |
if [ "$snmp_last_test_result" -eq 0 ] ; then |
| 157 |
CHECKAGENT 'line 33: Error:' |
| 158 |
if [ "$snmp_last_test_result" -ne 1 ] ; then |
| 159 |
return_value=1 |
| 160 |
fi |
| 161 |
elif [ "$snmp_last_test_result" -ne 1 ] ; then |
| 162 |
return_value=1 |
| 163 |
fi |
| 164 |
|
| 165 |
fi |
| 166 |
|
| 167 |
FINISHED |