Просмотр исходного кода

* More work on new link encryption system

svn: 1661
Bryan Drewery 21 лет назад
Родитель
Сommit
a43fb863ec
4 измененных файлов с 97 добавлено и 29 удалено
  1. 14 8
      src/dcc.c
  2. 77 19
      src/enclink.c
  3. 5 1
      src/enclink.h
  4. 1 1
      src/net.h

+ 14 - 8
src/dcc.c

@@ -302,7 +302,7 @@ cont_link(int idx, char *buf, int ii)
 
 
     if (snum >= 0) {
     if (snum >= 0) {
       socklist[snum].enclink = link_find_by_type(LINK_GHOST);
       socklist[snum].enclink = link_find_by_type(LINK_GHOST);
-      link_link(idx, LINK_GHOST, TO);
+      link_link(idx, LINK_GHOST, -1, TO);
     }
     }
 
 
     /* wait for "elink" now */
     /* wait for "elink" now */
@@ -330,7 +330,9 @@ dcc_bot_new(int idx, char *buf, int x)
     greet_new_bot(idx);
     greet_new_bot(idx);
   } else if (!egg_strcasecmp(code, "v")) {
   } else if (!egg_strcasecmp(code, "v")) {
     bot_version(idx, buf);
     bot_version(idx, buf);
-  } else if (!egg_strcasecmp(code, "elink")) {	/* we're connecting to THEM (old) */
+
+/* FIXME: remove after 1.2.2 */
+  } else if (!egg_strcasecmp(code, "elink")) { /* we're connecting to THEM (old) */
     int snum = findanysnum(dcc[idx].sock);
     int snum = findanysnum(dcc[idx].sock);
 
 
     /* putlog(LOG_DEBUG, "*", "Got elink: %s %s", code, buf); */
     /* putlog(LOG_DEBUG, "*", "Got elink: %s %s", code, buf); */
@@ -347,6 +349,8 @@ dcc_bot_new(int idx, char *buf, int x)
       putlog(LOG_BOTS, "*", "Handshake with %s succeeded, we're linked.", dcc[idx].nick);
       putlog(LOG_BOTS, "*", "Handshake with %s succeeded, we're linked.", dcc[idx].nick);
       free(tmp);
       free(tmp);
     }
     }
