[Pkg-privacy-commits] [onioncat] 120/241: stack size configurable -- needed for OpenBSD

Intrigeri intrigeri at moszumanska.debian.org
Wed Aug 26 16:16:47 UTC 2015


This is an automated email from the git hooks/post-receive script.

intrigeri pushed a commit to branch upstream-master
in repository onioncat.

commit 68367066a15595f7916446e6fe4a78950057279a
Author: eagle <eagle at 58e1ccc2-750e-0410-8d0d-f93ca75ab447>
Date:   Thu Jan 22 23:24:26 2009 +0000

    stack size configurable -- needed for OpenBSD
    
    git-svn-id: https://www.cypherpunk.at/svn/onioncat/trunk@432 58e1ccc2-750e-0410-8d0d-f93ca75ab447
---
 ChangeLog        |  6 +++++-
 configure        | 22 +++++++++++-----------
 man/ocat.1       | 31 +++++++++++++++++--------------
 src/ocat.h       | 15 +++++++++++++++
 src/ocatctrl.c   | 17 +++++++++++++++++
 src/ocatsocks.c  | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/ocatthread.c | 13 ++++++++++++-
 7 files changed, 129 insertions(+), 28 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3d87026..418bda6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,8 @@
-* version 
+* version 0.1.10
+ - thread stack size configurable (necessary because OpenBSD stacksize seems
+ to be to small)
+
+* version 0.1.9
  - man page updated
  - Local onion-URL may be generated randomly (option -R)
  - SOCKS destination IP configurable (v4 only)
diff --git a/configure b/configure
index 9fa86e0..b9db20b 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.61 for onioncat 0.1.10-430.
+# Generated by GNU Autoconf 2.61 for onioncat 0.1.10-430M.
 #
 # Report bugs to <rahra at cypherpunk.at>.
 #
@@ -574,8 +574,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
 # Identity of this package.
 PACKAGE_NAME='onioncat'
 PACKAGE_TARNAME='onioncat'
-PACKAGE_VERSION='0.1.10-430'
-PACKAGE_STRING='onioncat 0.1.10-430'
+PACKAGE_VERSION='0.1.10-430M'
+PACKAGE_STRING='onioncat 0.1.10-430M'
 PACKAGE_BUGREPORT='rahra at cypherpunk.at'
 
 # Factoring default headers for most tests.
