commit 3922f91c0fa2f3bf49c49098cae451d9e940068e Author: David Goulet dgoulet@ev0ke.net Date: Fri Aug 23 18:36:09 2013 -0400
Improve torsocks script in src/bin
Signed-off-by: David Goulet dgoulet@ev0ke.net --- configure.ac | 2 + src/Makefile.am | 2 +- src/bin/Makefile.am | 10 +++ src/bin/torsocks | 154 +++++++++++++++++++++++++++++++++++++++++++++ src/bin/torsocks.in | 154 +++++++++++++++++++++++++++++++++++++++++++++ src/lib/Makefile.am | 4 -- src/lib/torsocks.in | 167 ------------------------------------------------- src/lib/usewithtor.in | 113 --------------------------------- 8 files changed, 321 insertions(+), 285 deletions(-)
diff --git a/configure.ac b/configure.ac index 4cd3b14..d1726de 100644 --- a/configure.ac +++ b/configure.ac @@ -367,6 +367,8 @@ AC_SUBST(DEFAULT_INCLUDES) AC_CONFIG_FILES([ Makefile src/Makefile + src/bin/Makefile + src/bin/torsocks src/common/Makefile src/lib/Makefile doc/Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 67c8cf5..103337c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1 +1 @@ -SUBDIRS = common lib +SUBDIRS = common lib bin diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am new file mode 100644 index 0000000..396e2c0 --- /dev/null +++ b/src/bin/Makefile.am @@ -0,0 +1,10 @@ +# Makefile used by configure to create real Makefile + +libdir = @libdir@/torsocks + +# Install invocation scripts +bin_SCRIPTS = torsocks +INSTALL_SCRIPT = $(install_sh) -c -m 755 + +# Install main library to $(prefix)/lib/tor (must match torsocks.in) +CLEANFILES = torsocks diff --git a/src/bin/torsocks b/src/bin/torsocks new file mode 100644 index 0000000..17bc458 --- /dev/null +++ b/src/bin/torsocks @@ -0,0 +1,154 @@ +#!/bin/sh +# *************************************************************************** +# * * +# * * +# * Copyright (C) 2008 by Robert Hogan * +# * robert@roberthogan.net * +# * Copyright (C) 2012 by Jacob Appelbaum jacob@torproject.org * +# * Copyright (C) 2013 by David Goulet dgoulet@ev0ke.net * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU General Public License as published by * +# * the Free Software Foundation; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU General Public License for more details. * +# * * +# * You should have received a copy of the GNU General Public License * +# * along with this program; if not, write to the * +# * Free Software Foundation, Inc., * +# * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +# *************************************************************************** +# * * +# * This is a modified version of a source file from the Tor project. * +# * Original copyright information follows: * +# *************************************************************************** +# Wrapper script for use of the torsocks(8) transparent socksification library +# +# There are three forms of usage for this script: +# +# /usr/local/bin/torsocks program [program arguments...] +# +# This form sets the users LD_PRELOAD environment variable so that torsocks(8) +# will be loaded to socksify the application then executes the specified +# program (with the provided arguments). The following simple example might +# be used to ssh to www.foo.org via a torsocks.conf(5) configured socks server: +# +# /usr/local/bin/torsocks ssh www.foo.org +# +# The second form allows for torsocks(8) to be switched on and off for a +# session (that is, it adds and removes torsocks from the LD_PRELOAD environment +# variable). This form must be _sourced_ into the user's existing session +# (and will only work with bourne shell users): +# +# . /usr/local/bin/torsocks on +# telnet www.foo.org +# . /usr/local/bin/torsocks off +# +# Or +# +# source /usr/local/bin/torsocks on +# telnet www.foo.org +# source /usr/local/bin/torsocks off +# +# This script is originally from the debian torsocks package by +# Tamas Szerb toma@rulez.org +# Modified by Robert Hogan robert@roberthogan.net April 16th 2006 +# Modified by David Goulet dgoulet@ev0ke.net 2013 + +LIBDIR="/usr/local/${exec_prefix}/lib/torsocks" +LIB_NAME="libtorsocks" +SHLIB_EXT="so" +SHLIB="${LIBDIR}/${LIB_NAME}.${SHLIB_EXT}" + +# Set LD_PRELOAD variable with torsocks library path. +set_ld_preload () +{ + if [ -z "$LD_PRELOAD" ]; then + export LD_PRELOAD="${SHLIB}" + else + echo $LD_PRELOAD | grep -q "${SHLIB}" || \ + export LD_PRELOAD="${SHLIB} $LD_PRELOAD" + fi + + # OS X specific env variable + case "$OSTYPE" in + darwin*) + export DYLD_FORCE_FLAT_NAMESPACE=1 + ;; + esac +} + +# Spawn a torified shell. +tor_shell () +{ + set_ld_preload + echo "$0: New torified shell coming right up..." + ${SHELL:-/bin/sh} +} + +torify_app () +{ + local app_path=`which $1` + + # NEVER remove that line or else nothing it torified. + set_ld_preload + + if [ -z $app_path ]; then + echo "ERROR: $1 cannot be found." >&2 + exit 1 + elif [ -u $app_path -o -g $app_path ]; then + echo "ERROR: $1 is set${2}id. torsocks will not work on a set${2}id executable." >&2 + exit 1 + fi + + exec "$@" +} + +usage () +{ + echo "$0: Please see torsocks(1) or read comment at top of $0" +} + +if [ $# -eq 0 ] ; then + usage + exit 1 +fi + +# Ensure libtorsocks exists, +if [ ! -f $SHLIB ]; then + echo "$0: $SHLIB does not exist! Try re-installing torsocks." + exit +fi + +case "$1" in + on) + set_ld_preload + ;; + off) + export LD_PRELOAD=`echo -n $LD_PRELOAD | sed "s#$SHLIB *##"` + if [ -z "$LD_PRELOAD" ]; then + unset LD_PRELOAD + case "$OSTYPE" in + darwin*) + unset DYLD_FORCE_FLAT_NAMESPACE + ;; + esac + fi + ;; + show|sh) + echo "LD_PRELOAD="$LD_PRELOAD"" + ;; + -h|--help|-?) + usage + ;; + --shell) + tor_shell + ;; + *) + torify_app $@ + ;; +esac diff --git a/src/bin/torsocks.in b/src/bin/torsocks.in new file mode 100644 index 0000000..c000565 --- /dev/null +++ b/src/bin/torsocks.in @@ -0,0 +1,154 @@ +#!/bin/sh +# *************************************************************************** +# * * +# * * +# * Copyright (C) 2008 by Robert Hogan * +# * robert@roberthogan.net * +# * Copyright (C) 2012 by Jacob Appelbaum jacob@torproject.org * +# * Copyright (C) 2013 by David Goulet dgoulet@ev0ke.net * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU General Public License as published by * +# * the Free Software Foundation; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU General Public License for more details. * +# * * +# * You should have received a copy of the GNU General Public License * +# * along with this program; if not, write to the * +# * Free Software Foundation, Inc., * +# * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +# *************************************************************************** +# * * +# * This is a modified version of a source file from the Tor project. * +# * Original copyright information follows: * +# *************************************************************************** +# Wrapper script for use of the torsocks(8) transparent socksification library +# +# There are three forms of usage for this script: +# +# @prefix@/bin/torsocks program [program arguments...] +# +# This form sets the users @LDPRELOAD@ environment variable so that torsocks(8) +# will be loaded to socksify the application then executes the specified +# program (with the provided arguments). The following simple example might +# be used to ssh to www.foo.org via a torsocks.conf(5) configured socks server: +# +# @prefix@/bin/torsocks ssh www.foo.org +# +# The second form allows for torsocks(8) to be switched on and off for a +# session (that is, it adds and removes torsocks from the @LDPRELOAD@ environment +# variable). This form must be _sourced_ into the user's existing session +# (and will only work with bourne shell users): +# +# . @prefix@/bin/torsocks on +# telnet www.foo.org +# . @prefix@/bin/torsocks off +# +# Or +# +# source @prefix@/bin/torsocks on +# telnet www.foo.org +# source @prefix@/bin/torsocks off +# +# This script is originally from the debian torsocks package by +# Tamas Szerb toma@rulez.org +# Modified by Robert Hogan robert@roberthogan.net April 16th 2006 +# Modified by David Goulet dgoulet@ev0ke.net 2013 + +LIBDIR="@prefix@/@libdir@/torsocks" +LIB_NAME="libtorsocks" +SHLIB_EXT="@SHLIB_EXT@" +SHLIB="${LIBDIR}/${LIB_NAME}.${SHLIB_EXT}" + +# Set @LDPRELOAD@ variable with torsocks library path. +set_ld_preload () +{ + if [ -z "$@LDPRELOAD@" ]; then + export @LDPRELOAD@="${SHLIB}" + else + echo $@LDPRELOAD@ | grep -q "${SHLIB}" || \ + export @LDPRELOAD@="${SHLIB} $@LDPRELOAD@" + fi + + # OS X specific env variable + case "$OSTYPE" in + darwin*) + export DYLD_FORCE_FLAT_NAMESPACE=1 + ;; + esac +} + +# Spawn a torified shell. +tor_shell () +{ + set_ld_preload + echo "$0: New torified shell coming right up..." + ${SHELL:-/bin/sh} +} + +torify_app () +{ + local app_path=`which $1` + + # NEVER remove that line or else nothing it torified. + set_ld_preload + + if [ -z $app_path ]; then + echo "ERROR: $1 cannot be found." >&2 + exit 1 + elif [ -u $app_path -o -g $app_path ]; then + echo "ERROR: $1 is set${2}id. torsocks will not work on a set${2}id executable." >&2 + exit 1 + fi + + exec "$@" +} + +usage () +{ + echo "$0: Please see torsocks(1) or read comment at top of $0" +} + +if [ $# -eq 0 ] ; then + usage + exit 1 +fi + +# Ensure libtorsocks exists, +if [ ! -f $SHLIB ]; then + echo "$0: $SHLIB does not exist! Try re-installing torsocks." + exit +fi + +case "$1" in + on) + set_ld_preload + ;; + off) + export @LDPRELOAD@=`echo -n $@LDPRELOAD@ | sed "s#$SHLIB *##"` + if [ -z "$@LDPRELOAD@" ]; then + unset @LDPRELOAD@ + case "$OSTYPE" in + darwin*) + unset DYLD_FORCE_FLAT_NAMESPACE + ;; + esac + fi + ;; + show|sh) + echo "@LDPRELOAD@="$@LDPRELOAD@"" + ;; + -h|--help|-?) + usage + ;; + --shell) + tor_shell + ;; + *) + torify_app $@ + ;; +esac diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index f445c01..f043392 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -4,10 +4,6 @@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(builddir) libdir = @libdir@/torsocks
# Install invocation scripts -#bin_SCRIPTS = torsocks usewithtor -#INSTALL_SCRIPT = $(install_sh) -c -m 755 -EXTRA_DIST = torsocks.in usewithtor.in - lib_LTLIBRARIES = libtorsocks.la
libtorsocks_la_SOURCES = torsocks.c torsocks.h \ diff --git a/src/lib/torsocks.in b/src/lib/torsocks.in deleted file mode 100644 index 4eaed8f..0000000 --- a/src/lib/torsocks.in +++ /dev/null @@ -1,167 +0,0 @@ -#!/bin/sh -# *************************************************************************** -# * * -# * * -# * Copyright (C) 2008 by Robert Hogan * -# * robert@roberthogan.net * -# * Copyright (C) 2012 by Jacob Appelbaum jacob@torproject.org * -# * * -# * This program is free software; you can redistribute it and/or modify * -# * it under the terms of the GNU General Public License as published by * -# * the Free Software Foundation; either version 2 of the License, or * -# * (at your option) any later version. * -# * * -# * This program is distributed in the hope that it will be useful, * -# * but WITHOUT ANY WARRANTY; without even the implied warranty of * -# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -# * GNU General Public License for more details. * -# * * -# * You should have received a copy of the GNU General Public License * -# * along with this program; if not, write to the * -# * Free Software Foundation, Inc., * -#* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -# *************************************************************************** -# * * -# * This is a modified version of a source file from the Tor project. * -# * Original copyright information follows: * -# *************************************************************************** -# Wrapper script for use of the torsocks(8) transparent socksification library -# -# There are three forms of usage for this script: -# -# @prefix@/bin/torsocks program [program arguments...] -# -# This form sets the users @LDPRELOAD@ environment variable so that torsocks(8) -# will be loaded to socksify the application then executes the specified -# program (with the provided arguments). The following simple example might -# be used to telnet to www.foo.org via a torsocks.conf(5) configured socks server: -# -# @prefix@/bin/torsocks telnet www.foo.org -# -# The second form allows for torsocks(8) to be switched on and off for a -# session (that is, it adds and removes torsocks from the @LDPRELOAD@ environment -# variable). This form must be _sourced_ into the user's existing session -# (and will only work with bourne shell users): -# -# . @prefix@/bin/torsocks on -# telnet www.foo.org -# . @prefix@/bin/torsocks off -# -# Or -# -# source @prefix@/bin/torsocks on -# telnet www.foo.org -# source @prefix@/bin/torsocks off -# -# The third form creates a new shell with @LDPRELOAD@ set and is achieved -# simply by running the script with no arguments -# -# @prefix@/bin/torsocks -# -# When finished the user can simply terminate the shell with 'exit' -# -# This script is originally from the debian torsocks package by -# Tamas Szerb toma@rulez.org -# Modified by Robert Hogan robert@roberthogan.net April 16th 2006 - -not_found () { - echo "ERROR: $1 cannot be found in PATH." >&2 - exit 1 -} - -set_id () { - echo "ERROR: $1 is set${2}id. torsocks will not work on a set${2}id executable." >&2 - exit 1 -} - -if [ $# = 0 ] ; then - echo "$0: insufficient arguments" - exit -fi - -LIBDIR="@prefix@/lib/torsocks" -LIB_NAME="libtorsocks" -SHLIB_EXT="@SHLIB_EXT@" -SHLIB="${LIBDIR}/${LIB_NAME}.${SHLIB_EXT}" - -# Check for libtorsocks and if set the 64bit variant -if [ ! -f $SHLIB ]; then - LIBDIR="@prefix@/lib64/torsocks" - SHLIB="${LIBDIR}/${LIB_NAME}.${SHLIB_EXT}" -fi - -# Ensure libtorsocks exists, -if [ ! -f $SHLIB ]; then - echo "$0: $SHLIB does not exist! Try re-installing torsocks." - exit -fi - -case "$1" in - on) - if [ -z "$@LDPRELOAD@" ] - then - export @LDPRELOAD@="${SHLIB}" - else - echo $@LDPRELOAD@ | grep -q "${SHLIB}" || \ - export @LDPRELOAD@="${SHLIB} $@LDPRELOAD@" - fi - # FIXME: This env variable is only meaningful on Mac OSX, so it would be better - # not to set it at all on other platforms. - export DYLD_FORCE_FLAT_NAMESPACE=1 - ;; - off) - #replace '/' with '/' in @prefix@ - # escprefix=`echo '@prefix@' |sed 's/\//\\//g'` - # export @LDPRELOAD@=`echo -n $@LDPRELOAD@ | sed "s/$escprefix/lib/torsocks/libtorsocks.so ?//"` - export @LDPRELOAD@=`echo -n $@LDPRELOAD@ | sed "s#@prefix@/lib/torsocks/libtorsocks.@SHLIB_EXT@ *##"` - if [ -z "$@LDPRELOAD@" ] - then - unset @LDPRELOAD@ - # FIXME: This env variable is only meaningful on Mac OSX, so it would be better - # not to set it at all on other platforms. - unset DYLD_FORCE_FLAT_NAMESPACE=1 - fi - ;; - show|sh) - echo "@LDPRELOAD@="$@LDPRELOAD@"" - ;; - -h|-?) - echo "$0: Please see torsocks(1) or read comment at top of $0" - ;; - --shell) - if [ -z "$@LDPRELOAD@" ] - then - export @LDPRELOAD@="${SHLIB}" - else - echo $@LDPRELOAD@ | grep -q "${SHLIB}" || \ - export @LDPRELOAD@="${SHLIB} $@LDPRELOAD@" - fi - export DYLD_FORCE_FLAT_NAMESPACE=1 - echo "torsocks: new torified shell coming right up..." - ${SHELL:-/bin/sh} - ;; - *) - if [ -z "$@LDPRELOAD@" ] - then - export @LDPRELOAD@="${SHLIB}" - else - echo $@LDPRELOAD@ | grep -q "${SHLIB}" || \ - export @LDPRELOAD@="${SHLIB} $@LDPRELOAD@" - fi - export DYLD_FORCE_FLAT_NAMESPACE=1 - - if [ $# -gt 0 ] - then - if ! which "$1" >/dev/null 2>&1; then - not_found $1 - elif [ -u `which "$1"` ]; then - set_id $1 u - elif [ -g `which "$1"` ]; then - set_id $1 g - fi - exec "$@" - fi - ;; -esac - -#EOF diff --git a/src/lib/usewithtor.in b/src/lib/usewithtor.in deleted file mode 100644 index e606760..0000000 --- a/src/lib/usewithtor.in +++ /dev/null @@ -1,113 +0,0 @@ -#! /bin/sh -# *************************************************************************** -# * * -# * Copyright (C) 2008-2011 Robert Hogan robert@roberthogan.net * -# * * -# * This program is free software; you can redistribute it and/or modify * -# * it under the terms of the GNU General Public License as published by * -# * the Free Software Foundation; either version 2 of the License, or * -# * (at your option) any later version. * -# * * -# * This program is distributed in the hope that it will be useful, * -# * but WITHOUT ANY WARRANTY; without even the implied warranty of * -# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -# * GNU General Public License for more details. * -# * * -# * You should have received a copy of the GNU General Public License * -# * along with this program; if not, write to the * -# * Free Software Foundation, Inc., * -#* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -# *************************************************************************** -# * * -# * This is a modified version of a source file from the Tor project. * -# * Original copyright notice from tsocks source file follows: * -# *************************************************************************** - -# Wrapper script for use of the tsocks(8) transparent socksification library -# See the tsocks(1) and torify(1) manpages. - -# Copyright (c) 2004, 2006 Peter Palfrader -# Modified by Jacob Appelbaum jacob@appelbaum.net April 16th 2006 -# Modified by Marcus Griep marcus@griep.us June 16 2009 -# May be distributed under the same terms as Tor itself - - -# Define and ensure we have tsocks -# XXX: what if we don't have which? -TORSOCKS="`which torsocks`" -PROG= -VERBOSE= - -usage () { - echo "Usage: $0 [-hv] <command> [<options>...]" -} - -not_found () { - echo "ERROR: $1 cannot be found in PATH." >&2 - exit 1 -} - -set_id () { - echo "ERROR: $1 is set${2}id. usewithtor will not work on a set${2}id executable." >&2 - exit 1 -} - -# Check for any argument list -if [ "$#" = 0 ]; then - usage >&2 - exit 1 -fi - -while [ "$1" ]; do - case "$1" in - -h|--h*) - usage - exit 0 - ;; - -v|--v*) - VERBOSE=YesPlease - shift - ;; - *) - break; - esac -done - -if ! which "$1" >/dev/null 2>&1; then - not_found $1 -elif [ -u `which "$1"` ]; then - set_id $1 u -elif [ -g `which "$1"` ]; then - set_id $1 g -fi - -if [ -x "$TORSOCKS" ]; then - PROG=torsocks -else - echo "$0: Unable to find torsocks in PATH." >&2 - echo " Perhaps you haven't installed it?" >&2 - exit 1 -fi - -if [ "$VERBOSE" ]; then - echo "We're armed with the following torsocks: $TORSOCKS" - echo "We're attempting to use $PROG for all tor action." -fi - -if [ "$PROG" = "torsocks" ]; then - # Define our torsocks config file - TORSOCKS_CONF_FILE="@CONFDIR@/torsocks.conf" - export TORSOCKS_CONF_FILE - - # Check that we've got a torsocks config file - if [ -r "$TORSOCKS_CONF_FILE" ]; then - exec torsocks "$@" - else - echo "$0: Missing torsocks configuration file "$TORSOCKS_CONF_FILE" - torsocks will use defaults sensible for Tor." >&2 - exec torsocks "$@" - fi -fi - -# We should have hit an exec. If we get here, we didn't exec -echo "$0: failed to exec $PROG $@" >&2 -exit 1
tor-commits@lists.torproject.org