+  } else if (!egg_strcasecmp(code, "neg!")) {	/* something to parse in enclink.c */
+    link_parse(idx, buf);
   } else if (!egg_strcasecmp(code, "neg?")) {	/* we're connecting to THEM */
   } else if (!egg_strcasecmp(code, "neg?")) {	/* we're connecting to THEM */
     int snum = findanysnum(dcc[idx].sock);
     int snum = findanysnum(dcc[idx].sock);
 
 
@@ -369,8 +373,7 @@ dcc_bot_new(int idx, char *buf, int x)
       link_hash(idx, rand);
       link_hash(idx, rand);
       dprintf(idx, "neg %s %d\n", dcc[idx].shahash, enclink[i].type);
       dprintf(idx, "neg %s %d\n", dcc[idx].shahash, enclink[i].type);
       socklist[snum].enclink = i;
       socklist[snum].enclink = i;
-      if (enclink[i].link)
-        (enclink[i].link) (idx, TO);	
+      link_link(idx, -1, i, TO);
     }
     }
   } else if (!egg_strcasecmp(code, "error")) {
   } else if (!egg_strcasecmp(code, "error")) {
     putlog(LOG_MISC, "*", "ERROR linking %s: %s", dcc[idx].nick, buf);
     putlog(LOG_MISC, "*", "ERROR linking %s: %s", dcc[idx].nick, buf);
@@ -923,7 +926,10 @@ dcc_chat_pass(int idx, char *buf, int atr)
   pass = newsplit(&buf);
   pass = newsplit(&buf);
 
 
   if (dcc[idx].user->bot) {
   if (dcc[idx].user->bot) {
-    if (!egg_strcasecmp(pass, "elinkdone")) {		/* we're the hub */
+    if (!egg_strcasecmp(pass, "neg!")) {		/* we're the hub */
+      link_parse(idx, buf);
+/* FIXME: remove after 1.2.2 */
+    } else if (!egg_strcasecmp(pass, "neg.") || !egg_strcasecmp(pass, "elinkdone")) {		/* we're done, link up! */
       free(dcc[idx].u.chat);
       free(dcc[idx].u.chat);
       dcc[idx].type = &DCC_BOT_NEW;
       dcc[idx].type = &DCC_BOT_NEW;
       dcc[idx].u.bot = (struct bot_info *) my_calloc(1, sizeof(struct bot_info));
       dcc[idx].u.bot = (struct bot_info *) my_calloc(1, sizeof(struct bot_info));
@@ -955,8 +961,8 @@ dcc_chat_pass(int idx, char *buf, int atr)
           return;
           return;
         }
         }
         socklist[snum].enclink = i;
         socklist[snum].enclink = i;
-        if (enclink[i].link)
-          (enclink[i].link) (idx, FROM);
+
+        link_link(idx, -1, i, FROM);
       }
       }
     } else {
     } else {
       /* Invalid password/digest on hub */
       /* Invalid password/digest on hub */
@@ -1651,7 +1657,7 @@ dcc_telnet_pass(int idx, int atr)
 
 
       if (snum >= 0) {
       if (snum >= 0) {
         socklist[snum].enclink = link_find_by_type(LINK_GHOST);
         socklist[snum].enclink = link_find_by_type(LINK_GHOST);
-        link_link(idx, LINK_GHOST, FROM);
+        link_link(idx, LINK_GHOST, -1, FROM);
       }
       }
     } else {
     } else {
       /* negotiate a new linking scheme */
       /* negotiate a new linking scheme */

+ 77 - 19
src/enclink.c

@@ -8,16 +8,7 @@
 #include "net.h"
 #include "net.h"
 #include "misc.h"
 #include "misc.h"
 
 
-int link_find_by_type(int type)
-{
-  int i = 0;
-
-  for (i = 0; enclink[i].name; i++)
-    if (type == enclink[i].type)
-      return i;
-
-  return -1;
-}
+#include <stdarg.h>
 
 
 static void ghost_link(int idx, direction_t direction)
 static void ghost_link(int idx, direction_t direction)
 {
 {
@@ -67,7 +58,7 @@ static void ghost_link(int idx, direction_t direction)
       socklist[snum].encstatus = 1;
       socklist[snum].encstatus = 1;
       socklist[snum].gz = 1;
       socklist[snum].gz = 1;
 
 
-      dprintf(idx, "elink %s %d\n", tmp2, socklist[snum].oseed);
+      link_send(idx, "elink %s %d\n", tmp2, socklist[snum].oseed);
       free(tmp2);
       free(tmp2);
       strcpy(socklist[snum].okey, initkey);
       strcpy(socklist[snum].okey, initkey);
       strcpy(socklist[snum].ikey, initkey);
       strcpy(socklist[snum].ikey, initkey);
@@ -163,18 +154,74 @@ static char *ghost_write(int snum, char *src, size_t *len)
   return buf;
   return buf;
 }
 }
 
 
+void ghost_parse(int idx, int snum, char *buf)
+{
+  /* putlog(LOG_DEBUG, "*", "Got elink: %s %s", code, buf); */
+  /* Set the socket key and we're linked */
+
+  char *code = newsplit(&buf);
+
+  if (!egg_strcasecmp(code, "elink")) {
+    char *tmp = decrypt_string(settings.salt2, newsplit(&buf));
+
+    strncpyz(socklist[snum].okey, tmp, sizeof(socklist[snum].okey));
+    strncpyz(socklist[snum].ikey, socklist[snum].okey, sizeof(socklist[snum].ikey));
+    socklist[snum].iseed = atoi(buf);
+    socklist[snum].oseed = atoi(buf);
+    putlog(LOG_BOTS, "*", "Handshake with %s succeeded, we're linked.", dcc[idx].nick);
+    free(tmp);
+    if (dcc[idx].newbot)
+      link_done(idx);
+    else
+/* FIXME: remove after 1.2.2 */
+      dprintf(idx, "elinkdone\n");
+  }
+}
+
+void link_send(int idx, char *format, ...)
+{
+  char s[2001] = "";
+  va_list va;
 
 
+  va_start(va, format);
+  egg_vsnprintf(s, sizeof(s) - 1, format, va);
+  va_end(va);
+  remove_crlf(s);
+
+
+  dprintf(idx, "neg! %s\n", s);
+}
+
+void link_done(int idx)
+{
+  dprintf(idx, "neg.\n");
+}
 
 
-void link_link(int idx, int type, direction_t direction)
+int link_find_by_type(int type)
 {
 {
   int i = 0;
   int i = 0;
 
 
-  for (i = 0; enclink[i].name; i++) {
-    if (enclink[i].link && enclink[i].type == type) {
-      (enclink[i].link) (idx, direction);
-      return;
+  for (i = 0; enclink[i].name; i++)
+    if (type == enclink[i].type)
+      return i;
+
+  return -1;
+}
+
+void link_link(int idx, int type, int i, direction_t direction)
+{
+  if (i == -1 && type != -1) {
+    for (i = 0; enclink[i].name; i++) {
+      if (enclink[i].type == type)
+        break;
     }
     }
   }
   }
+
+  if (i != -1 && enclink[i].link)
+    (enclink[i].link) (idx, direction);
+  else if (direction == TO)		/* problem finding function, just assume we're done */
+    link_done(idx);
+
   return;
   return;
 }
 }
 
 
@@ -207,8 +254,19 @@ void link_hash(int idx, char *rand)
   return;
   return;
 }
 }
 
 
