瀏覽代碼

* Port [3209] to 1.2.14
* The socket file generated for restarting is now encrypted.



svn: 3210

Bryan Drewery 19 年之前
父節點
當前提交
3ffb80102a
共有 6 個文件被更改,包括 69 次插入34 次删除
  1. 1 0
      doc/UPDATES
  2. 23 15
      src/dccutil.c
  3. 1 1
      src/dccutil.h
  4. 24 7
      src/misc.c
  5. 19 10
      src/net.c
  6. 1 1
      src/net.h

+ 1 - 0
doc/UPDATES

@@ -11,6 +11,7 @@ Lines prefixed with '-' were disabled before release and are not finished, or ar
 * Fix typo in help for 'set' (fixes #342)
 * Fix cmd_swhois stripping multiple channel modes. (fixes #348)
 * Fix processing/killing/signalling of possible new localhub when editing binary.
+* The socket file generated for restarting is now encrypted.
 
 1.2.13 - http://wraith.shatow.net/milestone/1.2.13
 * Fix cmd_chanset accepting invalid flags

+ 23 - 15
src/dccutil.c

@@ -423,18 +423,24 @@ dcc_chatter(int idx)
 }
 
 int
-dcc_read(FILE *f)
+dcc_read(FILE *f, bool enc)
 {
-  char inbuf[1024] = "", *type = NULL, *buf = NULL;
+  char inbuf[1024] = "", *type = NULL, *buf = NULL, *buf_ptr = NULL;
   int idx = -1;
   bool isserv = 0;
 
   while (fgets(inbuf, sizeof(inbuf), f) != NULL) {
     remove_crlf(inbuf);
-    buf = inbuf;
+    if (enc)
+      buf = buf_ptr = decrypt_string(settings.salt1, inbuf);
+    else
+      buf = inbuf;
 
-    if (!strcmp(buf, "+dcc"))
+    if (!strcmp(buf, "+dcc")) {
+      if (enc)
+        free(buf_ptr);
       return idx;
+    }
     
     type = newsplit(&buf);
     if (!strcmp(type, "type")) {
@@ -473,6 +479,8 @@ dcc_read(FILE *f)
         strlcpy(dcc[idx].host, buf, UHOSTLEN);
       }
     }
+    if (enc)
+      free(buf_ptr);
   }
   return -1;
 }
@@ -481,24 +489,24 @@ void
 dcc_write(FILE *f, int idx)
 {
   if (dcc[idx].sock > 0) {
-    fprintf(f, "-dcc\n");
+    lfprintf(f, "-dcc\n");
     if (dcc[idx].type)
-      fprintf(f, "type %s\n", dcc[idx].type->name);
+      lfprintf(f, "type %s\n", dcc[idx].type->name);
 //  if (user)
-//  fprintf(f, "user %s\n", dcc[idx].user->handle);
+//  lfprintf(f, "user %s\n", dcc[idx].user->handle);
     if (dcc[idx].addr)
-      fprintf(f, "addr %u\n", dcc[idx].addr);
+      lfprintf(f, "addr %u\n", dcc[idx].addr);
     if (dcc[idx].status)
-      fprintf(f, "status %lu\n", dcc[idx].status);
-    fprintf(f, "sock %d\n", dcc[idx].sock);
-//  fprintf(f, "simul %d\n", dcc[idx].simul);
+      lfprintf(f, "status %lu\n", dcc[idx].status);
+    lfprintf(f, "sock %d\n", dcc[idx].sock);
+//  lfprintf(f, "simul %d\n", dcc[idx].simul);
     if (dcc[idx].port)
-      fprintf(f, "port %d\n", dcc[idx].port);  
+      lfprintf(f, "port %d\n", dcc[idx].port);  
     if (dcc[idx].nick[0])
-      fprintf(f, "nick %s\n", dcc[idx].nick);
+      lfprintf(f, "nick %s\n", dcc[idx].nick);
     if (dcc[idx].host[0])
-      fprintf(f, "host %s\n", dcc[idx].host);
-    fprintf(f, "+dcc\n");
+      lfprintf(f, "host %s\n", dcc[idx].host);
+    lfprintf(f, "+dcc\n");
   }
 }
 

+ 1 - 1
src/dccutil.h

@@ -54,7 +54,7 @@ void identd_open();
 void identd_close();
 int listen_all(port_t, bool);
 bool valid_idx(int);
-int dcc_read(FILE *);
+int dcc_read(FILE *, bool);
 void dcc_write(FILE *, int);
 int check_cmd_pass(const char *, char *);
 int has_cmd_pass(const char *);

+ 24 - 7
src/misc.c

@@ -575,25 +575,40 @@ readsocks(const char *fname)
     fatal("CANT READ SOCKSFILE", 0);
   }
 
-  char buf[1024] = "", *nick = NULL, *bufp = NULL, *type = NULL;
+  char buf[1024] = "", *nick = NULL, *bufp = NULL, *type = NULL, *buf_ptr = NULL;
   time_t old_buildts = 0;
 
