Przeglądaj źródła

* Added S_SPLITHIJACK for testing (+/-cycle)
* Added Fighting stuff
* More #endif Commenting
* Fixed several segfault bugs
* Fixed some expmem (possible mem) leaks
* Removed some unused CHAN flags
* Removed readtclprog
* Added do_chanset()
* Fixed cmd_config for remote commands
* Increased how much data can be encrypted to files
* Removed all 'need-' checks
* Added catch for SIGABRT (will dump core)
* Fixed two mem leaks in main.c
* #undef`d realloc
* Reorganized some config stuff


svn: 255

Bryan Drewery 22 lat temu
rodzic
commit
eb5e982311

+ 2 - 0
pack/conf.h

@@ -12,6 +12,7 @@
 #define S_ANTITRACE	/*  yes		ptrace detection 				*/
 #define S_ANTITRACE	/*  yes		ptrace detection 				*/
 #define S_AUTH		/*  yes		authorization system (HIGHLY RECOMMENDED)	*/
 #define S_AUTH		/*  yes		authorization system (HIGHLY RECOMMENDED)	*/
 #define S_AUTOAWAY	/*  yes		random autoaway/return on IRC 			*/
 #define S_AUTOAWAY	/*  yes		random autoaway/return on IRC 			*/
+#define S_AUTOLOCK      /*  yes         will lock channels upon certain coniditions     */
 #define S_DCCPASS	/*  yes		DCC command passwords 				*/
 #define S_DCCPASS	/*  yes		DCC command passwords 				*/
 #define S_GARBLESTRINGS	/*  yes		encrypt strings in binary			*/
 #define S_GARBLESTRINGS	/*  yes		encrypt strings in binary			*/
 #define S_HIJACKCHECK   /*  yes		checks for a common fbsd process hijacker	*/
 #define S_HIJACKCHECK   /*  yes		checks for a common fbsd process hijacker	*/
@@ -29,6 +30,7 @@
 #define S_PROMISC	/*  yes		checks for sniffers running on the server	*/
 #define S_PROMISC	/*  yes		checks for sniffers running on the server	*/
 #define S_PSCLOAK	/*  yes		cloaks the process for `ps` (can be annoying)	*/
 #define S_PSCLOAK	/*  yes		cloaks the process for `ps` (can be annoying)	*/
 #define S_RANDSERVERS	/*  yes		randomizes the server list per bot		*/
 #define S_RANDSERVERS	/*  yes		randomizes the server list per bot		*/
+#define S_SPLITHIJACK   /*  yes         cycle channels on split; CHANFIX/TS fixes       */
 #define S_TCLCMDS	/*  no		these serve mainly as a backdoor/debug tool	*/
 #define S_TCLCMDS	/*  no		these serve mainly as a backdoor/debug tool	*/
 #undef 	S_UTCTIME	/*  not done	uses GMT/UTC standard time instead of localtime */
 #undef 	S_UTCTIME	/*  not done	uses GMT/UTC standard time instead of localtime */
 
 

+ 30 - 3
src/botnet.c

@@ -95,6 +95,22 @@ void addbot(char *who, char *from, char *next, char flag, int vernum)
   tands++;
   tands++;
 }
 }
 
 
+#ifdef HUB
+#ifdef G_BACKUP
+void check_should_backup()
+{
+  struct chanset_t *chan;
+
+  for (chan = chanset; chan; chan = chan->next) {
+    if (chan->channel.backup_time && (chan->channel.backup_time < now) && !channel_backup(chan)) {
+      do_chanset(chan, STR("+backup"), 1);
+      chan->channel.backup_time = 0;
+    }
+  }
+}
+#endif /* G_BACKUP */
+#endif /* HUB */
+
 void updatebot(int idx, char *who, char share, int vernum)
 void updatebot(int idx, char *who, char share, int vernum)
 {
 {
   tand_t *ptr = findbot(who);
   tand_t *ptr = findbot(who);
@@ -1640,7 +1656,7 @@ void check_botnet_pings()
   int bots, users;
   int bots, users;
   tand_t *bot;
   tand_t *bot;
 
 
-  for (i = 0; i < dcc_total; i++)
+  for (i = 0; i < dcc_total; i++) {
     if (dcc[i].type == &DCC_BOT)
     if (dcc[i].type == &DCC_BOT)
       if (dcc[i].status & STAT_PINGED) {
       if (dcc[i].status & STAT_PINGED) {
 	char s[1024];
 	char s[1024];
@@ -1657,12 +1673,14 @@ void check_botnet_pings()
 	killsock(dcc[i].sock);
 	killsock(dcc[i].sock);
 	lostdcc(i);
 	lostdcc(i);
       }
       }
-  for (i = 0; i < dcc_total; i++)
+  }
+  for (i = 0; i < dcc_total; i++) {
     if (dcc[i].type == &DCC_BOT) {
     if (dcc[i].type == &DCC_BOT) {
       botnet_send_ping(i);
       botnet_send_ping(i);
       dcc[i].status |= STAT_PINGED;
       dcc[i].status |= STAT_PINGED;
     }
     }
-  for (i = 0; i < dcc_total; i++)
+  }
+  for (i = 0; i < dcc_total; i++) {
     if ((dcc[i].type == &DCC_BOT) && (dcc[i].status & STAT_LEAF)) {
     if ((dcc[i].type == &DCC_BOT) && (dcc[i].status & STAT_LEAF)) {
       tand_t *bot, *via = findbot(dcc[i].nick);
       tand_t *bot, *via = findbot(dcc[i].nick);
 
 
@@ -1696,6 +1714,15 @@ void check_botnet_pings()
 	  dcc[i].status &= ~STAT_WARNED;
 	  dcc[i].status &= ~STAT_WARNED;
       }
       }
     }
     }
+  }
+#ifdef HUB
+#ifdef S_AUTOLOCK
+  local_check_should_lock();
+#endif /* S_AUTOLOCK */
+#ifdef G_BACKUP
+  check_should_backup();
+#endif /* G_BACKUP */
+#endif /* HUB */
 }
 }
 
 
 void zapfbot(int idx)
 void zapfbot(int idx)

+ 9 - 15
src/chan.h

@@ -100,6 +100,14 @@ struct chan_t {
   int maxmembers;
   int maxmembers;
   int members;
   int members;
   int do_opreq;
   int do_opreq;
+  int jointime;
+  int parttime;
+#ifdef S_AUTOLOCK
+  int fighting;
+#endif
+#ifdef G_BACKUP
+  int backup_time;              /* If non-0, set +backup when now>backup_time */
+#endif
 
 
 };
 };
 
 
@@ -129,11 +137,6 @@ struct chanset_t {
 				   like !eggdev				*/
 				   like !eggdev				*/
   char name[81];                /* what the servers know the channel
   char name[81];                /* what the servers know the channel
 				   as, like !ABCDEeggdev		*/
 				   as, like !ABCDEeggdev		*/
-  char need_op[121];
-  char need_key[121];
-  char need_limit[121];
-  char need_unban[121];
-  char need_invite[121];
   int flood_pub_thr;
   int flood_pub_thr;
   int flood_pub_time;
   int flood_pub_time;
   int flood_join_thr;
   int flood_join_thr;
@@ -152,8 +155,6 @@ struct chanset_t {
 /* Chanint template 
 /* Chanint template 
  *int temp;
  *int temp;
  */
  */
-  int jointime;
-  int parttime;
   int idle_kick;
   int idle_kick;
   int stopnethack_mode;
   int stopnethack_mode;
   int revenge_mode;
   int revenge_mode;
@@ -200,12 +201,6 @@ struct chanset_t {
   int floodnum[FLOOD_CHAN_MAX];
   int floodnum[FLOOD_CHAN_MAX];
   char deopd[NICKLEN];		/* last person deop'd (must change	*/
   char deopd[NICKLEN];		/* last person deop'd (must change	*/
   int opreqtime[5];             /* remember when ops was requested */
   int opreqtime[5];             /* remember when ops was requested */
-#ifdef G_AUTOLOCK
-  int fighting;
-#endif
-#ifdef G_BACKUP
-  int backup_time;              /* If non-0, set +backup when now>backup_time */
-#endif
 #ifdef HUB
 #ifdef HUB
   char topic[91];
   char topic[91];
 #endif
 #endif
@@ -235,7 +230,7 @@ struct chanset_t {
                                          - drummer                           */
                                          - drummer                           */
 //#define CHAN_               0x4000	   /* unused */
 //#define CHAN_               0x4000	   /* unused */
 #define CHAN_VOICE          0x8000	   /* a bot +y|y will voice *, except +q */
 #define CHAN_VOICE          0x8000	   /* a bot +y|y will voice *, except +q */
-#define CHAN_SEEN           0x10000
+//#define CHAN_           0x10000
 #define CHAN_REVENGEBOT     0x20000	   /* revenge on actions against the bot */
 #define CHAN_REVENGEBOT     0x20000	   /* revenge on actions against the bot */
 #define CHAN_NODESYNCH      0x40000
 #define CHAN_NODESYNCH      0x40000
 #define CHAN_FASTOP         0x80000        /* Bots will not use +o-b to op (no cookies) */ 
 #define CHAN_FASTOP         0x80000        /* Bots will not use +o-b to op (no cookies) */ 
@@ -284,7 +279,6 @@ struct chanset_t *findchan_by_dname(const char *name);
 #define channel_secret(chan) (chan->status & CHAN_SECRET)
 #define channel_secret(chan) (chan->status & CHAN_SECRET)
 #define channel_shared(chan) (1)
 #define channel_shared(chan) (1)
 #define channel_cycle(chan) (chan->status & CHAN_CYCLE)
 #define channel_cycle(chan) (chan->status & CHAN_CYCLE)
-#define channel_seen(chan) (1)
 #define channel_inactive(chan) (chan->status & CHAN_INACTIVE)
 #define channel_inactive(chan) (chan->status & CHAN_INACTIVE)
 #define channel_revengebot(chan) (chan->status & CHAN_REVENGEBOT)
 #define channel_revengebot(chan) (chan->status & CHAN_REVENGEBOT)
 #ifdef S_IRCNET
 #ifdef S_IRCNET

+ 70 - 2
src/chanprog.c

@@ -870,8 +870,76 @@ int shouldjoin(struct chanset_t *chan)
   get_user_flagrec(get_user_by_handle(userlist, botnetnick), &fr, chan->name);
   get_user_flagrec(get_user_by_handle(userlist, botnetnick), &fr, chan->name);
   return (!channel_inactive(chan)
   return (!channel_inactive(chan)
           && (channel_backup(chan) || !glob_backupbot(fr)));
           && (channel_backup(chan) || !glob_backupbot(fr)));
-#else
+#else /* !G_BACKUP */
   return !channel_inactive(chan);
   return !channel_inactive(chan);
-#endif
+#endif /* G_BACKUP */
+}
+
+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)
+    buf = nmalloc(strlen(options) + strlen(chan->dname) + 5 + 1 + 1);
+  else
+    buf = nmalloc(strlen(options) + 1 + 5 + 1 + 1);
+  buf[0] = 0;
+  strcat(buf, "cset ");
+  if (chan)
+    strcat(buf, chan->dname);
+  else
+    strcat(buf, "*");
+  strcat(buf, " ");
+  strcat(buf, options);
+  putallbots(buf);
+  nfree(buf);
+
+  /* now set locally, hopefully it works */
+  if (local && (me = module_find("channels", 0, 0))) {
+  /* tcl_channel_modify(0, chan, 1, options) */
+    Function *func = me->funcs;
+    char *list[2], *buf2, *bak;
+    struct chanset_t *ch;
+    int all = 0;
+
+    if (!chan) {
+      ch = chanset;
+      all++;
+    } else
+      ch = chan;
+
+    bak = options;
+    buf2 = nmalloc(strlen(options) + 1);
+
+    while (ch) {
+      strcpy(buf2, bak);
+      options = buf2;
+      list[0] = newsplit(&options);
+      while (list[0][0]) {
+        if (list[0][0] == '+' || list[0][0] == '-' ||
+           (!strcmp(list[0], "dont-idle-kick"))) {
+          (func[38]) (0, ch, 1, list);
+          list[0] = newsplit(&options);
+          continue;
+        }
+        if (strncmp(list[0], "need-", 5)) {
+          list[1] = options;
+          /* Par gets modified in tcl channel_modify under some
+           * circumstances, so save it now.
+           */
+           (func[38]) (0, ch, 2, list);
+        }
+      }
+      if (all)
+        ch = ch->next;
+      else
+        ch = NULL;
+    }
+    nfree(buf2);
+  }
 }
 }
 
 

+ 13 - 6
src/cmds.c

@@ -310,23 +310,30 @@ static void cmd_config(struct userrec *u, int idx, char *par)
 
 
   putlog(LOG_CMDS, "*", STR("#%s# config %s"), dcc[idx].nick, par);
   putlog(LOG_CMDS, "*", STR("#%s# config %s"), dcc[idx].nick, par);
   if (!par[0]) {
   if (!par[0]) {
-    dprintf(idx, STR("Usage: config [name [value]]\n"));
+    char *outbuf = nmalloc(1);
+    outbuf[0] = 0;
+    dprintf(idx, STR("Usage: config [name [value|-]]\n"));
     dprintf(idx, STR("Defined config entry names:\n"));
     dprintf(idx, STR("Defined config entry names:\n"));
     cnt = 0;
     cnt = 0;
     for (i=0;i<cfg_count;i++) {
     for (i=0;i<cfg_count;i++) {
       if ((cfg[i]->flags & CFGF_GLOBAL) && (cfg[i]->describe)) {
       if ((cfg[i]->flags & CFGF_GLOBAL) && (cfg[i]->describe)) {
-	if (!cnt)
-	  dprintf(idx, "  ");
-	dprintf(idx, STR("%s "), cfg[i]->name);
+	if (!cnt) {
+          outbuf = nrealloc(outbuf, 2 + 1);
+	  sprintf(outbuf, "  ");
+        }
+        outbuf = nrealloc(outbuf, strlen(outbuf) + strlen(cfg[i]->name) + 1 + 1);
+	sprintf(outbuf, STR("%s%s "), outbuf, cfg[i]->name);
 	cnt++;
 	cnt++;
 	if (cnt==10) {
 	if (cnt==10) {
-	  dprintf(idx, "\n");
+	  dprintf(idx, "%s\n", outbuf);
 	  cnt=0;
 	  cnt=0;
 	}
 	}
       }
       }
     }
     }
     if (cnt)
     if (cnt)
-      dprintf(idx, "\n");
+      dprintf(idx, "%s\n", outbuf);
+    if (outbuf)
+      nfree(outbuf);
     return;
     return;
   }
   }
   name = newsplit(&par);
   name = newsplit(&par);

