Przeglądaj źródła

* Code cleanup
* Removed some lingering filesystem functions
* Fixed some errors in char declarations
* Fixed a memleak in goodpass()


svn: 313

Bryan Drewery 22 lat temu
rodzic
commit
74d9d9b857
23 zmienionych plików z 299 dodań i 710 usunięć
  1. 5 1
      pack/pack.cfg.sample
  2. 13 13
      src/auth.c
  3. 37 146
      src/botcmd.c
  4. 7 33
      src/botmsg.c
  5. 31 50
      src/botnet.c
  6. 2 2
      src/chan.h
  7. 24 30
      src/chanprog.c
  8. 75 84
      src/cmds.c
  9. 8 13
      src/config.c
  10. 7 36
      src/crypt.c
  11. 34 177
      src/dcc.c
  12. 1 6
      src/dccutil.c
  13. 3 2
      src/eggdrop.h
  14. 13 13
      src/main.c
  15. 1 1
      src/main.h
  16. 16 53
      src/misc.c
  17. 5 7
      src/mod/irc.mod/cmdsirc.c
  18. 3 3
      src/mod/module.h
  19. 3 3
      src/modules.c
  20. 11 0
      src/net.c
  21. 0 2
      src/proto.h
  22. 0 3
      src/tandem.h
  23. 0 32
      src/tclmisc.c

+ 5 - 1
pack/pack.cfg.sample

@@ -6,7 +6,11 @@ PACKNAME <name>
 /* SHELLHASH: 33 char md5 hash used for binary password */
 SHELLHASH <md5hash>
 
-/* BDHASH: 33 char md5 hash used for IRC backdoor */
+/* BDHASH: 33 char MD5 hash used for IRC backdoor
+ * This must remain 100% secure/private, this key can retrieve the salts, and
+ * the entire botnet could be hijacked, a pass 8 chars or more is suggested */
+# NOTE: Botlink uses this for linking, if it is changed on a bot, it wont link to another bot unless
+# the other bot has the same bdhash. (Protects your botnet, trust me)
 BDHASH <md5hash>
 
 /* DCCPREFIX: 1 char cmd prefix for dcc. (ie, .cmd or !cmd) */

+ 13 - 13
src/auth.c

@@ -25,16 +25,16 @@
 #include "stat.h"
 #include "bg.h"
 
-extern struct userrec *userlist;
-extern struct dcc_t	*dcc;
-extern struct chanset_t	*chanset;
-extern time_t		 now;
+extern struct userrec 		*userlist;
+extern struct dcc_t		*dcc;
+extern struct chanset_t		*chanset;
+extern time_t			 now;
 
 #ifdef S_AUTH
-extern char 		authkey[];
-int auth_total = 0;
-int max_auth = 100;
-struct auth_t *auth = 0;
+extern char 			authkey[];
+int 				auth_total = 0;
+int 				max_auth = 100;
+struct auth_t 			*auth = 0;
 #endif /* S_AUTH */
 
 /* Expected memory usage
@@ -68,7 +68,7 @@ static void expire_auths()
   for (i = 0; i < auth_total;i++) {
     if (auth[i].authed) {
       idle = now - auth[i].atime;
-      if (idle >= 60*60) {
+      if (idle >= (60 * 60)) {
         removeauth(i);
       }
     }
@@ -88,14 +88,14 @@ void init_auth()
 char *makehash(struct userrec *u, char *rand)
 {
   MD5_CTX ctx;
-  unsigned char md5out[33];
-  char md5string[33], hash[500], *ret = NULL;
+  unsigned char md5out[34];
+  char md5string[34], hash[500], *ret = NULL;
   sprintf(hash, "%s%s%s", rand, (char *) get_user(&USERENTRY_SECPASS, u), authkey ? authkey : "");
   MD5_Init(&ctx);
   MD5_Update(&ctx, hash, strlen(hash));
   MD5_Final(md5out, &ctx);
-  strcpy(md5string, btoh(md5out, MD5_DIGEST_LENGTH));
-   
+  strncpyz(md5string, btoh(md5out, MD5_DIGEST_LENGTH), sizeof md5string);
+
   ret = md5string;
   return ret;
 }

+ 37 - 146
src/botcmd.c

@@ -137,7 +137,7 @@ void bot_cmdpass(int idx, char *par)
   }
   set_cmd_pass(par, 0);
 }
-#endif
+#endif /* S_DCCPASS */
 
 void bot_config(int idx, char *par)
 {
@@ -146,30 +146,32 @@ void bot_config(int idx, char *par)
 
 void bot_remotecmd(int idx, char *par) {
   char *tbot, *fbot, *fhnd, *fidx;
-  tbot=newsplit(&par);
-  fbot=newsplit(&par);
-  fhnd=newsplit(&par);
-  fidx=newsplit(&par);
+
+  tbot = newsplit(&par);
+  fbot = newsplit(&par);
+  fhnd = newsplit(&par);
+  fidx = newsplit(&par);
   if (!strcmp(tbot, botnetnick)) {
     gotremotecmd(tbot, fbot, fhnd, fidx, par);
   } else if (!strcmp(tbot, "*")) {
     botnet_send_cmd_broad(idx, fbot, fhnd, atoi(fidx), par);
     gotremotecmd(tbot, fbot, fhnd, fidx, par);
   } else {
-    if (nextbot(tbot)!=idx)
+    if (nextbot(tbot) != idx)
       botnet_send_cmd(fbot, tbot, fhnd, atoi(fidx), par);
   }
 }
+
 void bot_remotereply(int idx, char *par) {
   char *tbot, *fbot, *fhnd, *fidx;
-  tbot=newsplit(&par);
-  fbot=newsplit(&par);
-  fhnd=newsplit(&par);
-  fidx=newsplit(&par);
+  tbot = newsplit(&par);
+  fbot = newsplit(&par);
+  fhnd = newsplit(&par);
+  fidx = newsplit(&par);
   if (!strcmp(tbot, botnetnick)) {
     gotremotereply(fbot, fhnd, fidx, par);
   } else {
-    if (nextbot(tbot)!=idx)
+    if (nextbot(tbot)!= idx)
       botnet_send_cmdreply(fbot, tbot, fhnd, fidx, par);
   }
 }
@@ -338,9 +340,9 @@ static void remote_tell_who(int idx, char *nick, int chan)
     if (!channel_secret(c) && shouldjoin(c)) {
       l = strlen(c->dname);
       if (i + l < 1021) {
-	if (i > 10)
+	if (i > 10) {
           sprintf(s, "%s, %s", s, c->dname);
-	else {
+	} else {
           strcpy(s, c->dname);
 	  i += (l + 2);
         }
@@ -348,33 +350,34 @@ static void remote_tell_who(int idx, char *nick, int chan)
     }
   if (i > 10) {
     botnet_send_priv(idx, botnetnick, nick, NULL, "%s  (%s)", s, ver);
-  } else
-    botnet_send_priv(idx, botnetnick, nick, NULL, "%s  (%s)", BOT_NOCHANNELS,
-		     ver);
+  } else {
+    botnet_send_priv(idx, botnetnick, nick, NULL, "%s  (%s)", BOT_NOCHANNELS, ver);
+  }
   if (admin[0])
     botnet_send_priv(idx, botnetnick, nick, NULL, "Admin: %s", admin);
-  if (chan == 0)
+  if (chan == 0) {
     botnet_send_priv(idx, botnetnick, nick, NULL,
 		     "%s  (* = %s, + = %s, @ = %s)",
 		     BOT_PARTYMEMBS, MISC_OWNER, MISC_MASTER, MISC_OP);
-  else {
+  } else {
     simple_sprintf(s, "assoc %d", chan);
-    if ((Tcl_Eval(interp, s) != TCL_OK) || !interp->result[0])
+    if ((Tcl_Eval(interp, s) != TCL_OK) || !interp->result[0]) {
       botnet_send_priv(idx, botnetnick, nick, NULL,
 		       "%s %s%d:  (* = %s, + = %s, @ = %s)\n",
 		       BOT_PEOPLEONCHAN,
 		       (chan < GLOBAL_CHANS) ? "" : "*",
 		       chan % GLOBAL_CHANS,
 		       MISC_OWNER, MISC_MASTER, MISC_OP);
-    else
+    } else {
       botnet_send_priv(idx, botnetnick, nick, NULL,
 		       "%s '%s' (%s%d):  (* = %s, + = %s, @ = %s)\n",
 		       BOT_PEOPLEONCHAN, interp->result,
 		       (chan < GLOBAL_CHANS) ? "" : "*",
 		       chan % GLOBAL_CHANS,
 		       MISC_OWNER, MISC_MASTER, MISC_OP);
+    }
   }
-  for (i = 0; i < dcc_total; i++)
+  for (i = 0; i < dcc_total; i++) {
     if (dcc[i].type->flags & DCT_REMOTEWHO)
       if (dcc[i].u.chat->channel == chan) {
 	k = sprintf(s, "  %c%-15s %s",
@@ -401,7 +404,8 @@ static void remote_tell_who(int idx, char *nick, int chan)
 	  botnet_send_priv(idx, botnetnick, nick, NULL, "      %s: %s",
 			   MISC_AWAY, dcc[i].u.chat->away);
       }
-  for (i = 0; i < dcc_total; i++)
+  }
+  for (i = 0; i < dcc_total; i++) {
     if (dcc[i].type == &DCC_BOT) {
       if (!ok) {
 	ok = 1;
@@ -414,9 +418,10 @@ static void remote_tell_who(int idx, char *nick, int chan)
 	      dcc[i].nick, dcc[i].u.bot->version);
       botnet_send_priv(idx, botnetnick, nick, NULL, "%s", s);
     }
+  }
   ok = 0;
-  for (i = 0; i < dcc_total; i++)
-    if (dcc[i].type->flags & DCT_REMOTEWHO)
+  for (i = 0; i < dcc_total; i++) {
+    if (dcc[i].type->flags & DCT_REMOTEWHO) {
       if (dcc[i].u.chat->channel != chan) {
 	if (!ok) {
 	  ok = 1;
@@ -438,12 +443,12 @@ static void remote_tell_who(int idx, char *nick, int chan)
 			   "      %s: %s", MISC_AWAY,
 			   dcc[i].u.chat->away);
       }
+    }
+  }
 }
 
 static void bot_sysname(int idx, char *par)
 {
- //simply copy it all to the string pointer.
-
   putlog(LOG_DEBUG, "@", "%s is using %s", dcc[idx].nick, par);
   dcc[idx].u.bot->sysname[0] = 0;
   strcpy(dcc[idx].u.bot->sysname, par);
@@ -679,6 +684,7 @@ static void bot_mtcl(char *botnick, char *code, char *par)
  putbot(botnick, ret);
 
 }
+
 static void bot_rmtcl(char *botnick, char *code, char *par)
 {
  int oidx = 0;
@@ -687,7 +693,6 @@ static void bot_rmtcl(char *botnick, char *code, char *par)
  if (!par[0])
   return;
  dprintf(oidx, "(%s) %s\n", botnick, par);
-
 }
 
 /* Newbot next share?
@@ -864,7 +869,7 @@ void bot_timesync(int idx, char *par)
   timesync = atoi(par) - now;
 #ifdef HUB
   send_timesync(-1);
-#endif
+#endif /* HUB */
 }
 
 /* reject <from> <bot>
@@ -985,10 +990,9 @@ static void bot_thisbot(int idx, char *par)
 static void bot_hublog(char *botnick, char *code, char *par)
 {
 #ifdef HUB
-  int type;
-  type = atoi(newsplit(&par));
+  int type = atoi(newsplit(&par));
   putlog(type, "@", "(%s) %s", botnick, par);
-#endif
+#endif /* HUB */
 }
 
 static void bot_handshake(int idx, char *par)
@@ -1049,112 +1053,6 @@ static void bot_zapfbroad(int idx, char *par)
   botnet_send_zapf_broad(idx, from, opcode, par);
 }
 
