[Pkg-privacy-commits] [onioncat] 206/340: - option -t did not work correctly - (optional) pid file is removed at exit - SIGUSR1 is handled in preparation for statistics output - controller sessions limited to MAX_DEF_CTRL_SESS (= 5 by default)

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:04:40 UTC 2015


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

infinity0 pushed a commit to branch debian
in repository onioncat.

commit 4511f93ab1bd862aaed002ad159a23ecfac3fcd4
Author: eagle <eagle at 58e1ccc2-750e-0410-8d0d-f93ca75ab447>
Date:   Sun Dec 27 19:37:46 2009 +0000

     - option -t did not work correctly
     - (optional) pid file is removed at exit
     - SIGUSR1 is handled in preparation for statistics output
     - controller sessions limited to MAX_DEF_CTRL_SESS (= 5 by default)
    
    
    
    git-svn-id: http://www.cypherpunk.at/svn/onioncat/trunk@535 58e1ccc2-750e-0410-8d0d-f93ca75ab447
---
 ChangeLog       |  4 ++++
 configure       | 22 +++++++++++-----------
 src/ocat.c      | 49 ++++++++++++++++++++++++++++++++++++++++++++-----
 src/ocat.h      |  7 +++++++
 src/ocatctrl.c  | 22 ++++++++++++++++++++++
 src/ocatlibe.c  |  2 +-
 src/ocatroute.c | 21 ++++++++++++++++++++-
 src/ocatsetup.c | 31 +++++++++++++++++++++++--------
 8 files changed, 132 insertions(+), 26 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c16237a..2c2a97f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,10 @@
 * version 0.2.2
  - GarliCat branch merged back into trunk
  - added onioncat-privatehosts.pl to trunk (written by zzz)
+ - option -t did not work correctly
+ - (optional) pid file is removed at exit
+ - SIGUSR1 is handled in preparation for statistics output
+ - controller sessions limited to MAX_DEF_CTRL_SESS (= 5 by default)
  
 * version 0.2.1
  - released 2009/11/29, Bernhard R. Fischer
diff --git a/configure b/configure
index de8078d..a45b58f 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.62 for onioncat 0.2.2.r534.
+# Generated by GNU Autoconf 2.62 for onioncat 0.2.2.r535.
 #
 # Report bugs to <rahra at cypherpunk.at>.
 #
@@ -596,8 +596,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
 # Identity of this package.
 PACKAGE_NAME='onioncat'
 PACKAGE_TARNAME='onioncat'
-PACKAGE_VERSION='0.2.2.r534'
-PACKAGE_STRING='onioncat 0.2.2.r534'
+PACKAGE_VERSION='0.2.2.r535'
+PACKAGE_STRING='onioncat 0.2.2.r535'
 PACKAGE_BUGREPORT='rahra at cypherpunk.at'
 
 ac_subst_vars='SHELL
