[Pkg-privacy-commits] [onioncat] 114/340: hidden service listening address now configurable

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:04:30 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 b1412c1b92e02a29e6eff8c0853a9d7aa148e60d
Author: eagle <eagle at 58e1ccc2-750e-0410-8d0d-f93ca75ab447>
Date:   Sat Jan 10 00:18:59 2009 +0000

    hidden service listening address now configurable
    
    git-svn-id: http://www.cypherpunk.at/svn/onioncat/trunk@426 58e1ccc2-750e-0410-8d0d-f93ca75ab447
---
 hosts.onioncat  |  3 +++
 src/ocat.c      | 11 +++++++----
 src/ocat.h      |  5 ++++-
 src/ocatctrl.c  |  2 +-
 src/ocatlibe.c  | 20 +++++++++++++++++++-
 src/ocatroute.c |  9 +++++----
 src/ocatsetup.c | 31 +++++++++++++++++++------------
 7 files changed, 58 insertions(+), 23 deletions(-)

diff --git a/hosts.onioncat b/hosts.onioncat
new file mode 100644
index 0000000..dbd4d6c
--- /dev/null
+++ b/hosts.onioncat
@@ -0,0 +1,3 @@
+fd87:d87e:eb43:f683:64ac:73f9:61ac:9a00 dot.onioncat
+fd87:d87e:eb43:2243:5f84:5b12:7bb5:bbc2 irc.onioncat
+
diff --git a/src/ocat.c b/src/ocat.c
index 2acccb8..ccb38e4 100644
--- a/src/ocat.c
+++ b/src/ocat.c
@@ -122,11 +122,13 @@ void background(void)
 int main(int argc, char *argv[])
 {
    //char tunname[IFNAMSIZ] = {0}, 
-   char *s, ip6addr[INET6_ADDRSTRLEN], hw[20];
+   char *s, ip6addr[INET6_ADDRSTRLEN], hw[20], def[100];
    int c, runasroot = 0;
    struct passwd *pwd;
    int urlconv = 0;
 
+   snprintf(def, 100, "127.0.0.1:%d", OCAT_LISTEN_PORT);
+
    init_setup();
 
    if (argc < 2)
@@ -161,9 +163,7 @@ int main(int argc, char *argv[])
             break;
 
          case 'l':
-            //CNF(ocat_listen_port) = atoi(optarg);
-            if (strsockaddr(optarg, (struct sockaddr*) CNF(oc_listen)) == -1)
-               exit(1);
+            add_listener(optarg, def);
             break;
 
          case 'L':
@@ -298,6 +298,9 @@ int main(int argc, char *argv[])
    if (CNF(daemon))
       background();
 
+   if (!CNF(oc_listen))
+      add_listener(def, def);
+
    // start socket receiver thread
    run_ocat_thread("receiver", socket_receiver, NULL);
    // create listening socket and start socket acceptor
diff --git a/src/ocat.h b/src/ocat.h
index 35ab3e9..be265a8 100644
--- a/src/ocat.h
+++ b/src/ocat.h
@@ -263,6 +263,8 @@ struct OcatSetup
    };
    //! local listening socket address for incoming connections
    struct sockaddr **oc_listen;
+   int *oc_listen_fd;
+   int oc_listen_cnt;
    int rand_addr;
    char version[VERSION_STRING_LEN];
    int sizeof_setup;
@@ -543,7 +545,6 @@ uint16_t checksum(const uint16_t *, int);
 void free_ckbuf(uint16_t *);
 uint16_t *malloc_ckbuf(const struct in6_addr *, const struct in6_addr *, uint16_t, uint8_t, const void *);
 
-
 /* ocatsocks.c */
 void socks_queue(struct in6_addr, int);
 void print_socks_queue(FILE *);
@@ -552,6 +553,8 @@ void print_socks_queue(FILE *);
 void oe_close(int);
 int oe_remtr(char *);
 int strsockaddr(const char *, struct sockaddr *);
+void add_local_listeners(void);
+void add_listener(const char *, const char *);
 
 /* ocatipv6route.c */
 struct in6_addr *ipv6_lookup_route(const struct in6_addr *);
diff --git a/src/ocatctrl.c b/src/ocatctrl.c
index e0dc357..96a6854 100644
--- a/src/ocatctrl.c
+++ b/src/ocatctrl.c
@@ -171,7 +171,7 @@ void *ctrl_handler(void *p)
       }
       else if (!strcmp(buf, "fds"))
       {
-         fprintf(fo, "acceptor sockets: %d/%d\nconntroller sockets: %d/%d\n", sockfd_[0], sockfd_[1], ctrlfd_[0], ctrlfd_[1]);
+         fprintf(fo, "conntroller sockets: %d/%d\n", ctrlfd_[0], ctrlfd_[1]);
       }
       else if (!strcmp(buf, "route"))
       {
diff --git a/src/ocatlibe.c b/src/ocatlibe.c
index 2751983..00d3328 100644
--- a/src/ocatlibe.c
+++ b/src/ocatlibe.c
@@ -128,7 +128,7 @@ int strsockaddr(const char *src, struct sockaddr *addr)
             return AF_INET;
 
          default:
-            log_debug("adress family %04x not supported", ((struct sockaddr_in*) addr)->sin_family);
+            log_debug("adress family 0x%04x not supported", ((struct sockaddr_in*) addr)->sin_family);
             return -1;
       }
    }
@@ -136,3 +136,21 @@ int strsockaddr(const char *src, struct sockaddr *addr)
    return -1;
 }
 
