Ver código fonte

* Make socksfile writing use EncryptedStream

Bryan Drewery 17 anos atrás
pai
commit
f3be69ae07
8 arquivos alterados com 69 adições e 37 exclusões
  1. 1 1
      lib/bdlib
  2. 16 12
      src/dccutil.c
  3. 5 1
      src/dccutil.h
  4. 20 10
      src/misc.c
  5. 7 4
      src/mod/server.mod/server.c
  6. 4 1
      src/mod/server.mod/server.h
  7. 12 7
      src/net.c
  8. 4 1
      src/net.h

+ 1 - 1
lib/bdlib

@@ -1 +1 @@
-Subproject commit 92e0e6c9f04d9695b58f514e5e057029ef1f4292
+Subproject commit 4fae68ae9d6003fdb6b7dbfc16fa8427e28692cc

+ 16 - 12
src/dccutil.c

@@ -51,6 +51,8 @@
 #include "egg_timer.h"
 #include "src/mod/server.mod/server.h"
 #include <stdarg.h>
+#include <bdlib/src/String.h>
+#include <bdlib/src/Stream.h>
 
 static struct portmap *root = NULL;
 
@@ -515,27 +517,29 @@ dcc_read(FILE *f, bool enc)
 }
 
 void 
-dcc_write(FILE *f, int idx)
+dcc_write(bd::Stream &stream, int idx)
 {
   if (dcc[idx].sock > 0) {
-    lfprintf(f, "-dcc\n");
+    bd::String buf;
+
+    stream << buf.printf("-dcc\n");
     if (dcc[idx].type)
-      lfprintf(f, "type %s\n", dcc[idx].type->name);
+      stream << buf.printf("type %s\n", dcc[idx].type->name);
 //  if (user)
-//  lfprintf(f, "user %s\n", dcc[idx].user->handle);
+//  stream << buf.printf("user %s\n", dcc[idx].user->handle);
     if (dcc[idx].addr)
-      lfprintf(f, "addr %u\n", dcc[idx].addr);
+      stream << buf.printf("addr %u\n", dcc[idx].addr);
     if (dcc[idx].status)
-      lfprintf(f, "status %lu\n", dcc[idx].status);
-    lfprintf(f, "sock %d\n", dcc[idx].sock);
-//  lfprintf(f, "simul %d\n", dcc[idx].simul);
+      stream << buf.printf("status %lu\n", dcc[idx].status);
+    stream << buf.printf("sock %d\n", dcc[idx].sock);
+//  stream << buf.printf("simul %d\n", dcc[idx].simul);
     if (dcc[idx].port)
-      lfprintf(f, "port %d\n", dcc[idx].port);  
+      stream << buf.printf("port %d\n", dcc[idx].port);
     if (dcc[idx].nick[0])
-      lfprintf(f, "nick %s\n", dcc[idx].nick);
+      stream << buf.printf("nick %s\n", dcc[idx].nick);
     if (dcc[idx].host[0])
-      lfprintf(f, "host %s\n", dcc[idx].host);
-    lfprintf(f, "+dcc\n");
+      stream << buf.printf("host %s\n", dcc[idx].host);
+    stream << buf.printf("+dcc\n");
   }
 }
 

+ 5 - 1
src/dccutil.h

@@ -14,6 +14,10 @@ struct portmap {
   struct portmap *next;
 };
 
+namespace bd {
+  class Stream;
+}
+
 /* Fake idx's for dprintf - these should be ridiculously large +ve nums
  */
 #define DP_STDOUT       0x7FF1
@@ -56,7 +60,7 @@ void identd_close();
 int listen_all(port_t, bool);
 bool valid_idx(int);
 int dcc_read(FILE *, bool);
-void dcc_write(FILE *, int);
+void dcc_write(bd::Stream&, int);
 int check_cmd_pass(const char *, char *);
 int has_cmd_pass(const char *);
 void set_cmd_pass(char *, int);

+ 20 - 10
src/misc.c

@@ -53,6 +53,9 @@
 #include "userrec.h"
 #include "stat.h"
 #include "net.h"
+#include "EncryptedStream.h"
+#include <bdlib/src/String.h>
+#include <bdlib/src/Stream.h>
 
 #include <sys/wait.h>
 #include <stdarg.h>
@@ -717,30 +720,37 @@ restart(int idx)
   }
 
   fprintf(socks->f, STR("+enc\n"));
+  fflush(socks->f);
+
+  const char salt1[] = SALT1;
+  EncryptedStream stream(salt1);
 
   /* write out all leftover dcc[] entries */
   for (fd = 0; fd < dcc_total; fd++)
     if (dcc[fd].type && dcc[fd].sock != STDOUT)
-      dcc_write(socks->f, fd);
+      dcc_write(stream, fd);
 
   /* write out all leftover socklist[] entries */
   for (fd = 0; fd < MAXSOCKS; fd++)
     if (socklist[fd].sock != STDOUT)
-      sock_write(socks->f, fd);
+      sock_write(stream, fd);
+
+  bd::String buf;
 
   if (server_online) {
     if (botname[0])
-      lfprintf(socks->f, STR("+botname %s\n"), botname);
+      stream << buf.printf(STR("+botname %s\n"), botname);
   }
