Fix: assert conn->fd typo

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: IPv6 typo in socks5_send_resolve_ptr_request

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: change socks5_send_ptr_request to use address type

inet_ntop returns a pointer to the destination string, so an IPv6
address would always be converted as if it were an IPv4 address
(AF_INET).

Add the address family as a third parameter to socks5_send_ptr_request
to reliably determine the address type to request. The order of
parameters to socks5_send_ptr_request has also been changed.

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: remove all variables with double underscore

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: deny connection to ANY address

It's possible to connect to 0.0.0.0/:: which are addresses that Tor
can't of course handle thus deny the call and send back EINVAL.

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: check strdup return value

Reported-by: Nick Mathewson <nickm@torproject.org>
Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: better document connection registry mutex

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: handle socket creation with multiple types

The switch case failed to handle extra type such as SOCK_NONBLOCK or/and
SOCK_CLOEXEC that are possible on Linux. This patch changes the code to
use a if/else statement to handle multiple flags.

Reported-by: Nick Mathewson <nickm@torproject.org>
Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: handle hints being NULL in getaddrinfo

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Deny libc function accept()/accept4()

Inbound connection to an application handled by torsocks should not be
allowed since we can't make them nor make sure that it goes/come through
the Tor network.

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Deny libc function bind()

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: check is_suid flag before each getenv()

Reported-by: Nick Mathewson <nickm@torproject.org>
Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: use strtok_r reentrant instead of strtok

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: use connection_get_ref on creation

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: use unsigned char for socks5 ABI

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Tests: add one for utils_tokenize_ignore_comments

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: remove the use of IPv4 sockaddr in connect

This modifies the onion find by ip to use generic sockaddr structure.
Also, a utils call is added to extract the port from a sockaddr
structure depending on the family.

This is a step in the direction of fully supported IPv6 thus removing
the use of a cast sockaddr_in.

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: overload listen and not bind

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: make tsock_tor_resolve support IPv6

Note that the tor daemon does not support IPv6 DNS resolution through
the SOCKS port thus for now it is denied.

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: check strdup return value in config-file.c

Signed-off-by: David Goulet <dgoulet@ev0ke.net>