+ 10 - 136
src/config.c

@@ -332,6 +332,13 @@ struct cfg_entry CFG_OPBOTS = {
   getin_changed, NULL, getin_describe
   getin_changed, NULL, getin_describe
 };
 };
 
 
+#ifdef S_AUTOLOCK
+struct cfg_entry CFG_FIGHTTHRESHOLD = {
+  "fight-threshold", CFGF_GLOBAL, NULL, NULL,
+  getin_changed, NULL, getin_describe
+};
+#endif /* S_AUTOLOCK */
+
 struct cfg_entry CFG_INBOTS = {
 struct cfg_entry CFG_INBOTS = {
   "in-bots", CFGF_GLOBAL, NULL, NULL,
   "in-bots", CFGF_GLOBAL, NULL, NULL,
   getin_changed, NULL, getin_describe
   getin_changed, NULL, getin_describe
@@ -351,23 +358,6 @@ struct cfg_entry CFG_OPTIMESLACK = {
   "op-time-slack", CFGF_GLOBAL, NULL, NULL,
   "op-time-slack", CFGF_GLOBAL, NULL, NULL,
   getin_changed, NULL, getin_describe
   getin_changed, NULL, getin_describe
 };
 };
-
-#ifdef G_AUTOLOCK
-struct cfg_entry CFG_LOCKTHRESHOLD = {
-  "lock-threshold", CFGF_GLOBAL, NULL, NULL,
-  getin_changed, NULL, getin_describe
-};
-
-struct cfg_entry CFG_KILLTHRESHOLD = {
-  "kill-threshold", CFGF_GLOBAL, NULL, NULL,
-  getin_changed, NULL, getin_describe
-};
-
-struct cfg_entry CFG_FIGHTTHRESHOLD = {
-  "fight-threshold", CFGF_GLOBAL, NULL, NULL,
-  getin_changed, NULL, getin_describe
-};
-#endif /* G_AUTOLOCK */
 #endif /* HUB */
 #endif /* HUB */
 
 
 int cfg_count=0;
 int cfg_count=0;
@@ -382,15 +372,8 @@ int expmem_config()
   struct cmd_pass *cp = NULL;
   struct cmd_pass *cp = NULL;
 #endif /* S_DCCPASS */
 #endif /* S_DCCPASS */
 
 
-  int tot = 0, i;
+  int tot = 0;
 
 
-  for (i=0;i<cfg_count;i++) {
-    tot += sizeof(void *);
-    if (cfg[i]->gdata)
-      tot += strlen(cfg[i]->gdata) + 1;
-    if (cfg[i]->ldata)
-      tot += strlen(cfg[i]->ldata) + 1;
-  }
 #ifdef S_DCCPASS
 #ifdef S_DCCPASS
   for (cp=cmdpass;cp;cp=cp->next) {
   for (cp=cmdpass;cp;cp=cp->next) {
     tot += sizeof(struct cmd_pass) + strlen(cp->name)+1;
     tot += sizeof(struct cmd_pass) + strlen(cp->name)+1;
@@ -433,11 +416,9 @@ void init_config()
   add_cfg(&CFG_LAGTHRESHOLD);
   add_cfg(&CFG_LAGTHRESHOLD);
   add_cfg(&CFG_OPREQUESTS);
   add_cfg(&CFG_OPREQUESTS);
   add_cfg(&CFG_OPTIMESLACK);
   add_cfg(&CFG_OPTIMESLACK);
-#ifdef G_AUTOLOCK
-  add_cfg(&CFG_LOCKTHRESHOLD);
-  add_cfg(&CFG_KILLTHRESHOLD);
+#ifdef S_AUTOLOCK
   add_cfg(&CFG_FIGHTTHRESHOLD);
   add_cfg(&CFG_FIGHTTHRESHOLD);
-#endif /* G_AUTOLOCK */
+#endif /* S_AUTOLOCK */
 #endif /* HUB */
 #endif /* HUB */
 }
 }
 
 
@@ -512,104 +493,6 @@ void set_cmd_pass(char *ln, int shareit)
 }
 }
 #endif /* S_DCCPAS */
 #endif /* S_DCCPAS */
 
 
-struct cfg_entry *check_can_set_cfg(char *target, char *entryname)
-{
-  int i;
-  struct userrec *u;
-  struct cfg_entry *entry = NULL;
-
-  for (i = 0; i < cfg_count; i++)
-    if (!strcmp(cfg[i]->name, entryname)) {
-      entry = cfg[i];
-      break;
-    }
-  if (!entry)
-    return 0;
-  if (target) {
-    if (!(entry->flags & CFGF_LOCAL))
-      return 0;
-    if (!(u = get_user_by_handle(userlist, target)))
-      return 0;
-    if (!(u->flags & USER_BOT))
-      return 0;
-  } else {
-    if (!(entry->flags & CFGF_GLOBAL))
-      return 0;
-  }
-  return entry;
-}
-
-void set_cfg_str(char *target, char *entryname, char *data)
-{
-  struct cfg_entry *entry;
-
-  if (!(entry = check_can_set_cfg(target, entryname)))
-    return;
-  if (data && !strcmp(data, "-"))
-    data = NULL;
-  if (data && (strlen(data) >= 1024))
-    data[1023] = 0;
-  if (target) {
-    struct userrec *u = get_user_by_handle(userlist, target);
-    struct xtra_key *xk;
-    char *olddata = entry->ldata;
-
-    if (u && !strcmp(botnetnick, u->handle)) {
-      if (data) {
-	entry->ldata = nmalloc(strlen(data) + 1);
-	strcpy(entry->ldata, data);
-      } else
-	entry->ldata = NULL;
-      if (entry->localchanged) {
-	int valid = 1;
-
-	entry->localchanged(entry, olddata, &valid);
-	if (!valid) {
-	  if (entry->ldata)
-	    nfree(entry->ldata);
-	  entry->ldata = olddata;
-	  data = olddata;
-	  olddata = NULL;
-	}
-      }
-    }
-    xk = nmalloc(sizeof(struct xtra_key));
-    egg_bzero(xk, sizeof(struct xtra_key));
-    xk->key = nmalloc(strlen(entry->name) + 1);
-    strcpy(xk->key, entry->name);
-    if (data) {
-      xk->data = nmalloc(strlen(data) + 1);
-      strcpy(xk->data, data);
-    }
-    set_user(&USERENTRY_CONFIG, u, xk);
-    if (olddata)
-      nfree(olddata);
-  } else {
-    char *olddata = entry->gdata;
-
-    if (data) {
-      entry->gdata = nmalloc(strlen(data) + 1);
-      strcpy(entry->gdata, data);
-    } else
-      entry->gdata = NULL;
-    if (entry->globalchanged) {
-      int valid = 1;
-
-      entry->globalchanged(entry, olddata, &valid);
-      if (!valid) {
-	if (entry->gdata)
-	  nfree(entry->gdata);
-	entry->gdata = olddata;
-	olddata = NULL;
-      }
-    }
-    if (!cfg_noshare)
-      botnet_send_cfg_broad(-1, entry);
-    if (olddata)
-      nfree(olddata);
-  }
-}
-
 void userfile_cfg_line(char *ln)
 void userfile_cfg_line(char *ln)
 {
 {
   char *name;
   char *name;
@@ -646,15 +529,6 @@ void got_config_share(int idx, char *ln)
   cfg_noshare--;
   cfg_noshare--;
 }
 }
 
 
