diff options
author | Yann E. MORIN" <yann.morin.1998@anciens.enib.fr> | 2008-04-18 22:16:28 (GMT) |
---|---|---|
committer | Yann E. MORIN" <yann.morin.1998@anciens.enib.fr> | 2008-04-18 22:16:28 (GMT) |
commit | 59ed1ed60064239d7f469e3d4dc653588e28ef05 (patch) | |
tree | beddea5327375babea45ead8574934dc2e1e539d /scripts/crosstool.sh | |
parent | b44e4e652ad5c5a6725a61b559eab1168e5f68cf (diff) |
Using SOCKS 4/5 proxy is no easy task:
- a machine may well be able to reach the proxy, even if it is not on the same sub-net(s) as the machine itself (absolutely legitimate)
- tsocks.conf needs a list of so-called 'local' networks that can be reached without the need for a SOCKS connection
- SOCKS proxies are expected to be in 'local' networks
- there is absolutely NO way to tell what networks are local, besides the sub-net(s) the machine is in
Therefore, appropriate configuration of SOCKS 4/5 configuration is really complex, and attempts to correctly overcome this issue are doomed.
/trunk/scripts/crosstool.sh | 52 46 6 0 ++++++++++++++++++++++++++++++++++----
/trunk/config/global/download_extract.in | 39 31 8 0 +++++++++++++++++++++++------
2 files changed, 77 insertions(+), 14 deletions(-)
Diffstat (limited to 'scripts/crosstool.sh')
-rwxr-xr-x | scripts/crosstool.sh | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/scripts/crosstool.sh b/scripts/crosstool.sh index 8066159..ae67457 100755 --- a/scripts/crosstool.sh +++ b/scripts/crosstool.sh @@ -224,15 +224,55 @@ case "${CT_PROXY_TYPE}" in export ftp_proxy="${http_proxy}" CT_DoLog DEBUG "http_proxy='${http_proxy}'" ;; - socks?) - # Re;ove any lingering config file from any previous run + sockssys) + CT_HasOrAbort tsocks + . tsocks -on + ;; + socks*) + CT_HasOrAbort tsocks + # Remove any lingering config file from any previous run rm -f "${CT_BUILD_DIR}/tsocks.conf" - ( echo "server=${CT_PROXY_HOST}"; - echo "server_port=${CT_PROXY_PORT}"; - echo "server_type=${CT_PROXY_TYPE#socks}"; + # Find all interfaces and build locally accessible networks + /sbin/ifconfig |gawk ' + $0 ~ /inet addr:/ { + split( $2, ip, ":|\\." ); + ip_num = ip[2]*2^24 + ip[3]*2^16 + ip[4]*2^8 + ip[5]*2^0; + # Skip 127.0.0.1 + if( ip_num == 2130706433 ) { + next; + } + split( $(NF), mask, ":|\\." ); + mask_num = mask[2]*2^24 + mask[3]*2^16 + mask[4]*2^8 + mask[5]*2^0; + ip_num = and( ip_num, mask_num ); + printf( "local = %d.%d.%d.%d/%d.%d.%d.%d\n", + and( 0xFF, rshift( ip_num, 24 ) ), + and( 0xFF, rshift( ip_num, 16 ) ), + and( 0xFF, rshift( ip_num, 8 ) ), + and( 0xFF, rshift( ip_num, 0 ) ), + and( 0xFF, rshift( mask_num, 24 ) ), + and( 0xFF, rshift( mask_num, 16 ) ), + and( 0xFF, rshift( mask_num, 8 ) ), + and( 0xFF, rshift( mask_num, 0 ) ) ); + } + ' >"${CT_BUILD_DIR}/tsocks.conf" + ( echo "server = ${CT_PROXY_HOST}"; + echo "server_port = ${CT_PROXY_PORT}"; [ -n "${CT_PROXY_USER}" ] && echo "default_user=${CT_PROXY_USER}"; [ -n "${CT_PROXY_PASS}" ] && echo "default_pass=${CT_PROXY_PASS}"; - ) >"${CT_BUILD_DIR}/tsocks.conf" + ) >>"${CT_BUILD_DIR}/tsocks.conf" + case "${CT_PROXY_TYPE/socks}" in + 4|5) proxy_type="${CT_PROXY_TYPE/socks}";; + auto) + reply=$(inspectsocks "${CT_PROXY_HOST}" "${CT_PROXY_PORT}" 2>&1 || true) + case "${reply}" in + *"server is a version 4 socks server"*) proxy_type=4;; + *"server is a version 5 socks server"*) proxy_type=5;; + *) CT_Abort "Unable to determine SOCKS proxy type for '${CT_PROXY_HOST}:${CT_PROXY_PORT}'" + esac + ;; + esac + echo "server_type = ${proxy_type}" >> "${CT_BUILD_DIR}/tsocks.conf" + validateconf -f "${CT_BUILD_DIR}/tsocks.conf" 2>&1 |CT_DoLog DEBUG export TSOCKS_CONF_FILE="${CT_BUILD_DIR}/tsocks.conf" . tsocks -on ;; |