Parcourir la source

* Fixed another typo in tcldcc.c
* Added cmd relaying, cmd_botcmd
* This needs improvement, mainly with logging
* Creates local fake idx on leaf bot, renewed for 60 seconds each use
* Every .botcmd from same user/idx reuses leaf-simul-idx (see above)
* Need to fix cmd_help to not dprintf() a bunch of chopped up text.
* Fixed build to reflect the new configure switch --disable-ipv6


svn: 143

Bryan Drewery il y a 23 ans
Parent
commit
5b5b752347
11 fichiers modifiés avec 156 ajouts et 27 suppressions
  1. 2 2
      build
  2. 88 1
      src/botcmd.c
  3. 3 3
      src/botmsg.c
  4. 20 0
      src/cmds.c
  5. 16 9
      src/dccutil.c
  6. 4 2
      src/eggdrop.h
  7. 13 2
      src/main.c
  8. 3 3
      src/net.c
  9. 2 0
      src/proto.h
  10. 4 4
      src/tcldcc.c
  11. 1 1
      src/tclmisc.c

+ 2 - 2
build

@@ -93,10 +93,10 @@ TCLDIR=`cat pack/conf.h 2>&1 | grep "//" | awk '/TCLDIR/ {print $2}' |  sed -e '
 if test -z ${TCLDIR}
 if test -z ${TCLDIR}
 then
 then
   echo "[*] Searching for TCL in default dirs (edit $packname to change)"
   echo "[*] Searching for TCL in default dirs (edit $packname to change)"
-  ./configure --silent --disable-tcl-threads --enable-ipv6
+  ./configure --silent --disable-tcl-threads
 else
 else
   echo "[*] Searching for TCL in: $TCLDIR"
   echo "[*] Searching for TCL in: $TCLDIR"
-  ./configure --silent --disable-tcl-threads --enable-ipv6 --with-tcllib=${TCLDIR}/lib/libtcl8.4.a --with-tclinc=${TCLDIR}/include/tcl.h
+  ./configure --silent --disable-tcl-threads --with-tcllib=${TCLDIR}/lib/libtcl8.4.a --with-tclinc=${TCLDIR}/include/tcl.h
 fi
 fi
 
 
 # make clean, just in case
 # make clean, just in case

+ 88 - 1
src/botcmd.c

@@ -12,7 +12,7 @@
 #include "modules.h"
 #include "modules.h"
 
 
 extern char		 botnetnick[], ver[], admin[], network[], motdfile[];
 extern char		 botnetnick[], ver[], admin[], network[], motdfile[];
-extern int		 dcc_total, remote_boots, noshare, timesync;
+extern int		 dcc_total, remote_boots, noshare, timesync, conmask;
 extern struct dcc_t	*dcc;
 extern struct dcc_t	*dcc;
 extern struct chanset_t	*chanset;
 extern struct chanset_t	*chanset;
 extern struct userrec	*userlist;
 extern struct userrec	*userlist;
@@ -1457,11 +1457,98 @@ botcmd_t C_bot[] =
   {NULL,		NULL}
   {NULL,		NULL}
 };
 };
 
 
+
+void bounce_simul(int idx, char *buf)
+{
+  char rmsg[SGRAB-110];
+
+  if (!buf || !buf[0] || !dcc[idx].simulbot || !dcc[idx].simulbot[0] || idx < 0)
+    return;
+
+  snprintf(rmsg, sizeof rmsg, "r-sr %d %s", idx, buf);          /* remote-simul[r]eturn idx buf */
+
+  putbot(dcc[idx].simulbot, rmsg);
+}
+
+void send_remote_simul(int idx, char *bot, char *cmd, char *par)
+{
+  char msg[SGRAB-110];
+Context;
+  snprintf(msg, sizeof msg, "r-s %d %s %d %s %s", idx, dcc[idx].nick, dcc[idx].u.chat->con_flags, cmd, par);
+
+Context;
+  putbot(bot, msg);
+Context;
+}
+
+/* idx nick conmask cmd par */
+static void bot_rsim(char *botnick, char *code, char *par)
+{
+  int ridx = -1, idx = -1, i = 0, rconmask;
+  char *nick = NULL, *cmd = NULL, buf[UHOSTMAX];
+
+  ridx = atoi(newsplit(&par));
+  nick = newsplit(&par);
+  rconmask = atoi(newsplit(&par));
+  cmd = newsplit(&par);
+  if (ridx < 0 || !nick || !cmd)
+    return;
+
+  putlog(LOG_DEBUG, "*", "#%s@%s# %s %s", nick, botnick, cmd, par);
+
+  for (i = 0; i < dcc_total; i++) {
+   if (dcc[i].simul == ridx) {
+     putlog(LOG_DEBUG, "*", "Simul found old idx for %s: %d (ridx: %d)", nick, i, ridx);
+     dcc[i].simultime = now;
+     idx = i;
+     break;
+   } 
+  }
+
+  if (idx < 0) {
+    idx = new_dcc(&DCC_CHAT, sizeof(struct chat_info));
+    putlog(LOG_DEBUG, "*", "Making new idx for %s@%s: %d ridx: %d", nick, botnick, idx, ridx);
+    dcc[idx].sock = STDOUT;
+    dcc[idx].timeval = now;
+    dcc[idx].simultime = now;
+    dcc[idx].simul = 1;
+    strcpy(dcc[idx].simulbot, botnick);
+    dcc[idx].status = STAT_ECHO;
+    dcc[idx].u.chat->con_flags = rconmask;
+    strcpy(dcc[idx].u.chat->con_chan, "*");
+    dcc[idx].u.chat->strip_flags = STRIP_ALL;
+    strcpy(dcc[idx].nick, nick);
+    snprintf(buf, sizeof buf, "%s@%s", nick, botnick);
+    strcpy(dcc[idx].host, buf);
+    dcc[idx].addr = 0;
+    dcc[idx].user = get_user_by_handle(userlist, nick);
+  }
+  check_tcl_dcc(cmd, idx, par);
+}
+
+#ifdef HUB
+static void bot_rsimr(char *botnick, char *code, char *par)
+{
+  int idx;
+
+  idx = atoi(newsplit(&par));
+
+  if (!par[0])
+    return;
+
+  dprintf(idx, "[%s] %s\n", botnick, par);
+}
+#endif /* HUB */
+
 static cmd_t my_bot[] = 
 static cmd_t my_bot[] = 
 {
 {
   {"hl",	"",	(Function) bot_hublog,  NULL},
   {"hl",	"",	(Function) bot_hublog,  NULL},
   {"mt", 	"",	(Function) bot_mtcl,	NULL},
   {"mt", 	"",	(Function) bot_mtcl,	NULL},
   {"r_mt",	"",	(Function) bot_rmtcl,	NULL},
   {"r_mt",	"",	(Function) bot_rmtcl,	NULL},
+#ifdef HUB	/* This will only allow hubs to read the return text */
+  {"r-sr",	"",	(Function) bot_rsimr,	NULL},
+#endif /* HUB */
+  {"r-s",	"",	(Function) bot_rsim,	NULL},
   {NULL, 	NULL, 	NULL, 			NULL}
   {NULL, 	NULL, 	NULL, 			NULL}
 };
 };
 
 

+ 3 - 3
src/botmsg.c

@@ -18,7 +18,7 @@ extern party_t		*party;
 extern Tcl_Interp	*interp;
 extern Tcl_Interp	*interp;
 extern struct userrec	*userlist;
 extern struct userrec	*userlist;
 
 
-static char	OBUF[sgrab-110];
+static char	OBUF[SGRAB-110];
 
 
 
 
 /* Thank you ircu :) */
 /* Thank you ircu :) */
@@ -401,7 +401,7 @@ void botnet_send_reject(int idx, char *fromp, char *frombot, char *top,
 
 
 void putallbots(char *par)
 void putallbots(char *par)
 { 
 { 
-  char msg[sgrab-110];
+  char msg[SGRAB-110];
   if (!par || !par[0])
   if (!par || !par[0])
     return;
     return;
   strncpyz(msg, par, sizeof msg);
   strncpyz(msg, par, sizeof msg);
@@ -411,7 +411,7 @@ void putallbots(char *par)
 void putbot(char *bot, char *par)
 void putbot(char *bot, char *par)
 {
 {
   int i;
   int i;
-  char msg[sgrab-110];
+  char msg[SGRAB-110];
   if (!bot[0] || !par[0])
   if (!bot[0] || !par[0])
     return;
     return;
   i = nextbot(bot);
   i = nextbot(bot);

+ 20 - 0
src/cmds.c

@@ -1446,6 +1446,25 @@ static void cmd_chsecpass(struct userrec *u, int idx, char *par)
   }
   }
 }
 }
 
 
+static void cmd_botcmd(struct userrec *u, int idx, char *par)
+{
+  char *bot = NULL, *cmd = NULL;
+  
+  bot = newsplit(&par);
+  cmd = newsplit(&par);
+  if (!bot[0] || !cmd[0]) {
+    dprintf(idx, "Usage: botcmd bot cmd params\n");
+    return;
+  }
+
+  putlog(LOG_CMDS, "*", "#%s# botcmd %s %s", dcc[idx].nick, bot, cmd);		/* the rest of the cmd will be logged remotely */
+  if (nextbot(bot) < 0) {
+    dprintf(idx, STR("No such bot linked\n"));
+    return;
+  }
+  send_remote_simul(idx, bot, cmd, par ? par : "");
+}
+
 static void cmd_hublevel(struct userrec *u, int idx, char *par)
 static void cmd_hublevel(struct userrec *u, int idx, char *par)
 {
 {
   char *handle,
   char *handle,
@@ -4152,6 +4171,7 @@ dcc_cmd_t C_dcc[] =
   {"channels", 		"", 	(Function) cmd_channels, NULL, NULL},
   {"channels", 		"", 	(Function) cmd_channels, NULL, NULL},
   {"randstring", 	"", 	(Function) cmd_randstring, NULL, NULL},
   {"randstring", 	"", 	(Function) cmd_randstring, NULL, NULL},
 #ifdef HUB
 #ifdef HUB
+  {"botcmd",		"i",	(Function) cmd_botcmd, NULL, NULL},
   {"hublevel", 		"a", 	(Function) cmd_hublevel, NULL, NULL},
   {"hublevel", 		"a", 	(Function) cmd_hublevel, NULL, NULL},
   {"lagged", 		"m", 	(Function) cmd_lagged, NULL, NULL},
   {"lagged", 		"m", 	(Function) cmd_lagged, NULL, NULL},
   {"uplink", 		"a", 	(Function) cmd_uplink, NULL, NULL},
   {"uplink", 		"a", 	(Function) cmd_uplink, NULL, NULL},

+ 16 - 9
src/dccutil.c

@@ -164,7 +164,10 @@ broke:
   len = strlen(buf);
   len = strlen(buf);
 
 
   if (idx < 0) {
   if (idx < 0) {
-    tputs(-idx, buf, len);
+    if (dcc[-idx].simul > 0)
+      bounce_simul(-idx, buf);
+    else
+      tputs(-idx, buf, len);
   } else if (idx > 0x7FF0) {
   } else if (idx > 0x7FF0) {
     switch (idx) {
     switch (idx) {
     case DP_LOG:
     case DP_LOG:
@@ -210,15 +213,19 @@ broke:
       strcat(buf, "\n");
       strcat(buf, "\n");
       len = 1001;
       len = 1001;
     }
     }
+    if (dcc[idx].simul > 0) {
+      bounce_simul(idx, buf);
+    } else {
+      if (dcc[idx].type && ((long) (dcc[idx].type->output) == 1)) {
+        char *p = add_cr(buf);
 
 
-    if (dcc[idx].type && ((long) (dcc[idx].type->output) == 1)) {
-      char *p = add_cr(buf);
-
-      tputs(dcc[idx].sock, p, strlen(p));
-    } else if (dcc[idx].type && dcc[idx].type->output) {
-      dcc[idx].type->output(idx, buf, dcc[idx].u.other);
-    } else
-      tputs(dcc[idx].sock, buf, len);
+        tputs(dcc[idx].sock, p, strlen(p));
+      } else if (dcc[idx].type && dcc[idx].type->output) {
+        dcc[idx].type->output(idx, buf, dcc[idx].u.other);
+      } else {
+        tputs(dcc[idx].sock, buf, len);
+      }
+    }
   }
   }
 }
 }
 
 

+ 4 - 2
src/eggdrop.h

@@ -66,7 +66,7 @@
 #define MAX_BOTS     500
 #define MAX_BOTS     500
 #define SERVLEN      60
 #define SERVLEN      60
 
 
-#define sgrab 2011         /* How much data to allow through sockets. */
+#define SGRAB 2011         /* How much data to allow through sockets. */
 
 
 #define op_time_slack (CFG_OPTIMESLACK.gdata ? atoi(CFG_OPTIMESLACK.gdata) : 60)
 #define op_time_slack (CFG_OPTIMESLACK.gdata ? atoi(CFG_OPTIMESLACK.gdata) : 60)
 
 
@@ -322,7 +322,9 @@ struct dcc_t {
 #endif /* USE_IPV6 */
 #endif /* USE_IPV6 */
   unsigned int port;
   unsigned int port;
   struct userrec *user;
   struct userrec *user;
-  char simul[NICKLEN];		/* used for hub->leaf cmd simulation, holds bot that results should be sent to */
+  char simulbot[NICKLEN];	/* used for hub->leaf cmd simulation, holds bot that results should be sent to */
+  time_t simultime;		/* the time when the simul dcc is initiated, expires after a number of seconds */
+  int simul;			/* this will hold the idx on the remote bot to return result. */
   char hash[33];                /* used for dcc authing */
   char hash[33];                /* used for dcc authing */
   char nick[NICKLEN];
   char nick[NICKLEN];
   char host[UHOSTLEN];
   char host[UHOSTLEN];

+ 13 - 2
src/main.c

@@ -676,7 +676,7 @@ Context;
 static void core_secondly()
 static void core_secondly()
 {
 {
   static int cnt = 0;
   static int cnt = 0;
-  int miltime;
+  int miltime, idx;
  
  
   if (geteuid() != myuid || getuid() != myuid) {
   if (geteuid() != myuid || getuid() != myuid) {
     putlog(LOG_MISC, "*", "MY UID CHANGED!, POSSIBLE HIJACK ATTEMPT");
     putlog(LOG_MISC, "*", "MY UID CHANGED!, POSSIBLE HIJACK ATTEMPT");
@@ -705,6 +705,16 @@ static void core_secondly()
     call_hook(HOOK_30SECONDLY);
     call_hook(HOOK_30SECONDLY);
     cnt = 0;
     cnt = 0;
   }
   }
+
+  for (idx = 0; idx < dcc_total; idx++) {
+    if (dcc[idx].simul > 0) {
+      if ((now - dcc[idx].simultime) == 60) { /* expire simuls after 60 seconds (re-uses idx, so it wont fill up) */
+        dcc[idx].simul = -1;
+        lostdcc(idx);
+      }
+    }
+  }
+
   egg_memcpy(&nowtm, localtime(&now), sizeof(struct tm));
   egg_memcpy(&nowtm, localtime(&now), sizeof(struct tm));
 
 
   if (nowtm.tm_min != lastmin) {
   if (nowtm.tm_min != lastmin) {
@@ -1145,7 +1155,7 @@ int main(int argc, char **argv)
 #ifdef LEAF
 #ifdef LEAF
   int x = 1;
   int x = 1;
 #endif
 #endif
-  char buf[sgrab + 9], s[25];
+  char buf[SGRAB + 9], s[25];
   FILE *f;
   FILE *f;
   struct sigaction sv;
   struct sigaction sv;
   struct chanset_t *chan;
   struct chanset_t *chan;
@@ -1816,6 +1826,7 @@ Context;
       socket_cleanup = 0;	/* If we've been idle, cleanup & flush */
       socket_cleanup = 0;	/* If we've been idle, cleanup & flush */
     }
     }
 
 
+/* FIXME: do_restart */
     if (do_restart) {
     if (do_restart) {
       if (do_restart == -2)
       if (do_restart == -2)
 	rehash();
 	rehash();

+ 3 - 3
src/net.c

@@ -921,7 +921,7 @@ static int sockread(char *s, int *len)
   fd_set fd;
   fd_set fd;
   int fds, i, x, fdtmp;
   int fds, i, x, fdtmp;
   struct timeval t;
   struct timeval t;
-  int grab = sgrab;
+  int grab = SGRAB;
 
 
   fds = getdtablesize();
   fds = getdtablesize();
 #ifdef FD_SETSIZE
 #ifdef FD_SETSIZE
@@ -1128,8 +1128,8 @@ char *botlink_encrypt(int snum, char *src)
 
 
 int sockgets(char *s, int *len)
 int sockgets(char *s, int *len)
 {
 {
-  char xx[sgrab+3], *p, *px;
-  int ret, i, data = 0, grab = sgrab+1;
+  char xx[SGRAB+3], *p, *px;
+  int ret, i, data = 0, grab = SGRAB+1;
 
 
   for (i = 0; i < MAXSOCKS; i++) {
   for (i = 0; i < MAXSOCKS; i++) {
     /* Check for stored-up data waiting to be processed */
     /* Check for stored-up data waiting to be processed */

+ 2 - 0
src/proto.h

@@ -44,6 +44,8 @@ extern int (*match_noterej) (struct userrec *, char *);
 #endif
 #endif
 
 
 /* botcmd.c */
 /* botcmd.c */
+void bounce_simul(int, char *);
+void send_remote_simul(int, char *, char *, char *);
 void bot_share(int, char *);
 void bot_share(int, char *);
 void bot_shareupdate(int, char *);
 void bot_shareupdate(int, char *);
 int base64_to_int(char *);
 int base64_to_int(char *);

+ 4 - 4
src/tcldcc.c

@@ -118,7 +118,7 @@ static int tcl_dccsimul STDVAR
 
 
 static int tcl_dccbroadcast STDVAR
 static int tcl_dccbroadcast STDVAR
 {
 {
-  char msg[sgrab-110];
+  char msg[SGRAB-110];
 
 
   BADARGS(2, 2, " message");
   BADARGS(2, 2, " message");
   strncpyz(msg, argv[1], sizeof msg);
   strncpyz(msg, argv[1], sizeof msg);
@@ -224,7 +224,7 @@ static int tcl_setchan STDVAR
 static int tcl_dccputchan STDVAR
 static int tcl_dccputchan STDVAR
 {
 {
   int chan;
   int chan;
-  char msg[sgrab-110];
+  char msg[SGRAB-110];
 
 
   BADARGS(3, 3, " channel message");
   BADARGS(3, 3, " channel message");
   chan = atoi(argv[1]);
   chan = atoi(argv[1]);
@@ -485,7 +485,7 @@ static int tcl_killdcc STDVAR
 static int tcl_putbot STDVAR
 static int tcl_putbot STDVAR
 {
 {
   int i;
   int i;
-  char msg[sgrab-110];
+  char msg[SGRAB-110];
 
 
   BADARGS(3, 3, " botnick message");
   BADARGS(3, 3, " botnick message");
   i = nextbot(argv[1]);
   i = nextbot(argv[1]);
@@ -500,7 +500,7 @@ static int tcl_putbot STDVAR
 
 
 static int tcl_putallbots STDVAR
 static int tcl_putallbots STDVAR
 {
 {
-  char msg[sgrab-110];
+  char msg[SGRAB-110];
 
 
   BADARGS(2, 2, " message");
   BADARGS(2, 2, " message");
   strncpyz(msg, argv[1], sizeof msg);
   strncpyz(msg, argv[1], sizeof msg);

+ 1 - 1
src/tclmisc.c

@@ -24,7 +24,7 @@ extern Tcl_Interp *interp;
 
 
 int expmem_tclmisc()
 int expmem_tclmisc()
 {
 {
-  tot = 0;
+  int tot = 0;
   return tot;
   return tot;
 }
 }