فهرست منبع

* Eliminated the conffile struct as it was a duplicate of conf
conf.bots is free'd if !localhub


svn: 1794

Bryan Drewery 21 سال پیش
والد
کامیت
a966a3b564
6فایلهای تغییر یافته به همراه166 افزوده شده و 179 حذف شده
  1. 1 0
      doc/UPDATES
  2. 26 26
      src/cmds.c
  3. 126 140
      src/conf.c
  4. 4 4
      src/conf.h
  5. 8 8
      src/main.c
  6. 1 1
      src/shell.c

+ 1 - 0
doc/UPDATES

@@ -19,6 +19,7 @@ Lines prefixxed with '-' were disabled before release and are not finishsed.
 * cmd_deluser change: only allow a |m user to remove users whom they have added.
 * cmd_deluser change: only allow a |m user to remove users whom they have added.
 * Fixed some botnet userfile sharing logs showing up on leaf bots.
 * Fixed some botnet userfile sharing logs showing up on leaf bots.
 * cmd_botconfig now supports wildcards for the bot parameter
 * cmd_botconfig now supports wildcards for the bot parameter
+* Eliminated a duplicate struct (conffile)
 
 
 1.2.2
 1.2.2
 * Don't sanity check flags for users on DCC CHAT if they are on the bot via .botcmd.
 * Don't sanity check flags for users on DCC CHAT if they are on the bot via .botcmd.

+ 26 - 26
src/cmds.c