+
+void add_listener(const char *buf, const char *def)
+{
+   CNF(oc_listen_cnt)++;
+   if (!(CNF(oc_listen) = realloc(CNF(oc_listen), sizeof(struct sockaddr*) * CNF(oc_listen_cnt))))
+      log_msg(LOG_ERR, "could not get memory for listener list: \"%s\"", strerror(errno)), exit(1);
+   if (!(CNF(oc_listen_fd) = realloc(CNF(oc_listen), sizeof(int) * CNF(oc_listen_cnt))))
+      log_msg(LOG_ERR, "could not get memory for listener fds: \"%s\"", strerror(errno)), exit(1);
+
+   if (!(CNF(oc_listen)[CNF(oc_listen_cnt) - 1] = calloc(1, sizeof(struct sockaddr_in6))))
+      log_msg(LOG_ERR, "could not get memory for listener : \"%s\"", strerror(errno)), exit(1);
+   if (def)
+      if (strsockaddr(def, CNF(oc_listen)[CNF(oc_listen_cnt) - 1]) == -1)
+         log_msg(LOG_EMERG, "illegal default string '%s'", def), exit(1);
+   if (strsockaddr(buf, CNF(oc_listen)[CNF(oc_listen_cnt) - 1]) == -1)
+      log_msg(LOG_EMERG, "could not convert address string '%s'", buf), exit(1);
+}
+
diff --git a/src/ocatroute.c b/src/ocatroute.c
index b6c405d..ecc47e9 100644
--- a/src/ocatroute.c
+++ b/src/ocatroute.c
@@ -35,7 +35,7 @@
 #endif
 
 // file descriptor of tcp listener
-int sockfd_[2];
+//int sockfd_[2];
 // file descriptors of socket_receiver pipe
 // used for internal communication
 static int lpfd_[2];
@@ -663,10 +663,10 @@ int run_listeners(struct sockaddr **addr, int *sockfd, int (action_accept)(int))
    socklen_t alen;
    char iabuf[INET6_ADDRSTRLEN];
 
-   for (i = 0, saddr = *addr; saddr; saddr = addr[i], i++)
+   for (i = 0; i < CNF(oc_listen_cnt); i++)
    {
       log_debug("create listener");
-      if ((sockfd[i] = create_listener(saddr, SOCKADDR_SIZE(saddr))) == -1)
+      if ((sockfd[i] = create_listener(CNF(oc_listen)[i], SOCKADDR_SIZE(CNF(oc_listen)[i]))) == -1)
          log_msg(LOG_EMERG, "exiting"), exit(1);
    }
    cnt = i;
@@ -802,7 +802,8 @@ int run_local_listeners(short port, int *sockfd, int (action_accept)(int))
 
 void *socket_acceptor(void *p)
 {
-   run_local_listeners(CNF(ocat_listen_port), sockfd_, insert_anon_peer);
+   //run_local_listeners(CNF(ocat_listen_port), sockfd_, insert_anon_peer);
+   run_listeners(CNF(oc_listen), CNF(oc_listen_fd), insert_anon_peer);
    return NULL;
 }
 
diff --git a/src/ocatsetup.c b/src/ocatsetup.c
index a189f27..cf51b3e 100644
--- a/src/ocatsetup.c
+++ b/src/ocatsetup.c
@@ -27,8 +27,6 @@
 
 
 static struct sockaddr_in6 socks_dst6_;
-static struct sockaddr_in6 oc_listen6_;
-static struct sockaddr* oc_listen_a_[] = {(struct sockaddr*) &oc_listen6_, NULL};
 
 struct OcatSetup setup_ =
 {
@@ -63,7 +61,12 @@ struct OcatSetup setup_ =
    0,
    "/dev/urandom",
    {(struct sockaddr_in*) &socks_dst6_},
-   oc_listen_a_,
+   // oc_listen
+   NULL,
+   // oc_listen_fd
+   NULL,
+   // oc_listen_cnt
+   0,
    //! rand_addr
    0,
    {0},
@@ -71,6 +74,9 @@ struct OcatSetup setup_ =
 };
 
 
+#define IADDRSTRLEN 128
+
+
 void init_setup(void)
 {
    struct timeval tv;
@@ -90,21 +96,14 @@ void init_setup(void)
    setup_.socks_dst->sin_len = sizeof(socks_dst6_);
 #endif
 
-   /*
-   ((struct sockaddr_in*) *setup_.oc_listen)->sin_family = AF_INET;
-   setup_.oc_listen->sin_port = htons(OCAT_LISTEN_PORT);
-   setup_.oc_listen->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-#ifdef HAVE_SIN_LEN
-   setup_.oc_listen->sin_len = sizeof(oc_listen6_);
-#endif
-*/
-
    snprintf(setup_.version, VERSION_STRING_LEN, "%s (c) %s -- compiled %s %s", PACKAGE_STRING, OCAT_AUTHOR, __DATE__, __TIME__);
+
 }
 
 
 #define SBUF 100
 
+
 void print_setup_struct(FILE *f)
 {
    char *c, ip[SBUF], nm[SBUF], ip6[SBUF], logf[SBUF], hw[SBUF], rp[SBUF];
@@ -210,5 +209,13 @@ void print_setup_struct(FILE *f)
    else
       log_msg(LOG_WARNING, "could not convert struct sockaddr: \"%s\"", strerror(errno));
  
+   for (i = 0; i < CNF(oc_listen_cnt); i++)
+   {
+      if (inet_ntops(CNF(oc_listen)[i], &sas))
+         fprintf(f, "oc_listen[%d]          = %s:%d", i, sas.sstr_addr, ntohs(sas.sstr_port));
+      else
+         log_msg(LOG_WARNING, "could not convert struct sockaddr: \"%s\"", strerror(errno));
+      fprintf(f, "oc_listen_fd[%d]       = %d", i, CNF(oc_listen_fd)[i]);
+   }
 }
 

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