@@ -1260,7 +1260,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.2.2.r534 to adapt to many kinds of systems.
+\`configure' configures onioncat 0.2.2.r535 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1330,7 +1330,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of onioncat 0.2.2.r534:";;
+     short | recursive ) echo "Configuration of onioncat 0.2.2.r535:";;
    esac
   cat <<\_ACEOF
 
@@ -1422,7 +1422,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-onioncat configure 0.2.2.r534
+onioncat configure 0.2.2.r535
 generated by GNU Autoconf 2.62
 
 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
@@ -1436,7 +1436,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.2.2.r534, which was
+It was created by onioncat $as_me 0.2.2.r535, which was
 generated by GNU Autoconf 2.62.  Invocation command line was
 
   $ $0 $@
@@ -2085,7 +2085,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE='onioncat'
- VERSION='0.2.2.r534'
+ VERSION='0.2.2.r535'
 
 
 cat >>confdefs.h <<_ACEOF
@@ -2236,7 +2236,7 @@ ac_config_headers="$ac_config_headers config.h"
 
 
 cat >>confdefs.h <<\_ACEOF
-#define SVN_REVISION "534"
+#define SVN_REVISION "535"
 _ACEOF
 
 
@@ -5220,7 +5220,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.2.2.r534, which was
+This file was extended by onioncat $as_me 0.2.2.r535, which was
 generated by GNU Autoconf 2.62.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -5273,7 +5273,7 @@ Report bugs to <bug-autoconf at gnu.org>."
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_version="\\
-onioncat config.status 0.2.2.r534
+onioncat config.status 0.2.2.r535
 configured by $0, generated by GNU Autoconf 2.62,
   with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
 
diff --git a/src/ocat.c b/src/ocat.c
index 46c09db..6d22c90 100644
--- a/src/ocat.c
+++ b/src/ocat.c
@@ -93,6 +93,7 @@ int open_logfile(void)
 int mk_pid_file(uid_t uid)
 {
    FILE *f;
+   char c;
 
    if (!(f = fopen(CNF(pid_file), "w")))
    {
@@ -104,10 +105,38 @@ int mk_pid_file(uid_t uid)
    fclose(f);
    log_debug("pid_file %s created, pid = %d", CNF(pid_file), getpid());
 
-   if (chown(CNF(pid_file), uid, 0) == -1)
-      log_msg(LOG_ERR, "could not change owner of pid_file \"%s\" to %d: %s", CNF(pid_file), uid, strerror(errno));
+   if (pipe(CNF(pid_fd)) == -1)
+   {
+      log_msg(LOG_WARNING, "could not open pid pipe: \"%s\"", strerror(errno));
+      return -1;
+   }
 
-   return 0;
+   switch (fork())
+   {
+      case -1:
+         oe_close(CNF(pid_fd[0]));
+         oe_close(CNF(pid_fd[1]));
+         return -1;
+
+      // child
+      case 0:
+         oe_close(CNF(pid_fd[1]));
+         if (read(CNF(pid_fd[0]), &c, 1) == -1)
+            log_msg(LOG_ERR, "error reading from pid_fd %d: \"%s\"",
+                  CNF(pid_fd[0]), strerror(errno)), exit(1);
+
+         if (unlink(CNF(pid_file)) == -1)
+            log_msg(LOG_WARNING, "error deleting pid ]ile \"%s\": \"%s\"",
+                  CNF(pid_file), strerror(errno)), exit(1);
+         exit(0);
+
+      // parent
+      default:
+         oe_close(CNF(pid_fd[0]));
+
+   }
+
+   return CNF(pid_fd[1]);
 }
 
 
@@ -163,6 +192,10 @@ void sig_handler(int sig)
 
          CNF(sig_term) = 1;
          break;
+
+      case SIGUSR1:
+         CNF(sig_usr1) = 1;
+         break;
    }
 }
 
@@ -180,12 +213,15 @@ void install_sig(void)
       log_msg(LOG_ERR, "could not install SIGINT handler: \"%s\"", strerror(errno)), exit(1);
    if (sigaction(SIGHUP, &sa, NULL) == -1)
       log_msg(LOG_ERR, "could not install SIGHUP handler: \"%s\"", strerror(errno)), exit(1);
+   if (sigaction(SIGUSR1, &sa, NULL) == -1)
+      log_msg(LOG_ERR, "could not install SIGUSR1 handler: \"%s\"", strerror(errno)), exit(1);
 }
 
 
 void cleanup_system(void)
 {
    OcatPeer_t *peer, *next;
+   char c;
 
    log_msg(LOG_NOTICE, "waiting for system cleanup...");
    // close tunnel interface
@@ -226,8 +262,11 @@ void cleanup_system(void)
 
    delete_listeners(CNF(oc_listen), CNF(oc_listen_fd), CNF(oc_listen_cnt));
 
-   if (CNF(create_pid_file) && (unlink(CNF(pid_file)) == -1))
-      log_msg(LOG_ERR, "could not remove pid file \"%s\": %s", CNF(pid_file), strerror(errno));
+   if (CNF(create_pid_file) && (CNF(pid_fd[1]) != -1))
+   {
+      if (write(CNF(pid_fd[1]), &c, 1) == -1)
+         log_msg(LOG_ERR, "cout not write to pid fd %d: \"%s\"", CNF(pid_fd[1]), strerror(errno));
+   }
 }
 
 
diff --git a/src/ocat.h b/src/ocat.h
index 2bdee4f..2c6a797 100644
--- a/src/ocat.h
+++ b/src/ocat.h
@@ -199,6 +199,8 @@
 #define RECONN_ATTEMPTS 3
 //! RECONN_ATTEMPTS must not be faster than MIN_RECONNECT_TIME
 #define MIN_RECONNECT_TIME 30
+//! define default maximum number of concurrent controller sessions
+#define MAX_DEF_CTRL_SESS 5
 
 #define MFD_SET(f,s,m) {FD_SET(f, s); m = f > m ? f : m;}
 
@@ -212,6 +214,7 @@
 
 #define VERSION_STRING_LEN 256
 
+#define MAX_DEF_CTRL 6
 
 #define NTYPE_TOR 0
 #define NTYPE_I2P 1
@@ -291,6 +294,10 @@ struct OcatSetup
    //! communication pipe for socks "selected" connector
    int socksfd[2];
    int net_type;
+   int max_ctrl, ctrl_active;
+   //! pipe filedescriptors for pid deletion process
+   int pid_fd[2];
+   int sig_usr1, clear_stats;
 };
 
 #ifdef PACKET_QUEUE
diff --git a/src/ocatctrl.c b/src/ocatctrl.c
index 5c9e82b..9985095 100644
--- a/src/ocatctrl.c
+++ b/src/ocatctrl.c
@@ -75,6 +75,10 @@ void *ctrl_handler(void *p)
       //CNF(config_read) = 1;
    }
 
+   lock_setup();
+   CNF(ctrl_active)++;
+   unlock_setup();
+
    fprintf(fo, "%s\n", CNF(version));
    fprintf(fo, "*** ATTENTION! Controller interface not thread-safe yet! Usage could cause deadlocks. ***\n");
 
@@ -302,12 +306,30 @@ void *ctrl_handler(void *p)
    oe_close(pfd[0]);
    oe_close(pfd[1]);
 
+   lock_setup();
+   CNF(ctrl_active)--;
+   unlock_setup();
+
    return NULL;
 }
 
 
 int run_ctrl_handler(int fd)
 {
+   // check number of controller sessions
+   // FIXME: listener should be closed or acceptor delayed instead of
+   // counting after session acceptance.
+   lock_setup();
+   if (CNF(ctrl_active) >= CNF(max_ctrl))
+   {
+      log_msg(LOG_WARNING, "maximum number of controller sessions reached");
+      oe_close(fd);
+      fd = -1;
+   }
+   unlock_setup();
+   if (fd == -1)
+      return -1;
+
    return (int) run_ocat_thread("ctrl_handler", ctrl_handler, (void*) (long) fd);
 }
 
diff --git a/src/ocatlibe.c b/src/ocatlibe.c
index 9b8a099..fc8ea73 100644
--- a/src/ocatlibe.c
+++ b/src/ocatlibe.c
@@ -141,7 +141,7 @@ void add_listener(const char *buf)
 {
    struct sockaddr_in6 saddr;
 
-   if (strsockaddr(buf, &saddr) == -1)
+   if (strsockaddr(buf, (struct sockaddr*) &saddr) == -1)
       log_msg(LOG_EMERG, "could not convert address string '%s'", buf), exit(1);
 
    CNF(oc_listen_cnt)++;
diff --git a/src/ocatroute.c b/src/ocatroute.c
index 6d015dd..b58f02f 100644
--- a/src/ocatroute.c
+++ b/src/ocatroute.c
@@ -630,7 +630,7 @@ int insert_anon_peer(int fd)
 int create_listener(struct sockaddr *addr, int sock_len)
 {
    int family;
-   int fd;
+   int fd, so;
 
    switch (addr->sa_family)
    {
@@ -651,6 +651,9 @@ int create_listener(struct sockaddr *addr, int sock_len)
       return -1;
    }
 
+   so = 1;  
+   if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &so, sizeof(so)) == -1)
+      log_msg(LOG_WARNING, "could not set socket %d to SO_REUSEADDR: \"%s\"", fd, strerror(errno));
    if (bind(fd, addr, sock_len) == -1)
    {
       log_msg(LOG_EMERG, "could not bind listener %d: \"%s\"", fd, strerror(errno));
@@ -821,6 +824,13 @@ void packet_forwarder(void)
                // set global termination flag
                set_term_req();
             }
+            if (CNF(sig_usr1))
+            {
+               lock_setup();
+               CNF(clear_stats) = 1;
+               unlock_setup();
+               log_msg(LOG_NOTICE, "stats will be cleared after next stats output");
+            }
          }
          log_debug("restarting");
          continue;
@@ -964,6 +974,15 @@ void *socket_cleaner(void *ptr)
       {
          stat_wup = act_time;
          log_msg(LOG_INFO, "stats: ... (not implemented yet)");
+
+         lock_setup();
+         if (CNF(clear_stats))
+         {
+            CNF(clear_stats) = 0;
+            // FIXME: implement stats clearing here
+            log_debug("stats cleared");
+         }
+         unlock_setup();
       }
 
       // cleanup MAC table
diff --git a/src/ocatsetup.c b/src/ocatsetup.c
index 9bd74b2..bfdbd7c 100644
--- a/src/ocatsetup.c
+++ b/src/ocatsetup.c
@@ -112,7 +112,13 @@ struct OcatSetup setup_ =
    // socksfd
    {-1, -1},
    // net_type
-   NTYPE_TOR
+   NTYPE_TOR,
+   // max_ctrl, ctrl_active
+   MAX_DEF_CTRL_SESS, 0,
+   // pid_fd
+   {-1, -1},
+   // sig_usr1, clear_stats
+   0, 0
 };
 
 
@@ -130,6 +136,12 @@ void init_setup(void)
 
    //setup_.logf = stderr;
    setup_.uptime = time(NULL);
+   memset(&socks_dst6_, 0, sizeof(socks_dst6_));
+   setup_.socks_dst->sin_family = AF_INET;
+   setup_.socks_dst->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+#ifdef HAVE_SIN_LEN
+   setup_.socks_dst->sin_len = SOCKADDR_SIZE(setup_.socks_dst);
+#endif
 }
 
 
@@ -140,12 +152,8 @@ void post_init_setup(void)
    setup_.ocat_dest_port = NDESC(vdest_port);
    setup_.ocat_ctrl_port = NDESC(ctrl_port);
 
-   setup_.socks_dst->sin_family = AF_INET;
-   setup_.socks_dst->sin_port = htons(NDESC(socks_port));
-   setup_.socks_dst->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-#ifdef HAVE_SIN_LEN
-   setup_.socks_dst->sin_len = SOCKADDR_SIZE(setup_.socks_dst);
-#endif
+   if (!setup_.socks_dst->sin_port)
+      setup_.socks_dst->sin_port = htons(NDESC(socks_port));
 
    ctrl_listen_.sin_family = AF_INET;
    ctrl_listen_.sin_port = htons(setup_.ocat_ctrl_port);
@@ -226,6 +234,10 @@ void print_setup_struct(FILE *f)
          "sizeof_setup           = %d\n"
          "term_req               = %d\n"
          "net_type               = %d (%s)\n"
+         "max_ctrl               = %d\n"
+         "ctrl_active            = %d\n"
+         "pid_fd[2]              = {%d, %d}\n"
+         "clear_stats            = %d\n"
          ,
          IPV4_KEY, ntohl(setup_.fhd_key[IPV4_KEY]), IPV6_KEY, ntohl(setup_.fhd_key[IPV6_KEY]),
          setup_.fhd_key_len,
@@ -259,7 +271,10 @@ void print_setup_struct(FILE *f)
          (int) strlen(setup_.version), VERSION_STRING_LEN, setup_.version,
          setup_.sizeof_setup,
          setup_.term_req,
-         setup_.net_type, setup_.net_type == NTYPE_TOR ? "NTYPE_TOR" : setup_.net_type == NTYPE_I2P ? "NTYPE_I2P" : "unknown"
+         setup_.net_type, setup_.net_type == NTYPE_TOR ? "NTYPE_TOR" : setup_.net_type == NTYPE_I2P ? "NTYPE_I2P" : "unknown",
+         setup_.max_ctrl, setup_.ctrl_active,
+         setup_.pid_fd[0], setup_.pid_fd[1],
+         setup_.clear_stats
          );
 
 #ifdef CONNECT_ROOT_PEERS

-- 
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