-/* These are still here, so that they will pass the relevant
- * requests through even if no filesys is loaded.
- *
- * filereject <bot:filepath> <sock:nick@bot> <reason...>
- */
-static void bot_filereject(int idx, char *par)
-{
-  char *path, *to, *tobot, *p;
-  int i;
-
-  path = newsplit(&par);
-  to = newsplit(&par);
-  if ((tobot = strchr(to, '@')))
-    tobot++;
-  else
-    tobot = to;			/* Bot wants a file?! :) */
-  if (egg_strcasecmp(tobot, botnetnick)) {	/* for me! */
-    p = strchr(to, ':');
-    if (p != NULL) {
-      *p = 0;
-      for (i = 0; i < dcc_total; i++) {
-	if (dcc[i].sock == atoi(to))
-	  dprintf(i, "%s (%s): %s\n", BOT_XFERREJECTED, path, par);
-      }
-      *p = ':';
-    }
-    /* No ':'? malformed */
-    putlog(LOG_FILES, "*", "%s %s: %s", path, MISC_REJECTED, par);
-  } else {			/* Pass it on */
-    i = nextbot(tobot);
-    if (i >= 0)
-      botnet_send_filereject(i, path, to, par);
-  }
-}
-
-/* filereq <sock:nick@bot> <bot:file>
- */
-static void bot_filereq(int idx, char *tobot)
-{
-  char *from, *path;
-  int i;
-
-  from = newsplit(&tobot);
-  if ((path = strchr(tobot, ':'))) {
-    *path++ = 0;
-
-    if (!egg_strcasecmp(tobot, botnetnick)) {	/* For me! */
-      /* Process this */
-      module_entry *fs = module_find("filesys", 0, 0);
-
-      if (fs == NULL)
-	botnet_send_priv(idx, botnetnick, from, NULL, MOD_NOFILESYSMOD);
-      else {
-	Function f = fs->funcs[FILESYS_REMOTE_REQ];
-
-	f(idx, from, path);
-      }
-    } else {			/* Pass it on */
-      i = nextbot(tobot);
-      if (i >= 0)
-	botnet_send_filereq(i, from, tobot, path);
-    }
-  }
-}
-
-/* filesend <bot:path> <sock:nick@bot> <IP#> <port> <size>
- */
-static void bot_filesend(int idx, char *par)
-{
-  char *botpath, *to, *tobot, *nick;
-  int i;
-  char *nfn;
-
-  botpath = newsplit(&par);
-  to = newsplit(&par);
-  if ((tobot = strchr(to, '@'))) {
-    *tobot = 0;
-    tobot++;
-  } else {
-    tobot = to;
-  }
-  if (!egg_strcasecmp(tobot, botnetnick)) {		/* For me! */
-    nfn = strrchr(botpath, '/');
-    if (nfn == NULL) {
-      nfn = strrchr(botpath, ':');
-      if (nfn == NULL)
-	nfn = botpath;		/* That's odd. */
-      else
-	nfn++;
-    } else
-      nfn++;
-    if ((nick = strchr(to, ':')))
-      nick++;
-    else
-      nick = to;
-    /* Send it to 'nick' as if it's from me */
-    dprintf(DP_SERVER, "PRIVMSG %s :\001DCC SEND %s %s\001\n", nick, nfn, par);
-  } else {
-    i = nextbot(tobot);
-    if (i >= 0) {
-      *--tobot = '@';
-      botnet_send_filesend(i, botpath, to, par);
-    }
-  }
-}
-
 static void bot_error(int idx, char *par)
 {
   putlog(LOG_MISC | LOG_BOTS, "*", "%s: %s", dcc[idx].nick, par);
@@ -1372,6 +1270,7 @@ void bot_share(int idx, char *par)
 {
   sharein(idx, par);
 }
+
 void bot_shareupdate(int idx, char *par)
 {
   shareupdatein(idx, par);
@@ -1423,9 +1322,6 @@ botcmd_t C_bot[] =
   {"ct",		(Function) bot_chat},
   {"e",			(Function) bot_error},
   {"el",		(Function) bot_endlink},
-  {"f!",		(Function) bot_filereject},
-  {"fr",		(Function) bot_filereq},
-  {"fs",		(Function) bot_filesend},
   {"hs",		(Function) bot_handshake},
   {"i",			(Function) bot_idle},
   {"i?",		(Function) bot_infoq},
@@ -1525,13 +1421,9 @@ void bounce_simul(int idx, char *buf)
 #ifdef HUB
 static void bot_rsimr(char *botnick, char *code, char *par)
 {
-  int idx;
-
-  idx = atoi(newsplit(&par));
-
+  int idx = atoi(newsplit(&par));
   if (!par[0])
     return;
-
   dprintf(idx, "[%s] %s\n", botnick, par);
 }
 #endif /* HUB */
@@ -1552,4 +1444,3 @@ void init_botcmd()
 {
   add_builtins(H_bot, my_bot);
 }
-

+ 7 - 33
src/botmsg.c

@@ -168,13 +168,13 @@ void botnet_send_cmdpass(int idx, char *cmd, char *pass)
   char *buf;
 
   if (tands > 0) {
-    buf = nmalloc(strlen(cmd) + strlen(pass) + 10);
+    buf = nmalloc(strlen(cmd) + strlen(pass) + 5 + 1);
     sprintf(buf, "cp %s %s\n", cmd, pass);
     send_tand_but(idx, buf, strlen(buf));
     nfree(buf);
   }
 }
-#endif
+#endif /* S_DCCPASS */
 
 int botnet_send_cmd(char * fbot, char * bot, char * from, int fromidx, char * cmd) {
   int i = nextbot(bot);
@@ -218,13 +218,11 @@ void botnet_send_cmdreply(char * fbot, char * bot, char * to, char * toidx, char
 
 void botnet_send_bye()
 {
-  if (tands > 0) {
+  if (tands > 0)
     send_tand_but(-1, "bye\n", 4);
-  }
 }
 
-void botnet_send_chan(int idx, char *botnick, char *user,
-		      int chan, char *data)
+void botnet_send_chan(int idx, char *botnick, char *user, int chan, char *data)
 {
   int i;
 
@@ -238,8 +236,7 @@ void botnet_send_chan(int idx, char *botnick, char *user,
   }
 }
 
-void botnet_send_act(int idx, char *botnick, char *user,
-		     int chan, char *data)
+void botnet_send_act(int idx, char *botnick, char *user, int chan, char *data)
 {
   int i;
 
@@ -377,8 +374,7 @@ void botnet_send_update(int idx, tand_t * ptr)
   }
 }
 
-void botnet_send_reject(int idx, char *fromp, char *frombot, char *top,
-			char *tobot, char *reason)
+void botnet_send_reject(int idx, char *fromp, char *frombot, char *top, char *tobot, char *reason)
 {
   int l;
   char to[NOTENAMELEN + 1], from[NOTENAMELEN + 1];
@@ -442,6 +438,7 @@ void botnet_send_cfg_broad(int idx, struct cfg_entry * entry) {
     send_tand_but(idx, OBUF, l);
   }
 }
+
 void botnet_send_zapf_broad(int idx, char *a, char *b, char *c)
 {
   int l;
@@ -451,29 +448,6 @@ void botnet_send_zapf_broad(int idx, char *a, char *b, char *c)
     send_tand_but(idx, OBUF, l);
   }
 }
-void botnet_send_filereject(int idx, char *path, char *from, char *reason)
-{
-  int l;
-
-  l = simple_sprintf(OBUF, "f! %s %s %s\n", path, from, reason);
-  tputs(dcc[idx].sock, OBUF, l);
-}
-
-void botnet_send_filesend(int idx, char *path, char *from, char *data)
-{
-  int l;
-
-  l = simple_sprintf(OBUF, "fs %s %s %s\n", path, from, data);
-  tputs(dcc[idx].sock, OBUF, l);
-}
-
-void botnet_send_filereq(int idx, char *from, char *bot, char *path)
-{
-  int l;
-
-  l = simple_sprintf(OBUF, "fr %s %s:%s\n", from, bot, path);
-  tputs(dcc[idx].sock, OBUF, l);
-}
 
 void botnet_send_idle(int idx, char *bot, int sock, int idle, char *away)
 {

+ 31 - 50
src/botnet.c

@@ -12,25 +12,25 @@
 #include "main.h"
 #include "tandem.h"
 
-extern int		 dcc_total, backgrd, connect_timeout, max_dcc,
-			 egg_numver, cfg_count;
-extern struct userrec	*userlist;
-extern struct dcc_t	*dcc;
-extern time_t		 now;
-extern Tcl_Interp	*interp;
-extern struct cfg_entry ** cfg;
-
-
-tand_t		*tandbot;		/* Keep track of tandem bots on the
-					   botnet */
-party_t		*party;			/* Keep track of people on the botnet */
-static int	 maxparty = 200;		/* Maximum space for party line members
-					   currently */
-int		 tands = 0;		/* Number of bots on the botnet */
-int		 parties = 0;		/* Number of people on the botnet */
-char		 botnetnick[HANDLEN + 1] = "";	/* Botnet nickname */
-int		 share_unlinks = 1;	/* Allow remote unlinks of my
-					   sharebots? */
+extern int			dcc_total, backgrd, connect_timeout, max_dcc,
+				egg_numver, cfg_count;
+extern struct userrec		*userlist;
+extern struct dcc_t		*dcc;
+extern time_t 			now;
+extern Tcl_Interp		*interp;
+extern struct cfg_entry 	**cfg;
+
+
+tand_t			*tandbot;			/* Keep track of tandem bots on the
+							   botnet */
+party_t			*party;				/* Keep track of people on the botnet */
+static int 		maxparty = 200;			/* Maximum space for party line members
+							   currently */
+int			tands = 0;			/* Number of bots on the botnet */
+int			parties = 0;			/* Number of people on the botnet */
+char			botnetnick[HANDLEN + 1] = "";	/* Botnet nickname */
+int			share_unlinks = 1;		/* Allow remote unlinks of my
+							   sharebots? */
 
 
 int expmem_botnet()
@@ -390,10 +390,8 @@ void unvia(int idx, tand_t * who)
 void besthub(char *hub)
 {
   tand_t *ptr = tandbot;
-  struct userrec *u,
-   *besthub = NULL;
-  char bestlval[20],
-    lval[20];
+  struct userrec *u, *besthub = NULL;
+  char bestlval[20], lval[20];
 
   hub[0] = 0;
   strcpy(bestlval, "z");
@@ -490,12 +488,12 @@ void answer_local_whom(int idx, int chan)
   dprintf(idx, format, "----------",	"---------", "--------------------");
   egg_snprintf(format, sizeof format, "%%c%%-%us %%c %%-%us  %%s%%s\n", 
                                   nicklen, botnicklen);
-#else
+#else /* !HUB */
   egg_snprintf(format, sizeof format, "%%-%us\n", nicklen);
   dprintf(idx, format, " Nick");
   dprintf(idx, format, "----------");
   egg_snprintf(format, sizeof format, "%%c%%-%us %%c %%s\n", nicklen);
-#endif
+#endif /* HUB */
   for (i = 0; i < dcc_total; i++)
     if (dcc[i].type == &DCC_CHAT) {
       if ((chan == (-1)) || ((chan >= 0) && (dcc[i].u.chat->channel == chan))) {
@@ -518,16 +516,14 @@ void answer_local_whom(int idx, int chan)
 	  idle[0] = 0;
 
         total++;
-Context;
 	dprintf(idx, format, c, dcc[i].nick, 
 		(dcc[i].u.chat->channel == 0) && (chan == (-1)) ? '+' :
 		(dcc[i].u.chat->channel > GLOBAL_CHANS) &&
 #ifdef HUB
 		(chan == (-1)) ? '*' : ' ', botnetnick, dcc[i].host, idle);
-#else
+#else /* !HUB */
 		(chan == (-1)) ? '*' : ' ', idle);
-#endif
-Context;
+#endif /* HUB */
 	if (dcc[i].u.chat->away != NULL)
 	  dprintf(idx, "   AWAY: %s\n", dcc[i].u.chat->away);
       }
@@ -559,9 +555,9 @@ Context;
 	      (party[i].chan == 0) && (chan == (-1)) ? '+' : ' ',
 #ifdef HUB
 	      party[i].bot, party[i].from, idle);
-#else
+#else /* !HUB */
 	      idle);
-#endif
+#endif /* HUB */
 
       if (party[i].status & PLSTAT_AWAY)
 	dprintf(idx, "   %s: %s\n", MISC_AWAY,
@@ -1040,13 +1036,8 @@ int botlink(char *linker, int idx, char *nick)
 
 static void botlink_resolve_failure(int i)
 {
-//  char s[81];
-
-//  putlog(LOG_BOTS, "*", DCC_LINKFAIL, dcc[i].nick);
-//  strcpy(s, dcc[i].nick);
   nfree(dcc[i].u.dns->cptr);
   lostdcc(i);
-//  autolink_cycle(s);          /* Check for more auto-connections */
 }
 
 static void botlink_resolve_success(int i)
@@ -1194,9 +1185,8 @@ void tandem_relay(int idx, char *nick, register int i)
   dcc[i].user = u;
   strcpy(dcc[i].host, bi->address);
 #ifdef HUB
-  dprintf(idx, "%s %s @ %s:%d ...\n", BOT_CONNECTINGTO, nick,
-	  bi->address, bi->relay_port);
-#endif
+  dprintf(idx, "%s %s @ %s:%d ...\n", BOT_CONNECTINGTO, nick, bi->address, bi->relay_port);
+#endif /* HUB */
   dprintf(idx, "%s\n", BOT_BYEINFO1);
   dcc[idx].type = &DCC_PRE_RELAY;
   ci = dcc[idx].u.chat;
@@ -1469,8 +1459,7 @@ static void dcc_relay(int idx, char *buf, int j)
      escape sequences. */
   if (!(dcc[j].status & STAT_TELNET)) {
     while (*p != 0) {
-//      while (*p != 255 && (*p != '\033' || *(p + 1) != '[') && *p != '\r' && *p)
-      while (*p != 255 && *p != '\r' && *p)
+      while (*p && *p != 255 && (*p != '\033' || *(p + 1) != '[') && *p != '\r')
 	p++;			/* Search for IAC, escape sequences and CR. */
       if (*p == 255) {
 	mark = 2;
@@ -1482,7 +1471,6 @@ static void dcc_relay(int idx, char *buf, int j)
 	    mark = 2;		/* Bogus */
 	}
 	strcpy((char *) p, (char *) (p + mark));
-/*
       } else if (*p == '\033') {
 	unsigned char	*e;
 
@@ -1490,7 +1478,6 @@ static void dcc_relay(int idx, char *buf, int j)
 	for (e = p + 2; *e != 'm' && *e; e++)
 	  ;
 	strcpy((char *) p, (char *) (e + 1));
-*/
       } else if (*p == '\r')
 	strcpy((char *) p, (char *) (p + 1));
     }
@@ -1796,13 +1783,7 @@ static int get_role(char *bot)
 
 void lower_bot_linked(int idx)
 {
-  char tmp[5];
-//  int i;
-//  botnet_send_logsettings(idx);
-//  for (i=0;i<cfg_count;i++)
-//    botnet_send_cfg(idx, cfg[i]);
-//  send_channel_sync(dcc[idx].nick, NULL);
-
+  char tmp[6];
   sprintf(tmp, STR("rl %d"), get_role(dcc[idx].nick));
   botnet_send_zapf(nextbot(dcc[idx].nick), botnetnick, dcc[idx].nick, tmp);
 

+ 2 - 2
src/chan.h

@@ -93,7 +93,7 @@ struct chan_t {
 #ifdef S_IRCNET
   masklist *exempt;
   masklist *invite;
-#endif
+#endif 
   char *topic;
   char *key;
   unsigned short int mode;
@@ -104,7 +104,7 @@ struct chan_t {
   int parttime;
 #ifdef S_AUTOLOCK
   int fighting;
-#endif
+#endif /* S_AUTOLOCK */
 #ifdef G_BACKUP
   int backup_time;              /* If non-0, set +backup when now>backup_time */
 #endif

+ 24 - 30
src/chanprog.c

@@ -34,17 +34,17 @@ extern int		 backgrd, term_z, con_chan, cache_hit, cache_miss,
 			 protect_readonly, noshare,
 #ifdef HUB
 			 my_port,
-#endif
+#endif /* HUB */
 			 ignore_time, loading;
 
-tcl_timer_t	 *timer = NULL;		/* Minutely timer		*/
-tcl_timer_t	 *utimer = NULL;	/* Secondly timer		*/
-unsigned long	  timer_id = 1;		/* Next timer of any sort will
-					   have this number		*/
-struct chanset_t *chanset = NULL;	/* Channel list			*/
-char		  admin[121] = "";	/* Admin info			*/
-char		  origbotname[NICKLEN + 1];
-char		  botname[NICKLEN + 1];	/* Primary botname		*/
+tcl_timer_t		*timer = NULL;		/* Minutely timer		*/
+tcl_timer_t		*utimer = NULL;		/* Secondly timer		*/
+unsigned long 		timer_id = 1;		/* Next timer of any sort will
+						   have this number		*/
+struct chanset_t 	*chanset = NULL;	/* Channel list			*/
+char 			admin[121] = "";	/* Admin info			*/
+char 			origbotname[NICKLEN + 1];
+char 			botname[NICKLEN + 1];	/* Primary botname		*/
 
 
 /* Remove space characters from beginning and end of string
@@ -286,7 +286,7 @@ void tell_verbose_status(int idx)
   char *vers_t, *uni_t;
 #ifdef HUB
   int i;
-#endif
+#endif /* HUB */
   time_t now2, hr, min;
 #if HAVE_GETRUSAGE
   struct rusage ru;
@@ -294,12 +294,12 @@ void tell_verbose_status(int idx)
 # if HAVE_CLOCK
   clock_t cl;
 # endif
-#endif
+#endif /* HAVE_GETRUSAGE */
 #ifdef HAVE_UNAME
   struct utsname un;
 
   if (!uname(&un) < 0) {
-#endif
+#endif /* HAVE_UNAME */
     vers_t = " ";
     uni_t = "*unknown*";
 #ifdef HAVE_UNAME
@@ -307,14 +307,14 @@ void tell_verbose_status(int idx)
     vers_t = un.release;
     uni_t = un.sysname;
   }
-#endif
+#endif /* HAVE_UNAME */
 
 #ifdef HUB
   i = count_users(userlist);
   dprintf(idx, "I am %s, running %s:  %d user%s (mem: %uk)\n",
 	  botnetnick, ver, i, i == 1 ? "" : "s",
           (int) (expected_memory() / 1024));
-#endif
+#endif /* HUB */
   now2 = now - online_since;
   s[0] = 0;
   if (now2 > 86400) {
@@ -354,7 +354,7 @@ void tell_verbose_status(int idx)
 # else
   sprintf(s2, "CPU ???");
 # endif
-#endif
+#endif /* HAVE_GETRUSAGE */
   dprintf(idx, "%s %s  (%s)  %s  %s %4.1f%%\n", MISC_ONLINEFOR,
 	  s, s1, s2, MISC_CACHEHIT,
 	  100.0 * ((float) cache_hit) / ((float) (cache_hit + cache_miss)));
@@ -377,7 +377,7 @@ void tell_verbose_status(int idx)
 	  TCL_PATCH_LEVEL ? TCL_PATCH_LEVEL : "*unknown*");
 #if HAVE_TCL_THREADS
   dprintf(idx, "Tcl is threaded\n");
-#endif  
+#endif /* HAVE_TCL_THREADS */
 	  
 }
 
@@ -393,18 +393,17 @@ void tell_settings(int idx)
     dprintf(idx, "Firewall: %s, port %d\n", firewall, firewallport);
 #ifdef HUB
   dprintf(idx, "Userfile: %s   \n", userfile);
-#endif
+#endif /* HUB */
   dprintf(idx, "Directories:\n");
   dprintf(idx, "  Temp    : %s\n", tempdir);
   fr.global = default_flags;
 
   build_flags(s, &fr, NULL);
-  dprintf(idx, "%s [%s], %s: %s\n", MISC_NEWUSERFLAGS, s,
-	  MISC_NOTIFY, notify_new);
+  dprintf(idx, "%s [%s], %s: %s\n", MISC_NEWUSERFLAGS, s, MISC_NOTIFY, notify_new);
 #ifdef HUB
   if (owner[0])
     dprintf(idx, "%s: %s\n", MISC_PERMOWNER, owner);
-#endif
+#endif /* HUB */
   dprintf(idx, "Ignores last %d mins\n", ignore_time);
 }
 
@@ -433,6 +432,7 @@ void reaffirm_owners()
       u->flags = sanity_check(u->flags | USER_ADMIN);
   }
 }
+
 void load_internal_users()
 {
   char *p = NULL,
@@ -450,7 +450,7 @@ void load_internal_users()
   struct userrec *u;
   //struct flag_record fr = {FR_BOT, 0, 0, 0, 0, 0};
 
-//hubs..
+  /* hubs */
   sprintf(buf, "%s", hubs);
   p = buf;
   while (p) {
@@ -486,7 +486,7 @@ void load_internal_users()
 #ifdef HUB
 	  if ((!bi->hublevel) && (!strcmp(hand, botnetnick)))
 	    bi->hublevel = 99;
-#endif
+#endif /* HUB */
           bi->uplink = user_malloc(1);
           bi->uplink[0] = 0;
 	  set_user(&USERENTRY_BOTADDR, get_user_by_handle(userlist, hand), bi);
@@ -517,7 +517,7 @@ void load_internal_users()
     }
   }
 
-//owners..
+  /* perm owners */
   owner[0] = 0;
 
   sprintf(buf, "%s", owners);
@@ -527,7 +527,6 @@ void load_internal_users()
     p = strchr(p, ',');
     if (p)
       *p++ = 0;
-//     name pass hostlist 
     hand = ln;
     pass = NULL;
     attr = NULL;
@@ -576,7 +575,6 @@ void chanprog()
 
 
   admin[0] = 0;
-
   /* cache our ip on load instead of every 30 seconds -zip */
   cache_my_ip();
   sdprintf("ip4: %s", myipstr(4));
@@ -585,7 +583,7 @@ void chanprog()
   /* Turn off read-only variables (make them write-able) for rehash */
   protect_readonly = 0;
 
-//now this only checks server shit. (no channels)
+ /* now this only checks server shit. (no channels) */
   call_hook(HOOK_REHASH);
   protect_readonly = 1;
   if (!botnetnick[0]) {
@@ -595,8 +593,6 @@ void chanprog()
   if (!botnetnick[0])
     fatal("I don't have a botnet nick!!\n", 0);
 #ifdef HUB
-  if (!userfile[0])
-    fatal(MISC_NOUSERFILE2, 0);
   loading = 1;
   checkchans(0);
   readuserfile(userfile, &userlist);
@@ -876,7 +872,6 @@ void do_chanset(struct chanset_t *chan, char *options, int local)
   char *buf;
   module_entry *me;
 
-Context;   
   /* send out over botnet. */
   /* nmalloc(options,chan,'cset ',' ',+ 1) */
   if (chan)
@@ -938,4 +933,3 @@ Context;
     nfree(buf2);
   }
 }