+void link_parse(int idx, char *buf)
+{
+  int snum = findanysnum(dcc[idx].sock);
+  int i = socklist[snum].enclink;
+
+  if (i >= 0 && enclink[i].parse)
+    (enclink[i].parse) (idx, snum, buf);
+
+  return;
+}
+
 struct enc_link enclink[] = {
 struct enc_link enclink[] = {
-  { "ghost", LINK_GHOST, ghost_link, ghost_write, ghost_read },
-  { "cleartext", LINK_CLEARTEXT, NULL, NULL, NULL },
-  { NULL, 0, NULL, NULL, NULL }
+  { "ghost", LINK_GHOST, ghost_link, ghost_write, ghost_read, ghost_parse },
+  { "cleartext", LINK_CLEARTEXT, NULL, NULL, NULL, NULL },
+  { NULL, 0, NULL, NULL, NULL, NULL }
 };
 };

+ 5 - 1
src/enclink.h

@@ -24,6 +24,7 @@ struct enc_link {
   void (*link) (int, direction_t);
   void (*link) (int, direction_t);
   char *(*write) (int, char *, size_t *);
   char *(*write) (int, char *, size_t *);
   int (*read) (int, char *, size_t *);
   int (*read) (int, char *, size_t *);
+  void (*parse) (int, int, char *);
 };
 };
 
 
 
 
@@ -32,9 +33,12 @@ extern struct enc_link enclink[];
 
 
 extern int link_find_by_type(int);
 extern int link_find_by_type(int);
 
 
-extern void link_link(int, int, direction_t);
+extern void link_link(int, int, int, direction_t);
 extern char *link_write(int, char *, size_t *);
 extern char *link_write(int, char *, size_t *);
 extern int link_read(int, char *, size_t *);
 extern int link_read(int, char *, size_t *);
 extern void link_hash(int, char *);
 extern void link_hash(int, char *);
+extern void link_send(int, char *, ...) __attribute__((format(printf, 2, 3)));
+extern void link_done(int);
+extern void link_parse(int, char *);
 
 
 #endif /* !_ENCLINK_H */
 #endif /* !_ENCLINK_H */

+ 1 - 1
src/net.h

@@ -107,7 +107,7 @@ typedef struct {
   int oseed;                            /* botlink out seed */
   int oseed;                            /* botlink out seed */
   int iseed;                            /* botlink in seed */
   int iseed;                            /* botlink in seed */
   int gz; /* gzip compression */
   int gz; /* gzip compression */
-  int enclink;				/* new encrypted botlink type */
+  int enclink;				/* new encrypted botlink */
 #ifdef HAVE_SSL
 #ifdef HAVE_SSL
   SSL           *ssl;
   SSL           *ssl;
 #endif /* HAVE_SSL */
 #endif /* HAVE_SSL */