Skip to content

Commit

Permalink
Add a build option to disable direct connections.
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-davis committed Mar 29, 2010
1 parent f8ac8a1 commit ed414e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
18 changes: 15 additions & 3 deletions configure.in
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
AC_INIT([shim], [0.1])
AC_INIT([shim], [0.1.0])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([main.c])

AC_CONFIG_HEADER(config.h)

AC_PROG_CC
AC_PROG_INSTALL

AC_PROG_GCC_TRADITIONAL
AC_HEADER_STDC

if test "$GCC" = yes; then
CFLAGS="$CFLAGS -g -Wall"
CFLAGS="$CFLAGS -Wall"
fi

AC_ARG_ENABLE(direct-connections,
AS_HELP_STRING(--disable-direct-connections,
only make connections through a SOCKS proxy),
[],
[enable_direct_connections=yes])

PKG_CHECK_MODULES(LIBEVENT, libevent >= 2.0.0)
AC_SUBST(LIBEVENT_CFLAGS)
AC_SUBST(LIBEVENT_LIBS)

if test x$enable_direct_connections = xno; then
AC_DEFINE(DISABLE_DIRECT_CONNECTIONS, 1,
[Define if shim should only allow connections through a SOCKS proxy])
fi

AC_OUTPUT(Makefile)
15 changes: 9 additions & 6 deletions conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <event2/util.h>
#include <event2/dns.h>

#include "config.h"
#include "conn.h"
#include "util.h"
#include "log.h"
Expand Down Expand Up @@ -189,7 +190,10 @@ conn_connect_bufferevent(struct bufferevent *bev, struct evdns_base *dns,
rv = bufferevent_socket_connect(bev,
(struct sockaddr*)&socks_addr,
socks_addr_len);
} else {
return rv;
}
#ifndef DISABLE_DIRECT_CONNECTIONS
else {
struct evutil_addrinfo hint;
char portstr[NI_MAXSERV];

Expand All @@ -199,17 +203,16 @@ conn_connect_bufferevent(struct bufferevent *bev, struct evdns_base *dns,
hint.ai_protocol = IPPROTO_TCP;
hint.ai_socktype = SOCK_STREAM;

evdns_getaddrinfo(dns, name, portstr, &hint,
rv = evdns_getaddrinfo(dns, name, portstr, &hint,
socks_resolvecb, info);
rv = 0;
return rv;
}

return rv;
#endif
}
#ifdef DISABLE_DIRECT_CONNECTIONS
{
const char *msg;
msg = "Direct connections disabled, but I have no SOCKS "
msg = "Direct connections disabled, but I have no SOCKS 4a "
"proxy to connect to!";
log_error("conn: %s", msg);
finish_connection(info, 0, msg);
Expand Down

0 comments on commit ed414e1

Please sign in to comment.