@@ -1206,7 +1206,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures onioncat 0.1.10-430 to adapt to many kinds of systems.
+\`configure' configures onioncat 0.1.10-430M to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1272,7 +1272,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of onioncat 0.1.10-430:";;
+     short | recursive ) echo "Configuration of onioncat 0.1.10-430M:";;
    esac
   cat <<\_ACEOF
 
@@ -1362,7 +1362,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-onioncat configure 0.1.10-430
+onioncat configure 0.1.10-430M
 generated by GNU Autoconf 2.61
 
 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
@@ -1376,7 +1376,7 @@ cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by onioncat $as_me 0.1.10-430, which was
+It was created by onioncat $as_me 0.1.10-430M, which was
 generated by GNU Autoconf 2.61.  Invocation command line was
 
   $ $0 $@
@@ -2066,7 +2066,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE='onioncat'
- VERSION='0.1.10-430'
+ VERSION='0.1.10-430M'
 
 
 cat >>confdefs.h <<_ACEOF
@@ -2217,7 +2217,7 @@ ac_config_headers="$ac_config_headers config.h"
 
 
 cat >>confdefs.h <<\_ACEOF
-#define SVN_REVISION "430"
+#define SVN_REVISION "430M"
 _ACEOF
 
 
@@ -5300,7 +5300,7 @@ exec 6>&1
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by onioncat $as_me 0.1.10-430, which was
+This file was extended by onioncat $as_me 0.1.10-430M, which was
 generated by GNU Autoconf 2.61.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -5353,7 +5353,7 @@ Report bugs to <bug-autoconf at gnu.org>."
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF
 ac_cs_version="\\
-onioncat config.status 0.1.10-430
+onioncat config.status 0.1.10-430M
 configured by $0, generated by GNU Autoconf 2.61,
   with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
 
diff --git a/man/ocat.1 b/man/ocat.1
index 09a8e67..ddf1400 100644
--- a/man/ocat.1
+++ b/man/ocat.1
@@ -16,7 +16,7 @@
 .\"
 .TH OCAT 1 2008-12-07 "ocat" "OnionCat User's Manual"
 .SH NAME
-ocat \- OnionCat creates a transparent IPv6 layer on top of TOR's hidden services.
+ocat \- OnionCat creates a transparent IPv6 layer on top of Tor's hidden services.
 .SH SYNOPSIS
 .B ocat
 -i \fIonion_id                      (1st form)\fP
@@ -31,31 +31,32 @@ ocat \- OnionCat creates a transparent IPv6 layer on top of TOR's hidden service
 -R [\fIOPTION\fP]\fI                      (4th form)\fP
 .br
 .SH DESCRIPTION
-OnionCat creates a transparent IPv6 layer on top of TOR's hidden services. It
-transmits any kind of IP-based data transparently through the TOR network on a
+OnionCat creates a transparent IPv6 layer on top of Tor's hidden services. It
+transmits any kind of IP-based data transparently through the Tor network on a
 location hidden basis. You can think of it as a point-to-multipoint VPN
 between hidden services.
 
 OnionCat is a stand-alone application which runs in userland and is a connector
-between TOR and the local OS. Any protocol which is based on IP can be
+between Tor and the local OS. Any protocol which is based on IP can be
 transmitted. Of course, UDP and TCP (and probably ICMP) are the most important
 ones but all other protocols can also be forwarded through it.
 
 OnionCat opens a TUN device and assigns an IPv6 address to it. All packets
 forwarded to the TUN device by the kernel are forwarded by OnionCat to other
-OnionCats listening on TOR's hidden service ports.  The IPv6 address depends on
+OnionCats listening on Tor's hidden service ports.  The IPv6 address depends on
 the \fIonion_id\fP of the locally configured hidden service (see \fBtor(8)\fP).
-Depending on the configuration of TOR the \fIonion_id\fP usually can be found
+Depending on the configuration of Tor the \fIonion_id\fP usually can be found
 at \fI/var/lib/tor/hidden_service/hostname\fP or similar location.
 
 .SS OPTIONS
 .TP
 \fB\-4\fP
-Enable IPv4 forwarding.
+Enable IPv4 forwarding. See http://www.cypherpunk.at/onioncat/wiki/IPv4 for further
+information on IPv4.
 .TP
 \fB\-a\fP
 OnionCat creates a log file at $HOME/.ocat/connect_log. All incomming connects are
-log to that file. $HOME is determined from the user under which OnionCat runs
+logged to that file. $HOME is determined from the user under which OnionCat runs
 (see option -u).
 .TP
 \fB\-b\fP
@@ -70,7 +71,8 @@ in production environments.
 .TP
 \fB\-d\fP \fIn\fP
 Set debug level to \fIn\fP. Default = 7 which is maximum. Debug output will
-only be created if OnionCat was compiled with option DEBUG.
+only be created if OnionCat was compiled with option DEBUG (i.e. configure was
+run with option --enable-debug).
 .TP
 \fB\-f\fP \fIconfig file\fP
 Read initial configuration from \fIconfig file\fP. 
@@ -101,9 +103,10 @@ Create \fIpid file\fP instead of \fB/var/run/ocat.pid\fP.
 Run OnionCat as root and don't change user id (see option \fB\-u\fP).
 .TP
 \fB\-R\fP
+Use this option only if you really know what you do!
 Generate a random local onion_id. With this option it is not necessary to add a
-hidden service to the Tor configuration file \fBtorrc\fP.  With this option set
-one might use OnionCat services within Tor as usualy but it is NOT possible to
+hidden service to the Tor configuration file \fBtorrc\fP.
+One might use OnionCat services within Tor as usualy but it is NOT possible to
 receive incoming connections. If you plan to also receive connections (e.g.
 because you provide a service or you use software which opens sockets for
 incomming connections like Bitorrent) you MUST configure a hidden service and
@@ -113,7 +116,7 @@ supply its hostname to OnionCat on the command line.
 Set OnionCat's virtual hidden service port to \fIport\fP.
 .TP
 \fB\-t\fP \fI(IP|[IP:]port)\fP
-Set TOR SOCKS \fIIP\fP and/or \fIport\fP. If no \fIIP\fP is specified 127.0.0.1
+Set Tor SOCKS \fIIP\fP and/or \fIport\fP. If no \fIIP\fP is specified 127.0.0.1
 will be used, if no \fIport\fP is specified 9050 will be used as defaults. IPv6
 addresses must be escaped by square brackets.
 .TP
@@ -142,9 +145,9 @@ Software and man page written by Bernhard R. Fischer.
 Concept by Bernhard R. Fischer and Daniel Haslinger.
 
 .SH "SEE ALSO"
-OnionCat project page http://www.abenteuerland.at/onioncat/
+OnionCat project page http://www.cypherpunk.at/onioncat/
 
-TOR project homepage http://www.torproject.org/
+Tor project homepage http://www.torproject.org/
 
 .SH COPYRIGHT
 Copyright 2008 Bernhard R. Fischer, Daniel Haslinger.
diff --git a/src/ocat.h b/src/ocat.h
index 00287a4..2b8d403 100644
--- a/src/ocat.h
+++ b/src/ocat.h
@@ -169,6 +169,8 @@
 #define PEER_OUTGOING 1
 
 #define THREAD_NAME_LEN 11
+//! thread stack size (default stack size on OpenBSD is too small)
+#define THREAD_STACK_SIZE 1048576
 
 #define SOCKS_CONNECTING 1
 #define SOCKS_MAX_RETRY 3
@@ -211,6 +213,8 @@
 
 #define VERSION_STRING_LEN 256
 
+typedef enum PeerType {PT_TOR, PT_I2P} PeerType_t;
+
 struct OcatSetup
 {
    //! frame header of local OS in network byte order
@@ -293,6 +297,15 @@ typedef struct SocksHdr
    struct in_addr addr;
 } __attribute__((packed)) SocksHdr_t;
 
+typedef struct Socks5Hdr
+{
+   char ver;
+   char cmd;
+   char rsv;
+   char atyp;
+   char addr;
+} __attribute__((packed)) Socks5Hdr_t;
+
 typedef struct OcatPeer
 {
    struct OcatPeer *next;  //!< pointer to next peer in list
@@ -314,12 +327,14 @@ typedef struct OcatPeer
    time_t last_io;         //!< timestamp when last I/O packet measurement started
    unsigned inm;
    unsigned outm;
+   PeerType_t type;
 } OcatPeer_t;
 
 typedef struct OcatThread
 {
    struct OcatThread *next;
    pthread_t handle;
+   pthread_attr_t attr;
    int id;
    char name[THREAD_NAME_LEN];
    void *(*entry)(void*);
diff --git a/src/ocatctrl.c b/src/ocatctrl.c
index 96a6854..0f4d95e 100644
--- a/src/ocatctrl.c
+++ b/src/ocatctrl.c
@@ -59,6 +59,8 @@ void *ctrl_handler(void *p)
       }
       log_debug("fd %d fdopen'ed \"r+\"", fd);
       fo = ff;
+      if (setvbuf(ff, NULL, _IONBF, 0))
+         log_msg(LOG_ERR, "could not setup line buffering: %s", strerror(errno));
    }
    else
    {
@@ -92,6 +94,15 @@ void *ctrl_handler(void *p)
          log_debug("^D received.");
          break;
       }
+      else if (c == 0x1b)
+      {
+         log_debug("ESC received");
+         if (ungetc(c, ff) == EOF)
+         {
+            log_debug("received EOF on ungetc");
+            break;
+         }
+      }
       else
       {
          if (ungetc(c, ff) == EOF)
@@ -108,6 +119,12 @@ void *ctrl_handler(void *p)
          break;
       }
 
+#ifdef DEBUG
+      for (c = 0; c < strlen(buf); c++)
+         snprintf(&buf[strlen(buf) + 2 + c * 3], FRAME_SIZE - strlen(buf) - 2 - c * 3, "%02x ", buf[c]);
+      log_debug("xenc input buf: %s", &buf[strlen(buf) + 2]);
+#endif 
+
       if (!(rlen = oe_remtr(buf)))
          continue;
 
diff --git a/src/ocatsocks.c b/src/ocatsocks.c
index ca1452a..407263a 100644
--- a/src/ocatsocks.c
+++ b/src/ocatsocks.c
@@ -22,6 +22,7 @@
  *  @version 2008/02/03-01
  */
 
+/* SOCKS5 is defined in RFC1928 */
 
 #include "ocat.h"
 
@@ -34,6 +35,27 @@ static pthread_mutex_t socks_queue_mutex_ = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t socks_queue_cond_ = PTHREAD_COND_INITIALIZER;
 
 
+int socks_srv_con(void)
+{
+   int fd, t;
+   char addr[INET6_ADDRSTRLEN];
+
+   if ((fd = socket(CNF(socks_dst)->sin_family == AF_INET ? PF_INET : PF_INET6, SOCK_STREAM, 0)) < 0)
+      return E_SOCKS_SOCK;
+
+   t = time(NULL);
+   if (connect(fd, (struct sockaddr*) CNF(socks_dst), sizeof(struct sockaddr_in6)) == -1)
+   {
+      log_msg(LOG_ERR, "connect() to SOCKS port %s:%d failed: \"%s\". Sleeping for %d seconds.", inet_ntop(CNF(socks_dst)->sin_family, CNF(socks_dst)->sin_family == AF_INET ? (char*) &CNF(socks_dst)->sin_addr : (char*) &CNF(socks_dst6)->sin6_addr, addr, sizeof(addr)), ntohs(CNF(socks_dst)->sin_port), strerror(errno), TOR_SOCKS_CONN_TIMEOUT);
+      oe_close(fd);
+      sleep(TOR_SOCKS_CONN_TIMEOUT);
+      return E_SOCKS_CONN;
+   }
+   log_debug("connected");
+   return fd;
+}
+
+
 int socks_connect(const SocksQueue_t *sq)
 {
 //   struct sockaddr_in in;
@@ -56,7 +78,10 @@ int socks_connect(const SocksQueue_t *sq)
    strlcat(onion, ".onion", sizeof(onion));
 
    log_msg(LOG_INFO, "trying to connect to \"%s\" [%s]", onion, inet_ntop(AF_INET6, &sq->addr, buf, FRAME_SIZE));
+   if ((fd = socks_srv_con()) < 0)
+      return fd;
 
+   /*
    if ((fd = socket(CNF(socks_dst)->sin_family == AF_INET ? PF_INET : PF_INET6, SOCK_STREAM, 0)) < 0)
       return E_SOCKS_SOCK;
 
@@ -68,8 +93,9 @@ int socks_connect(const SocksQueue_t *sq)
       sleep(TOR_SOCKS_CONN_TIMEOUT);
       return E_SOCKS_CONN;
    }
+   */
 
-   log_debug("connected to TOR, doing SOCKS handshake");
+   log_debug("doing SOCKS4a handshake");
 
    shdr->ver = 4;
    shdr->cmd = 1;
@@ -296,3 +322,28 @@ void print_socks_queue(FILE *f)
    pthread_mutex_unlock(&socks_queue_mutex_);
 }
 
+
+int socks5_connect(const SocksQueue_t *sq)
+{
+   char buf[256 + sizeof(uint16_t) + sizeof(Socks5Hdr_t)];
+   char dest[ONION_URL_LEN + 1];
+   Socks5Hdr_t *shdr = (Socks5Hdr_t*) buf;
+   int fd;
+
+   log_msg(LOG_INFO, "trying to connect to \"%s\" [%s]", dest, inet_ntop(AF_INET6, &sq->addr, buf, 256));
+   if ((fd = socks_srv_con()) < 0)
+      return fd;
+
+   memset(buf, 0, sizeof(buf));
+   shdr->ver = '\x05';  // Version 5
+   shdr->cmd = '\x01';  // CONNECT
+   shdr->atyp = '\x03'; // DOMAINNAME
+
+   ipv6tonion(&sq->addr, dest);
+   shdr->addr = strlen(dest);
+   memcpy(&buf[sizeof(Socks5Hdr_t)], dest, strlen(dest));
+   *((uint16_t*) &buf[sizeof(Socks5Hdr_t) + strlen(dest)]) = htons(CNF(ocat_dest_port));
+
+   return fd;
+}
+
diff --git a/src/ocatthread.c b/src/ocatthread.c
index 886c41c..fcef448 100644
--- a/src/ocatthread.c
+++ b/src/ocatthread.c
@@ -110,8 +110,19 @@ int run_ocat_thread(const char *name, void *(*thfunc)(void*), void *parm)
    th->entry = thfunc;
    th->parm = parm;
 
+   if ((rc = pthread_attr_init(&th->attr)))
+   {
+      log_msg(LOG_ERR, "could not init pthread attr: \"%s\"", strerror(rc));
+      return rc;
+   }
+   if ((rc - pthread_attr_setstacksize(&th->attr, THREAD_STACK_SIZE)))
+   {
+      log_msg(LOG_EMERG, "could not init thread stack size attr - system may be unstable: \"%s\"", strerror(rc));
+      return rc;
+   }
+
    log_debug("starting [%s]", name);
-   if ((rc = pthread_create(&th->handle, NULL, thread_run, th)))
+   if ((rc = pthread_create(&th->handle, &th->attr, thread_run, th)))
    {
       log_msg(LOG_EMERG, "could not start thread %s: \"%s\"", name, strerror(rc));
       free(th);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onioncat.git



More information about the Pkg-privacy-commits mailing list