@@ -1823,19 +1823,19 @@ static void cmd_conf(int idx, char *par)
       if (par[0] && what) { /* set */
       if (par[0] && what) { /* set */
         set++;
         set++;
         save = 1;
         save = 1;
-/*        if (!egg_strcasecmp(what, "uid"))            conffile.uid = atoi(par);
-        else if (!egg_strcasecmp(what, "uname"))     str_redup(&conffile.uname, par);
-        else if (!egg_strcasecmp(what, "username"))  str_redup(&conffile.username, par);
+/*        if (!egg_strcasecmp(what, "uid"))            conf.uid = atoi(par);
+        else if (!egg_strcasecmp(what, "uname"))     str_redup(&conf.uname, par);
+        else if (!egg_strcasecmp(what, "username"))  str_redup(&conf.username, par);
 */
 */
-        if (!egg_strcasecmp(what, "homedir"))   str_redup(&conffile.homedir, par);
-        else if (!egg_strcasecmp(what, "binpath"))   str_redup(&conffile.binpath, par);
-        else if (!egg_strcasecmp(what, "binname"))   str_redup(&conffile.binname, par);
-        else if (!egg_strcasecmp(what, "portmin"))   conffile.portmin = atoi(par);
-        else if (!egg_strcasecmp(what, "portmax"))   conffile.portmax = atoi(par);
-        else if (!egg_strcasecmp(what, "pscloak"))   conffile.pscloak = atoi(par);
-        else if (!egg_strcasecmp(what, "autocron"))  conffile.autocron = atoi(par);
-        else if (!egg_strcasecmp(what, "autouname")) conffile.autouname = atoi(par);
-        else if (!egg_strcasecmp(what, "watcher"))  conffile.watcher = atoi(par);
+        if (!egg_strcasecmp(what, "homedir"))   str_redup(&conf.homedir, par);
+        else if (!egg_strcasecmp(what, "binpath"))   str_redup(&conf.binpath, par);
+        else if (!egg_strcasecmp(what, "binname"))   str_redup(&conf.binname, par);
+        else if (!egg_strcasecmp(what, "portmin"))   conf.portmin = atoi(par);
+        else if (!egg_strcasecmp(what, "portmax"))   conf.portmax = atoi(par);
+        else if (!egg_strcasecmp(what, "pscloak"))   conf.pscloak = atoi(par);
+        else if (!egg_strcasecmp(what, "autocron"))  conf.autocron = atoi(par);
+        else if (!egg_strcasecmp(what, "autouname")) conf.autouname = atoi(par);
+        else if (!egg_strcasecmp(what, "watcher"))  conf.watcher = atoi(par);
         else { 
         else { 
           set--;
           set--;
           save = 0;
           save = 0;
@@ -1846,19 +1846,19 @@ static void cmd_conf(int idx, char *par)
     if (show) {
     if (show) {
       const char *ss = set ? "Set: " : "";
       const char *ss = set ? "Set: " : "";
       
       
-/*      if (!what || !egg_strcasecmp(what, "uid"))        dprintf(idx, "%suid: %d\n", ss, conffile.uid);
-      if (!what || !egg_strcasecmp(what, "uname"))      dprintf(idx, "%suname: %s\n", ss, conffile.uname);
-      if (!what || !egg_strcasecmp(what, "username"))   dprintf(idx, "%susername: %s\n", ss, conffile.username);
+/*      if (!what || !egg_strcasecmp(what, "uid"))        dprintf(idx, "%suid: %d\n", ss, conf.uid);
+      if (!what || !egg_strcasecmp(what, "uname"))      dprintf(idx, "%suname: %s\n", ss, conf.uname);
+      if (!what || !egg_strcasecmp(what, "username"))   dprintf(idx, "%susername: %s\n", ss, conf.username);
 */
 */
-      if (!what || !egg_strcasecmp(what, "homedir"))    dprintf(idx, "%shomedir: %s\n", ss, conffile.homedir);
-      if (!what || !egg_strcasecmp(what, "binpath"))    dprintf(idx, "%sbinpath: %s\n", ss, conffile.binpath);
-      if (!what || !egg_strcasecmp(what, "binname"))    dprintf(idx, "%sbinname: %s\n", ss, conffile.binname);
-      if (!what || !egg_strcasecmp(what, "portmin"))    dprintf(idx, "%sportmin: %d\n", ss, conffile.portmin);
-      if (!what || !egg_strcasecmp(what, "portmax"))    dprintf(idx, "%sportmax: %d\n", ss, conffile.portmax);
-      if (!what || !egg_strcasecmp(what, "pscloak"))    dprintf(idx, "%spscloak: %d\n", ss, conffile.pscloak);
-      if (!what || !egg_strcasecmp(what, "autocron"))   dprintf(idx, "%sautocron: %d\n", ss, conffile.autocron);
-      if (!what || !egg_strcasecmp(what, "autouname"))  dprintf(idx, "%sautouname: %d\n", ss, conffile.autouname);
-      if (!what || !egg_strcasecmp(what, "watcher"))    dprintf(idx, "%swatcher: %d\n", ss, conffile.watcher);
+      if (!what || !egg_strcasecmp(what, "homedir"))    dprintf(idx, "%shomedir: %s\n", ss, conf.homedir);
+      if (!what || !egg_strcasecmp(what, "binpath"))    dprintf(idx, "%sbinpath: %s\n", ss, conf.binpath);
+      if (!what || !egg_strcasecmp(what, "binname"))    dprintf(idx, "%sbinname: %s\n", ss, conf.binname);
+      if (!what || !egg_strcasecmp(what, "portmin"))    dprintf(idx, "%sportmin: %d\n", ss, conf.portmin);
+      if (!what || !egg_strcasecmp(what, "portmax"))    dprintf(idx, "%sportmax: %d\n", ss, conf.portmax);
+      if (!what || !egg_strcasecmp(what, "pscloak"))    dprintf(idx, "%spscloak: %d\n", ss, conf.pscloak);
+      if (!what || !egg_strcasecmp(what, "autocron"))   dprintf(idx, "%sautocron: %d\n", ss, conf.autocron);
+      if (!what || !egg_strcasecmp(what, "autouname"))  dprintf(idx, "%sautouname: %d\n", ss, conf.autouname);
+      if (!what || !egg_strcasecmp(what, "watcher"))    dprintf(idx, "%swatcher: %d\n", ss, conf.watcher);
     }
     }
   }
   }
 #endif /* !CYGWIN_HACKS || HUB */
 #endif /* !CYGWIN_HACKS || HUB */
@@ -1868,7 +1868,7 @@ static void cmd_conf(int idx, char *par)
     conf_bot *bot = NULL;
     conf_bot *bot = NULL;
     unsigned int i = 0;
     unsigned int i = 0;
 
 
-    for (bot = conffile.bots; bot && bot->nick; bot = bot->next) {
+    for (bot = conf.bots; bot && bot->nick; bot = bot->next) {
       i++;
       i++;
       if (!listbot || (listbot && !strcmp(listbot, bot->nick)))
       if (!listbot || (listbot && !strcmp(listbot, bot->nick)))
         dprintf(idx, "%d: %s IP: %s HOST: %s IP6: %s HOST6: %s PID: %d\n", i,
         dprintf(idx, "%d: %s IP: %s HOST: %s IP6: %s HOST6: %s PID: %d\n", i,
@@ -1887,7 +1887,7 @@ static void cmd_conf(int idx, char *par)
   if (save) {
   if (save) {
     write_settings(binname, -1);
     write_settings(binname, -1);
 #ifdef LEAF
 #ifdef LEAF
-    spawnbots();			/* parse conffile struct and spawn/kill as needed */
+    spawnbots();			/* parse conf struct and spawn/kill as needed */
 #endif /* LEAF */
 #endif /* LEAF */
   }
   }
 }
 }

+ 126 - 140
src/conf.c

@@ -28,7 +28,6 @@
 char cfile[DIRMAX] = "";
 char cfile[DIRMAX] = "";
 #endif /* CYGWIN_HACKS */
 #endif /* CYGWIN_HACKS */
 conf_t conf;                    /* global conf struct */
 conf_t conf;                    /* global conf struct */
-conf_t conffile;                /* just some config options only avail during loading */
 
 
 static void
 static void
 tellconf(conf_t * inconf)
 tellconf(conf_t * inconf)
@@ -93,7 +92,7 @@ spawnbots()
 {
 {
   conf_bot *bot = NULL;
   conf_bot *bot = NULL;
 
 
-  for (bot = conffile.bots; bot && bot->nick; bot = bot->next) {
+  for (bot = conf.bots; bot && bot->nick; bot = bot->next) {
     sdprintf("checking bot: %s", bot->nick);
     sdprintf("checking bot: %s", bot->nick);
 
 
     if (bot->nick[0] == '/') {
     if (bot->nick[0] == '/') {
@@ -127,7 +126,7 @@ killbot(char *botnick, int signal)
 {
 {
   conf_bot *bot = NULL;
   conf_bot *bot = NULL;
 
 
-  for (bot = conffile.bots; bot && bot->nick; bot = bot->next) {
+  for (bot = conf.bots; bot && bot->nick; bot = bot->next) {
     if (bot->nick[0] == '/')
     if (bot->nick[0] == '/')
       continue;
       continue;
     else if (!egg_strcasecmp(botnick, bot->nick)) {
     else if (!egg_strcasecmp(botnick, bot->nick)) {
@@ -255,7 +254,7 @@ confedit()
     fatal("Error reading new config file", 0);
     fatal("Error reading new config file", 0);
   readconf((const char *) tmpconf.file, 0);               /* read cleartext conf tmp into &settings */
   readconf((const char *) tmpconf.file, 0);               /* read cleartext conf tmp into &settings */
   unlink(tmpconf.file);
   unlink(tmpconf.file);
-  conf_to_bin(&conffile, 0);       /* will exit */
+  conf_to_bin(&conf, 0);	/* will exit */
   exit(0);                      /* never reached */
   exit(0);                      /* never reached */
 
 
 fatal:
 fatal:
@@ -265,32 +264,32 @@ fatal:
 #endif /* !CYGWIN_HACKS */
 #endif /* !CYGWIN_HACKS */
 
 
 void
 void
-init_conffile()
+init_conf()
 {
 {
-  conffile.bots = (conf_bot *) my_calloc(1, sizeof(conf_bot));
-  conffile.bots->nick = NULL;
-  conffile.bots->next = NULL;
-  conffile.bot = NULL;
+  conf.bots = (conf_bot *) my_calloc(1, sizeof(conf_bot));
+  conf.bots->nick = NULL;
+  conf.bots->next = NULL;
+  conf.bot = NULL;
 
 
-  conffile.watcher = 0;
+  conf.watcher = 0;
 #ifdef CYGWIN_HACKS
 #ifdef CYGWIN_HACKS
-  conffile.autocron = 0;
+  conf.autocron = 0;
 #else
 #else
-  conffile.autocron = 1;
+  conf.autocron = 1;
 #endif /* !CYGWIN_HACKS */
 #endif /* !CYGWIN_HACKS */
-  conffile.autouname = 0;
+  conf.autouname = 0;
 #ifdef CYGWIN_HACKS
 #ifdef CYGWIN_HACKS
-  conffile.binpath = strdup(homedir());
+  conf.binpath = strdup(homedir());
 #else /* !CYGWIN_HACKS */
 #else /* !CYGWIN_HACKS */
 #  ifdef LEAF
 #  ifdef LEAF
-  conffile.binpath = strdup(STR("~/"));
+  conf.binpath = strdup(STR("~/"));
 #  endif /* LEAF */
 #  endif /* LEAF */
 #  ifdef HUB
 #  ifdef HUB
-  conffile.binpath = strdup(dirname(binname));
+  conf.binpath = strdup(dirname(binname));
 #  endif /* HUB */
 #  endif /* HUB */
 #endif /* CYGWIN_HACKS */
 #endif /* CYGWIN_HACKS */
 //#ifdef LEAF
 //#ifdef LEAF
-//  conffile.binname = strdup(STR(".sshrc"));
+//  conf.binname = strdup(STR(".sshrc"));
 //#endif /* LEAF */
 //#endif /* LEAF */
 //#ifdef HUB
 //#ifdef HUB
 //  {
 //  {
@@ -298,16 +297,16 @@ init_conffile()
 
 
     p = strrchr(binname, '/');
     p = strrchr(binname, '/');
     p++;
     p++;
-    conffile.binname = strdup(p);
+    conf.binname = strdup(p);
 //  }
 //  }
 //#endif /* HUB */
 //#endif /* HUB */
-  conffile.portmin = 0;
-  conffile.portmax = 0;
-  conffile.pscloak = 0;
-  conffile.uid = 0;
-  conffile.uname = NULL;
-  conffile.username = NULL;
-  conffile.homedir = NULL;
+  conf.portmin = 0;
+  conf.portmax = 0;
+  conf.pscloak = 0;
+  conf.uid = 0;
+  conf.uname = NULL;
+  conf.username = NULL;
+  conf.homedir = NULL;
 }
 }
 
 
 /*
 /*
@@ -364,16 +363,16 @@ conf_addbot(char *nick, char *ip, char *host, char *ip6)
 {
 {
   conf_bot *bot = NULL;
   conf_bot *bot = NULL;
 
 
-  for (bot = conffile.bots; bot && bot->nick; bot = bot->next) ;
+  for (bot = conf.bots; bot && bot->nick; bot = bot->next) ;
 
 
   bot->next = (conf_bot *) my_calloc(1, sizeof(conf_bot));
   bot->next = (conf_bot *) my_calloc(1, sizeof(conf_bot));
   bot->next->next = NULL;
   bot->next->next = NULL;
   bot->pid_file = NULL;
   bot->pid_file = NULL;
   bot->nick = strdup(nick);
   bot->nick = strdup(nick);
 #ifdef LEAF
 #ifdef LEAF
-  if (bot == conffile.bots) {
+  if (bot == conf.bots) {
     bot->localhub = 1;          /* first bot */
     bot->localhub = 1;          /* first bot */
-    conffile.localhub = strdup(nick ? nick : origbotname);
+    conf.localhub = strdup(nick ? nick : origbotname);
     /* perhaps they did -B localhub-bot ? */
     /* perhaps they did -B localhub-bot ? */
     if (origbotname[0] && !strcmp(origbotname, bot->nick))
     if (origbotname[0] && !strcmp(origbotname, bot->nick))
       localhub = 1;
       localhub = 1;
@@ -426,7 +425,7 @@ free_bot(char *botn)
 {
 {
   conf_bot *bot = NULL, *old = NULL;
   conf_bot *bot = NULL, *old = NULL;
 
 
-  for (bot = conffile.bots; bot && bot->nick; old = bot, bot = bot->next) {
+  for (bot = conf.bots; bot && bot->nick; old = bot, bot = bot->next) {
     if (!strcmp(botn, bot->nick)) {
     if (!strcmp(botn, bot->nick)) {
       free(bot->nick);
       free(bot->nick);
       free(bot->pid_file);
       free(bot->pid_file);
@@ -442,7 +441,7 @@ free_bot(char *botn)
       if (old)
       if (old)
         old->next = bot->next;
         old->next = bot->next;
       else
       else
-        conffile.bots = bot->next;
+        conf.bots = bot->next;
       free(bot);
       free(bot);
 
 
       break;
       break;
@@ -456,7 +455,7 @@ conf_delbot(char *botn)
 {
 {
   conf_bot *bot = NULL;
   conf_bot *bot = NULL;
 
 
-  for (bot = conffile.bots; bot && bot->nick; bot = bot->next) {
+  for (bot = conf.bots; bot && bot->nick; bot = bot->next) {
     if (!strcmp(bot->nick, botn)) {     /* found it! */
     if (!strcmp(bot->nick, botn)) {     /* found it! */
       bot->pid = checkpid(bot->nick, bot);
       bot->pid = checkpid(bot->nick, bot);
       killbot(bot->nick, SIGKILL);
       killbot(bot->nick, SIGKILL);
@@ -468,61 +467,58 @@ conf_delbot(char *botn)
 }
 }
 #endif /* LEAF */
 #endif /* LEAF */
 
 
-static void
-free_conffile_bots(void)
+void
+free_conf_bots(void)
 {
 {
   conf_bot *bot = NULL, *bot_n = NULL;
   conf_bot *bot = NULL, *bot_n = NULL;
 
 
-  for (bot = conffile.bots; bot; bot = bot_n) {
+  for (bot = conf.bots; bot; bot = bot_n) {
     bot_n = bot->next;
     bot_n = bot->next;
+
     free_bot(bot->nick);
     free_bot(bot->nick);
   }
   }
-}
-
-void free_conffile(void)
-{
-  free_conffile_bots();
-  free(conffile.uname);
-  free(conffile.username);
-  free(conffile.homedir);
-  free(conffile.binname);
-  free(conffile.binpath);
+  if (conf.bots) {
+    if (!conf.bots->next)
+      free(conf.bots);
+    else
+      sdprintf("FAILED TO CLEAR ALL OF .bots!, MEMORY LEAK!\n");
+  }
 }
 }
 
 
 int
 int
 parseconf(bool error)
 parseconf(bool error)
 {
 {
-  if (error && !conffile.bots->nick && !conffile.bots->next)     /* no bots ! */
+  if (error && !conf.bots->nick && !conf.bots->next)     /* no bots ! */
     werr(ERR_NOBOTS);
     werr(ERR_NOBOTS);
 
 
-  if (conffile.username) {
-    str_redup(&conffile.username, my_username());
+  if (conf.username) {
+    str_redup(&conf.username, my_username());
   } else {
   } else {
-    conffile.username = strdup(my_username());
+    conf.username = strdup(my_username());
   }
   }
 
 
 #ifndef CYGWIN_HACKS
 #ifndef CYGWIN_HACKS
-  if (error && conffile.uid && conffile.uid != myuid) {
-    sdprintf("wrong uid, conf: %d :: %d", conffile.uid, myuid);
+  if (error && conf.uid && conf.uid != myuid) {
+    sdprintf("wrong uid, conf: %d :: %d", conf.uid, myuid);
     werr(ERR_WRONGUID);
     werr(ERR_WRONGUID);
-  } else if (!conffile.uid)
-    conffile.uid = myuid;
+  } else if (!conf.uid)
+    conf.uid = myuid;
 
 
-  if (conffile.uname && strcmp(conffile.uname, my_uname()) && !conffile.autouname) {
-    baduname(conffile.uname, my_uname());       /* its not auto, and its not RIGHT, bail out. */
-    sdprintf("wrong uname, conf: %s :: %s", conffile.uname, my_uname());
+  if (conf.uname && strcmp(conf.uname, my_uname()) && !conf.autouname) {
+    baduname(conf.uname, my_uname());       /* its not auto, and its not RIGHT, bail out. */
+    sdprintf("wrong uname, conf: %s :: %s", conf.uname, my_uname());
     if (error)
     if (error)
       werr(ERR_WRONGUNAME);
       werr(ERR_WRONGUNAME);
-  } else if (conffile.uname && conffile.autouname) {    /* if autouname, dont bother comparing, just set uname to output */
-    str_redup(&conffile.uname, my_uname());
-  } else if (!conffile.uname) { /* if not set, then just set it, wont happen again next time... */
-    conffile.uname = strdup(my_uname());
+  } else if (conf.uname && conf.autouname) {    /* if autouname, dont bother comparing, just set uname to output */
+    str_redup(&conf.uname, my_uname());
+  } else if (!conf.uname) { /* if not set, then just set it, wont happen again next time... */
+    conf.uname = strdup(my_uname());
   }
   }
 
 
-  if (conffile.homedir) {
-    str_redup(&conffile.homedir, homedir());
+  if (conf.homedir) {
+    str_redup(&conf.homedir, homedir());
   } else {
   } else {
-    conffile.homedir = strdup(homedir());
+    conf.homedir = strdup(homedir());
   }
   }
 
 
 #endif /* !CYGWIN_HACKS */
 #endif /* !CYGWIN_HACKS */
@@ -569,14 +565,14 @@ readconf(const char *fname, int bits)
       /* - uid */
       /* - uid */
       if (line[0] == '-') {
       if (line[0] == '-') {
         newsplit(&line);
         newsplit(&line);
-        if (!conffile.uid)
-          conffile.uid = atoi(line);
+        if (!conf.uid)
+          conf.uid = atoi(line);
 
 
         /* + uname */
         /* + uname */
       } else if (line[0] == '+') {
       } else if (line[0] == '+') {
         newsplit(&line);
         newsplit(&line);
-        if (!conffile.uname)
-          conffile.uname = strdup(line);
+        if (!conf.uname)
+          conf.uname = strdup(line);
 
 
         /* ! is misc options */
         /* ! is misc options */
       } else if (line[0] == '!') {
       } else if (line[0] == '!') {
@@ -591,49 +587,49 @@ readconf(const char *fname, int bits)
 
 
         if (!strcmp(option, "autocron")) {      /* automatically check/create crontab? */
         if (!strcmp(option, "autocron")) {      /* automatically check/create crontab? */
           if (egg_isdigit(line[0]))
           if (egg_isdigit(line[0]))
-            conffile.autocron = atoi(line);
+            conf.autocron = atoi(line);
 
 
         } else if (!strcmp(option, "autouname")) {      /* auto update uname contents? */
         } else if (!strcmp(option, "autouname")) {      /* auto update uname contents? */
           if (egg_isdigit(line[0]))
           if (egg_isdigit(line[0]))
-            conffile.autouname = atoi(line);
+            conf.autouname = atoi(line);
 
 
         } else if (!strcmp(option, "username")) {       /* shell username */
         } else if (!strcmp(option, "username")) {       /* shell username */
-          conffile.username = strdup(line);
+          conf.username = strdup(line);
 
 
         } else if (!strcmp(option, "homedir")) {        /* homedir */
         } else if (!strcmp(option, "homedir")) {        /* homedir */
-          conffile.homedir = strdup(line);
+          conf.homedir = strdup(line);
 
 
         } else if (!strcmp(option, "binpath")) {        /* path that the binary should move to? */
         } else if (!strcmp(option, "binpath")) {        /* path that the binary should move to? */
-          str_redup(&conffile.binpath, line);
+          str_redup(&conf.binpath, line);
 
 
         } else if (!strcmp(option, "binname")) {        /* filename of the binary? */
         } else if (!strcmp(option, "binname")) {        /* filename of the binary? */
-          str_redup(&conffile.binname, line);
+          str_redup(&conf.binname, line);
 
 
         } else if (!strcmp(option, "portmin")) {
         } else if (!strcmp(option, "portmin")) {
           if (egg_isdigit(line[0]))
           if (egg_isdigit(line[0]))
-            conffile.portmin = atoi(line);
+            conf.portmin = atoi(line);
 
 
         } else if (!strcmp(option, "portmax")) {
         } else if (!strcmp(option, "portmax")) {
           if (egg_isdigit(line[0]))
           if (egg_isdigit(line[0]))
-            conffile.portmax = atoi(line);
+            conf.portmax = atoi(line);
 
 
         } else if (!strcmp(option, "pscloak")) {        /* should bots on this shell pscloak? */
         } else if (!strcmp(option, "pscloak")) {        /* should bots on this shell pscloak? */
           if (egg_isdigit(line[0]))
           if (egg_isdigit(line[0]))
-            conffile.pscloak = atoi(line);
+            conf.pscloak = atoi(line);
 
 
         } else if (!strcmp(option, "uid")) {    /* new method uid */
         } else if (!strcmp(option, "uid")) {    /* new method uid */
           if (egg_isdigit(line[0]))
           if (egg_isdigit(line[0]))
-            conffile.uid = atoi(line);
+            conf.uid = atoi(line);
 
 
         } else if (!strcmp(option, "uname")) {  /* new method uname */
         } else if (!strcmp(option, "uname")) {  /* new method uname */
-          if (!conffile.uname)
-            conffile.uname = strdup(line);
+          if (!conf.uname)
+            conf.uname = strdup(line);
           else
           else
-            str_redup(&conffile.uname, line);
+            str_redup(&conf.uname, line);
 
 
         } else if (!strcmp(option, "watcher")) {
         } else if (!strcmp(option, "watcher")) {
           if (egg_isdigit(line[0]))
           if (egg_isdigit(line[0]))
-            conffile.watcher = atoi(line);
+            conf.watcher = atoi(line);
 
 
         } else {
         } else {
           putlog(LOG_MISC, "*", "Unrecognized config option '%s'", option);
           putlog(LOG_MISC, "*", "Unrecognized config option '%s'", option);
@@ -642,11 +638,11 @@ readconf(const char *fname, int bits)
         /* read in portmin */
         /* read in portmin */
       } else if (line[0] == '>') {
       } else if (line[0] == '>') {
         newsplit(&line);
         newsplit(&line);
-        conffile.portmin = atoi(line);
+        conf.portmin = atoi(line);
 
 
       } else if (line[0] == '<') {
       } else if (line[0] == '<') {
         newsplit(&line);
         newsplit(&line);
-        conffile.portmax = atoi(line);
+        conf.portmax = atoi(line);
 
 
         /* now to parse nick/hosts */
         /* now to parse nick/hosts */
       } else if (line[0] != '#') {
       } else if (line[0] != '#') {
@@ -703,66 +699,66 @@ writeconf(char *filename, FILE * stream, int bits)
   comment("# Lines beginning with # are what the preceeding line SHOULD be");
   comment("# Lines beginning with # are what the preceeding line SHOULD be");
   comment("# They are simply comments and are not parsed at all.\n");
   comment("# They are simply comments and are not parsed at all.\n");
 
 
-  my_write(f, "! uid %d\n", conffile.uid);
+  my_write(f, "! uid %d\n", conf.uid);
 
 
-  if ((bits & CONF_COMMENT) && conffile.uid != myuid)
+  if ((bits & CONF_COMMENT) && conf.uid != myuid)
     my_write(f, "#! uid %d\n\n", myuid);
     my_write(f, "#! uid %d\n\n", myuid);
 
 
-  if (!conffile.uname || (conffile.uname && conffile.autouname && strcmp(conffile.uname, my_uname()))) {
+  if (!conf.uname || (conf.uname && conf.autouname && strcmp(conf.uname, my_uname()))) {
     comment("# Automatic");
     comment("# Automatic");
     my_write(f, "! uname %s\n", my_uname());
     my_write(f, "! uname %s\n", my_uname());
-  } else if (conffile.uname && !conffile.autouname && strcmp(conffile.uname, my_uname())) {
-    my_write(f, "! uname %s\n", conffile.uname);
+  } else if (conf.uname && !conf.autouname && strcmp(conf.uname, my_uname())) {
+    my_write(f, "! uname %s\n", conf.uname);
     comment("# autouname is OFF");
     comment("# autouname is OFF");
     my_write(f, "#! uname %s\n\n", my_uname());
     my_write(f, "#! uname %s\n\n", my_uname());
   } else
   } else
-    my_write(f, "! uname %s\n", conffile.uname);
+    my_write(f, "! uname %s\n", conf.uname);
 
 
-  my_write(f, "! username %s\n", conffile.username ? conffile.username : my_username());
-  if (conffile.username && strcmp(conffile.username, my_username()))
+  my_write(f, "! username %s\n", conf.username ? conf.username : my_username());
+  if (conf.username && strcmp(conf.username, my_username()))
     my_write(f, "#! username %s\n", my_username());
     my_write(f, "#! username %s\n", my_username());
 
 
-  my_write(f, "! homedir %s\n", conffile.homedir ? conffile.homedir : homedir());
-  if (conffile.homedir && strcmp(conffile.homedir, homedir()))
+  my_write(f, "! homedir %s\n", conf.homedir ? conf.homedir : homedir());
+  if (conf.homedir && strcmp(conf.homedir, homedir()))
     my_write(f, "#! homedir %s\n", homedir());
     my_write(f, "#! homedir %s\n", homedir());
 
 
   comment("\n# binpath needs to be full path unless it begins with '~', which uses 'homedir', ie, '~/'");
   comment("\n# binpath needs to be full path unless it begins with '~', which uses 'homedir', ie, '~/'");
 
 
-  if (strstr(conffile.binpath, homedir())) {
-    p = replace(conffile.binpath, homedir(), "~");
+  if (strstr(conf.binpath, homedir())) {
+    p = replace(conf.binpath, homedir(), "~");
     my_write(f, "! binpath %s\n", p);
     my_write(f, "! binpath %s\n", p);
   } else
   } else
-    my_write(f, "! binpath %s\n", conffile.binpath);
+    my_write(f, "! binpath %s\n", conf.binpath);
 
 
   comment
   comment
     ("# binname is relative to binpath, if you change this, you'll need to manually remove the old one from crontab.");
     ("# binname is relative to binpath, if you change this, you'll need to manually remove the old one from crontab.");
-  my_write(f, "! binname %s\n", conffile.binname);
+  my_write(f, "! binname %s\n", conf.binname);
 
 
   comment("");
   comment("");
 
 
   comment("# portmin/max are for incoming connections (DCC) [0 for any]");
   comment("# portmin/max are for incoming connections (DCC) [0 for any]");
-  my_write(f, "! portmin %d\n", conffile.portmin);
-  my_write(f, "! portmax %d\n", conffile.portmax);
+  my_write(f, "! portmin %d\n", conf.portmin);
+  my_write(f, "! portmax %d\n", conf.portmax);
 
 
   comment("");
   comment("");
 
 
   comment("# Attempt to \"cloak\" the process name in `ps` for Linux?");
   comment("# Attempt to \"cloak\" the process name in `ps` for Linux?");
-  my_write(f, "! pscloak %d\n", conffile.pscloak);
+  my_write(f, "! pscloak %d\n", conf.pscloak);
 
 
   comment("");
   comment("");
 
 
   comment("# Automatically add the bot to crontab?");
   comment("# Automatically add the bot to crontab?");
-  my_write(f, "! autocron %d\n", conffile.autocron);
+  my_write(f, "! autocron %d\n", conf.autocron);
 
 
   comment("");
   comment("");
 
 
   comment("# Automatically update 'uname' if it changes? (DANGEROUS)");
   comment("# Automatically update 'uname' if it changes? (DANGEROUS)");
-  my_write(f, "! autouname %d\n", conffile.autouname);
+  my_write(f, "! autouname %d\n", conf.autouname);
 
 
   comment("");
   comment("");
 
 
   comment("# This will spawn a child process for EACH BOT that will block ALL process hijackers.");
   comment("# This will spawn a child process for EACH BOT that will block ALL process hijackers.");
-  my_write(f, "! watcher %d\n", conffile.watcher);
+  my_write(f, "! watcher %d\n", conf.watcher);
 
 
   comment("");
   comment("");
 
 
@@ -771,7 +767,7 @@ writeconf(char *filename, FILE * stream, int bits)
   comment("# A '/' in front of BOT will disable that bot.");
   comment("# A '/' in front of BOT will disable that bot.");
   comment("#[/]BOT IP|. [+]HOST|. [IPV6-IP]");
   comment("#[/]BOT IP|. [+]HOST|. [IPV6-IP]");
 #endif /* CYGWIN_HACKS */
 #endif /* CYGWIN_HACKS */
-  for (bot = conffile.bots; bot && bot->nick; bot = bot->next) {
+  for (bot = conf.bots; bot && bot->nick; bot = bot->next) {
     my_write(f, "%s %s %s%s %s\n", bot->nick,
     my_write(f, "%s %s %s%s %s\n", bot->nick,
              bot->net.ip ? bot->net.ip : ".", bot->net.host6 ? "+" : "",
              bot->net.ip ? bot->net.ip : ".", bot->net.host6 ? "+" : "",
              bot->net.host ? bot->net.host : (bot->net.host6 ? bot->net.host6 : "."), bot->net.ip6 ? bot->net.ip6 : "");
              bot->net.host ? bot->net.host : (bot->net.host6 ? bot->net.host6 : "."), bot->net.ip6 ? bot->net.ip6 : "");
@@ -803,62 +799,52 @@ conf_bot_dup(conf_bot * dest, conf_bot * src)
   dest->next = NULL;
   dest->next = NULL;
 }
 }
 
 
+
 void
 void
-fillconf(conf_t * inconf)
+fill_conf_bot()
 {
 {
-  conf_bot *bot = NULL;
+  conf_bot *me = NULL;
   char *mynick = NULL;
   char *mynick = NULL;
 
 
-  if (localhub && conffile.bots && conffile.bots->nick) {
-    mynick = strdup(conffile.bots->nick);
-    strlcpy(origbotname, conffile.bots->nick, NICKLEN + 1);
+  if (localhub && conf.bots && conf.bots->nick) {
+    mynick = strdup(conf.bots->nick);
+    strlcpy(origbotname, conf.bots->nick, NICKLEN + 1);
   } else
   } else
     mynick = strdup(origbotname);
     mynick = strdup(origbotname);
 
 
-  for (bot = conffile.bots; bot && bot->nick; bot = bot->next)
-    if (!strcmp(bot->nick, mynick))
+  for (me = conf.bots; me && me->nick; me = me->next)
+    if (!strcmp(me->nick, mynick))
       break;
       break;
 
 
-  if (bot->nick && bot->nick[0] == '/')
+  if (me->nick && me->nick[0] == '/')
     werr(ERR_BOTDISABLED);
     werr(ERR_BOTDISABLED);
 
 
-  if (!bot->nick || (bot->nick && strcmp(bot->nick, mynick)))
+  if (!me->nick || (me->nick && strcmp(me->nick, mynick)))
     werr(ERR_BADBOT);
     werr(ERR_BADBOT);
 
 
   free(mynick);
   free(mynick);
-  inconf->bot = (conf_bot *) my_calloc(1, sizeof(conf_bot));
-  conf_bot_dup(inconf->bot, bot);
-  inconf->localhub = conffile.localhub ? strdup(conffile.localhub) : NULL;
-  inconf->binpath = conffile.binpath ? strdup(conffile.binpath) : NULL;
-  inconf->binname = conffile.binname ? strdup(conffile.binname) : NULL;
-  inconf->uname = conffile.uname ? strdup(conffile.uname) : NULL;
-  inconf->username = conffile.username ? strdup(conffile.username) : NULL;
-  inconf->homedir = conffile.homedir ? strdup(conffile.homedir) : NULL;
-  inconf->autocron = conffile.autocron;
-  inconf->watcher = conffile.watcher;
-  inconf->autouname = conffile.autouname;
-  inconf->portmin = conffile.portmin;
-  inconf->portmax = conffile.portmax;
-  inconf->pscloak = conffile.pscloak;
-  inconf->uid = conffile.uid;
+
+  /* for future, we may just want to make this a pointer to ->bots if we do an emech style currentbot-> */
+  conf.bot = (conf_bot *) my_calloc(1, sizeof(conf_bot));
+  conf_bot_dup(conf.bot, me);
 }
 }
 
 
 void
 void
 bin_to_conf(void)
 bin_to_conf(void)
 {
 {
 /* printf("Converting binary data to conf struct\n"); */
 /* printf("Converting binary data to conf struct\n"); */
-  conffile.uid = atol(settings.uid);
-  conffile.username = strdup(settings.username);
-  conffile.uname = strdup(settings.uname);
-  conffile.homedir = strdup(settings.homedir);
-  conffile.binpath = strdup(settings.binpath);
-  conffile.binname = strdup(settings.binname);
-  conffile.portmin = atol(settings.portmin);
-  conffile.portmax = atol(settings.portmax);
-  conffile.autouname = atoi(settings.autouname);
-  conffile.autocron = atoi(settings.autocron);
-  conffile.watcher = atoi(settings.watcher);
-  conffile.pscloak = atoi(settings.pscloak);
+  conf.uid = atol(settings.uid);
+  conf.username = strdup(settings.username);
+  conf.uname = strdup(settings.uname);
+  conf.homedir = strdup(settings.homedir);
+  conf.binpath = strdup(settings.binpath);
+  conf.binname = strdup(settings.binname);
+  conf.portmin = atol(settings.portmin);
+  conf.portmax = atol(settings.portmax);
+  conf.autouname = atoi(settings.autouname);
+  conf.autocron = atoi(settings.autocron);
+  conf.watcher = atoi(settings.watcher);
+  conf.pscloak = atoi(settings.pscloak);
 
 
   /* BOTS */
   /* BOTS */
   {
   {
@@ -888,5 +874,5 @@ bin_to_conf(void)
     }
     }
     free(tmpp);
     free(tmpp);
   }
   }
-  tellconf(&conffile);
+  tellconf(&conf);
 }
 }

+ 4 - 4
src/conf.h

@@ -47,7 +47,7 @@ typedef struct conf_b {
   port_t portmax;       /* for hubs, the reserved port range for incoming connections */
   port_t portmax;       /* for hubs, the reserved port range for incoming connections */
 } conf_t;
 } conf_t;
 
 
-extern conf_t		conf, conffile;
+extern conf_t		conf;
 
 
 enum {
 enum {
   CONF_ENC = 1,
   CONF_ENC = 1,
@@ -66,12 +66,12 @@ void conf_addbot(char *, char *, char *, char *);
 int conf_delbot(char *);
 int conf_delbot(char *);
 #endif /* LEAF */
 #endif /* LEAF */
 pid_t checkpid(char *, conf_bot *);
 pid_t checkpid(char *, conf_bot *);
-void init_conffile();
-void free_conffile();
+void init_conf();
+void free_conf_bots();
 int readconf(const char *, int);
 int readconf(const char *, int);
 int parseconf(bool);
 int parseconf(bool);
 int writeconf(char *, FILE *, int);
 int writeconf(char *, FILE *, int);
-void fillconf(conf_t *);
+void fill_conf_bot();
 void bin_to_conf(void);
 void bin_to_conf(void);
 
 
 #ifdef CYGWIN_HACKS
 #ifdef CYGWIN_HACKS

+ 8 - 8
src/main.c

@@ -301,7 +301,7 @@ static void dtx_arg(int argc, char *argv[])
       case '4':
       case '4':
         readconf(optarg, CONF_ENC);
         readconf(optarg, CONF_ENC);
         parseconf(0);
         parseconf(0);
-        conf_to_bin(&conffile, 1);		/* this will exit() in write_settings() */
+        conf_to_bin(&conf, 1);		/* this will exit() in write_settings() */
 #ifdef LEAF
 #ifdef LEAF
       case 'B':
       case 'B':
         localhub = 0;
         localhub = 0;
@@ -599,7 +599,7 @@ static void startup_checks(int hack) {
   egg_snprintf(cfile, sizeof cfile, STR("%s/conf.txt"), confdir());
   egg_snprintf(cfile, sizeof cfile, STR("%s/conf.txt"), confdir());
 
 
   if (can_stat(cfile))
   if (can_stat(cfile))
-    readconf(cfile, 0);	/* will read into &conffile struct */
+    readconf(cfile, 0);	/* will read into &conf struct */
 #endif /* CYGWIN_HACKS */
 #endif /* CYGWIN_HACKS */
 
 
 #ifndef CYGWIN_HACKS
 #ifndef CYGWIN_HACKS
@@ -618,10 +618,10 @@ static void startup_checks(int hack) {
    werr(ERR_BINMOD);
    werr(ERR_BINMOD);
   
   
 #ifndef CYGWIN_HACKS
 #ifndef CYGWIN_HACKS
-  move_bin(conffile.binpath, conffile.binname, 1);
+  move_bin(conf.binpath, conf.binname, 1);
 #endif /* !CYGWIN_HACKS */
 #endif /* !CYGWIN_HACKS */
 
 
-  fillconf(&conf);
+  fill_conf_bot();
 #ifdef LEAF
 #ifdef LEAF
   if (conf.bot->localhub && !used_B) {
   if (conf.bot->localhub && !used_B) {
     if (do_killbot[0]) {
     if (do_killbot[0]) {
@@ -654,8 +654,8 @@ static void startup_checks(int hack) {
       exit(0); /* our job is done! */
       exit(0); /* our job is done! */
     }
     }
   }
   }
-  if (!conf.bot->localhub)		/* only clear conf on NON localhubs, we need it for cmd_conf */
-    free_conffile();
+  if (!conf.bot->localhub)
+    free_conf_bots();			/* not a localhub, so no need to store all bot info */
 #endif /* LEAF */
 #endif /* LEAF */
 }
 }
 
 
@@ -725,7 +725,7 @@ printf("out: %s\n", out);
   }
   }
 #endif
 #endif
 
 
-  init_conffile();			/* establishes conffile and sets to defaults */
+  init_conf();			/* establishes conf and sets to defaults */
 
 
   /* Version info! */
   /* Version info! */
   egg_snprintf(ver, sizeof ver, "[%s] Wraith %s", settings.packname, egg_version);
   egg_snprintf(ver, sizeof ver, "[%s] Wraith %s", settings.packname, egg_version);
@@ -811,7 +811,7 @@ printf("out: %s\n", out);
     sdprintf("I am localhub (%s)", conf.bot->nick);
     sdprintf("I am localhub (%s)", conf.bot->nick);
 #endif /* LEAF */
 #endif /* LEAF */
 #ifndef CYGWIN_HACKS
 #ifndef CYGWIN_HACKS
-    if (conffile.autocron)
+    if (conf.autocron)
       check_crontab();
       check_crontab();
 #endif /* !CYGWIN_HACKS */
 #endif /* !CYGWIN_HACKS */
 #ifdef LEAF
 #ifdef LEAF

+ 1 - 1
src/shell.c

@@ -785,7 +785,7 @@ void baduname(char *confhas, char *myuname) {
     uname(&un);
     uname(&un);
     egg_snprintf(subject, sizeof subject, "CONF/UNAME() mismatch notice");
     egg_snprintf(subject, sizeof subject, "CONF/UNAME() mismatch notice");
     egg_snprintf(msg, sizeof msg, STR("This is an auto email from a wraith bot which has you in it's OWNER_EMAIL list..\n \nThe uname() output on this box has changed, probably due to a kernel upgrade...\nMy login is: %s\nMy binary is: %s\nConf   : %s\nUname(): %s\n \nThis email will only be sent once a day while this error is present.\nYou need to login to my shell (%s) and fix my local config.\n"), 
     egg_snprintf(msg, sizeof msg, STR("This is an auto email from a wraith bot which has you in it's OWNER_EMAIL list..\n \nThe uname() output on this box has changed, probably due to a kernel upgrade...\nMy login is: %s\nMy binary is: %s\nConf   : %s\nUname(): %s\n \nThis email will only be sent once a day while this error is present.\nYou need to login to my shell (%s) and fix my local config.\n"), 
-                                  conffile.username ? conffile.username : (conf.username ? conf.username : "unknown"), 
+                                  conf.username ? conf.username : "unknown", 
                                   binname,
                                   binname,
                                   confhas, myuname, un.nodename);
                                   confhas, myuname, un.nodename);
     email(subject, msg, EMAIL_OWNERS);
     email(subject, msg, EMAIL_OWNERS);