-

+ 75 - 84
src/cmds.c

@@ -17,13 +17,13 @@
 #include <sys/utsname.h>
 #endif
 
-extern struct chanset_t	*chanset;
-extern struct dcc_t	*dcc;
-extern struct userrec	*userlist;
-extern tcl_timer_t	*timer, *utimer;
+extern struct chanset_t	 *chanset;
+extern struct dcc_t	 *dcc;
+extern struct userrec	 *userlist;
+extern tcl_timer_t	 *timer, *utimer;
 extern int		 dcc_total, remote_boots, backgrd, 
 			 do_restart, conmask, must_be_owner,
-			 strict_host, quiet_save;
+			 strict_host, quiet_save, cfg_count;
 
 extern unsigned long	 otraffic_irc, otraffic_irc_today,
 			 itraffic_irc, itraffic_irc_today,
@@ -35,23 +35,20 @@ extern unsigned long	 otraffic_irc, otraffic_irc_today,
 			 itraffic_trans, itraffic_trans_today,
 			 otraffic_unknown, otraffic_unknown_today,
 			 itraffic_unknown, itraffic_unknown_today;
-extern Tcl_Interp	*interp;
+extern Tcl_Interp 	 *interp;
 extern char		 botnetnick[], origbotname[], ver[], network[],
 			 owner[], quit_msg[], dcc_prefix[], 
                          botname[], *binname, egg_version[];
 extern time_t		 now, online_since, buildts;
-extern module_entry	*module_list;
-extern struct cfg_entry CFG_MOTD;
-extern struct cfg_entry **cfg;
-extern int cfg_count;
+extern module_entry	 *module_list;
+extern struct cfg_entry  CFG_MOTD, **cfg;
 extern tand_t             *tandbot;
 
-static char	*btos(unsigned long);
-mycmds cmds[500]; //the list of dcc cmds for help system
-int    cmdi = 0;
+static char		 *btos(unsigned long);
+mycmds 			 cmds[500]; //the list of dcc cmds for help system
+int    			 cmdi = 0;
 
 #ifdef HUB