+  bool enc = 0, first = 1;
+
   while (fgets(buf, sizeof(buf), f) != NULL) {
     remove_crlf(buf);
-    bufp = buf;
+
+    if (first) {
+      if (!strncmp(buf, "+enc", 4))
+        enc = 1;
+      first = 0;
+    }
+
+    if (enc)
+      bufp = buf_ptr = decrypt_string(settings.salt1, buf);
+    else
+      bufp = buf;
 
 //    dprintf(DP_STDOUT, "read line: %s\n", buf);
     type = newsplit(&bufp);
     if (!strcmp(type, "-dcc"))
-      dprintf(DP_STDOUT, "Added dcc: %d\n", dcc_read(f));
+      dprintf(DP_STDOUT, "Added dcc: %d\n", dcc_read(f, enc));
     else if (!strcmp(type, "-sock"))
-      dprintf(DP_STDOUT, "Added fd: %d\n", sock_read(f));
+      dprintf(DP_STDOUT, "Added fd: %d\n", sock_read(f, enc));
     else if (!strcmp(type, "+online_since"))
       online_since = strtol(bufp, NULL, 10);
     else if (!strcmp(type, "+buildts"))
       old_buildts = strtol(bufp, NULL, 10);
     else if (!strcmp(type, "+botname"))
       nick = strdup(bufp);
+
+    if (enc)
+      free(buf_ptr);
   }
 
   restart_time = now;
@@ -653,6 +668,8 @@ restart(int idx)
     }
   }
 
+  fprintf(socks->f, "+enc\n");
+
   /* write out all leftover dcc[] entries */
   for (fd = 0; fd < dcc_total; fd++)
     if (dcc[fd].type && dcc[fd].sock != STDOUT)
@@ -665,10 +682,10 @@ restart(int idx)
 
   if (server_online) {
     if (botname[0])
-      fprintf(socks->f, "+botname %s\n", botname);
+      lfprintf(socks->f, "+botname %s\n", botname);
   }
-  fprintf(socks->f, "+online_since %li\n", online_since);
-  fprintf(socks->f, "+buildts %li\n", buildts);
+  lfprintf(socks->f, "+online_since %li\n", online_since);
+  lfprintf(socks->f, "+buildts %li\n", buildts);
   fflush(socks->f);
   socks->my_close();
 

+ 19 - 10
src/net.c

@@ -333,17 +333,24 @@ int sockoptions(int sock, int operation, int sock_options)
 }
 
 int
-sock_read(FILE *f)
+sock_read(FILE *f, bool enc)
 {
-  char inbuf[1024] = "", *type = NULL, *buf = NULL;
+  char inbuf[1024] = "", *type = NULL, *buf = NULL, *buf_ptr = NULL;
   int fd = -1;
 
   while (fgets(inbuf, sizeof(inbuf), f) != NULL) {
     remove_crlf(inbuf);
 
-    buf = inbuf;
-    if (!strcmp(buf, "+sock"))
+    if (enc)
+      buf = buf_ptr = decrypt_string(settings.salt1, inbuf);
+    else
+      buf = inbuf;
+
+    if (!strcmp(buf, "+sock")) {
+      if (enc)
+        free(buf_ptr);
       return fd;
+    }
 
     type = newsplit(&buf);
     if (!strcmp(type, "sock")) {
@@ -362,6 +369,8 @@ sock_read(FILE *f)
       if (!strcmp(type, "port"))
         socklist[fd].port = atoi(buf);
     }
+    if (enc)
+      free(buf_ptr);
   }
   return -1;
 }
@@ -370,16 +379,16 @@ void
 sock_write(FILE *f, int fd)
 {
   if (socklist[fd].sock > 0) {
-    fprintf(f, "-sock\n");
-    fprintf(f, "sock %d %d\n", socklist[fd].sock, socklist[fd].flags);
+    lfprintf(f, "-sock\n");
+    lfprintf(f, "sock %d %d\n", socklist[fd].sock, socklist[fd].flags);
 #ifdef USE_IPV6
-    fprintf(f, "af %u\n", socklist[fd].af);
+    lfprintf(f, "af %u\n", socklist[fd].af);
 #endif
     if (socklist[fd].host)
-      fprintf(f, "host %s\n", socklist[fd].host);
+      lfprintf(f, "host %s\n", socklist[fd].host);
     if (socklist[fd].port)
-      fprintf(f, "port %d\n", socklist[fd].port);
-    fprintf(f, "+sock\n");
+      lfprintf(f, "port %d\n", socklist[fd].port);
+    lfprintf(f, "+sock\n");
   }    
 }
 

+ 1 - 1
src/net.h

@@ -147,7 +147,7 @@ char *iptostr(in_addr_t);
 bool sock_has_data(int, int);
 int sockoptions(int sock, int operation, int sock_options);
 void init_net(void);
-int sock_read(FILE *);
+int sock_read(FILE *, bool);
 void sock_write(FILE *, int);
 
 extern union sockaddr_union 		cached_myip4_so;