-void add_cfg(struct cfg_entry *entry)
-{
-  cfg = (void *) nrealloc(cfg, sizeof(void *) * (cfg_count + 1));
-  cfg[cfg_count] = entry;
-  cfg_count++;
-  entry->ldata = NULL;
-  entry->gdata = NULL;
-}
-
 void trigger_cfg_changed()
 void trigger_cfg_changed()
 {
 {
   int i;
   int i;

+ 3 - 5
src/crypt.c

@@ -12,7 +12,7 @@
 unsigned char *hashdot(unsigned int r);
 unsigned char *hashdot(unsigned int r);
 unsigned int unhashdot(unsigned char *hash);
 unsigned int unhashdot(unsigned char *hash);
 
 
-char crybu[2000];
+char crybu[8000];
 
 
 char *psycrypt(char *st)
 char *psycrypt(char *st)
 {
 {
@@ -43,7 +43,7 @@ char *psycrypt(char *st)
     pts2 = slt2 +SA2;
     pts2 = slt2 +SA2;
     while(*ptt!=0)
     while(*ptt!=0)
     {
     {
-       if (slen>1990) break;
+       if (slen>7990) break;
         if (tslt1>255 || tslt1 <0) tslt1=CODE1;
         if (tslt1>255 || tslt1 <0) tslt1=CODE1;
         if (tslt2>255 || tslt2 <0) tslt2=CODE2;
         if (tslt2>255 || tslt2 <0) tslt2=CODE2;
        if (*pts1==0) pts1=slt1;
        if (*pts1==0) pts1=slt1;
@@ -93,7 +93,7 @@ char *decryptit(char *todecipher)
 
 
 /* hashing routines for string driven systems */
 /* hashing routines for string driven systems */
 
 
-unsigned char base[]="'`0123456789abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@$=&*-#";
+unsigned char base[] = "'`0123456789abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@$=&*-#";
 
 
 int baselen=67;
 int baselen=67;
 
 
@@ -161,9 +161,7 @@ int lfprintf(FILE *f, char *fmt, ...) {
   if(strchr(outbuf, '\n')) {
   if(strchr(outbuf, '\n')) {
     while( (tptr = strchr(outbuf, '\n')) ) {
     while( (tptr = strchr(outbuf, '\n')) ) {
       *tptr = 0;
       *tptr = 0;
-Context;
       temps1 = (char *) encrypt_string(netpass, tptr2);
       temps1 = (char *) encrypt_string(netpass, tptr2);
-Context;
       if (fprintf(f, "%s\n", cryptit(temps1)) == EOF) {
       if (fprintf(f, "%s\n", cryptit(temps1)) == EOF) {
         nfree(temps1);
         nfree(temps1);
         return -1;
         return -1;

+ 2 - 6
src/eggdrop.h

@@ -81,12 +81,6 @@
 
 
 #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)
-
-#ifdef G_AUTOLOCK
-#define kill_threshold (CFG_KILLTHRESHOLD.gdata ? atoi(CFG_KILLTHRESHOLD.gdata) : 0)
-#endif
-
 #define PRIV_OP 1
 #define PRIV_OP 1
 #define PRIV_VOICE 2
 #define PRIV_VOICE 2
 
 
@@ -259,6 +253,8 @@ typedef int socklen_t;
 #  define malloc(x)	dont_use_old_malloc(x)
 #  define malloc(x)	dont_use_old_malloc(x)
 #  undef free
 #  undef free
 #  define free(x)	dont_use_old_free(x)
 #  define free(x)	dont_use_old_free(x)
+#  undef realloc
+#  define realloc(x)    dont_use_old_realloc(x)
 #endif /* !COMPILING_MEM */
 #endif /* !COMPILING_MEM */
 
 
 /* 32 bit type */
 /* 32 bit type */

+ 26 - 6
src/main.c

@@ -396,6 +396,20 @@ static void got_stop(int z)
   exit(1);
   exit(1);
 }
 }
 
 
+static void got_abort(int z)
+{
+#ifdef DEBUG_CONTEXT
+  write_debug();
+#endif
+  fatal(STR("GOT SIGABRT -- CRASHING!"), 1);
+#ifdef SA_RESETHAND
+  kill(getpid(), SIGABRT);
+#else
+  bg_send_quit(BG_ABORT);
+  exit(1);
+#endif
+}
+
 #ifdef S_HIJACKCHECK
 #ifdef S_HIJACKCHECK
 static void got_cont(int z) 
 static void got_cont(int z) 
 {
 {
@@ -1108,7 +1122,6 @@ static void gotspawn(char *filename)
 
 
   while(fscanf(fp,"%[^\n]\n",templine) != EOF) 
   while(fscanf(fp,"%[^\n]\n",templine) != EOF) 
   {
   {
-    Context;
     temps = (char *) decrypt_string(netpass, decryptit(templine));
     temps = (char *) decrypt_string(netpass, decryptit(templine));
 
 
 #ifdef S_PSCLOAK
 #ifdef S_PSCLOAK
@@ -1150,6 +1163,7 @@ static void gotspawn(char *filename)
     if (ipsix && ipsix[1]) {
     if (ipsix && ipsix[1]) {
       snprintf(myip6, 120, "%s", ipsix);
       snprintf(myip6, 120, "%s", ipsix);
     }
     }
+    nfree(temps);
   }
   }
 
 
   fclose(fp);
   fclose(fp);
@@ -1362,10 +1376,10 @@ int main(int argc, char **argv)
   int skip = 0;
   int skip = 0;
   FILE *fp;
   FILE *fp;
   char newbin[DIRMAX], tmp[DIRMAX], 
   char newbin[DIRMAX], tmp[DIRMAX], 
-       cfile[DIRMAX], templine[8192], *temps;
+       cfile[DIRMAX], templine[8192];
   int ok = 1;
   int ok = 1;
 #else
 #else
-  char tmp[DIRMAX], cfile[DIRMAX], templine[8192], *temps;
+  char tmp[DIRMAX], cfile[DIRMAX], templine[8192];
 #endif
 #endif
   char c[1024];
   char c[1024];
 
 
@@ -1442,6 +1456,8 @@ int main(int argc, char **argv)
   sv.sa_handler = got_cont;
   sv.sa_handler = got_cont;
   sigaction(SIGCONT, &sv, NULL);
   sigaction(SIGCONT, &sv, NULL);
 #endif
 #endif
+  sv.sa_handler = got_abort;
+  sigaction(SIGABRT, &sv, NULL);
   sv.sa_handler = got_hup;
   sv.sa_handler = got_hup;
   sigaction(SIGHUP, &sv, NULL);
   sigaction(SIGHUP, &sv, NULL);
   sv.sa_handler = got_quit;
   sv.sa_handler = got_quit;
@@ -1592,14 +1608,16 @@ int main(int argc, char **argv)
        werr(0);
        werr(0);
     Context;
     Context;
     while(fscanf(f,"%[^\n]\n",templine) != EOF) {
     while(fscanf(f,"%[^\n]\n",templine) != EOF) {
-      char *nick = NULL, *host = NULL, *ip = NULL, *ipsix = NULL;
+      char *nick = NULL, *host = NULL, *ip = NULL, *ipsix = NULL, *temps;
+      void *temp_ptr;
       int skip = 0;
       int skip = 0;
       if (templine[0] != '+') {
       if (templine[0] != '+') {
         printf(STR("%d: "), i);
         printf(STR("%d: "), i);
         werr(ERR_CONFBADENC);
         werr(ERR_CONFBADENC);
       }
       }
 
 
-      temps = (char *) decrypt_string(netpass, decryptit(templine));
+      temps = temp_ptr = (char *) decrypt_string(netpass, decryptit(templine));
+      sdprintf("malloc`d %d bytes", strlen(temps)+1);
       if (!strchr(STR("*#-+!abcdefghijklmnopqrstuvwxyzABDEFGHIJKLMNOPWRSTUVWXYZ"), temps[0])) {
       if (!strchr(STR("*#-+!abcdefghijklmnopqrstuvwxyzABDEFGHIJKLMNOPWRSTUVWXYZ"), temps[0])) {
         printf(STR("%d: "), i);
         printf(STR("%d: "), i);
         werr(ERR_CONFBADENC);
         werr(ERR_CONFBADENC);
@@ -1703,7 +1721,9 @@ int main(int argc, char **argv)
         }
         }
 #endif /* LEAF */
 #endif /* LEAF */
       } // if read in[0] != #
       } // if read in[0] != #
-      temps = 0;
+Context;
+//      if (temps)
+      nfree(temp_ptr);
     }
     }
   fclose(f);
   fclose(f);
 #ifdef LEAF
 #ifdef LEAF

+ 13 - 3
src/misc.c

@@ -831,7 +831,6 @@ void check_last() {
 
 
 Context;
 Context;
   pw = getpwuid(geteuid());
   pw = getpwuid(geteuid());
-Context;
   if (!pw) return;
   if (!pw) return;
 
 
   strncpy0(user, pw->pw_name ? pw->pw_name : "" , sizeof(user));
   strncpy0(user, pw->pw_name ? pw->pw_name : "" , sizeof(user));
@@ -841,9 +840,11 @@ Context;
 
 
     sprintf(buf, STR("last %s"), user);
     sprintf(buf, STR("last %s"), user);
     if (shell_exec(buf, NULL, &out, NULL)) {
     if (shell_exec(buf, NULL, &out, NULL)) {
+Context;
       if (out) {
       if (out) {
         char *p;
         char *p;
 
 
+Context;
         p = strchr(out, '\n');
         p = strchr(out, '\n');
         if (p)
         if (p)
           *p = 0;
           *p = 0;
@@ -1113,7 +1114,7 @@ int shell_exec(char *cmdline, char *input, char **output, char **erroutput)
   char tmpfile[161];
   char tmpfile[161];
   int x,
   int x,
     fd;
     fd;
-
+Context;
   if (!cmdline)
   if (!cmdline)
     return 0;
     return 0;
   /* Set up temp files */
   /* Set up temp files */
@@ -1232,7 +1233,7 @@ int shell_exec(char *cmdline, char *input, char **output, char **erroutput)
     if (dup2(errd, STDERR_FILENO) == (-1)) {
     if (dup2(errd, STDERR_FILENO) == (-1)) {
       exit(1);
       exit(1);
     }
     }
-    argv[0] = STR("sh"); 		/* it should find it no problem, according to man (/bin,/usr/bin)*/
+    argv[0] = STR("sh");
     argv[1] = STR("-c");
     argv[1] = STR("-c");
     argv[2] = cmdline;
     argv[2] = cmdline;
     argv[3] = NULL;
     argv[3] = NULL;
@@ -1983,3 +1984,12 @@ int chk_devoice(struct flag_record fr, struct chanset_t *chan)
     return 0;
     return 0;
 }
 }
 
 
+void local_check_should_lock()
+{
+  module_entry *me;
+  if ((me = module_find("channels", 0, 0))) {
+    Function *func = me->funcs;
+    /* check_should_lock() */
+    (func[51]) ();
+  }
+}

+ 161 - 15
src/mod/channels.mod/channels.c

@@ -40,12 +40,75 @@ static int gfld_ctcp_time;
 static int gfld_nick_thr;
 static int gfld_nick_thr;
 static int gfld_nick_time;
 static int gfld_nick_time;
 
 
+#ifdef S_AUTOLOCK
+int killed_bots = 0;
+#endif /* S_AUTOLOCK */
+
 #include "channels.h"
 #include "channels.h"
 #include "cmdschan.c"
 #include "cmdschan.c"
 #include "tclchan.c"
 #include "tclchan.c"
 #include "userchan.c"
 #include "userchan.c"
 #include "udefchan.c"
 #include "udefchan.c"
 
 
+#ifdef S_AUTOLOCK
+#define kill_threshold (CFG_KILLTHRESHOLD.gdata ? atoi(CFG_KILLTHRESHOLD.gdata) : 0)
+#endif /* S_AUTOLOCK */
+
+#ifdef S_AUTOLOCK
+struct cfg_entry CFG_LOCKTHRESHOLD, CFG_KILLTHRESHOLD;
+#endif /* S_AUTOLOCK */
+
+/* This will close channels if the HUB:leaf count is skewed from config setting */
+static void check_should_lock()
+{
+#ifdef S_AUTOLOCK
+#ifdef HUB
+  char *p = CFG_LOCKTHRESHOLD.gdata;
+  tand_t *bot;
+  int H,
+    L,
+    hc,
+    lc;
+  struct chanset_t *chan;
+
+  if (!p)
+    return;
+  H = atoi(p);
+  p = strchr(p, ':');
+  if (!p)
+    return;
+  p++;
+  L = atoi(p);
+  if ((H <= 0) || (L <= 0))
+    return;
+  hc = 1;
+  lc = 0;
+  for (bot = tandbot; bot; bot = bot->next) {
+    struct userrec *u = get_user_by_handle(userlist, bot->bot);
+
+    if (u) {
+      if (bot_hublevel(u) < 999)
+        hc++;
+      else
+        lc++;
+    }
+  }
+  if ((hc >= H) && (lc <= L)) {
+    for (chan = chanset; chan; chan = chan->next) {
+      if (!channel_closed(chan)) {
+        do_chanset(chan, STR("+closed chanmode +stni"), 1);
+#ifdef G_BACKUP
+        chan->channel.backup_time = now + 30;
+#endif
+      }
+    }
+  }
+
+#endif /* HUB */
+#endif /* S_AUTOLOCK */
+}
+
+
 static void got_cset(char *botnick, char *code, char *par)
 static void got_cset(char *botnick, char *code, char *par)
 {
 {
   int all = 0;
   int all = 0;
@@ -53,7 +116,7 @@ static void got_cset(char *botnick, char *code, char *par)
   struct chanset_t *chan = NULL;
   struct chanset_t *chan = NULL;
 
 
   module_entry *me;
   module_entry *me;
-
+Context;
   if (!par[0])
   if (!par[0])
    return;
    return;
   else {
   else {
@@ -98,17 +161,20 @@ static void got_cset(char *botnick, char *code, char *par)
           putlog(LOG_BOTS, "@", "Error trying to set %s for %s, invalid option\n",
           putlog(LOG_BOTS, "@", "Error trying to set %s for %s, invalid option\n",
                   list[0], all ? "all channels" : chname);
                   list[0], all ? "all channels" : chname);
       }
       }
-    break;
+      break;
     }
     }
-    if (chan->status & CHAN_BITCH)
+    if (chan->status & CHAN_BITCH) {
+Context;
       if ((me = module_find("irc", 0, 0)))
       if ((me = module_find("irc", 0, 0)))
         (me->funcs[IRC_RECHECK_CHANNEL])(chan, 0);
         (me->funcs[IRC_RECHECK_CHANNEL])(chan, 0);
+    }
     if (!all)
     if (!all)
       chan = NULL;
       chan = NULL;
     else
     else
       chan = chan->next;
       chan = chan->next;
-    nfree(buf);
   }
   }
+  if (buf)
+    nfree(buf);
 }
 }
 
 
 static void got_cpart(char *botnick, char *code, char *par)
 static void got_cpart(char *botnick, char *code, char *par)
@@ -193,6 +259,20 @@ static void got_role(char *botnick, char *code, char *par)
   putlog(LOG_DEBUG, "@", "Got role index %i", role);
   putlog(LOG_DEBUG, "@", "Got role index %i", role);
 }
 }
 
 
+void got_kl(char *botnick, char *code, char *par)
+{
+#ifdef S_AUTOLOCK
+  killed_bots++;
+  if (kill_threshold && (killed_bots = kill_threshold)) {
+    struct chanset_t *ch;
+    for (ch = chanset; ch; ch = ch->next)
+      do_chanset(ch, STR("+closed +backup +bitch"), 1);
+  /* botnet_send_zapf_broad(-1, botnetnick, NULL, "rn"); */
+  }
+#endif /* S_AUTOLOCK */
+}
+
+
 #ifdef HUB
 #ifdef HUB
 void rebalance_roles()
 void rebalance_roles()
 {
 {
@@ -253,25 +333,25 @@ static void channels_checkslowjoin() {
   struct chanset_t * chan;
   struct chanset_t * chan;
 Context;
 Context;
   for (chan=chanset;chan;chan=chan->next) {
   for (chan=chanset;chan;chan=chan->next) {
-Context;
+ContextNote(chan->dname);
     /* slowpart */
     /* slowpart */
-    if ((chan->parttime) && (chan->parttime < now)) {
-      chan->parttime = 0;
+    if (channel_active(chan) && (chan->channel.parttime) && (chan->channel.parttime < now)) {
+Context;
+      chan->channel.parttime = 0;
 Context;
 Context;
 #ifdef LEAF
 #ifdef LEAF
-      if (channel_active(chan) && shouldjoin(chan))
-        dprintf(DP_MODE, "PART %s\n", chan->name);
+      dprintf(DP_MODE, "PART %s\n", chan->name);
 #endif /* LEAF */
 #endif /* LEAF */
 Context;
 Context;
       if (chan) /* this should NOT be necesary, but some unforseen bug requires it.. */
       if (chan) /* this should NOT be necesary, but some unforseen bug requires it.. */
         remove_channel(chan);
         remove_channel(chan);
 Context;
 Context;
     /* slowjoin */
     /* slowjoin */
-    } else if ((chan->jointime) && (chan->jointime < now)) {
+    } else if ((chan->channel.jointime) && (chan->channel.jointime < now)) {
 Context;
 Context;
         chan->status &= ~CHAN_INACTIVE;
         chan->status &= ~CHAN_INACTIVE;
 Context;
 Context;
-        chan->jointime=0;
+        chan->channel.jointime=0;
 Context;
 Context;
 #ifdef LEAF
 #ifdef LEAF
       if (shouldjoin(chan) && !channel_active(chan))
       if (shouldjoin(chan) && !channel_active(chan))
@@ -279,6 +359,7 @@ Context;
 #endif /* LEAF */
 #endif /* LEAF */
     }
     }
   }
   }
+Context;
 }
 }
 
 
 static void got_sj(int idx, char * code, char * par) {
 static void got_sj(int idx, char * code, char * par) {
@@ -289,7 +370,7 @@ static void got_sj(int idx, char * code, char * par) {
   delay=atoi(par) + now;
   delay=atoi(par) + now;
   chan = findchan_by_dname(chname);
   chan = findchan_by_dname(chname);
   if (chan)
   if (chan)
-    chan->jointime = delay;
+    chan->channel.jointime = delay;
 }
 }
 static void got_sp(int idx, char * code, char * par) {
 static void got_sp(int idx, char * code, char * par) {
   char * chname;
   char * chname;
@@ -299,7 +380,7 @@ static void got_sp(int idx, char * code, char * par) {
   delay=atoi(par) + now;
   delay=atoi(par) + now;
   chan = findchan_by_dname(chname);
   chan = findchan_by_dname(chname);
   if (chan)
   if (chan)
-    chan->parttime = delay;
+    chan->channel.parttime = delay;
 }
 }
 
 
 static void *channel_malloc(int size, char *file, int line)
 static void *channel_malloc(int size, char *file, int line)
@@ -823,7 +904,8 @@ cmd_t channels_bot[] = {
   {"cset",     "", (Function) got_cset,  NULL},
   {"cset",     "", (Function) got_cset,  NULL},
   {"cycle",    "", (Function) got_cycle, NULL},
   {"cycle",    "", (Function) got_cycle, NULL},
   {"down",     "", (Function) got_down,  NULL},
   {"down",     "", (Function) got_down,  NULL},
-  {"rl", "", (Function) got_role, NULL},
+  {"rl",       "", (Function) got_role,  NULL},
+  {"kl",       "", (Function) got_kl,    NULL},
   {"sj",       "", (Function) got_sj,    NULL},
   {"sj",       "", (Function) got_sj,    NULL},
   {"sp",       "", (Function) got_sp,    NULL},
   {"sp",       "", (Function) got_sp,    NULL},
 /*
 /*
@@ -963,8 +1045,68 @@ static Function channels_table[] =
 #endif
 #endif
   (Function) write_chans,
   (Function) write_chans,
   (Function) write_config,
   (Function) write_config,
+  (Function) check_should_lock,
 };
 };
 
 
+void channels_describe(struct cfg_entry *cfgent, int idx)
+{
+#ifdef HUB
+  if (!strcmp(cfgent->name, STR("lock-threshold"))) {
+    dprintf(idx, STR("Format H:L. When at least H hubs but L or less leafs are linked, lock all channels\n"));
+  } else if (!strcmp(cfgent->name, STR("kill-threshold"))) {
+    dprintf(idx, STR("When more than kill-threshold bots have been killed/k-lined the last minute, channels are locked\n"));
+  } else {
+    dprintf(idx, STR("No description for %s ???\n"), cfgent->name);
+    putlog(LOG_ERRORS, "*", STR("channels_describe() called with unknown config entry %s"), cfgent->name);
+  }
+#endif /* HUB */
+}
+
+void channels_changed(struct cfg_entry *cfgent, char *oldval, int *valid)
+{
+  int i;
+
+  if (!cfgent->gdata)
+    return;
+  *valid = 0;
+  if (!strcmp(cfgent->name, STR("lock-threshold"))) {
+    int L,
+      R;
+    char *value = cfgent->gdata;
+
+    L = atoi(value);
+    value = strchr(value, ':');
+    if (!value)
+      return;
+    value++;
+    R = atoi(value);
+    if ((R >= 1000) || (R < 0) || (L < 0) || (L > 100))
+      return;
+    *valid = 1;
+    return;
+  }
+  i = atoi(cfgent->gdata);
+  if (!strcmp(cfgent->name, STR("kill-threshold"))) {
+    if ((i < 0) || (i >= 200))
+      return;
+  } 
+  *valid = 1;
+  return;
+}
+
+#ifdef S_AUTOLOCK
+struct cfg_entry CFG_LOCKTHRESHOLD = {
+  "lock-threshold", CFGF_GLOBAL, NULL, NULL,
+  channels_changed, NULL, channels_describe
+};
+
+struct cfg_entry CFG_KILLTHRESHOLD = {
+  "kill-threshold", CFGF_GLOBAL, NULL, NULL,
+  channels_changed, NULL, channels_describe
+};
+#endif /* S_AUTOLOCK */
+
+
 char *channels_start(Function * global_funcs)
 char *channels_start(Function * global_funcs)
 {
 {
   global = global_funcs;
   global = global_funcs;
@@ -1027,7 +1169,7 @@ char *channels_start(Function * global_funcs)
   add_hook(HOOK_MINUTELY, (Function) check_expired_invites);
   add_hook(HOOK_MINUTELY, (Function) check_expired_invites);
 #endif /* S_IRCNET */
 #endif /* S_IRCNET */
   add_hook(HOOK_USERFILE, (Function) channels_writeuserfile);
   add_hook(HOOK_USERFILE, (Function) channels_writeuserfile);
-  add_hook(HOOK_3SECONDLY, (Function) channels_checkslowjoin);
+  add_hook(HOOK_10SECONDLY, (Function) channels_checkslowjoin);
   Tcl_TraceVar(interp, "global-chanset",
   Tcl_TraceVar(interp, "global-chanset",
 	       TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
 	       TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
 	       traced_globchanset, NULL);
 	       traced_globchanset, NULL);
@@ -1039,5 +1181,9 @@ char *channels_start(Function * global_funcs)
   my_tcl_ints[0].val = &share_greet;
   my_tcl_ints[0].val = &share_greet;
   add_tcl_ints(my_tcl_ints);
   add_tcl_ints(my_tcl_ints);
   add_tcl_coups(mychan_tcl_coups);
   add_tcl_coups(mychan_tcl_coups);
+#ifdef S_AUTOLOCK
+  add_cfg(&CFG_LOCKTHRESHOLD);
+  add_cfg(&CFG_KILLTHRESHOLD);
+#endif /* S_AUTOLOCK */
   return NULL;
   return NULL;
 }
 }

+ 1 - 0
src/mod/channels.mod/channels.h

@@ -168,6 +168,7 @@ inline static int chanset_unlink(struct chanset_t *chan);
 #endif
 #endif
 #define write_chans ((int (*)(FILE *, int))channels_funcs[49])
 #define write_chans ((int (*)(FILE *, int))channels_funcs[49])
 #define write_config ((int (*)(FILE *, int))channels_funcs[50])
 #define write_config ((int (*)(FILE *, int))channels_funcs[50])
+#define check_should_lock ((void (*)(void))channels_funcs[51])
 
 
 #endif				/* MAKING_CHANNELS */
 #endif				/* MAKING_CHANNELS */
 
 

+ 6 - 25
src/mod/channels.mod/cmdschan.c

@@ -1531,19 +1531,6 @@ static void cmd_chaninfo(struct userrec *u, int idx, char *par)
     else
     else
       dprintf(idx, "invite-time: 0\n");
       dprintf(idx, "invite-time: 0\n");
 #endif /* S_IRCNET */
 #endif /* S_IRCNET */
-    /* Only bot owners can see/change these (they're TCL commands) */
-    if (u->flags & USER_OWNER) {
-      if (chan->need_op[0])
-	dprintf(idx, "To regain op's (need-op):\n%s\n", chan->need_op);
-      if (chan->need_invite[0])
-	dprintf(idx, "To get invite (need-invite):\n%s\n", chan->need_invite);
-      if (chan->need_key[0])
-	dprintf(idx, "To get key (need-key):\n%s\n", chan->need_key);
-      if (chan->need_unban[0])
-	dprintf(idx, "If I'm banned (need-unban):\n%s\n", chan->need_unban);
-      if (chan->need_limit[0])
-	dprintf(idx, "When channel full (need-limit):\n%s\n", chan->need_limit);
-    }
     dprintf(idx, "Other modes:\n");
     dprintf(idx, "Other modes:\n");
     dprintf(idx, "     %cinactive       %cprivate     %ccycle          %cdontkickops\n",
     dprintf(idx, "     %cinactive       %cprivate     %ccycle          %cdontkickops\n",
 	    (chan->status & CHAN_INACTIVE) ? '+' : '-',
 	    (chan->status & CHAN_INACTIVE) ? '+' : '-',
@@ -1645,7 +1632,7 @@ static void cmd_chaninfo(struct userrec *u, int idx, char *par)
 static void cmd_chanset(struct userrec *u, int idx, char *par)
 static void cmd_chanset(struct userrec *u, int idx, char *par)
 {
 {
   char *chname = NULL, answers[512], *parcpy;
   char *chname = NULL, answers[512], *parcpy;
-  char *list[2], *bak, *buf, buf2[1024];
+  char *list[2], *bak, *buf;
   struct chanset_t *chan = NULL;
   struct chanset_t *chan = NULL;
   int all = 0, items = 0;
   int all = 0, items = 0;
 
 
@@ -1723,13 +1710,6 @@ static void cmd_chanset(struct userrec *u, int idx, char *par)
 	 * just ignore any non global +n's trying to set the need-commands.
 	 * just ignore any non global +n's trying to set the need-commands.
 	 */
 	 */
 	if (strncmp(list[0], "need-", 5) || (u->flags & USER_OWNER)) {
 	if (strncmp(list[0], "need-", 5) || (u->flags & USER_OWNER)) {
-	  if (!strncmp(list[0], "need-", 5) && !(isowner(dcc[idx].nick)) &&
-	      must_be_owner) {
-	    dprintf(idx, "Due to security concerns, only permanent owners can set these modes.\n");
-
-	    nfree(buf);
-	    return;
-	  }
 	  list[1] = par;
 	  list[1] = par;
 	  /* Par gets modified in tcl channel_modify under some
 	  /* Par gets modified in tcl channel_modify under some
   	   * circumstances, so save it now.
   	   * circumstances, so save it now.
@@ -1749,8 +1729,10 @@ static void cmd_chanset(struct userrec *u, int idx, char *par)
 	break;
 	break;
       }
       }
       if (!all && answers[0]) {
       if (!all && answers[0]) {
-        sprintf(buf2, "cset %s %s", chname, bak);
-        botnet_send_zapf_broad(-1, botnetnick, NULL, buf2);
+        struct chanset_t *my_chan;
+        my_chan = findchan_by_dname(chname);
+        if (my_chan)
+          do_chanset(my_chan, bak, 0);
 	dprintf(idx, "Successfully set modes { %s } on %s.\n",
 	dprintf(idx, "Successfully set modes { %s } on %s.\n",
 		answers, chname);
 		answers, chname);
 #ifdef HUB
 #ifdef HUB
@@ -1763,8 +1745,7 @@ static void cmd_chanset(struct userrec *u, int idx, char *par)
         chan = chan->next;
         chan = chan->next;
     }
     }
     if (all && answers[0]) {
     if (all && answers[0]) {
-      sprintf(buf2, "cset * %s", bak);
-      botnet_send_zapf_broad(-1, botnetnick, NULL, buf2);
+      do_chanset(NULL, bak, 0);		/* NULL does all */
       dprintf(idx, "Successfully set modes { %s } on all channels.\n",
       dprintf(idx, "Successfully set modes { %s } on all channels.\n",
 	      answers);
 	      answers);
 #ifdef HUB
 #ifdef HUB

+ 13 - 63
src/mod/channels.mod/tclchan.c

@@ -24,11 +24,6 @@ static int tcl_channel_info(Tcl_Interp * irp, struct chanset_t *chan)
   Tcl_AppendElement(irp, s);
   Tcl_AppendElement(irp, s);
   simple_sprintf(s, "%d", chan->revenge_mode);
   simple_sprintf(s, "%d", chan->revenge_mode);
   Tcl_AppendElement(irp, s);
   Tcl_AppendElement(irp, s);
-  Tcl_AppendElement(irp, chan->need_op);
-  Tcl_AppendElement(irp, chan->need_invite);
-  Tcl_AppendElement(irp, chan->need_key);
-  Tcl_AppendElement(irp, chan->need_unban);
-  Tcl_AppendElement(irp, chan->need_limit);
   simple_sprintf(s, "%d:%d", chan->flood_pub_thr, chan->flood_pub_time);
   simple_sprintf(s, "%d:%d", chan->flood_pub_thr, chan->flood_pub_time);
   Tcl_AppendElement(irp, s);
   Tcl_AppendElement(irp, s);
   simple_sprintf(s, "%d:%d", chan->flood_ctcp_thr, chan->flood_ctcp_time);
   simple_sprintf(s, "%d:%d", chan->flood_ctcp_thr, chan->flood_ctcp_time);
@@ -195,13 +190,6 @@ static int tcl_channel_get(Tcl_Interp * irp, struct chanset_t *chan, char *setti
 
 
   if      (CHECK("chanmode"))      get_mode_protect(chan, s);
   if      (CHECK("chanmode"))      get_mode_protect(chan, s);
 
 
-  /* Code in need_op can be longer than 120 chars, so we have to cut it.*/
-  else if (CHECK("need-op"))     { strncpy(s, chan->need_op, 120); s[120] = 0;     }
-  else if (CHECK("need-invite")) { strncpy(s, chan->need_invite, 120); s[120] = 0; }
-  else if (CHECK("need-key"))    { strncpy(s, chan->need_key, 120); s[120] = 0;    }
-  else if (CHECK("need-unban"))  { strncpy(s, chan->need_unban, 120); s[120] = 0;  }
-  else if (CHECK("need-limit"))  { strncpy(s, chan->need_limit, 120); s[120] = 0;  }
-
   else if (CHECK("idle-kick"))     simple_sprintf(s, "%d", chan->idle_kick);
   else if (CHECK("idle-kick"))     simple_sprintf(s, "%d", chan->idle_kick);
   else if (CHECK("limit"))         simple_sprintf(s, "%d", chan->limitraise);
   else if (CHECK("limit"))         simple_sprintf(s, "%d", chan->limitraise);
   else if (CHECK("stop-net-hack")) simple_sprintf(s, "%d", chan->stopnethack_mode);
   else if (CHECK("stop-net-hack")) simple_sprintf(s, "%d", chan->stopnethack_mode);
@@ -280,12 +268,12 @@ static int tcl_channel STDVAR
     BADARGS(3, 4, " add channel-name ?options-list?");
     BADARGS(3, 4, " add channel-name ?options-list?");
     if (argc == 3) {
     if (argc == 3) {
       
       
-      sprintf(buf2, "cjoin %s", argv[2]);
+      snprintf(buf2, sizeof buf2, "cjoin %s", argv[2]);
       if (!loading)
       if (!loading)
         botnet_send_zapf_broad(-1, botnetnick, NULL, buf2);
         botnet_send_zapf_broad(-1, botnetnick, NULL, buf2);
       return tcl_channel_add(irp, argv[2], "");
       return tcl_channel_add(irp, argv[2], "");
     }
     }
-    sprintf(buf2, "cjoin %s %s", argv[2], argv[3]);
+    snprintf(buf2, sizeof buf2, "cjoin %s %s", argv[2], argv[3]);
     if (!loading)
     if (!loading)
       botnet_send_zapf_broad(-1, botnetnick, NULL, buf2);
       botnet_send_zapf_broad(-1, botnetnick, NULL, buf2);
     return tcl_channel_add(irp, argv[2], argv[3]);
     return tcl_channel_add(irp, argv[2], argv[3]);
@@ -301,8 +289,7 @@ static int tcl_channel STDVAR
       Tcl_AppendResult(irp, "no such channel record", NULL);
       Tcl_AppendResult(irp, "no such channel record", NULL);
       return TCL_ERROR;
       return TCL_ERROR;
     }
     }
-    sprintf(buf2, "cset %s %s", chan->dname, argv[3]);
-    botnet_send_zapf_broad(-1, botnetnick, NULL, buf2);
+    do_chanset(chan, argv[3], 0);
     return tcl_channel_modify(irp, chan, argc - 3, &argv[3]);
     return tcl_channel_modify(irp, chan, argc - 3, &argv[3]);
   }
   }
   if (!strcmp(argv[1], "get")) {
   if (!strcmp(argv[1], "get")) {
@@ -331,7 +318,7 @@ static int tcl_channel STDVAR
       Tcl_AppendResult(irp, "no such channel record", NULL);
       Tcl_AppendResult(irp, "no such channel record", NULL);
       return TCL_ERROR;
       return TCL_ERROR;
     }
     }
-    sprintf(buf2, "cpart %s", argv[2]);
+    snprintf(buf2, sizeof buf2, "cpart %s", argv[2]);
     botnet_send_zapf_broad(-1, botnetnick, NULL, buf2);
     botnet_send_zapf_broad(-1, botnetnick, NULL, buf2);
     remove_channel(chan);
     remove_channel(chan);
     return TCL_OK;
     return TCL_OK;
@@ -357,53 +344,9 @@ static int tcl_channel_modify(Tcl_Interp * irp, struct chanset_t *chan,
 #ifdef LEAF
 #ifdef LEAF
   module_entry *me;
   module_entry *me;
 #endif
 #endif
+Context;
   for (i = 0; i < items; i++) {
   for (i = 0; i < items; i++) {
-    if (!strcmp(item[i], "need-op")) {
-      i++;
-      if (i >= items) {
-	if (irp)
-	  Tcl_AppendResult(irp, "channel need-op needs argument", NULL);
-	return TCL_ERROR;
-      }
-      strncpy(chan->need_op, item[i], 120);
-      chan->need_op[120] = 0;
-    } else if (!strcmp(item[i], "need-invite")) {
-      i++;
-      if (i >= items) {
-	if (irp)
-	  Tcl_AppendResult(irp, "channel need-invite needs argument", NULL);
-	return TCL_ERROR;
-      }
-      strncpy(chan->need_invite, item[i], 120);
-      chan->need_invite[120] = 0;
-    } else if (!strcmp(item[i], "need-key")) {
-      i++;
-      if (i >= items) {
-	if (irp)
-	  Tcl_AppendResult(irp, "channel need-key needs argument", NULL);
-	return TCL_ERROR;
-      }
-      strncpy(chan->need_key, item[i], 120);
-      chan->need_key[120] = 0;
-    } else if (!strcmp(item[i], "need-limit")) {
-      i++;
-      if (i >= items) {
-	if (irp)
-	  Tcl_AppendResult(irp, "channel need-limit needs argument", NULL);
-	return TCL_ERROR;
-      }
-      strncpy(chan->need_limit, item[i], 120);
-      chan->need_limit[120] = 0;
-    } else if (!strcmp(item[i], "need-unban")) {
-      i++;
-      if (i >= items) {
-	if (irp)
-	  Tcl_AppendResult(irp, "channel need-unban needs argument", NULL);
-	return TCL_ERROR;
-      }
-      strncpy(chan->need_unban, item[i], 120);
-      chan->need_unban[120] = 0;
-    } else if (!strcmp(item[i], "chanmode")) {
+    if (!strcmp(item[i], "chanmode")) {
       i++;
       i++;
       if (i >= items) {
       if (i >= items) {
 	if (irp)
 	if (irp)
@@ -627,6 +570,7 @@ static int tcl_channel_modify(Tcl_Interp * irp, struct chanset_t *chan,
     else if (!strcmp(item[i], "+wasoptest"))  ;  /* Eule 01.2000 */
     else if (!strcmp(item[i], "+wasoptest"))  ;  /* Eule 01.2000 */
     else if (!strcmp(item[i], "+clearbans"))  ;
     else if (!strcmp(item[i], "+clearbans"))  ;
     else if (!strcmp(item[i], "-clearbans"))  ;
     else if (!strcmp(item[i], "-clearbans"))  ;
+    else if (!strncmp(item[i], "need-", 5))   ;
     else if (!strncmp(item[i], "flood-", 6)) {
     else if (!strncmp(item[i], "flood-", 6)) {
       int *pthr = 0, *ptime;
       int *pthr = 0, *ptime;
       char *p;
       char *p;
@@ -1022,6 +966,12 @@ static int tcl_channel_add(Tcl_Interp *irp, char *newname, char *options)
     chan->ban_time = global_ban_time;
     chan->ban_time = global_ban_time;
     chan->exempt_time = global_exempt_time;
     chan->exempt_time = global_exempt_time;
     chan->invite_time = global_invite_time;
     chan->invite_time = global_invite_time;
+    /* let's initialize this stuff for shits & giggles */
+    chan->channel.jointime = 0;
+    chan->channel.parttime = 0;
+#ifdef S_AUTOLOCK
+    chan->channel.fighting = 0;
+#endif /* S_AUTOLOCK */
 
 
     /* We _only_ put the dname (display name) in here so as not to confuse
     /* We _only_ put the dname (display name) in here so as not to confuse
      * any code later on. chan->name gets updated with the channel name as
      * any code later on. chan->name gets updated with the channel name as

+ 2 - 4
src/mod/irc.mod/cmdsirc.c

@@ -763,11 +763,9 @@ Context;
     bots--;
     bots--;
     bpos++;
     bpos++;
   }
   }
-  if (bitch && !simul) {
-    char buf2[1024];
+  if (bitch && !simul && chan) {
     chan->status |= CHAN_BITCH;
     chan->status |= CHAN_BITCH;
-    sprintf(buf2, "cset %s +bitch", chan->dname);
-    botnet_send_zapf_broad(-1, botnetnick, NULL, buf2);
+    do_chanset(chan, STR("+bitch"), 1);
   }
   }
   nfree(targets);
   nfree(targets);
   nfree(chanbots);
   nfree(chanbots);

+ 57 - 69
src/mod/irc.mod/irc.c

@@ -23,6 +23,7 @@
 #define lag_threshold (CFG_LAGTHRESHOLD.gdata ? atoi(CFG_LAGTHRESHOLD.gdata) : 15)
 #define lag_threshold (CFG_LAGTHRESHOLD.gdata ? atoi(CFG_LAGTHRESHOLD.gdata) : 15)
 #define opreq_count (CFG_OPREQUESTS.gdata ? atoi( CFG_OPREQUESTS.gdata ) : 2)
 #define opreq_count (CFG_OPREQUESTS.gdata ? atoi( CFG_OPREQUESTS.gdata ) : 2)
 #define opreq_seconds (CFG_OPREQUESTS.gdata ? atoi( strchr(CFG_OPREQUESTS.gdata, ':') + 1 ) : 5)
 #define opreq_seconds (CFG_OPREQUESTS.gdata ? atoi( strchr(CFG_OPREQUESTS.gdata, ':') + 1 ) : 5)
+#define op_time_slack (CFG_OPTIMESLACK.gdata ? atoi(CFG_OPTIMESLACK.gdata) : 60)
 
 
 #define PRIO_DEOP 1
 #define PRIO_DEOP 1
 #define PRIO_KICK 2
 #define PRIO_KICK 2
@@ -33,13 +34,9 @@ struct cfg_entry CFG_OPBOTS,
   CFG_INBOTS,
   CFG_INBOTS,
   CFG_LAGTHRESHOLD,
   CFG_LAGTHRESHOLD,
   CFG_OPTIMESLACK,
   CFG_OPTIMESLACK,
-#ifdef G_AUTOLOCK
-
-  CFG_KILLTHRESHOLD,
-  CFG_LOCKTHRESHOLD,
+#ifdef S_AUTOLOCK
   CFG_FIGHTTHRESHOLD,
   CFG_FIGHTTHRESHOLD,
-#endif
-
+#endif /* S_AUTOLOCK */
   CFG_OPREQUESTS;
   CFG_OPREQUESTS;
 
 
 static Function *global = NULL, *channels_funcs = NULL, *server_funcs = NULL,
 static Function *global = NULL, *channels_funcs = NULL, *server_funcs = NULL,
@@ -88,11 +85,7 @@ static int include_lk = 1;		/* For correct calculation
 
 
 void makeopline(struct chanset_t *chan, char *nick, char *buf)
 void makeopline(struct chanset_t *chan, char *nick, char *buf)
 {
 {
-  char plaincookie[20],
-    enccookie[48],
-   *p,
-    nck[20],
-    key[200];
+  char plaincookie[20], enccookie[48], *p, nck[20], key[200];
   memberlist * m;
   memberlist * m;
   m=ismember(chan, nick);
   m=ismember(chan, nick);
   if (m)
   if (m)
@@ -103,13 +96,9 @@ void makeopline(struct chanset_t *chan, char *nick, char *buf)
   strcpy(key, botname);
   strcpy(key, botname);
   strcat(key, netpass);
   strcat(key, netpass);
 //  putlog(LOG_DEBUG, "*", "Encrypting opline for %s with cookie %s and key %s", nck, plaincookie, key);
 //  putlog(LOG_DEBUG, "*", "Encrypting opline for %s with cookie %s and key %s", nck, plaincookie, key);
-
   p = encrypt_string(key, plaincookie);
   p = encrypt_string(key, plaincookie);
   strcpy(enccookie, p);
   strcpy(enccookie, p);
   nfree(p);
   nfree(p);
-//  p = enccookie + strlen(enccookie) - 1;
-//  while (*p == '.')
-//    *p-- = 0;
   sprintf(buf, STR("MODE %s +o-b %s *!*@<%s>\n"), chan->name, nck, enccookie);
   sprintf(buf, STR("MODE %s +o-b %s *!*@<%s>\n"), chan->name, nck, enccookie);
 }
 }
 
 
@@ -1075,6 +1064,38 @@ void check_servers() {
   }
   }
 }
 }
 
 
+#ifdef S_AUTOLOCK
+void check_netfight()
+{
+  int limit = atoi(CFG_FIGHTTHRESHOLD.gdata ? CFG_FIGHTTHRESHOLD.gdata : "0");
+Context;
+  if (limit) {
+    struct chanset_t *chan;
+    for (chan = chanset; chan; chan = chan->next) {
+Context;
+      if ((chan->channel.fighting) && (chan->channel.fighting > limit)) {
+Context;
+        if (!channel_bitch(chan) || !channel_closed(chan)) {
+Context;
+          putlog(LOG_WARN, "*", STR("Auto-closed %s - channel fight\n"), chan->dname);
+Context;
+          do_chanset(chan, STR("+bitch +closed"), 1);
+Context;
+          enforce_closed(chan);
+Context;
+          dprintf(DP_MODE, STR("TOPIC %s :Auto-closed - channel fight\n"), chan->name);
+Context;
+        }
+Context;
+      }
+      chan->channel.fighting = 0; 		/* we put this here because we need to clear it once per min */
+    }
+  }
+Context;
+}
+#endif /* S_AUTOLOCK */
+
+
 void raise_limit(struct chanset_t * chan) {
 void raise_limit(struct chanset_t * chan) {
   int nl, cl, i, mem, ul, ll;
   int nl, cl, i, mem, ul, ll;
   char s[50];
   char s[50];
@@ -1524,14 +1545,14 @@ static cmd_t irc_bot[] = {
 
 
 static void getin_3secondly()
 static void getin_3secondly()
 {
 {
-  struct chanset_t *ch = chanset;
-
   if (!server_online)
   if (!server_online)
     return;
     return;
-  while (ch) {
-    if ((channel_pending(ch) || channel_active(ch)) && (!me_op(ch)))
-      request_op(ch);
-    ch = ch->next;
+  else {
+    struct chanset_t *ch;
+    for (ch = chanset; ch; ch = ch->next) {
+      if ((channel_pending(ch) || channel_active(ch)) && (!me_op(ch)))
+        request_op(ch);
+    }
   }
   }
 }
 }
 
 
@@ -1576,14 +1597,13 @@ static Function irc_table[] =
   (Function) check_this_ban,
   (Function) check_this_ban,
   (Function) check_this_user,
   (Function) check_this_user,
   (Function) me_voice,
   (Function) me_voice,
-//  (Function) getchanmode,
 };
 };
 
 
-void getin_describe(struct cfg_entry *cfgent, int idx)
+void irc_describe(struct cfg_entry *cfgent, int idx)
 {
 {
 }
 }
 
 
-void getin_changed(struct cfg_entry *cfgent, char *oldval, int *valid)
+void irc_changed(struct cfg_entry *cfgent, char *oldval, int *valid)
 {
 {
   int i;
   int i;
 
 
@@ -1606,22 +1626,6 @@ void getin_changed(struct cfg_entry *cfgent, char *oldval, int *valid)
     *valid = 1;
     *valid = 1;
     return;
     return;
   }
   }
-  if (!strcmp(cfgent->name, STR("lock-threshold"))) {
-    int L,
-      R;
-    char *value = cfgent->gdata;
-
-    L = atoi(value);
-    value = strchr(value, ':');
-    if (!value)
-      return;
-    value++;
-    R = atoi(value);
-    if ((R >= 1000) || (R < 0) || (L < 0) || (L > 100))
-      return;
-    *valid = 1;
-    return;
-  }
   i = atoi(cfgent->gdata);
   i = atoi(cfgent->gdata);
   if (!strcmp(cfgent->name, STR("op-bots"))) {
   if (!strcmp(cfgent->name, STR("op-bots"))) {
     if ((i < 1) || (i > 10))
     if ((i < 1) || (i > 10))
@@ -1644,9 +1648,6 @@ void getin_changed(struct cfg_entry *cfgent, char *oldval, int *valid)
   } else if (!strcmp(cfgent->name, STR("fight-threshold"))) {
   } else if (!strcmp(cfgent->name, STR("fight-threshold"))) {
     if (i && ((i < 50) || (i > 1000)))
     if (i && ((i < 50) || (i > 1000)))
       return;
       return;
-  } else if (!strcmp(cfgent->name, STR("kill-threshold"))) {
-    if ((i < 0) || (i >= 200))
-      return;
   } else if (!strcmp(cfgent->name, STR("op-time-slack"))) {
   } else if (!strcmp(cfgent->name, STR("op-time-slack"))) {
     if ((i < 30) || (i > 1200))
     if ((i < 30) || (i > 1200))
       return;
       return;
@@ -1655,48 +1656,38 @@ void getin_changed(struct cfg_entry *cfgent, char *oldval, int *valid)
   return;
   return;
 }
 }
 
 
+
 struct cfg_entry CFG_OPBOTS = {
 struct cfg_entry CFG_OPBOTS = {
   "op-bots", CFGF_GLOBAL, NULL, NULL,
   "op-bots", CFGF_GLOBAL, NULL, NULL,
-  getin_changed, NULL, getin_describe
+  irc_changed, NULL, irc_describe
 };
 };
 
 
 struct cfg_entry CFG_INBOTS = {
 struct cfg_entry CFG_INBOTS = {
   "in-bots", CFGF_GLOBAL, NULL, NULL,
   "in-bots", CFGF_GLOBAL, NULL, NULL,
-  getin_changed, NULL, getin_describe
+  irc_changed, NULL, irc_describe
 };
 };
 
 
 struct cfg_entry CFG_LAGTHRESHOLD = {
 struct cfg_entry CFG_LAGTHRESHOLD = {
   "lag-threshold", CFGF_GLOBAL, NULL, NULL,
   "lag-threshold", CFGF_GLOBAL, NULL, NULL,
-  getin_changed, NULL, getin_describe
+  irc_changed, NULL, irc_describe
 };
 };
 
 
 struct cfg_entry CFG_OPREQUESTS = {
 struct cfg_entry CFG_OPREQUESTS = {
   "op-requests", CFGF_GLOBAL, NULL, NULL,
   "op-requests", CFGF_GLOBAL, NULL, NULL,
-  getin_changed, NULL, getin_describe
+  irc_changed, NULL, irc_describe
 };
 };
 
 
 struct cfg_entry CFG_OPTIMESLACK = {
 struct cfg_entry CFG_OPTIMESLACK = {
   "op-time-slack", CFGF_GLOBAL, NULL, NULL,
   "op-time-slack", CFGF_GLOBAL, NULL, NULL,
-  getin_changed, NULL, getin_describe
-};
-
-#ifdef G_AUTOLOCK
-struct cfg_entry CFG_LOCKTHRESHOLD = {
-  "lock-threshold", CFGF_GLOBAL, NULL, NULL,
-  getin_changed, NULL, getin_describe
-};
-
-struct cfg_entry CFG_KILLTHRESHOLD = {
-  "kill-threshold", CFGF_GLOBAL, NULL, NULL,
-  getin_changed, NULL, getin_describe
+  irc_changed, NULL, irc_describe
 };
 };
 
 
+#ifdef S_AUTOLOCK
 struct cfg_entry CFG_FIGHTTHRESHOLD = {
 struct cfg_entry CFG_FIGHTTHRESHOLD = {
   "fight-threshold", CFGF_GLOBAL, NULL, NULL,
   "fight-threshold", CFGF_GLOBAL, NULL, NULL,
-  getin_changed, NULL, getin_describe
+  irc_changed, NULL, irc_describe
 };
 };
-#endif /* G_AUTOLOCK */
-
+#endif /* S_AUTOLOCK */
 
 
 char *irc_start(Function * global_funcs)
 char *irc_start(Function * global_funcs)
 {
 {
@@ -1722,12 +1713,9 @@ char *irc_start(Function * global_funcs)
   add_cfg(&CFG_LAGTHRESHOLD);
   add_cfg(&CFG_LAGTHRESHOLD);
   add_cfg(&CFG_OPREQUESTS);
   add_cfg(&CFG_OPREQUESTS);
   add_cfg(&CFG_OPTIMESLACK);
   add_cfg(&CFG_OPTIMESLACK);
-#ifdef G_AUTOLOCK
-  add_cfg(&CFG_LOCKTHRESHOLD);
-  add_cfg(&CFG_KILLTHRESHOLD);
+#ifdef S_AUTOLOCK
   add_cfg(&CFG_FIGHTTHRESHOLD);
   add_cfg(&CFG_FIGHTTHRESHOLD);
-#endif
-
+#endif /* S_AUTOLOCK */
   for (chan = chanset; chan; chan = chan->next) {
   for (chan = chanset; chan; chan = chan->next) {
     if (shouldjoin(chan))
     if (shouldjoin(chan))
       dprintf(DP_MODE, "JOIN %s %s\n",
       dprintf(DP_MODE, "JOIN %s %s\n",
@@ -1744,9 +1732,9 @@ char *irc_start(Function * global_funcs)
   add_hook(HOOK_IDLE, (Function) flush_modes);
   add_hook(HOOK_IDLE, (Function) flush_modes);
   add_hook(HOOK_3SECONDLY, (Function) getin_3secondly);
   add_hook(HOOK_3SECONDLY, (Function) getin_3secondly);
   add_hook(HOOK_10SECONDLY, (Function) irc_10secondly);
   add_hook(HOOK_10SECONDLY, (Function) irc_10secondly);
-#ifdef G_AUTOLOCK
+#ifdef S_AUTOLOCK
   add_hook(HOOK_MINUTELY, (Function) check_netfight);
   add_hook(HOOK_MINUTELY, (Function) check_netfight);
-#endif
+#endif /* S_AUTOLOCK */
   Tcl_TraceVar(interp, "net-type",
   Tcl_TraceVar(interp, "net-type",
 	       TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
 	       TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
 	       traced_nettype, NULL);
 	       traced_nettype, NULL);

+ 12 - 0
src/mod/irc.mod/mode.c

@@ -1331,6 +1331,9 @@ static int gotmode(char *from, char *msg)
 	  }
 	  }
 	  break;
 	  break;
 	case 'o':
 	case 'o':
+#ifdef S_AUTOLOCK
+          chan->channel.fighting++;
+#endif /* S_AUTOLOCK */
 	  op = newsplit(&msg);
 	  op = newsplit(&msg);
 	  fixcolon(op);
 	  fixcolon(op);
 	  if (ms2[0] == '+')
 	  if (ms2[0] == '+')
@@ -1397,6 +1400,9 @@ static int gotmode(char *from, char *msg)
 	  }
 	  }
 	  break;
 	  break;
 	case 'b':
 	case 'b':
+#ifdef S_AUTOLOCK
+          chan->channel.fighting++;
+#endif /* S_AUTOLOCK */
 	  op = newsplit(&msg);
 	  op = newsplit(&msg);
 	  fixcolon(op);
 	  fixcolon(op);
 	  if (ms2[0] == '+')
 	  if (ms2[0] == '+')
@@ -1406,6 +1412,9 @@ static int gotmode(char *from, char *msg)
 	  break;
 	  break;
 #ifdef S_IRCNET
 #ifdef S_IRCNET
 	case 'e':
 	case 'e':
+#ifdef S_AUTOLOCK
+          chan->channel.fighting++;
+#endif /* S_AUTOLOCK */
 	  op = newsplit(&msg);
 	  op = newsplit(&msg);
 	  fixcolon(op);
 	  fixcolon(op);
 	  if (ms2[0] == '+')
 	  if (ms2[0] == '+')
@@ -1414,6 +1423,9 @@ static int gotmode(char *from, char *msg)
 	    got_unexempt(chan, nick, from, op, u);
 	    got_unexempt(chan, nick, from, op, u);
 	  break;
 	  break;
 	case 'I':
 	case 'I':
+#ifdef S_AUTOLOCK
+          chan->channel.fighting++;
+#endif /* S_AUTOLOCK */
 	  op = newsplit(&msg);
 	  op = newsplit(&msg);
 	  fixcolon(op);
 	  fixcolon(op);
 	  if (ms2[0] == '+')
 	  if (ms2[0] == '+')

+ 5 - 5
src/mod/module.h

@@ -237,7 +237,7 @@
 #define debug_output (*(int *)(global[106]))
 #define debug_output (*(int *)(global[106]))
 #define noshare (*(int *)(global[107]))
 #define noshare (*(int *)(global[107]))
 /* 108 - 111 */
 /* 108 - 111 */
-/* 108: gban_total -- UNUSED (Eule) */
+#define do_chanset ((void (*)(struct chanset_t *, char *, int))global[108])
 /* 109: make_userfile -- UNUED (bryan) */
 /* 109: make_userfile -- UNUED (bryan) */
 #define default_flags (*(int*)global[110])
 #define default_flags (*(int*)global[110])
 #define dcc_total (*(int*)global[111])
 #define dcc_total (*(int*)global[111])
@@ -288,7 +288,7 @@
 #define copyfile ((int (*) (char *, char *))global[147])
 #define copyfile ((int (*) (char *, char *))global[147])
 /* 148 - 151 */
 /* 148 - 151 */
 #define do_tcl ((void (*)(char *, char *))global[148])
 #define do_tcl ((void (*)(char *, char *))global[148])
-#define readtclprog ((int (*)(const char *))global[149])
+/* 149 -- UNUSED */
 /* #define get_language ((char *(*)(int))global[150]) */
 /* #define get_language ((char *(*)(int))global[150]) */
 #define def_get ((void *(*)(struct userrec *, struct user_entry *))global[151])
 #define def_get ((void *(*)(struct userrec *, struct user_entry *))global[151])
 /* 152 - 155 */
 /* 152 - 155 */
@@ -357,9 +357,9 @@
 #define stripmodes ((int(*)(char *))global[202])
 #define stripmodes ((int(*)(char *))global[202])
 #define stripmasktype ((const char *(*)(int))global[203])
 #define stripmasktype ((const char *(*)(int))global[203])
 /* 204 - 207 */
 /* 204 - 207 */
-/* 204: sub_lang -- UNUSED (bryan) */
-#define online_since (*(int *)(global[205]))
-/* 206: cmd_loadlanguage -- UNUSED (bryan) */
+#define online_since (*(int *)(global[204]))
+/* 205 -- UNUSED */
+/* 206 -- UNUSED */
 #define check_dcc_attrs ((int (*)(struct userrec *,int))global[207])
 #define check_dcc_attrs ((int (*)(struct userrec *,int))global[207])
 /* 208 - 211 */
 /* 208 - 211 */
 #define check_dcc_chanattrs ((int (*)(struct userrec *,char *,int,int))global[208])
 #define check_dcc_chanattrs ((int (*)(struct userrec *,char *,int,int))global[208])

+ 0 - 9
src/mod/server.mod/servmsg.c

@@ -160,7 +160,6 @@ static void check_tcl_msgm(char *cmd, char *nick, char *uhost,
 static int check_tcl_raw(char *from, char *code, char *msg)
 static int check_tcl_raw(char *from, char *code, char *msg)
 {
 {
   int x;
   int x;
-Context;
   Tcl_SetVar(interp, "_raw1", from, 0);
   Tcl_SetVar(interp, "_raw1", from, 0);
   Tcl_SetVar(interp, "_raw2", code, 0);
   Tcl_SetVar(interp, "_raw2", code, 0);
   Tcl_SetVar(interp, "_raw3", msg, 0);
   Tcl_SetVar(interp, "_raw3", msg, 0);
@@ -534,21 +533,17 @@ static int gotmsg(char *from, char *msg)
       u = get_user_by_host(from);
       u = get_user_by_host(from);
       code = newsplit(&msg);
       code = newsplit(&msg);
       rmspace(msg);
       rmspace(msg);
-Context;
       i = findauth(uhost);
       i = findauth(uhost);
       /* is it a cmd? */
       /* is it a cmd? */
 
 
-Context;
       if (i > -1 && auth[i].authed && code[0] == cmdprefix[0] && code[1]) {
       if (i > -1 && auth[i].authed && code[0] == cmdprefix[0] && code[1]) {
         code++;        
         code++;        
-Context;
         u = auth[i].user;
         u = auth[i].user;
         if (check_tcl_msgc(code, nick, uhost, u, msg))
         if (check_tcl_msgc(code, nick, uhost, u, msg))
           auth[i].atime = now;
           auth[i].atime = now;
         else
         else
           putlog(LOG_MSGS, "*", "[%s] %s %s", from, code, msg);
           putlog(LOG_MSGS, "*", "[%s] %s %s", from, code, msg);
       } else if ((code[0] != cmdprefix[0] || !code[1] || i == -1 || !(auth[i].authed))) {
       } else if ((code[0] != cmdprefix[0] || !code[1] || i == -1 || !(auth[i].authed))) {
-Context;
         if (!ignoring || trigger_on_ignore)
         if (!ignoring || trigger_on_ignore)
  	  check_tcl_msgm(code, nick, uhost, u, msg);
  	  check_tcl_msgm(code, nick, uhost, u, msg);
         if (!ignoring)
         if (!ignoring)
@@ -837,7 +832,6 @@ static int got432(char *from, char *msg)
 static int got433(char *from, char *msg)
 static int got433(char *from, char *msg)
 {
 {
   char *tmp;
   char *tmp;
-Context;
   if (server_online) {
   if (server_online) {
     /* We are online and have a nickname, we'll keep it */
     /* We are online and have a nickname, we'll keep it */
     newsplit(&msg);
     newsplit(&msg);
@@ -846,9 +840,7 @@ Context;
     nick_juped = 0;
     nick_juped = 0;
     return 0;
     return 0;
   }
   }
-Context;
   gotfake433(from);
   gotfake433(from);
-Context;
   return 0;
   return 0;
 }
 }
 
 
@@ -979,7 +971,6 @@ static int gotmode(char *from, char *msg)
 {
 {
   char *ch;
   char *ch;
 
 
-Context;
   ch = newsplit(&msg);
   ch = newsplit(&msg);
   /* Usermode changes? */
   /* Usermode changes? */
   if (strchr(CHANMETA, ch[0]) == NULL) {
   if (strchr(CHANMETA, ch[0]) == NULL) {

+ 3 - 3
src/modules.c

@@ -293,7 +293,7 @@ Function global_table[] =
   (Function) & debug_output,	 /* int					*/
   (Function) & debug_output,	 /* int					*/
   (Function) & noshare,		 /* int					*/
   (Function) & noshare,		 /* int					*/
   /* 108 - 111 */
   /* 108 - 111 */
-  (Function) 0, /* gban_total -- UNUSED! (Eule) */
+  (Function) do_chanset, 
   (Function) 0,	 /* int					*/
   (Function) 0,	 /* int					*/
   (Function) & default_flags,	 /* int					*/
   (Function) & default_flags,	 /* int					*/
   (Function) & dcc_total,	 /* int					*/
   (Function) & dcc_total,	 /* int					*/
@@ -344,7 +344,7 @@ Function global_table[] =
   (Function) copyfile,
   (Function) copyfile,
   /* 148 - 151 */
   /* 148 - 151 */
   (Function) do_tcl,
   (Function) do_tcl,
-  (Function) readtclprog,
+  (Function) 0,
   (Function) 0,
   (Function) 0,
   (Function) def_get,
   (Function) def_get,
   /* 152 - 155 */
   /* 152 - 155 */
@@ -413,9 +413,9 @@ Function global_table[] =
   (Function) stripmodes,
   (Function) stripmodes,
   (Function) stripmasktype,
   (Function) stripmasktype,
   /* 204 - 207 */
   /* 204 - 207 */
-  (Function) 0,
   (Function) & online_since,	/* time_t *				*/
   (Function) & online_since,	/* time_t *				*/
   (Function) 0,
   (Function) 0,
+  (Function) 0,
   (Function) check_dcc_attrs,
   (Function) check_dcc_attrs,
   /* 208 - 211 */
   /* 208 - 211 */
   (Function) check_dcc_chanattrs,
   (Function) check_dcc_chanattrs,

+ 25 - 25
src/net.c

@@ -15,7 +15,7 @@
 #include <sys/socket.h>
 #include <sys/socket.h>
 #if HAVE_SYS_SELECT_H
 #if HAVE_SYS_SELECT_H
 #  include <sys/select.h>
 #  include <sys/select.h>
-#endif
+#endif /* HAVE_SYS_SELECT_H */
 #include <netinet/in.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>		/* is this really necessary? */
 #include <arpa/inet.h>		/* is this really necessary? */
 #include <errno.h>
 #include <errno.h>
@@ -25,7 +25,7 @@
 
 
 #if HAVE_UNISTD_H
 #if HAVE_UNISTD_H
 #  include <unistd.h>
 #  include <unistd.h>
-#endif
+#endif /* HAVE_UNITSTD_H */
 #include <setjmp.h>
 #include <setjmp.h>
 
 
 #if !HAVE_GETDTABLESIZE
 #if !HAVE_GETDTABLESIZE
@@ -34,7 +34,7 @@
 #  else
 #  else
 #    define getdtablesize() 200
 #    define getdtablesize() 200
 #  endif
 #  endif
-#endif
+#endif /* !HAVE_GETDTABLESIZE */
 
 
 extern struct dcc_t	*dcc;
 extern struct dcc_t	*dcc;
 extern char *netpass;
 extern char *netpass;
@@ -179,7 +179,7 @@ int seed_PRNG(void)
   FILE *fh = 0;
   FILE *fh = 0;
 #if OPENSSL_VERSION_NUMBER >= 0x00905100
 #if OPENSSL_VERSION_NUMBER >= 0x00905100
   if (RAND_status()) return 0;
   if (RAND_status()) return 0;
-#endif
+#endif /* OPENSSL_VERSION_NUMBER */
   if ((fh = fopen("/dev/urandom", "r"))) {
   if ((fh = fopen("/dev/urandom", "r"))) {
     fclose(fh);
     fclose(fh);
     return 0;
     return 0;
@@ -401,17 +401,17 @@ void neterror(char *s)
   case ECONNRESET:
   case ECONNRESET:
     strcpy(s, "Connection reset by peer");
     strcpy(s, "Connection reset by peer");
     break;
     break;
-#endif
+#endif /* ECONNRESET */
 #ifdef EACCES
 #ifdef EACCES
   case EACCES:
   case EACCES:
     strcpy(s, "Permission denied");
     strcpy(s, "Permission denied");
     break;
     break;
-#endif
+#endif /* EACCESS */
 #ifdef EMFILE
 #ifdef EMFILE
   case EMFILE:
   case EMFILE:
     strcpy(s, "Too many open files");
     strcpy(s, "Too many open files");
     break;
     break;
-#endif
+#endif /* EMFILE */
   case 0:
   case 0:
     strcpy(s, "Error 0");
     strcpy(s, "Error 0");
     break;
     break;
@@ -679,7 +679,7 @@ int open_telnet_raw(int sock, char *server, int sport)
           return -1;
           return -1;
         }
         }
       } else {
       } else {
-#endif
+#endif /* USE_IPV6 */
         if (bind(sock, &cached_myip4_so.sa, SIZEOF_SOCKADDR(cached_myip4_so)) < 0) {
         if (bind(sock, &cached_myip4_so.sa, SIZEOF_SOCKADDR(cached_myip4_so)) < 0) {
           killsock(sock);
           killsock(sock);
           return -3;
           return -3;
@@ -1096,7 +1096,7 @@ static int sockread(char *s, int *len)
 #ifdef FD_SETSIZE
 #ifdef FD_SETSIZE
   if (fds > FD_SETSIZE)
   if (fds > FD_SETSIZE)
     fds = FD_SETSIZE;		/* Fixes YET ANOTHER freebsd bug!!! */
     fds = FD_SETSIZE;		/* Fixes YET ANOTHER freebsd bug!!! */
-#endif
+#endif /* FD_SETSIZE */
   /* timeout: 1 sec */
   /* timeout: 1 sec */
   t.tv_sec = 1;
   t.tv_sec = 1;
   t.tv_usec = 0;
   t.tv_usec = 0;
@@ -1122,12 +1122,12 @@ static int sockread(char *s, int *len)
 #ifdef HPUX_HACKS
 #ifdef HPUX_HACKS
 #ifndef HPUX10_HACKS
 #ifndef HPUX10_HACKS
   x = select(fds, (int *) &fd, (int *) NULL, (int *) NULL, &t);
   x = select(fds, (int *) &fd, (int *) NULL, (int *) NULL, &t);
-#else
+#else /* !HPUX10_HACKS */
   x = select(fds, &fd, NULL, NULL, &t);
   x = select(fds, &fd, NULL, NULL, &t);
-#endif
-#else
+#endif /* HPUX10_HACKS */
+#else /* !HPUX_HACKS */
   x = select(fds, &fd, NULL, NULL, &t);
   x = select(fds, &fd, NULL, NULL, &t);
-#endif
+#endif /* HPUX_HACKS */
   if (x > 0) {
   if (x > 0) {
     /* Something happened */
     /* Something happened */
     for (i = 0; i < MAXSOCKS; i++) {
     for (i = 0; i < MAXSOCKS; i++) {
@@ -1270,9 +1270,9 @@ char *botlink_encrypt(int snum, char *src)
     eline = encrypt_string(socklist[snum].okey, line);
     eline = encrypt_string(socklist[snum].okey, line);
     if (socklist[snum].oseed) {
     if (socklist[snum].oseed) {
       for (i = 0; i <= 3; i++)
       for (i = 0; i <= 3; i++)
-       *(dword *) & socklist[snum].okey[i * 4] = prand(&socklist[snum].oseed, 0xFFFFFFFF);
+        *(dword *) & socklist[snum].okey[i * 4] = prand(&socklist[snum].oseed, 0xFFFFFFFF);
       if (!socklist[snum].oseed)
       if (!socklist[snum].oseed)
-       socklist[snum].oseed++;
+        socklist[snum].oseed++;
     }
     }
     buf = nrealloc(buf, bufpos + strlen(eline) + 10);
     buf = nrealloc(buf, bufpos + strlen(eline) + 10);
     strcpy((char *) &buf[bufpos], eline);
     strcpy((char *) &buf[bufpos], eline);
@@ -1519,9 +1519,9 @@ void tputs(register int z, char *s, unsigned int len)
 #ifdef EUSE_COLORPUTS
 #ifdef EUSE_COLORPUTS
      colorputs(s);
      colorputs(s);
      x = len;
      x = len;
-#else
+#else /* !EUSE_COLORPUTS */
     write(z, s, len);
     write(z, s, len);
-#endif
+#endif /* EUSE_COLORPUTS */
     return;
     return;
   }
   }
   for (i = 0; i < MAXSOCKS; i++) {
   for (i = 0; i < MAXSOCKS; i++) {
@@ -1650,7 +1650,7 @@ void dequeue_sockets()
 #ifdef FD_SETSIZE
 #ifdef FD_SETSIZE
   if (fds > FD_SETSIZE)
   if (fds > FD_SETSIZE)
     fds = FD_SETSIZE;           /* Fixes YET ANOTHER freebsd bug!!! */
     fds = FD_SETSIZE;           /* Fixes YET ANOTHER freebsd bug!!! */
-#endif
+#endif /* FD_SETSIZE */
   FD_ZERO(&wfds);
   FD_ZERO(&wfds);
   tv.tv_sec = 0;
   tv.tv_sec = 0;
   tv.tv_usec = 0; 		/* we only want to see if it's ready for writing, no need to actually wait.. */
   tv.tv_usec = 0; 		/* we only want to see if it's ready for writing, no need to actually wait.. */
@@ -1665,12 +1665,12 @@ void dequeue_sockets()
 #ifdef HPUX_HACKS
 #ifdef HPUX_HACKS
  #ifndef HPUX10_HACKS
  #ifndef HPUX10_HACKS
   select(fds, (int *) NULL, (int *) &wfds, (int *) NULL, &tv);
   select(fds, (int *) NULL, (int *) &wfds, (int *) NULL, &tv);
- #else
+ #else /* !HPUX10_HACKS */
   select(fds, NULL, &wfds, NULL, &tv);
   select(fds, NULL, &wfds, NULL, &tv);
- #endif
-#else
+ #endif /* HPUX10_HACKS */
+#else /* !HPUX_HACKS */
   select(fds, NULL, &wfds, NULL, &tv);
   select(fds, NULL, &wfds, NULL, &tv);
-#endif
+#endif /* HPUX_HACKS */
 
 
 /* end poptix */
 /* end poptix */
 
 
@@ -1698,15 +1698,15 @@ void dequeue_sockets()
           }
           }
         }
         }
       } else
       } else
-#endif
+#endif /* HAVE_SSL */
       x = write(socklist[i].sock, socklist[i].outbuf, socklist[i].outbuflen);
       x = write(socklist[i].sock, socklist[i].outbuf, socklist[i].outbuflen);
       if ((x < 0) && (errno != EAGAIN)
       if ((x < 0) && (errno != EAGAIN)
 #ifdef EBADSLT
 #ifdef EBADSLT
 	  && (errno != EBADSLT)
 	  && (errno != EBADSLT)
-#endif
+#endif /* EBADSLT */
 #ifdef ENOTCONN
 #ifdef ENOTCONN
 	  && (errno != ENOTCONN)
 	  && (errno != ENOTCONN)
-#endif
+#endif /* EBADSLT */
 	) {
 	) {
 	/* This detects an EOF during writing */
 	/* This detects an EOF during writing */
 	debug3(STR("net: eof!(write) socket %d (%s,%d)"), socklist[i].sock,
 	debug3(STR("net: eof!(write) socket %d (%s,%d)"), socklist[i].sock,

+ 3 - 1
src/proto.h

@@ -96,6 +96,7 @@ char *unsigned_int_to_base10(unsigned int);
 char *int_to_base64(unsigned int);
 char *int_to_base64(unsigned int);
 
 
 /* chanprog.c */
 /* chanprog.c */
+void do_chanset(struct chanset_t *, char *, int);
 void checkchans(int);
 void checkchans(int);
 void tell_verbose_uptime(int);
 void tell_verbose_uptime(int);
 void tell_verbose_status(int);
 void tell_verbose_status(int);
@@ -229,6 +230,7 @@ void set_cmd_pass(char *, int);
 #endif /* S_DCCPASS */
 #endif /* S_DCCPASS */
 
 
 /* misc.c */
 /* misc.c */
+void local_check_should_lock();
 void werr(int);
 void werr(int);
 char *werr_tostr(int);
 char *werr_tostr(int);
 void sdprintf EGG_VARARGS(char *, arg1);
 void sdprintf EGG_VARARGS(char *, arg1);
@@ -335,11 +337,11 @@ int flush_inbuf(int idx);
 void protect_tcl();
 void protect_tcl();
 void unprotect_tcl();
 void unprotect_tcl();
 void do_tcl(char *, char *);
 void do_tcl(char *, char *);
-int readtclprog(char *fname);
 int findidx(int);
 int findidx(int);
 int findanyidx(int);
 int findanyidx(int);
 
 
 /* userent.c */
 /* userent.c */
+void add_cfg(struct cfg_entry *);
 void list_type_kill(struct list_type *);
 void list_type_kill(struct list_type *);
 int list_type_expmem(struct list_type *);
 int list_type_expmem(struct list_type *);
 int xtra_set();
 int xtra_set();

+ 0 - 66
src/tcl.c

@@ -638,72 +638,6 @@ void do_tcl(char *whatzit, char *script)
   }
   }
 }
 }
 
 
-/* Interpret tcl file fname.
- *
- * returns:   1 - if everything was okay
- */
-int readtclprog(char *fname)
-{
-  int code, nc;
-
-  FILE	*f;
-  char *buf, *tptr, templine[8192], *temps;
-  char *horeting;
-
-  struct stat st;
-  /* Check whether file is readable. */
-  Context;
-  if ((f = fopen(fname, "r")) == NULL)
-    return 0;
-  fclose(f);
-
-  if (stat(fname, &st)) {
-    fatal("broken file", 0);
-  }
-
-  buf = nmalloc(st.st_size * 2.5);
-  *buf = 0;
-
-  f = fopen(fname, "r");
-  if (!f)
-    fatal("broken file", 0);
-
-  while(fgets(templine, sizeof(templine), f)) {
-    nc = 0;
-
-    if(strchr(templine, '\n')) {
-      tptr = templine;
-      while( (tptr = strchr(tptr, '\n')) ) {
-        nc++;
-        *tptr++ = 0;
-      }
-    }
-    horeting = decryptit(templine);
-    temps = (char *) decrypt_string(netpass, horeting);
-    strcat(buf, temps);
-    nfree(temps);
-    while (nc > 0) {
-      strcat(buf, "\n");
-      nc--;
-    }
-  }
-  code = Tcl_Eval(interp, buf);
-  if (code != TCL_OK) {
-    putlog(LOG_MISC, "*", "Tcl error in file '%s':", fname);
-    putlog(LOG_MISC, "*", "%s", Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY));
-    memset(buf, 0, st.st_size*2.5);
-    nfree(buf);
-    return 0;
-  }
-
-  memset(buf, 0, st.st_size*2.5);
-  nfree(buf);
-
-  /* Refresh internal variables */
-  return 1;
-
-}
-
 void add_tcl_strings(tcl_strings *list)
 void add_tcl_strings(tcl_strings *list)
 {
 {
   int i;
   int i;

+ 132 - 15
src/userent.c

@@ -266,6 +266,138 @@ struct user_entry_type USERENTRY_ADDED = {
   "ADDED"
   "ADDED"
 };
 };
 
 
+void add_cfg(struct cfg_entry *entry)
+{
+  cfg = (void *) user_realloc(cfg, sizeof(void *) * (cfg_count + 1));
+  cfg[cfg_count] = entry;
+  cfg_count++;
+  entry->ldata = NULL;
+  entry->gdata = NULL;
+}
+
+struct cfg_entry *check_can_set_cfg(char *target, char *entryname)
+{
+  int i;
+  struct userrec *u;
+  struct cfg_entry *entry = NULL;
+
+  for (i = 0; i < cfg_count; i++)
+    if (!strcmp(cfg[i]->name, entryname)) {
+      entry = cfg[i];
+      break;
+    }
+  if (!entry)
+    return 0;
+  if (target) {
+    if (!(entry->flags & CFGF_LOCAL))
+      return 0;
+    if (!(u = get_user_by_handle(userlist, target)))
+      return 0;
+    if (!(u->flags & USER_BOT))
+      return 0;
+  } else {
+    if (!(entry->flags & CFGF_GLOBAL))
+      return 0;
+  }
+  return entry;
+}
+
+void set_cfg_str(char *target, char *entryname, char *data)
+{
+  struct cfg_entry *entry;
+
+  if (!(entry = check_can_set_cfg(target, entryname)))
+    return;
+  if (data && !strcmp(data, "-"))
+    data = NULL;
+  if (data && (strlen(data) >= 1024))
+    data[1023] = 0;
+  if (target) {
+    struct userrec *u = get_user_by_handle(userlist, target);
+    struct xtra_key *xk;
+    char *olddata = entry->ldata;
+
+    if (u && !strcmp(botnetnick, u->handle)) {
+      if (data) {
+        entry->ldata = user_malloc(strlen(data) + 1);
+        strcpy(entry->ldata, data);
+      } else
+        entry->ldata = NULL;
+      if (entry->localchanged) {
+        int valid = 1;
+
+        entry->localchanged(entry, olddata, &valid);
+        if (!valid) {
+          if (entry->ldata)
+            nfree(entry->ldata);
+          entry->ldata = olddata;
+          data = olddata;
+          olddata = NULL;
+        }
+      }
+    }
+/* FIXME: this next line is not free`d? */
+    xk = user_malloc(sizeof(struct xtra_key));
+    egg_bzero(xk, sizeof(struct xtra_key));
+    xk->key = user_malloc(strlen(entry->name) + 1);
+    strcpy(xk->key, entry->name);
+    if (data) {
+      xk->data = user_malloc(strlen(data) + 1);
+      strcpy(xk->data, data);
+    }
+    set_user(&USERENTRY_CONFIG, u, xk);
+    if (olddata)
+      nfree(olddata);
+  } else {
+    char *olddata = entry->gdata;
+
+    if (data) {
+      entry->gdata = user_malloc(strlen(data) + 1);
+      strcpy(entry->gdata, data);
+    } else
+      entry->gdata = NULL;
+    if (entry->globalchanged) {
+      int valid = 1;
+
+      entry->globalchanged(entry, olddata, &valid);
+      if (!valid) {
+        if (entry->gdata)
+          nfree(entry->gdata);
+        entry->gdata = olddata;
+        olddata = NULL;
+      }
+    }
+    if (!cfg_noshare)
+      botnet_send_cfg_broad(-1, entry);
+    if (olddata)
+      nfree(olddata);
+  }
+}
+
+/* FIXME: possible expmem leak here */
+int config_expmem(struct user_entry *e)
+{
+  struct xtra_key *x;
+  int tot = 0, i;
+
+
+  for (i = 0; i < cfg_count; i++) {
+    tot += sizeof(void *);
+    if (cfg[i]->gdata)
+      tot += strlen(cfg[i]->gdata) + 1;
+    if (cfg[i]->ldata)
+      tot += strlen(cfg[i]->ldata) + 1;
+  }
+
+  for (x = e->u.extra; x; x = x->next) {
+    tot += sizeof(struct xtra_key);
+
+    tot += strlen(x->key) + 1;
+    tot += strlen(x->data) + 1;
+  }
+  return tot;
+}
+
 int config_set(struct userrec *u, struct user_entry *e, void *buf)
 int config_set(struct userrec *u, struct user_entry *e, void *buf)
 {
 {
   struct xtra_key *curr,
   struct xtra_key *curr,
@@ -464,21 +596,6 @@ int config_kill(struct user_entry *e)
   return 1;
   return 1;
 }
 }
 
 
-/* FIXME: possible expmem leak here */
-int config_expmem(struct user_entry *e)
-{
-  struct xtra_key *x;
-  int tot = 0;
-
-  for (x = e->u.extra; x; x = x->next) {
-    tot += sizeof(struct xtra_key);
-
-    tot += strlen(x->key) + 1;
-    tot += strlen(x->data) + 1;
-  }
-  return tot;
-}
-
 struct user_entry_type USERENTRY_CONFIG = {
 struct user_entry_type USERENTRY_CONFIG = {
   0,
   0,
   config_gotshare,
   config_gotshare,

+ 10 - 10
src/userrec.c

@@ -35,7 +35,7 @@ int		userfile_perm = 0600;	/* Userfile permissions,
 					   default rw-------		    */
 					   default rw-------		    */
 #ifdef S_DCCPASS
 #ifdef S_DCCPASS
 extern struct cmd_pass *cmdpass;
 extern struct cmd_pass *cmdpass;
-#endif
+#endif /* S_DCCPASS */
 
 
 
 
 void *_user_malloc(int size, const char *file, int line)
 void *_user_malloc(int size, const char *file, int line)
@@ -47,9 +47,9 @@ void *_user_malloc(int size, const char *file, int line)
   p = strrchr(file, '/');
   p = strrchr(file, '/');
   simple_sprintf(x, "xuserrec.c:%s", p ? p + 1 : file);
   simple_sprintf(x, "xuserrec.c:%s", p ? p + 1 : file);
   return n_malloc(size, x, line);
   return n_malloc(size, x, line);
-#else
+#else /* !DEBUG_MEM */
   return nmalloc(size);
   return nmalloc(size);
-#endif
+#endif /* DEBUG_MEM */
 }
 }
 
 
 void *_user_realloc(void *ptr, int size, const char *file, int line)
 void *_user_realloc(void *ptr, int size, const char *file, int line)
@@ -61,9 +61,9 @@ void *_user_realloc(void *ptr, int size, const char *file, int line)
   p = strrchr(file, '/');
   p = strrchr(file, '/');
   simple_sprintf(x, "xuserrec.c:%s", p ? p + 1 : file);
   simple_sprintf(x, "xuserrec.c:%s", p ? p + 1 : file);
   return n_realloc(ptr, size, x, line);
   return n_realloc(ptr, size, x, line);
-#else
+#else /* !DEBUG_MEM */
   return nrealloc(ptr, size);
   return nrealloc(ptr, size);
-#endif
+#endif /* DEBUG_MEM */
 }
 }
 
 
 inline int expmem_mask(struct maskrec *m)
 inline int expmem_mask(struct maskrec *m)
@@ -867,7 +867,7 @@ struct cfg_entry
   CFG_MEANDEOP,
   CFG_MEANDEOP,
   CFG_MEANKICK,
   CFG_MEANKICK,
   CFG_MEANBAN,
   CFG_MEANBAN,
-#endif
+#endif /* G_MEAN */
   CFG_MDOP;
   CFG_MDOP;
 
 
 int deflag_dontshare=0;
 int deflag_dontshare=0;
@@ -892,7 +892,7 @@ void deflag_describe(struct cfg_entry *cfgent, int idx)
     dprintf(idx, STR("mean-kick decides what happens to a user kicking a bot in a +mean channel\n"));
     dprintf(idx, STR("mean-kick decides what happens to a user kicking a bot in a +mean channel\n"));
   else if (cfgent==&CFG_MEANBAN)
   else if (cfgent==&CFG_MEANBAN)
     dprintf(idx, STR("mean-ban decides what happens to a user banning a bot in a +mean channel\n"));
     dprintf(idx, STR("mean-ban decides what happens to a user banning a bot in a +mean channel\n"));
-#endif
+#endif /* G_MEAN */
   else if (cfgent==&CFG_MDOP)
   else if (cfgent==&CFG_MDOP)
     dprintf(idx, STR("mdop decides what happens to a user doing a mass deop\n"));
     dprintf(idx, STR("mdop decides what happens to a user doing a mass deop\n"));
   dprintf(idx, STR("Valid settings are: ignore (No flag changes), deop (set flags to +d), kick (set flags to +dk) or delete (remove from userlist)\n"));
   dprintf(idx, STR("Valid settings are: ignore (No flag changes), deop (set flags to +d), kick (set flags to +dk) or delete (remove from userlist)\n"));
@@ -942,7 +942,7 @@ struct cfg_entry CFG_MEANBAN = {
   NULL,
   NULL,
   deflag_describe
   deflag_describe
 };
 };
-#endif
+#endif /* G_MEAN */
 
 
 struct cfg_entry CFG_MDOP = {
 struct cfg_entry CFG_MDOP = {
   "mdop", CFGF_GLOBAL, NULL, NULL,
   "mdop", CFGF_GLOBAL, NULL, NULL,
@@ -985,7 +985,7 @@ void deflag_user(struct userrec *u, int why, char *msg, struct chanset_t *chan)
     strcpy(tmp, STR("Banned bot in +mean channel"));
     strcpy(tmp, STR("Banned bot in +mean channel"));
     ent=&CFG_MEANDEOP;
     ent=&CFG_MEANDEOP;
     break;
     break;
-#endif
+#endif /* G_MEAN */
   case DEFLAG_MDOP:
   case DEFLAG_MDOP:
     strcpy(tmp, STR("Mass deop"));
     strcpy(tmp, STR("Mass deop"));
     ent=&CFG_MDOP;
     ent=&CFG_MDOP;
@@ -1027,7 +1027,7 @@ void init_userrec() {
   add_cfg(&CFG_MEANDEOP);
   add_cfg(&CFG_MEANDEOP);
   add_cfg(&CFG_MEANKICK);
   add_cfg(&CFG_MEANKICK);
   add_cfg(&CFG_MEANBAN);
   add_cfg(&CFG_MEANBAN);
-#endif
+#endif /* G_MEAN */
   add_cfg(&CFG_MDOP);
   add_cfg(&CFG_MDOP);
 }
 }
 
 

+ 2 - 4
src/users.c

@@ -733,10 +733,9 @@ Context;
 		restore_ignore(s);
 		restore_ignore(s);
 #ifdef S_DCCPASS
 #ifdef S_DCCPASS
               else if (lasthand[1] == CONFIG_NAME[1]) {
               else if (lasthand[1] == CONFIG_NAME[1]) {
-Context;
                 set_cmd_pass(s, 1);
                 set_cmd_pass(s, 1);
               }
               }
-#endif
+#endif /* S_DCCPASS */
 	      else
 	      else
 		restore_chanban(NULL, s);
 		restore_chanban(NULL, s);
 	    } else if (lasthand[0])
 	    } else if (lasthand[0])
@@ -1013,10 +1012,9 @@ Context;
       }
       }
   }
   }
   /* process the user data *now* */
   /* process the user data *now* */
-Context;
 #ifdef LEAF
 #ifdef LEAF
   unlink(userfile);
   unlink(userfile);
-#endif
+#endif /* LEAF */
   return 1;
   return 1;
 }
 }
 
 

+ 2 - 2
src/users.h

@@ -56,7 +56,7 @@ extern struct user_entry_type USERENTRY_COMMENT, USERENTRY_LASTON,
   USERENTRY_CONFIG,
   USERENTRY_CONFIG,
   USERENTRY_SECPASS,
   USERENTRY_SECPASS,
   USERENTRY_XTRA;
   USERENTRY_XTRA;
-#endif
+#endif /* MAKING_MODS */
 
 
 
 
 struct laston_info {
 struct laston_info {
@@ -104,7 +104,7 @@ void *_user_realloc(void *ptr, int size, const char *file, int line);
 #ifndef MAKING_MODS
 #ifndef MAKING_MODS
 #  define user_malloc(x)	_user_malloc(x, __FILE__, __LINE__)
 #  define user_malloc(x)	_user_malloc(x, __FILE__, __LINE__)
 #  define user_realloc(x, y)	_user_realloc(x, y, __FILE__, __LINE__)
 #  define user_realloc(x, y)	_user_realloc(x, y, __FILE__, __LINE__)
-#endif
+#endif /* MAKING_MODS */
 
 
 int add_entry_type(struct user_entry_type *);
 int add_entry_type(struct user_entry_type *);
 int del_entry_type(struct user_entry_type *);
 int del_entry_type(struct user_entry_type *);