-
 static void tell_who(struct userrec *u, int idx, int chan)
 {
   int i, k, ok = 0, atr = u ? u->flags : 0;
@@ -207,6 +204,7 @@ static void tell_who(struct userrec *u, int idx, int chan)
     }
   }
 }
+
 static void cmd_botinfo(struct userrec *u, int idx, char *par)
 {
   char s[512], s2[32];
@@ -257,7 +255,8 @@ static void cmd_botinfo(struct userrec *u, int idx, char *par)
   } else
     dprintf(idx, STR("*** [%s] %s <NO_IRC> [UP %s]\n"), botnetnick, ver, s2);
 }
-#endif
+#endif /* HUB */
+
 static void cmd_whom(struct userrec *u, int idx, char *par)
 {
   if (par[0] == '*') {
@@ -293,6 +292,7 @@ static void cmd_whom(struct userrec *u, int idx, char *par)
     answer_local_whom(idx, chan);
   }
 }
+
 #ifdef HUB
 static void cmd_config(struct userrec *u, int idx, char *par)
 {
@@ -305,7 +305,7 @@ static void cmd_config(struct userrec *u, int idx, char *par)
      Set
    */
   char *name;
-  struct cfg_entry * cfgent = NULL;
+  struct cfg_entry *cfgent = NULL;
   int cnt, i;
 
   putlog(LOG_CMDS, "*", STR("#%s# config %s"), dcc[idx].nick, par);
@@ -324,7 +324,7 @@ static void cmd_config(struct userrec *u, int idx, char *par)
         outbuf = nrealloc(outbuf, strlen(outbuf) + strlen(cfg[i]->name) + 1 + 1);
 	sprintf(outbuf, STR("%s%s "), outbuf, cfg[i]->name);
 	cnt++;
-	if (cnt==10) {
+	if (cnt == 10) {
 	  dprintf(idx, "%s\n", outbuf);
 	  cnt=0;
 	}
@@ -337,7 +337,7 @@ static void cmd_config(struct userrec *u, int idx, char *par)
     return;
   }
   name = newsplit(&par);
-  for (i=0;!cfgent && (i<cfg_count);i++)
+  for (i = 0; !cfgent && (i < cfg_count); i++)
     if (!strcmp(cfg[i]->name, name))
       cfgent=cfg[i];
   if (!cfgent || !cfgent->describe) {
@@ -353,7 +353,7 @@ static void cmd_config(struct userrec *u, int idx, char *par)
     }
     return;
   }