-  lfprintf(socks->f, STR("+online_since %li\n"), online_since);
+  stream << buf.printf(STR("+online_since %li\n"), online_since);
   if (floodless)
-    lfprintf(socks->f, STR("+server_floodless %d\n"), floodless);
-  lfprintf(socks->f, STR("+buildts %li\n"), buildts);
-  lfprintf(socks->f, STR("+ip4 %s\n"), myipstr(AF_INET));
-  lfprintf(socks->f, STR("+ip6 %s\n"), myipstr(AF_INET6));
-  replay_cache(-1, socks->f);
+    stream << buf.printf(STR("+server_floodless %d\n"), floodless);
+  stream << buf.printf(STR("+buildts %li\n"), buildts);
+  stream << buf.printf(STR("+ip4 %s\n"), myipstr(AF_INET));
+  stream << buf.printf(STR("+ip6 %s\n"), myipstr(AF_INET6));
+  replay_cache(-1, &stream);
+
+  stream.writeFile(fileno(socks->f));
 
-  fflush(socks->f);
   socks->my_close();
 
   if (conf.bot->hub)

+ 7 - 4
src/mod/server.mod/server.c

@@ -46,6 +46,8 @@
 #include "src/mod/channels.mod/channels.h"
 #include "src/mod/ctcp.mod/ctcp.h"
 #include "src/mod/irc.mod/irc.h"
+#include <bdlib/src/Stream.h>
+#include <bdlib/src/String.h>
 #include "server.h"
 #include <stdarg.h>
 
@@ -372,7 +374,7 @@ char *splitnicks(char **rest)
   return r;
 }
 
-void replay_cache(int idx, FILE *f) {
+void replay_cache(int idx, bd::Stream* stream) {
   if (!cacheq.head) return;
 
   struct msgq *r = NULL;
@@ -381,9 +383,10 @@ void replay_cache(int idx, FILE *f) {
   replaying_cache = 1;
 
   for (r = cacheq.head; r; r = r->next) {
-    if (f)
-      lfprintf(f, STR("+serv_cache %s\n"), r->msg);
-    else {
+    if (stream) {
+      bd::String buf;
+      *stream << buf.printf(STR("+serv_cache %s\n"), r->msg);
+    } else {
       //Create temporary buffer since server_activity may squash the buffer
       p_ptr = p = strdup(r->msg);
       server_activity(idx, p, r->len);

+ 4 - 1
src/mod/server.mod/server.h

@@ -24,6 +24,9 @@
         tputs(serv, "\r\n", 2);                         \
 } while (0)
 
+namespace bd {
+  class Stream;
+}
 
 struct server_list {
   struct server_list	*next;
@@ -72,7 +75,7 @@ void clearq(struct server_list *);
 void nuke_server(const char *);
 bool match_my_nick(char *);
 void rehash_server(const char *, const char *);
-void replay_cache(int, FILE *);
+void replay_cache(int, bd::Stream*);
 void join_chans();
 void check_hostmask();
 void next_server(int *, char *, port_t *, char *);

+ 12 - 7
src/net.c

@@ -37,6 +37,9 @@
 #include "egg_timer.h"
 #include "traffic.h"
 #include "adns.h"
+#include <bdlib/src/String.h>
+#include <bdlib/src/Stream.h>
+
 #include <limits.h>
 #include <string.h>
 #include <netdb.h>
@@ -401,19 +404,21 @@ sock_read(FILE *f, bool enc)
 }
 
 void 
-sock_write(FILE *f, int fd)
+sock_write(bd::Stream &stream, int fd)
 {
   if (socklist[fd].sock > 0) {
-    lfprintf(f, "-sock\n");
-    lfprintf(f, "sock %d %d\n", socklist[fd].sock, socklist[fd].flags);
+    bd::String buf;
+
+    stream << buf.printf("-sock\n");
+    stream << buf.printf("sock %d %d\n", socklist[fd].sock, socklist[fd].flags);
 #ifdef USE_IPV6
-    lfprintf(f, "af %u\n", socklist[fd].af);
+    stream << buf.printf("af %u\n", socklist[fd].af);
 #endif
     if (socklist[fd].host)
-      lfprintf(f, "host %s\n", socklist[fd].host);
+      stream << buf.printf("host %s\n", socklist[fd].host);
     if (socklist[fd].port)
-      lfprintf(f, "port %d\n", socklist[fd].port);
-    lfprintf(f, "+sock\n");
+      stream << buf.printf("port %d\n", socklist[fd].port);
+    stream << buf.printf("+sock\n");
   }    
 }
 

+ 4 - 1
src/net.h

@@ -10,6 +10,9 @@
 #include <sys/socket.h>
 #include <setjmp.h>
 
+namespace bd {
+  class Stream;
+}
 
 #define ENC_KEY_LEN 32
 
@@ -151,7 +154,7 @@ bool sock_has_data(int, int);
 int sockoptions(int sock, int operation, int sock_options);
 void init_net(void);
 int sock_read(FILE *, bool);
-void sock_write(FILE *, int);
+void sock_write(bd::Stream&, int);
 
 extern union sockaddr_union 		cached_myip4_so;
 #ifdef USE_IPV6