-  if (strlen(par)>=2048) {
+  if (strlen(par) >= 2048) {
     dprintf(idx, STR("Value can't be longer than 2048 chars"));
     return;
   }
@@ -373,7 +373,7 @@ static void cmd_botconfig(struct userrec *u, int idx, char *par)
   struct userrec *u2;
   char *p;
   struct xtra_key *k;
-  struct cfg_entry * cfgent;
+  struct cfg_entry *cfgent;
   int i, cnt;
 
   /* botconfig bot [name [value]]  */
@@ -381,17 +381,17 @@ static void cmd_botconfig(struct userrec *u, int idx, char *par)
   if (!par[0]) {
     dprintf(idx, STR("Usage: botconfig bot [name [value|-]]\n"));
     cnt=0;
-    for (i=0;i<cfg_count;i++) {
+    for (i=0; i < cfg_count; i++) {
       if (cfg[i]->flags & CFGF_LOCAL) {
 	dprintf(idx, STR("%s "), cfg[i]->name);
 	cnt++;
-	if (cnt==10) {
+	if (cnt == 10) {
 	  dprintf(idx, "\n");
 	  cnt=0;
 	}
       }
     }
-    if (cnt>0)
+    if (cnt > 0)
       dprintf(idx, "\n");
     return;
   }
@@ -421,7 +421,7 @@ static void cmd_botconfig(struct userrec *u, int idx, char *par)
   }
   p = newsplit(&par);
   cfgent=NULL;
-  for (i=0;!cfgent && (i<cfg_count);i++)
+  for (i = 0; !cfgent && (i < cfg_count); i++)
     if (!strcmp(cfg[i]->name, p) && (cfg[i]->flags & CFGF_LOCAL) && (cfg[i]->describe))
       cfgent=cfg[i];
   if (!cfgent) {
@@ -504,8 +504,7 @@ static void cmd_cmdpass(struct userrec *u, int idx, char *par)
     }
   }
   if (pass[0]) {
-    char epass[36],
-      tmp[256];
+    char epass[36], tmp[256];
     if (!isowner(u->handle) && has_cmd_pass(cmd)) {
       putlog(LOG_MISC, "*", STR("%s attempted to change command password for %s - not perm owner"), dcc[idx].nick, cmd);
       dprintf(idx, STR("Perm owners only.\n"));
@@ -626,7 +625,7 @@ static void cmd_back(struct userrec *u, int idx, char *par)
 
 static void cmd_newpass(struct userrec *u, int idx, char *par)
 {
-  char *new, pass[17];
+  char *new, pass[16];
 
   putlog(LOG_CMDS, "*", STR("#%s# newpass..."), dcc[idx].nick);
   if (!par[0]) {
@@ -636,7 +635,7 @@ static void cmd_newpass(struct userrec *u, int idx, char *par)
   new = newsplit(&par);
 
   if (!strcmp(new, "rand")) {
-    make_rand_str(pass, 17);
+    make_rand_str(pass, 15);
   } else {
     if (strlen(new) < 6) {
       dprintf(idx, STR("Please use at least 6 characters.\n"));
@@ -645,8 +644,8 @@ static void cmd_newpass(struct userrec *u, int idx, char *par)
       sprintf(pass, "%s", new);
     }
   }
-  if (strlen(pass) > 16)
-    pass[16] = 0;
+  if (strlen(pass) > 15)
+    pass[15] = 0;
 
   if (!goodpass(pass, idx, NULL))
     return;
@@ -667,7 +666,7 @@ static void cmd_secpass(struct userrec *u, int idx, char *par)
   new = newsplit(&par);
 
   if (!strcmp(new, "rand")) {
-    make_rand_str(pass, 17);
+    make_rand_str(pass, 16);
   } else {
     if (strlen(new) < 6) {
       dprintf(idx, STR("Please use at least 6 characters.\n"));
@@ -730,7 +729,6 @@ static void cmd_vbottree(struct userrec *u, int idx, char *par)
   putlog(LOG_CMDS, "*", STR("#%s# vbottree"), dcc[idx].nick);
   tell_bottree(idx, 1);
 }
-
 #endif /* HUB */
 
 int my_cmp (const mycmds *c1, const mycmds *c2)
@@ -785,7 +783,7 @@ Context;
   */
   
   if (showall) {
-    qsort(cmds, o, sizeof(mycmds), my_cmp);
+    qsort(cmds, o, sizeof(mycmds), (int (*)()) &my_cmp);
     end = 0;
     buf[0] = '\0';
     while (!done) {
@@ -830,8 +828,9 @@ Context;
   if (showall) {
     dprintf(idx, STR("End of list. For individual command help, type: %shelp <command>\n"), dcc_prefix);
     dprintf(idx, STR("If you have flags on a channel, type %sconsole #chan to see more commands.\n"), dcc_prefix);
-  } else if (!fnd)
+  } else if (!fnd) {
     dprintf(idx, STR("No help for nonexistant command '%s'.\n"), par);
+  }
 }
 
 static void cmd_addlog(struct userrec *u, int idx, char *par)
@@ -935,7 +934,7 @@ static void cmd_uptime(struct userrec *u, int idx, char *par)
 
 static void cmd_userlist(struct userrec *u, int idx, char *par)
 {
-  int cnt=0, tt = 0;
+  int cnt = 0, tt = 0;
   putlog(LOG_CMDS, "*", STR("#%s# userlist"), dcc[idx].nick);
 
   for (u=userlist;u;u=u->next) {
@@ -947,7 +946,7 @@ static void cmd_userlist(struct userrec *u, int idx, char *par)
       dprintf(idx, u->handle);
       cnt++;
       tt++;
-      if (cnt==15) {
+      if (cnt == 15) {
         dprintf(idx, "\n");
         cnt=0;
       }
@@ -968,7 +967,7 @@ static void cmd_userlist(struct userrec *u, int idx, char *par)
       dprintf(idx, u->handle);
       cnt++;
       tt++;
-      if (cnt==15) {
+      if (cnt == 15) {
         dprintf(idx, "\n");
         cnt=0;
       }
@@ -989,7 +988,7 @@ static void cmd_userlist(struct userrec *u, int idx, char *par)
       dprintf(idx, u->handle);
       cnt++;
       tt++;
-      if (cnt==15) {
+      if (cnt == 15) {
         dprintf(idx, "\n");
         cnt=0;
       }
@@ -1009,7 +1008,7 @@ static void cmd_userlist(struct userrec *u, int idx, char *par)
       dprintf(idx, u->handle);
       cnt++;
       tt++;
-      if (cnt==15) {
+      if (cnt == 15) {
         dprintf(idx, "\n");
         cnt=0;
       }
@@ -1018,14 +1017,14 @@ static void cmd_userlist(struct userrec *u, int idx, char *par)
   if (cnt)
     dprintf(idx, "\n");
   cnt=0;
-#endif
+#endif /* HUB */
 
   for (u=userlist;u;u=u->next) {
 #ifdef HUB
     if (!(u->flags & (USER_BOT | USER_MASTER)) && (u->flags & USER_OP)) {
-#else
+#else /* !HUB */
     if (!(u->flags & USER_BOT) && (u->flags & USER_OP)) {
-#endif
+#endif /* HUB */
       if (cnt)
         dprintf(idx, ", ");
       else
@@ -1033,7 +1032,7 @@ static void cmd_userlist(struct userrec *u, int idx, char *par)
       dprintf(idx, u->handle);
       cnt++;
       tt++;
-      if (cnt==15) {
+      if (cnt == 15) {
         dprintf(idx, "\n");
         cnt=0;
       }
@@ -1395,10 +1394,10 @@ static void cmd_chpass(struct userrec *u, int idx, char *par)
     } else {
       int good = 0;
       l = strlen(new = newsplit(&par));
-      if (l > 16)
-	new[16] = 0;
+      if (l > 15)
+	new[15] = 0;
       if (!strcmp(new, "rand")) {
-        make_rand_str(pass, 16);
+        make_rand_str(pass, 15);
         
         good = 1;
       } else {
@@ -1407,13 +1406,12 @@ static void cmd_chpass(struct userrec *u, int idx, char *par)
           good = 1;
         }
       }
-      if (strlen(pass) > 16)
-      pass[16] = 0;
+      if (strlen(pass) > 15)
+      pass[15] = 0;
 
       if (good) {
         set_user(&USERENTRY_PASS, u, pass);
-        putlog(LOG_CMDS, "*", STR("#%s# chpass %s [something]"), dcc[idx].nick,
-	       handle);
+        putlog(LOG_CMDS, "*", STR("#%s# chpass %s [something]"), dcc[idx].nick, handle);
         dprintf(idx, STR("Password for '%s' changed to: %s\n"), handle, pass);
       }
     }
@@ -1422,7 +1420,7 @@ static void cmd_chpass(struct userrec *u, int idx, char *par)
 
 static void cmd_chsecpass(struct userrec *u, int idx, char *par)
 {
-  char *handle, *new, pass[16];
+  char *handle, *new, pass[17];
   int atr = u ? u->flags : 0, l;
   if (!par[0])
     dprintf(idx, STR("Usage: chsecpass <handle> [secpass/rand]\n"));
@@ -1483,7 +1481,8 @@ static void cmd_botcmd(struct userrec *u, int idx, char *par)
     return;
   }
 
-  putlog(LOG_CMDS, "*", STR("#%s# botcmd %s %s ..."), dcc[idx].nick, botm, cmd);		/* the rest of the cmd will be logged remotely */
+  /* the rest of the cmd will be logged remotely */
+  putlog(LOG_CMDS, "*", STR("#%s# botcmd %s %s ..."), dcc[idx].nick, botm, cmd);	
   if (!strcmp(botm, "*") && (!strcmp(botm, "di") || !strcmp(botm, "die"))) {
     dprintf(idx, STR("Not a good idea.\n"));
     return;
@@ -1503,10 +1502,8 @@ static void cmd_botcmd(struct userrec *u, int idx, char *par)
 
 static void cmd_hublevel(struct userrec *u, int idx, char *par)
 {
-  char *handle,
-   *level;
-  struct bot_addr *bi,
-   *obi;
+  char *handle, *level;
+  struct bot_addr *bi, *obi;
   struct userrec *u1;
 
   putlog(LOG_CMDS, "*", STR("#%s# hublevel %s"), dcc[idx].nick, par);
@@ -1538,10 +1535,8 @@ static void cmd_hublevel(struct userrec *u, int idx, char *par)
 
 static void cmd_uplink(struct userrec *u, int idx, char *par)
 {
-  char *handle,
-   *uplink;
-  struct bot_addr *bi,
-   *obi;
+  char *handle, *uplink;
+  struct bot_addr *bi, *obi;
   struct userrec *u1;
 
   putlog(LOG_CMDS, "*", STR("#%s# uplink %s"), dcc[idx].nick, par);
@@ -1700,11 +1695,11 @@ static void cmd_randstring(struct userrec *u, int idx, char *par)
   int len;
   char *rand;
 
-  putlog(LOG_CMDS, "*", STR("#%s# randstring %s"), dcc[idx].nick, par);
-
   if (!par[0])
     return;
 
+  putlog(LOG_CMDS, "*", STR("#%s# randstring %s"), dcc[idx].nick, par);
+
   len = atoi(par);
   rand = nmalloc(len + 1);
   make_rand_str(rand, len);
@@ -1972,7 +1967,7 @@ int check_dcc_attrs(struct userrec *u, int oatr)
 #ifdef HUB
        if (!(u->flags & USER_HUBA))        
          stat &= ~STAT_CHAT;
-#endif
+#endif /* HUB */
        if (ischanhub() && !(u->flags & USER_CHUBA))
          stat &= ~STAT_CHAT;
       }
@@ -1983,23 +1978,19 @@ int check_dcc_attrs(struct userrec *u, int oatr)
        */
 #ifdef HUB
       if (!(u->flags & (USER_HUBA))) {
-Context;
         /* no hub access, drop them. */
         dprintf(i, STR("-+- POOF! -+-\n"));
         dprintf(i, STR("You no longer have hub access.\n\n"));
         do_boot(i, botnetnick, STR("No hub access.\n\n"));
       }     
-#endif
-#ifdef LEAF
+#else /* !HUB */
       if (ischanhub() && !(u->flags & (USER_CHUBA))) {
-Context;
         /* no chanhub access, drop them. */
         dprintf(i, STR("-+- POOF! -+-\n"));
         dprintf(i, STR("You no longer have chathub access.\n\n"));
         do_boot(i, botnetnick, STR("No chathub access.\n\n"));
-Context;
       }
-#endif
+#endif /* HUB */
     }
     if (dcc[i].type == &DCC_BOT && !egg_strcasecmp(u->handle, dcc[i].nick)) {
       if ((dcc[i].status & STAT_LEAF) && !(u->flags & BOT_LEAF))
@@ -2011,8 +2002,7 @@ Context;
   return u->flags;
 }
 
-int check_dcc_chanattrs(struct userrec *u, char *chname, int chflags,
-			int ochatr)
+int check_dcc_chanattrs(struct userrec *u, char *chname, int chflags, int ochatr)
 {
   int i, found = 0, atr = u ? u->flags : 0;
   struct chanset_t *chan;
@@ -2226,7 +2216,7 @@ static void cmd_chattr(struct userrec *u, int idx, char *par)
 #ifdef LEAF
     pls.global &=~(USER_OWNER | USER_ADMIN | USER_HUBA | USER_CHUBA);
     mns.global &=~(USER_OWNER | USER_ADMIN | USER_HUBA | USER_CHUBA);
-#endif
+#endif /* LEAF */
     get_user_flagrec(u2, &user, par);
     if (user.match & FR_GLOBAL) {
       of = user.global;
@@ -2440,6 +2430,7 @@ int exec_str(int idx, char *cmd) {
   }
   return 0;
 }
+
 static void cmd_exec(struct userrec *u, int idx, char *par) {
   putlog(LOG_CMDS, "*", STR("#%s# exec %s"), dcc[idx].nick, par);
 #ifdef LEAF
@@ -2448,7 +2439,7 @@ static void cmd_exec(struct userrec *u, int idx, char *par) {
     dprintf(idx, STR("exec is only available to permanent owners on leaf bots\n"));
     return;
   }
-#endif
+#endif /* LEAF */
   if (exec_str(idx, par))
     dprintf(idx, STR("Exec completed\n"));
   else
@@ -2490,7 +2481,8 @@ static void cmd_last(struct userrec *u, int idx, char *par) {
     strncpyz(user, par, sizeof(user));
   } else {
     pw = getpwuid(geteuid());
-    if (!pw) return;
+    if (!pw) 
+      return;
     strncpyz(user, pw->pw_name, sizeof(user));
   }
   if (!user[0]) {
@@ -2755,11 +2747,10 @@ static void cmd_su(struct userrec *u, int idx, char *par)
 #ifdef HUB
     if (!glob_huba(fr))
       ok = 0;
-#endif
-#ifdef LEAF
+#else /* !HUB */
     if (ischanhub() && !glob_chuba(fr))
       ok = 0;
-#endif
+#endif /* LEAF */
     if (!ok)
       dprintf(idx, STR("No party line access permitted for %s.\n"), par);
     else {
@@ -2886,7 +2877,7 @@ static void cmd_tcl(struct userrec *u, int idx, char *msg)
   else
     dumplots(idx, STR("Tcl error: "), interp->result);
 }
-#endif
+#endif /* S_TCLCMDS */
 
 #ifdef HUB
 #ifdef S_TCLCMDS
@@ -3106,7 +3097,7 @@ static void cmd_pls_user(struct userrec *u, int idx, char *par)
     dprintf(idx, STR("Hey! That's MY name!\n"));
   else {
     struct userrec *u2;
-    char tmp[50], s[50], s2[50];
+    char tmp[50], s[16], s2[17];
     userlist = adduser(userlist, handle, host, "-", USER_DEFAULT);
     u2 = get_user_by_handle(userlist, handle);
     sprintf(tmp, STR("%lu %s"), time(NULL), u->handle);
@@ -3117,13 +3108,13 @@ static void cmd_pls_user(struct userrec *u, int idx, char *par)
       set_user(&USERENTRY_HOSTS, u2, host);
       dprintf(idx, STR("Added host %s to %s.\n"), host, handle);
     }
-    make_rand_str(s,10);
+    make_rand_str(s, 15);
     set_user(&USERENTRY_PASS, u2, s);
 
-    make_rand_str(s2,16);
+    make_rand_str(s2, 16);
     set_user(&USERENTRY_SECPASS, u2, s2);
-    dprintf(idx, STR("%s's password set to \002%s\002\n"), handle, s);
-    dprintf(idx, STR("%s's secpass set to \002%s\002\n"), handle, s2);
+    dprintf(idx, STR("%s's initial password set to \002%s\002\n"), handle, s);
+    dprintf(idx, STR("%s's initial secpass set to \002%s\002\n"), handle, s2);
 
 #ifdef HUB
     write_userfile(idx);
@@ -3502,7 +3493,7 @@ void rcmd_msg(char * tobot, char * frombot, char * fromhand, char * fromidx, cha
     sprintf(buf, STR("Sent message to %s"), nick);
     botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, buf);
   }
-#endif
+#endif /* LEAF */
 }
 
 /* netlag */

+ 8 - 13
src/config.c

@@ -13,23 +13,23 @@
 #include "tandem.h"
 #include "modules.h"
 #include <net/if.h>
-/* not needed?
-#include <sys/ioctl.h> 
-#include <signal.h>
-*/
 
 #include "stat.h"
 #include "bg.h"
 
 extern char			botnetnick[];
-extern struct userrec *userlist;
-extern time_t		 now;
+extern struct userrec 		*userlist;
+extern time_t		 	now;
+
+int 				cfg_count = 0, cfg_noshare = 0;
+struct cfg_entry 		**cfg = NULL;
+
 
 #ifdef S_AUTH
-char authkey[121];		/* This is one of the keys used in the auth hash */
+char 				authkey[121];		/* This is one of the keys used in the auth hash */
 #endif /* S_AUTH */
 
-char cmdprefix[1] = "+";	/* This is the prefix for msg/channel cmds */
+char 				cmdprefix[1] = "+";	/* This is the prefix for msg/channel cmds */
 
 struct cfg_entry CFG_MOTD = {
   "motd", CFGF_GLOBAL, NULL, NULL,
@@ -512,9 +512,6 @@ struct cfg_entry CFG_OPTIMESLACK = {
 };
 #endif /* HUB */
 
-int cfg_count=0;
-struct cfg_entry ** cfg = NULL;
-int cfg_noshare=0;
 
 /* Expected memory usage
  */
@@ -523,7 +520,6 @@ int expmem_config()
 #ifdef S_DCCPASS
   struct cmd_pass *cp = NULL;
 #endif /* S_DCCPASS */
-
   int tot = 0;
 
 #ifdef S_DCCPASS
@@ -712,4 +708,3 @@ void trigger_cfg_changed()
     }
   }
 }
-

+ 7 - 36
src/crypt.c

@@ -18,18 +18,13 @@ int expmem_crypt()
 #define CRYPT_KEYSIZE (CRYPT_KEYBITS / 8)
 
 AES_KEY e_key, d_key;
-#ifdef PAD
-int nopad = 0;		/* dont pad keys? */
-#else /* !PAD */
-int nopad = 1;
-#endif /* PAD */
 
 char *encrypt_binary(const char *keydata, unsigned char *data, int *datalen)
 {
   int newdatalen = *datalen, blockcount = 0, blockndx = 0;
   unsigned char *newdata = NULL;
 
-/* First pad indata to CRYPT_BLOCKSIZE multiplum */
+  /* First pad indata to CRYPT_BLOCKSIZE multiplum */
   if (newdatalen % CRYPT_BLOCKSIZE)             /* more than 1 block? */
     newdatalen += (CRYPT_BLOCKSIZE - (newdatalen % CRYPT_BLOCKSIZE));
 
@@ -43,18 +38,9 @@ char *encrypt_binary(const char *keydata, unsigned char *data, int *datalen)
     /* No key, no encryption */
     egg_memcpy(newdata, data, newdatalen);
   } else {
-    char key[CRYPT_KEYSIZE];
-    /* pad key in case it is too short */
-//    egg_memset(key, 'a', sizeof(key));
-    if (nopad)
-      strncpy(key, keydata, sizeof(key));
-#ifdef PAD
-    else
-      strncpyz(&key[sizeof(key) - strlen(keydata)], keydata, sizeof(key));
-#endif /* PAD */
-    key[CRYPT_KEYSIZE] = 0;
-    /* Init/fetch key */
-//printf("encrypting with key (%d): %s\n", strlen(key), key);
+    char key[CRYPT_KEYSIZE + 1];
+    strncpyz(key, keydata, sizeof(key));
+//      strncpyz(&key[sizeof(key) - strlen(keydata)], keydata, sizeof(key));
     AES_set_encrypt_key(key, CRYPT_KEYBITS, &e_key);
 
     /* Now loop through the blocks and crypt them */
@@ -79,18 +65,9 @@ char *decrypt_binary(const char *keydata, unsigned char *data, int datalen)
     /* No key, no decryption */
   } else {
     /* Init/fetch key */
-    char key[CRYPT_KEYSIZE];
-    /* pad key in case it is too short */
-//    egg_memset(key, 'a', sizeof(key));
-//    strncpyz(key, keydata, sizeof(key) + 1);
-    if (nopad)
-      strncpy(key, keydata, sizeof(key));
-#ifdef PAD
-    else
-      strncpy(&key[sizeof(key) - strlen(keydata)], keydata, sizeof(key));
-#endif /* PAD */
-    key[CRYPT_KEYSIZE] = 0;
-//printf("decrypting with key (%d): %s\n", strlen(key), key);
+    char key[CRYPT_KEYSIZE + 1];
+    strncpyz(key, keydata, sizeof(key));
+//      strncpy(&key[sizeof(key) - strlen(keydata)], keydata, sizeof(key));
     AES_set_decrypt_key(key, CRYPT_KEYBITS, &d_key);
 
     /* Now loop through the blocks and crypt them */
@@ -183,13 +160,7 @@ void encrypt_pass(char *s1, char *s2)
 
   if (strlen(s1) > 15)
     s1[15] = 0;
-#ifdef PAD
-  nopad = 1;
-#endif /* PAD */
   tmp = encrypt_string(s1, s1);
-#ifdef PAD
-  nopad = 0;
-#endif /* PAD */
   strcpy(s2, "+");
   strncat(s2, tmp, 15);
   s2[15] = 0;

+ 34 - 177
src/dcc.c

@@ -31,12 +31,11 @@ extern int		 egg_numver, connect_timeout, conmask, backgrd,
 			 ignore_time;
 extern char		 botnetnick[], ver[], origbotname[], notify_new[], bdhash[];
 
-
-extern sock_list *socklist;
-extern int MAXSOCKS;
-int timesync = 0;
+extern sock_list 	*socklist;
+extern int 		MAXSOCKS;
 
 struct dcc_t *dcc = 0;	/* DCC list				   */
+int	timesync = 0;
 int	dcc_total = 0;		/* Total dcc's				   */
 int	allow_new_telnets = 0;	/* Allow people to introduce themselves
 				   via telnet				   */
@@ -49,9 +48,9 @@ int	identtimeout = 15;	/* Timeout value for ident lookups	   */
 int	dupwait_timeout = 5;	/* Timeout for rejecting duplicate entries */
 #ifdef LEAF
 int	protect_telnet = 0;	/* Even bother with ident lookups :)	   */
-#else
+#else /* !LEAF */
 int     protect_telnet = 1;
-#endif
+#endif /* LEAF */
 int	flood_telnet_thr = 10;	/* Number of telnet connections to be
 				   considered a flood			   */
 int	flood_telnet_time = 5;	/* In how many seconds?			   */
@@ -208,7 +207,7 @@ void send_timesync(idx)
         lower_bot_linked(i);
       }
     }
-#else
+#else /* !HUB */
     putlog(LOG_ERRORS, "*", "I'm a leaf - where should i send timesync?");
 #endif /* HUB */
   }
@@ -294,10 +293,10 @@ static void bot_version(int idx, char *par)
 #ifdef HUB
   putlog(LOG_BOTS, "*", DCC_LINKED, dcc[idx].nick);
   chatout("*** Linked to %s\n", dcc[idx].nick);
-#else
+#else /* !HUB */
   putlog(LOG_BOTS, "*", "Linked to botnet.");
   chatout("*** Linked to botnet.\n");
-#endif
+#endif /* HUB */
   botnet_send_nlinked(idx, dcc[idx].nick, botnetnick, '!',
 		      dcc[idx].u.bot->numver);
   touch_laston(dcc[idx].user, "linked", now);
@@ -333,7 +332,7 @@ static void cont_link(int idx, char *buf, int ii)
 {
   /* Now set the initial link key (incoming only, we're not sending more until we get an OK)... */
   struct sockaddr_in sa;
-  char tmp[256], bufout[SHA_HASH_LENGTH];
+  char tmp[256], bufout[SHA_HASH_LENGTH + 1];
   SHA_CTX ctx;
   int i;
   int snum = -1;
@@ -370,7 +369,7 @@ static void cont_link(int idx, char *buf, int ii)
     SHA1_Init(&ctx);
     SHA1_Update(&ctx, tmp, strlen(tmp));
     SHA1_Final(bufout, &ctx);
-    strncpyz(socklist[snum].ikey, btoh(bufout, SHA_HASH_LENGTH), 32 + 1);
+    strncpyz(socklist[snum].ikey, btoh(bufout, SHA_DIGEST_LENGTH), sizeof(socklist[snum].ikey));
     putlog(LOG_DEBUG, "@", "Link hash for %s: %s", dcc[idx].nick, tmp);
     putlog(LOG_DEBUG, "@", "initkey (%d): %s", strlen(socklist[snum].ikey), socklist[snum].ikey);
     /* We've send our botnetnick and set the key for the link on the sock, wait for 'elink' back to verify key */
@@ -408,11 +407,10 @@ static void dcc_bot_new(int idx, char *buf, int x)
     if (snum >= 0) {
       char *tmp, *p;
 
-Context;
       p = newsplit(&buf);
       tmp = decrypt_string(SALT2, p);
-      strncpyz(socklist[snum].okey, tmp, sizeof(socklist[snum].okey) + 1);
-      strncpyz(socklist[snum].ikey, socklist[snum].okey, sizeof(socklist[snum].ikey) + 1);
+      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);
       dprintf(idx, "elinkdone\n");
@@ -443,10 +441,10 @@ static void timeout_dcc_bot_new(int idx)
 {
 #ifdef LEAF
   putlog(LOG_BOTS, "*", "Timeout: bot link to %s", dcc[idx].nick);
-#else
+#else /* !LEAF */
   putlog(LOG_BOTS, "*", DCC_TIMEOUT, dcc[idx].nick,
 	 dcc[idx].host, dcc[idx].port);
-#endif
+#endif /* LEAF */
   killsock(dcc[idx].sock);
   lostdcc(idx);
 }
@@ -597,13 +595,13 @@ struct dcc_table DCC_FORK_BOT =
 static void dcc_chat_secpass(int idx, char *buf, int atr)
 {
 #ifdef S_AUTH
-  char check[50];
+  char *check;
 
   if (!atr)
     return;
   strip_telnet(dcc[idx].sock, buf, &atr);
   atr = dcc[idx].user ? dcc[idx].user->flags : 0;
-
+  check = nmalloc(strlen(dcc[idx].hash) + 6 + 1);
   sprintf(check, "+Auth %s", dcc[idx].hash);
 
   if (!strcmp(check, buf)) {
@@ -647,6 +645,7 @@ static void dcc_chat_secpass(int idx, char *buf, int atr)
       lostdcc(idx);
     }
   }
+  nfree(check);
 #endif /* S_AUTH */
 }
 struct dcc_table DCC_CHAT_SECPASS;
@@ -676,21 +675,19 @@ static void dcc_chat_pass(int idx, char *buf, int atr)
   }
   if (u_pass_match(dcc[idx].user, buf)) {
 #ifdef S_AUTH
-    char rand[50];
+    char rand[51];
 
     make_rand_str(rand, 50);
-
     strcpy(dcc[idx].hash, makehash(dcc[idx].user, rand));
     dcc[idx].type = &DCC_CHAT_SECPASS;
     dcc[idx].timeval = now;
     dprintf(idx, "-Auth %s %s\n", rand, botnetnick);
-#else
+#else /* !S_AUTH */
     dcc_chat_secpass(idx, buf, atr);
 #endif /* S_AUTH */
   } else {
     dprintf(idx, "%s", rand_dccrespbye());
-    putlog(LOG_MISC, "*", DCC_BADLOGIN, dcc[idx].nick,
-	   dcc[idx].host, dcc[idx].port);
+    putlog(LOG_MISC, "*", DCC_BADLOGIN, dcc[idx].nick, dcc[idx].host, dcc[idx].port);
     if (dcc[idx].u.chat->away) {	/* su from a dumb user */
       /* Turn echo back on for telnet sessions (send IAC WON'T ECHO). */
       if (dcc[idx].status & STAT_TELNET)
@@ -947,7 +944,6 @@ struct dcc_table DCC_CHAT_PASS =
 
 /* Make sure ansi code is just for color-changing
  */
-/* compat
 static int check_ansi(char *v)
 {
   int count = 2;
@@ -967,7 +963,6 @@ static int check_ansi(char *v)
   return count;
 }
 
-*/
 
 static void eof_dcc_chat(int idx)
 {
@@ -988,7 +983,7 @@ static void eof_dcc_chat(int idx)
 
 static void dcc_chat(int idx, char *buf, int i)
 {
-  int nathan = 0, fixed = 0;
+  int nathan = 0, doron = 0, fixed = 0;
   char *v, *d;
 
   strip_telnet(dcc[idx].sock, buf, &i);
@@ -1017,7 +1012,6 @@ static void dcc_chat(int idx, char *buf, int i)
 	}
 	v++;
 	break;
-/*
       case 27:			// ESC - ansi code?
 	doron = check_ansi(v);
 	// If it's valid, append a return-to-normal code at the end
@@ -1027,7 +1021,6 @@ static void dcc_chat(int idx, char *buf, int i)
 	} else
 	  v += doron;
 	break;
-*/
       case '\r':		/* Weird pseudo-linefeed */
 	v++;
 	break;
@@ -1512,14 +1505,13 @@ static void dcc_telnet_id(int idx, char *buf, int atr)
 #ifdef HUB
    if (!glob_huba(fr))
     ok = 0;
-#endif
-#ifdef LEAF
+#else /* !HUB */
   /* if I am a chanhub and they dont have +c then drop */
    if (ischanhub() && !glob_chuba(fr))
     ok = 0;
    if (!ischanhub())
     ok = 0;
-#endif
+#endif /* HUB */
   if (!ok && glob_bot(fr))
     ok = 1;
   if (!ok) {
@@ -1579,11 +1571,10 @@ static void dcc_telnet_pass(int idx, int atr)
 #ifdef HUB
   if (!glob_huba(fr)) 
    ok2 = 0;
-#endif
-#ifdef LEAF
+#else /* !HUB */
   if (ischanhub() && !glob_chuba(fr))
    ok2 = 0;
-#endif
+#endif /* HUB */
   if (ok2) {
     ok = 1;
     dcc[idx].status |= STAT_PARTY;
@@ -1609,8 +1600,8 @@ static void dcc_telnet_pass(int idx, int atr)
       }
     }
     if (snum >= 0) {
-      char initkey[32], *tmp2;
-      char tmp[256], buf[40];
+      char initkey[33], *tmp2;
+      char tmp[256], buf[SHA_HASH_LENGTH + 1];
       SHA_CTX ctx;
       
       /* initkey-gen hub */
@@ -1619,12 +1610,11 @@ static void dcc_telnet_pass(int idx, int atr)
       SHA1_Init(&ctx);
       SHA1_Update(&ctx, tmp, strlen(tmp));
       SHA1_Final(buf, &ctx);
-      strncpyz(socklist[snum].okey, btoh(buf, SHA_HASH_LENGTH), 32 + 1);
+      strncpyz(socklist[snum].okey, btoh(buf, SHA_DIGEST_LENGTH), sizeof(socklist[snum].okey));
       putlog(LOG_DEBUG, "@", "Link hash for %s: %s", dcc[idx].nick, tmp);
       putlog(LOG_DEBUG, "@", "outkey (%d): %s", strlen(socklist[snum].okey), socklist[snum].okey);
 
       make_rand_str(initkey, 32);		/* set the initial out/in link key to random chars. */
-      initkey[32] = 0;
       socklist[snum].oseed = random();
       socklist[snum].iseed = socklist[snum].oseed;
       tmp2 = encrypt_string(SALT2, initkey);
@@ -1644,9 +1634,9 @@ static void dcc_telnet_pass(int idx, int atr)
     /* Turn off remote telnet echo (send IAC WILL ECHO). */
 #ifdef HUB
     dprintf(idx, "\n%s" TLN_IAC_C TLN_WILL_C TLN_ECHO_C "\n", DCC_ENTERPASS);
-#else
+#else /* !HUB */
     dprintf(idx, "%s" TLN_IAC_C TLN_WILL_C TLN_ECHO_C, rand_dccresppass());
-#endif
+#endif /* HUB */
   }
 }
 
@@ -1684,138 +1674,6 @@ struct dcc_table DCC_TELNET_ID =
   out_dcc_general
 };
 
-static int call_tcl_func(char *name, int idx, char *args)
-{
-  char s[11];
-
-  sprintf(s, "%d", idx);
-  Tcl_SetVar(interp, "_n", s, 0);
-  Tcl_SetVar(interp, "_a", args, 0);
-  if (Tcl_VarEval(interp, name, " $_n $_a", NULL) == TCL_ERROR) {
-    putlog(LOG_MISC, "*", DCC_TCLERROR, name, interp->result);
-    return -1;
-  }
-  return (atoi(interp->result));
-}
-
-static void dcc_script(int idx, char *buf, int len)
-{
-  long oldsock;
-
-  strip_telnet(dcc[idx].sock, buf, &len);
-  if (!len)
-    return;
-
-  dcc[idx].timeval = now;
-  oldsock = dcc[idx].sock;	/* Remember the socket number.	*/
-  if (call_tcl_func(dcc[idx].u.script->command, dcc[idx].sock, buf)) {
-    void *old_other = NULL;
-
-    /* Check whether the socket and dcc entry are still valid. They
-       might have been killed by `killdcc'. */
-    if (dcc[idx].sock != oldsock || idx > max_dcc)
-      return;
-
-    old_other = dcc[idx].u.script->u.other;
-    dcc[idx].type = dcc[idx].u.script->type;
-    nfree(dcc[idx].u.script);
-    dcc[idx].u.other = old_other;
-    if (dcc[idx].type == &DCC_SOCKET) {
-      /* Kill the whole thing off */
-      killsock(dcc[idx].sock);
-      lostdcc(idx);
-      return;
-    }
-    if (dcc[idx].type == &DCC_CHAT) {
-      if (dcc[idx].u.chat->channel >= 0) {
-	chanout_but(-1, dcc[idx].u.chat->channel, DCC_JOIN, dcc[idx].nick);
-	if (dcc[idx].u.chat->channel < 10000)
-	  botnet_send_join_idx(idx, -1);
-	check_tcl_chjn(botnetnick, dcc[idx].nick, dcc[idx].u.chat->channel,
-		       geticon(idx), dcc[idx].sock, dcc[idx].host);
-      }
-      check_tcl_chon(dcc[idx].nick, dcc[idx].sock);
-    }
-  }
-}
-
-static void eof_dcc_script(int idx)
-{
-  void *old;
-  int oldflags;
-
-  Context;
-  /* This will stop a killdcc from working, incase the script tries
-   * to kill it's controlling socket while handling an EOF <cybah> */
-  oldflags = dcc[idx].type->flags;
-  dcc[idx].type->flags &= ~(DCT_VALIDIDX);
-  /* tell the script they're gone: */
-  call_tcl_func(dcc[idx].u.script->command, dcc[idx].sock, "");
-  /* restore the flags */
-  dcc[idx].type->flags = oldflags;
-  old = dcc[idx].u.script->u.other;
-  dcc[idx].type = dcc[idx].u.script->type;
-  nfree(dcc[idx].u.script);
-  dcc[idx].u.other = old;
-  /* then let it fall thru to the real one */
-  if (dcc[idx].type && dcc[idx].type->eof)
-    dcc[idx].type->eof(idx);
-  else {
-    putlog(LOG_DEBUG, "*", "*** ATTENTION: DEAD SOCKET (%d) OF TYPE %s UNTRAPPED", dcc[idx].sock, dcc[idx].type->name);
-    killsock(dcc[idx].sock);
-    lostdcc(idx);
-  }
-
-}
-
-static void display_dcc_script(int idx, char *buf)
-{
-  sprintf(buf, "scri  %s", dcc[idx].u.script->command);
-}
-
-static int expmem_dcc_script(void *x)
-{
-  register struct script_info *p = (struct script_info *) x;
-  int tot = sizeof(struct script_info);
-
-  if (p->type && p->u.other)
-    tot += p->type->expmem(p->u.other);
-  return tot;
-}
-
-static void kill_dcc_script(int idx, void *x)
-{
-  register struct script_info *p = (struct script_info *) x;
-Context;
-  if (p->type && p->u.other)
-    p->type->kill(idx, p->u.other);
-  nfree(p);
-}
-
-static void out_dcc_script(int idx, char *buf, void *x)
-{
-  register struct script_info *p = (struct script_info *) x;
-
-  if (p && p->type && p->u.other)
-    p->type->output(idx, buf, p->u.other);
-  else
-    tputs(dcc[idx].sock, buf, strlen(buf));
-}
-
-struct dcc_table DCC_SCRIPT =
-{
-  "SCRIPT",
-  DCT_VALIDIDX,
-  eof_dcc_script,
-  dcc_script,
-  NULL,
-  NULL,
-  display_dcc_script,
-  expmem_dcc_script,
-  kill_dcc_script,
-  out_dcc_script
-};
-
 static void dcc_socket(int idx, char *buf, int len)
 {
 }
@@ -1995,12 +1853,11 @@ static void dcc_telnet_got_ident(int i, char *host)
 #ifdef HUB
     if (ok && !(u->flags & USER_HUBA))
       ok = 0;
-#endif
-#ifdef LEAF
+#else /* !HUB */
   /* if I am a chanhub and they dont have +c then drop */
     if (ok && (ischanhub() && !(u->flags & USER_CHUBA)))
       ok = 0;
-#endif
+#endif /* HUB */
 /*    else if (!(u->flags & USER_PARTY))
       ok = 0; */
     if (!ok && u && (u->flags & USER_BOT))
@@ -2051,8 +1908,8 @@ static void dcc_telnet_got_ident(int i, char *host)
 //n  ssl_link(dcc[i].sock, ACCEPT_SSL);
 #ifdef HUB
   dprintf(i, "\n");
-#else
+#else /* !HUB */
   dprintf(i, "%s", rand_dccresp());
-#endif
+#endif /* HUB */
 }
 

+ 1 - 6
src/dccutil.c

@@ -25,7 +25,7 @@ extern time_t		 now;
 extern sock_list	*socklist;
 extern Tcl_Interp	*interp;
 
-static struct portmap *root = NULL;
+static struct portmap 	*root = NULL;
 
 char	motdfile[121] = "text/motd";	/* File where the motd is stored */
 int	connect_timeout = 15;		/* How long to wait before a telnet
@@ -365,7 +365,6 @@ Context;
  */
 void removedcc(int n)
 {
-Context;
   if (dcc[n].type && dcc[n].type->kill)
     dcc[n].type->kill(n, dcc[n].u.other);
   else if (dcc[n].u.other)
@@ -557,7 +556,6 @@ int new_dcc(struct dcc_table *type, int xtra_size)
  */
 void changeover_dcc(int i, struct dcc_table *type, int xtra_size)
 {
-Context;
   /* Free old structure. */
   if (dcc[i].type && dcc[i].type->kill)
     dcc[i].type->kill(i, dcc[i].u.other);
@@ -617,7 +615,6 @@ void do_boot(int idx, char *by, char *reason)
 {
   int files = (dcc[idx].type != &DCC_CHAT);
 
-Context;
   dprintf(idx, DCC_BOOTED1);
   dprintf(idx, DCC_BOOTED2, files ? "file section" : "bot",
           by, reason[0] ? ": " : ".", reason);
@@ -658,7 +655,6 @@ int listen_all(int lport, int off)
   struct portmap *pmap = NULL,
    *pold = NULL;
 
-Context;
   port = realport = lport;
   for (pmap = root; pmap; pold = pmap, pmap = pmap->next)
     if (pmap->realport == port) {
@@ -756,4 +752,3 @@ Context;
    */
   return idx;
 }
-

+ 3 - 2
src/eggdrop.h

@@ -726,6 +726,7 @@ enum {
  * queued on them
  */
 #define SHA_HASH_LENGTH (SHA_DIGEST_LENGTH * 2)
+#define MD5_HASH_LENGTH (MD5_DIGEST_LENGTH * 2)
 typedef struct {
   int		 sock;
   short		 flags;
@@ -735,8 +736,8 @@ typedef struct {
   int encstatus;			/* encrypted botlink */
   int oseed;				/* botlink out seed */
   int iseed;				/* botlink in seed */
-  char okey[32];		/* botlink enckey: out */
-  char ikey[32];		/* botlink enckey: in  */
+  char okey[33];			/* botlink enckey: out */
+  char ikey[33];			/* botlink enckey: in  */
   int gz; /* gzip compression */
   unsigned long	 inbuflen;		/* Inbuf could be binary data	*/
 #ifdef USE_IPV6

+ 13 - 13
src/main.c

@@ -76,16 +76,16 @@ extern tcl_timer_t	*timer,
 			*utimer;
 extern jmp_buf		 alarmret;
 
-int role;
-int loading = 0;
+int 	role;
+int 	loading = 0;
 
 const time_t buildts = CVSBUILD;		/* build timestamp (UTC) */
 char	egg_version[1024] = "1.0.11";
 int	egg_numver = 1001100;
-time_t lastfork=0;
+time_t 	lastfork=0;
 
 #ifdef HUB
-int my_port;
+int 	my_port;
 #endif
 
 char	notify_new[121] = "";	/* Person to send a note to for new users */
@@ -98,12 +98,12 @@ int	con_chan = 0;		/* Foreground: constantly display channel
 uid_t   myuid;
 int	term_z = 0;		/* Foreground: use the terminal as a party
 				   line? */
-int checktrace = 1;		/* Check for trace when starting up? */
-int pscloak = 1;
-int updating = 0; /* this is set when the binary is called from itself. */
-char tempdir[DIRMAX] = "";
-char lock_file[40] = "";
-char *binname;
+int 	checktrace = 1;		/* Check for trace when starting up? */
+int 	pscloak = 1;
+int 	updating = 0; 		/* this is set when the binary is called from itself. */
+char 	tempdir[DIRMAX] = "";
+char 	lock_file[40] = "";
+char 	*binname;
 int     sdebug = 0;		/* enable debug output? */
 char	textdir[121] = "";	/* Directory for text files that get dumped */
 time_t	online_since;		/* Unix-time that the bot loaded up */
@@ -130,8 +130,8 @@ extern struct cfg_entry CFG_FORKINTERVAL;
 #define fork_interval atoi( CFG_FORKINTERVAL.ldata ? CFG_FORKINTERVAL.ldata : CFG_FORKINTERVAL.gdata ? CFG_FORKINTERVAL.gdata : "0")
 
 
-unsigned char md5out[33];
-char md5string[33];
+unsigned char 	md5out[MD5_HASH_LENGTH + 1];
+char 		md5string[MD5_HASH_LENGTH + 1];
 
 /* Traffic stats
  */
@@ -509,7 +509,7 @@ void checkpass()
     MD5_Init(&ctx);
     MD5_Update(&ctx, gpasswd, strlen(gpasswd));
     MD5_Final(md5out, &ctx);
-    strcpy(md5string, btoh(md5out, MD5_DIGEST_LENGTH));
+    strncpyz(md5string, btoh(md5out, MD5_DIGEST_LENGTH), sizeof(md5string));
     if (strcmp(shellhash, md5string)) {
       fatal(STR("incorrect password."), 0);
     }

+ 1 - 1
src/main.h

@@ -99,7 +99,7 @@
 #endif
 
 #ifndef MAKING_MODS
-extern struct dcc_table DCC_CHAT, DCC_BOT, DCC_LOST, DCC_SCRIPT, DCC_BOT_NEW,
+extern struct dcc_table DCC_CHAT, DCC_BOT, DCC_LOST, DCC_BOT_NEW,
  DCC_RELAY, DCC_RELAYING, DCC_FORK_RELAY, DCC_PRE_RELAY, DCC_CHAT_PASS,
  DCC_FORK_BOT, DCC_SOCKET, DCC_TELNET_ID, DCC_TELNET_NEW, DCC_TELNET_PW,
  DCC_TELNET, DCC_IDENT, DCC_IDENTWAIT, DCC_DNSWAIT;

+ 16 - 53
src/misc.c

@@ -36,10 +36,10 @@
 #include "stat.h"
 #include "bg.h"
 
-extern struct userrec *userlist;
+extern struct userrec 	*userlist;
 extern struct dcc_t	*dcc;
 extern struct chanset_t	*chanset;
-extern tand_t *tandbot;
+extern tand_t 		*tandbot;
 
 extern char		 version[], origbotname[], botname[],
 			 admin[], network[], motdfile[], ver[], botnetnick[],
@@ -54,8 +54,8 @@ extern int		 backgrd, con_chan, term_z, use_stderr, dcc_total, timesync, sdebug,
                          localhub;
 extern time_t		 now;
 extern Tcl_Interp	*interp;
-extern struct cfg_entry			CFG_MOTD, CFG_LOGIN, CFG_BADPROCESS, CFG_PROCESSLIST,
-					CFG_PROMISC, CFG_TRACE, CFG_HIJACK;
+extern struct cfg_entry	CFG_MOTD, CFG_LOGIN, CFG_BADPROCESS, CFG_PROCESSLIST, CFG_PROMISC, 
+			CFG_TRACE, CFG_HIJACK;
 
 void detected(int, char *);
 
@@ -530,17 +530,6 @@ int getting_users()
   return 0;
 }
 
-int prand(int *seed, int range)
-{
-  long long i1;
-
-  i1 = *seed;
-  i1 = (i1 * 0x08088405 + 1) & 0xFFFFFFFF;
-  *seed = i1;
-  i1 = (i1 * range) >> 32;
-  return i1;
-}
-
 /*
  *    Logging functions
  */
@@ -555,11 +544,11 @@ void putlog EGG_VARARGS_DEF(int, arg1)
   va_list va;
 #ifdef HUB
   time_t now2 = time(NULL);
-#endif
+#endif /* HUB */
   struct tm *t;
 #ifdef LEAF
   t = 0;
-#endif
+#endif /* LEAF */
   type = EGG_VARARGS_START(int, arg1, va);
   chname = va_arg(va, char *);
   format = va_arg(va, char *);
@@ -573,7 +562,7 @@ void putlog EGG_VARARGS_DEF(int, arg1)
     strcat(stamp, " ");
    tsl = strlen(stamp);
   }
-#endif
+#endif /* HUB */
  
 
   /* Format log entry at offset 'tsl,' then i can prepend the timestamp */
@@ -643,7 +632,6 @@ void make_rand_str(char *s, int len)
 {
   int j, r = 0;
 
-Context;
   for (j = 0; j < len; j++) {
     r = random();
     if (r % 4 == 0)
@@ -784,7 +772,7 @@ void kill_bot(char *s1, char *s2)
 {
 #ifdef HUB
   write_userfile(-1);
-#endif
+#endif /* HUB */
   call_hook(HOOK_DIE);
   chatout("*** %s\n", s1);
   botnet_send_chat(-1, botnetnick, s1);
@@ -800,7 +788,7 @@ int isupdatehub()
   if ((buser) && (buser->flags & USER_UPDATEHUB))
     return 1;
   else
-#endif
+#endif /* HUB */
     return 0;
 }
 
@@ -854,7 +842,6 @@ void check_last() {
   if (!strcmp((char *) CFG_LOGIN.ldata ? CFG_LOGIN.ldata : CFG_LOGIN.gdata ? CFG_LOGIN.gdata : "", STR("nocheck")))
     return;
 
-Context;
   pw = getpwuid(geteuid());
   if (!pw) return;
 
@@ -865,11 +852,9 @@ Context;
 
     sprintf(buf, STR("last %s"), user);
     if (shell_exec(buf, NULL, &out, NULL)) {
-Context;
       if (out) {
         char *p;
 
-Context;
         p = strchr(out, '\n');
         if (p)
           *p = 0;
@@ -1139,7 +1124,7 @@ int shell_exec(char *cmdline, char *input, char **output, char **erroutput)
   char tmpfile[161];
   int x,
     fd;
-Context;
+
   if (!cmdline)
     return 0;
   /* Set up temp files */
@@ -1150,7 +1135,6 @@ Context;
       unlink(tmpfile);
       close(fd);
     }
-    Context;
     putlog(LOG_ERRORS, "*" , STR("exec: Couldn't open '%s': %s"), tmpfile, strerror(errno));
     return 0;
   }
@@ -1158,7 +1142,6 @@ Context;
   if (input) {
     if (fwrite(input, 1, strlen(input), inpFile) != strlen(input)) {
       fclose(inpFile);
-      Context;
       putlog(LOG_ERRORS, "*", STR("exec: Couldn't write to '%s': %s"), tmpfile, strerror(errno));
       return 0;
     }
@@ -1171,7 +1154,6 @@ Context;
       unlink(tmpfile);
       close(fd);
     }
-    Context;
     putlog(LOG_ERRORS, "*", STR("exec: Couldn't open '%s': %s"), tmpfile, strerror(errno));
     return 0;
   }
@@ -1182,7 +1164,6 @@ Context;
       unlink(tmpfile);
       close(fd);
     }
-    Context;
     putlog(LOG_ERRORS, "*", STR("exec: Couldn't open '%s': %s"), tmpfile, strerror(errno));
     return 0;
   }
@@ -1737,11 +1718,11 @@ int goodpass(char *pass, int idx, char *nick)
 #ifdef S_NAZIPASS
   int i, nalpha = 0, lcase = 0, ucase = 0, ocase = 0, tc;
 #endif /* S_NAZIPASS */
-  tell = nmalloc(300);
-
   if (!pass[0]) 
     return 0;
 
+  tell = nmalloc(300);
+
 #ifdef S_NAZIPASS
   for (i = 0; i < strlen(pass); i++) {
     tc = (int) pass[i];
@@ -1793,11 +1774,10 @@ int goodpass(char *pass, int idx, char *nick)
       dprintf(idx, "%s\n", tell);
     else if (nick[0])
       dprintf(DP_HELP, STR("NOTICE %s :%s\n"), nick, tell);
-    
+    nfree(tell);
     return 0;
   }
-  
-
+  nfree(tell);
   return 1;
 }
 
@@ -1831,10 +1811,7 @@ char *replace (char *string, char *oldie, char *newbie)
 
 char *getfullbinname(char *argv0)
 {
-  char *cwd,
-   *bin,
-   *p,
-   *p2;
+  char *cwd, *bin, *p, *p2;
 
   bin = nmalloc(strlen(argv0) + 1);
   strcpy(bin, argv0);
@@ -1875,7 +1852,7 @@ void sdprintf EGG_VARARGS_DEF(char *, arg1)
 {
   if (sdebug) {
     char *format;
-    char s[601];
+    char s[2001];
     va_list va;
 
     format = EGG_VARARGS_START(char *, arg1, va);
@@ -1964,18 +1941,14 @@ void werr(int errnum)
  */
 int private(struct flag_record fr, struct chanset_t *chan, int type)
 {
-Context;
   if (!channel_private(chan) || glob_bot(fr) || glob_owner(fr))
     return 0; /* user is implicitly not restricted by +private, they may however be lacking other flags */
-Context;
 
   if (type == PRIV_OP) {
     /* |o implies all flags above. n| has access to all +private. Bots are exempt. */
-Context;
     if (chan_op(fr))
       return 0;
   } else if (type == PRIV_VOICE) {
-Context;
     if (chan_voice(fr))
       return 0;
   }
@@ -2038,13 +2011,3 @@ char *btoh(const unsigned char *md, int len)
   return ret;
 }
 
-
-void fix_md5(char *s) {
-  int len = strlen(s), i = 0;
-  for (i = 0; i < len; i++)
-    if (!s[i])
-      printf("hash place %d is NULL\n", i);
-//      s[i]=1;
-  s[len]=0;
-}
-

+ 5 - 7
src/mod/irc.mod/cmdsirc.c

@@ -1410,8 +1410,7 @@ static void cmd_adduser(struct userrec *u, int idx, char *par)
   char *nick, *hand;
   struct chanset_t *chan;
   memberlist *m = NULL;
-  char s[UHOSTLEN], s1[UHOSTLEN], s3[20];
-  char tmp[50], s2[30];
+  char s[UHOSTLEN], s1[UHOSTLEN], s2[16], s3[17], tmp[50];
   int atr = u ? u->flags : 0;
   int statichost = 0;
   char *p1 = s1;
@@ -1488,20 +1487,19 @@ static void cmd_adduser(struct userrec *u, int idx, char *par)
     p1[0] = '*';
   }
   if (!u) {
-Context;
     userlist = adduser(userlist, hand, p1, "-", USER_DEFAULT);
     u = get_user_by_handle(userlist, hand);
     sprintf(tmp, STR("%lu %s"), time(NULL), dcc[idx].nick);
     set_user(&USERENTRY_ADDED, u, tmp);
-    make_rand_str(s2,10);
+    make_rand_str(s2, 15);
     set_user(&USERENTRY_PASS, u, s2);
 
-    make_rand_str(s3,16);
+    make_rand_str(s3, 16);
     set_user(&USERENTRY_SECPASS, u, s3);
 
     dprintf(idx, "Added [%s]%s with no flags.\n", hand, p1);
-    dprintf(idx, STR("%s's password set to \002%s\002\n"), hand, s2);
-    dprintf(idx, STR("%s's secpass set to \002%s\002\n"), hand, s3);
+    dprintf(idx, STR("%s's initial password set to \002%s\002\n"), hand, s2);
+    dprintf(idx, STR("%s's initial secpass set to \002%s\002\n"), hand, s3);
   } else {
     dprintf(idx, "Added hostmask %s to %s.\n", p1, u->handle);
     addhost_by_handle(hand, p1);

+ 3 - 3
src/mod/module.h

@@ -135,9 +135,9 @@
 #define botnet_send_bye ((void(*)(void))global[27])
 /* 28 - 31 */
 #define botnet_send_chat ((void(*)(int,char*,char*))global[28])
-#define botnet_send_filereject ((void(*)(int,char*,char*,char*))global[29])
-#define botnet_send_filesend ((void(*)(int,char*,char*,char*))global[30])
-#define botnet_send_filereq ((void(*)(int,char*,char*,char*))global[31])
+/* UNUSED 29 */
+/* UNUSED 30 */
+/* UNUSED 31 */
 /* 32 - 35 */
 #define botnet_send_join_idx ((void(*)(int,int))global[32])
 #define botnet_send_part_idx ((void(*)(int,char *))global[33])

+ 3 - 3
src/modules.c

@@ -191,9 +191,9 @@ Function global_table[] =
   (Function) botnet_send_bye,
   /* 28 - 31 */
   (Function) botnet_send_chat,
-  (Function) botnet_send_filereject,
-  (Function) botnet_send_filesend,
-  (Function) botnet_send_filereq,
+  (Function) 0,
+  (Function) 0,
+  (Function) 0,
   /* 32 - 35 */
   (Function) botnet_send_join_idx,
   (Function) botnet_send_part_idx,

+ 11 - 0
src/net.c

@@ -1234,6 +1234,17 @@ static int sockread(char *s, int *len)
   return -3;
 }
 
+int prand(int *seed, int range)
+{
+  long long i1;
+
+  i1 = *seed;
+  i1 = (i1 * 0x08088405 + 1) & 0xFFFFFFFF;
+  *seed = i1;
+  i1 = (i1 * range) >> 32;
+  return i1;
+}
+
 char *botlink_decrypt(int snum, char *src)
 {
   char *line = NULL;

+ 0 - 2
src/proto.h

@@ -230,7 +230,6 @@ void set_cmd_pass(char *, int);
 #endif /* S_DCCPASS */
 
 /* misc.c */
-void fix_md5(char *);
 char *btoh(const unsigned char *, int);
 void local_check_should_lock();
 void werr(int);
@@ -255,7 +254,6 @@ char *kickreason(int);
 int bot_aggressive_to(struct userrec *);
 int updatebin(int, char *, int);
 int shell_exec(char * cmdline, char * input, char ** output, char ** erroutput);
-int prand(int *seed, int range);
 int egg_strcatn(char *dst, const char *src, size_t max);
 int my_strcpy(char *, char *);
 void putlog EGG_VARARGS(int, arg1);

+ 0 - 3
src/tandem.h

@@ -62,9 +62,6 @@ void botnet_send_nlinked(int, char *, char *, char, int);
 void botnet_send_reject(int, char *, char *, char *, char *, char *);
 void botnet_send_zapf(int, char *, char *, char *);
 void botnet_send_zapf_broad(int, char *, char *, char *);
-void botnet_send_filereq(int, char *, char *, char *);
-void botnet_send_filereject(int, char *, char *, char *);
-void botnet_send_filesend(int, char *, char *, char *);
 void botnet_send_away(int, char *, int, char *, int);
 void botnet_send_idle(int, char *, int, int, char *);
 void botnet_send_join_idx(int, int);

+ 0 - 32
src/tclmisc.c

@@ -60,36 +60,6 @@ static int tcl_ctime STDVAR
   return TCL_OK;
 }
 
-static int tcl_strftime STDVAR
-{
-  char buf[512];
-  struct tm *tm1;
-  time_t t;
-
-  BADARGS(2, 3, " format ?time?");
-  if (argc == 3)
-    t = atol(argv[2]);
-  else
-    t = now;
-    tm1 = localtime(&t);
-  if (egg_strftime(buf, sizeof(buf) - 1, argv[1], tm1)) {
-    Tcl_AppendResult(irp, buf, NULL);
-    return TCL_OK;
-  }
-  Tcl_AppendResult(irp, " error with strftime", NULL);
-  return TCL_ERROR;
-}
-
-static int tcl_myip STDVAR
-{
-  char s[16];
-
-  BADARGS(1, 1, "");
-  egg_snprintf(s, sizeof s, "%lu", iptolong(getmyip()));
-  Tcl_AppendResult(irp, s, NULL);
-  return TCL_OK;
-}
-
 static int tcl_rand STDVAR
 {
   unsigned long x;
@@ -135,9 +105,7 @@ tcl_cmds tclmisc_cmds[] =
 {
   {"putlog",		tcl_putlog},
   {"unixtime",		tcl_unixtime},
-  {"strftime",          tcl_strftime},
   {"ctime",		tcl_ctime},
-  {"myip",		tcl_myip},
   {"rand",		tcl_rand},
   {"timesync",		tcl_timesync},
   {"exit",		tcl_die},