Browse Source

Merge branch 'conf-cleanup'

* conf-cleanup:
  * Use special header for marking dynamic settings are initialized or not
  * Use homedir to see if the binary has been initialized, datadir always has a default
  * Remove extra conf lines
  * Remove conf.binpath and conf.binname
  * Don't auto move binary to binpath/binname
  * Update settings_t padding
  * Use env HOME to lookup default homedir instead of getpwent
  * Use env USER to lookup username instead of getpwent
  * Remove obsoleted conf.watcher
  * Remove conf.uname and conf.autouname
Bryan Drewery 16 years ago
parent
commit
612932b3ed
12 changed files with 36 additions and 354 deletions
  1. 0 3
      src/bg.h
  2. 8 26
      src/binary.c
  3. 1 1
      src/chanprog.c
  4. 0 10
      src/cmds.c
  5. 3 116
      src/conf.c
  6. 0 5
      src/conf.h
  7. 4 9
      src/main.c
  8. 1 1
      src/misc_file.c
  9. 3 3
      src/mod/update.mod/update.c
  10. 7 9
      src/settings.h
  11. 9 166
      src/shell.c
  12. 0 5
      src/shell.h

+ 0 - 3
src/bg.h

@@ -8,9 +8,6 @@
 #include <sys/types.h>
 
 extern time_t 		lastfork;
-#if !defined(CYGWIN_HACKS) && !defined(__sun__)
-extern pid_t 		watcher;
-#endif
 
 pid_t do_fork();
 int close_tty();

+ 8 - 26
src/binary.c

@@ -32,7 +32,7 @@ settings_t settings = {
   /* -- STATIC -- */
   "", "", "", "", "", "", "", "", "", "",
   /* -- DYNAMIC -- */
-  "", "", "", "", "", "", "", "", "", "", "", "", "",
+  "", "", "", "", "", "", "", "", "",
   /* -- PADDING */
   ""
 };
@@ -135,7 +135,7 @@ bin_checksum(const char *fname, int todo)
     OPENSSL_cleanse(hash, sizeof(hash));
 
     /* Copy over only the dynamic data, leaving the pack config static */
-    memcpy(&settings.bots, &newsettings.bots, SIZE_CONF);
+    memcpy(&settings.DYNAMIC_HEADER, &newsettings.DYNAMIC_HEADER, SIZE_CONF);
     OPENSSL_cleanse(&newsettings, sizeof(settings_t));
 
     munmap(map, size);
@@ -206,7 +206,7 @@ bin_checksum(const char *fname, int todo)
 
     if (todo & WRITE_CONF) {
       /* Copy in the encrypted conf data */
-      memcpy(&outmap[newpos], &settings.bots, SIZE_CONF);
+      memcpy(&outmap[newpos], &settings.DYNAMIC_HEADER, SIZE_CONF);
 #ifdef DEBUG
       sdprintf(STR("writing conf: %d\n"), SIZE_CONF);
 #endif
@@ -474,17 +474,13 @@ static void edpack(settings_t *incfg, const char *in_hash, int what)
   update_hash();
 
   /* -- DYNAMIC -- */
+  dofield(incfg->dynamic_initialized);
   dofield(incfg->bots);
   dofield(incfg->uid);
-  dofield(incfg->autouname);
   dofield(incfg->autocron);
-  dofield(incfg->watcher);
-  dofield(incfg->uname);
   dofield(incfg->username);
   dofield(incfg->datadir);
   dofield(incfg->homedir);
-  dofield(incfg->binpath);
-  dofield(incfg->binname);
   dofield(incfg->portmin);
   dofield(incfg->portmax);
 
@@ -512,17 +508,13 @@ tellconfig(settings_t *incfg)
 //  dofield(incfg->salt1);
 //  dofield(incfg->salt2);
   // -- DYNAMIC --
+  dofield(incfg->dynamic_initialized);
   dofield(incfg->bots);
   dofield(incfg->uid);
-  dofield(incfg->autouname);
   dofield(incfg->autocron);
-  dofield(incfg->watcher);
-  dofield(incfg->uname);
   dofield(incfg->username);
   dofield(incfg->datadir);
   dofield(incfg->homedir);
-  dofield(incfg->binpath);
-  dofield(incfg->binname);
   dofield(incfg->portmin);
   dofield(incfg->portmax);
 #undef dofield
@@ -660,7 +652,7 @@ static void
 clear_settings(void)
 {
 //  memset(&settings.bots, 0, sizeof(settings_t) - SIZE_PACK - PREFIXLEN);
-  memset(&settings.bots, 0, SIZE_CONF);
+  memset(&settings.DYNAMIC_HEADER, 0, SIZE_CONF);
 }
 
 void conf_to_bin(conf_t *in, bool move, int die)
@@ -671,21 +663,16 @@ void conf_to_bin(conf_t *in, bool move, int die)
   clear_settings();
   sdprintf("converting conf to bin\n");
   simple_snprintf(settings.uid, sizeof(settings.uid), "%d", in->uid);
-  simple_snprintf(settings.watcher, sizeof(settings.watcher), "%d", in->watcher);
+  strlcpy(settings.dynamic_initialized, "1", sizeof(settings.dynamic_initialized));
   simple_snprintf(settings.autocron, sizeof(settings.autocron), "%d", in->autocron);
-  simple_snprintf(settings.autouname, sizeof(settings.autouname), "%d", in->autouname);
   simple_snprintf(settings.portmin, sizeof(settings.portmin), "%d", in->portmin);
   simple_snprintf(settings.portmax, sizeof(settings.portmax), "%d", in->portmax);
 
-  strlcpy(settings.binname, in->binname, sizeof(settings.binname));
   if (in->username)
     strlcpy(settings.username, in->username, sizeof(settings.username));
-  if (in->uname)
-    strlcpy(settings.uname, in->uname, sizeof(settings.uname));
   strlcpy(settings.datadir, in->datadir, sizeof(settings.datadir));
   if (in->homedir)
     strlcpy(settings.homedir, in->homedir, sizeof(settings.homedir));
-  strlcpy(settings.binpath, in->binpath, sizeof(settings.binpath));
   for (bot = in->bots; bot && bot->nick; bot = bot->next) {
     simple_snprintf(settings.bots, sizeof(settings.bots), STR("%s%s%s %s %s%s %s,"), 
                            settings.bots && settings.bots[0] ? settings.bots : "",
@@ -697,12 +684,7 @@ void conf_to_bin(conf_t *in, bool move, int die)
                            bot->net.ip6 ? bot->net.ip6 : "");
     }
 
-#ifndef CYGWIN_HACKS
-  if (move)
-    newbin = move_bin(in->binpath, in->binname, 0);
-  else
-#endif /* !CYGWIN_HACKS */
-    newbin = binname;
+  newbin = binname;
 //  tellconfig(&settings); 
   write_settings(newbin, -1, 1);
 

+ 1 - 1
src/chanprog.c

@@ -582,7 +582,7 @@ void chanprog()
 
   sdprintf("I am: %s", conf.bot->nick);
   if (conf.bot->hub) {
-    simple_snprintf(userfile, 121, "%s/.u", conf.binpath);
+    simple_snprintf(userfile, 121, "%s/.u", dirname(binname));
     loading = 1;
     checkchans(0);
     readuserfile(userfile, &userlist);

+ 0 - 10
src/cmds.c

@@ -1745,18 +1745,13 @@ static void cmd_conf(int idx, char *par)
         set++;
         save = 1;
 /*        if (!strcasecmp(what, "uid"))            conf.uid = atoi(par);
-        else if (!strcasecmp(what, "uname"))     str_redup(&conf.uname, par);
         else if (!strcasecmp(what, "username"))  str_redup(&conf.username, par);
 */
         if (!strcasecmp(what, "homedir"))   str_redup(&conf.homedir, par);
-        else if (!strcasecmp(what, "binpath"))   str_redup(&conf.binpath, par);
-        else if (!strcasecmp(what, "binname"))   str_redup(&conf.binname, par);
         else if (!strcasecmp(what, "datadir"))   str_redup(&conf.datadir, par);
         else if (!strcasecmp(what, "portmin"))   conf.portmin = atoi(par);
         else if (!strcasecmp(what, "portmax"))   conf.portmax = atoi(par);
         else if (!strcasecmp(what, "autocron"))  conf.autocron = atoi(par);
-        else if (!strcasecmp(what, "autouname")) conf.autouname = atoi(par);
-        else if (!strcasecmp(what, "watcher"))  conf.watcher = atoi(par);
         else { 
           set--;
           save = 0;
@@ -1768,18 +1763,13 @@ static void cmd_conf(int idx, char *par)
       const char *ss = set ? "Set: " : "";
       
 /*      if (!what || !strcasecmp(what, "uid"))        dprintf(idx, "%suid: %d\n", ss, conf.uid);
-      if (!what || !strcasecmp(what, "uname"))      dprintf(idx, "%suname: %s\n", ss, conf.uname);
       if (!what || !strcasecmp(what, "username"))   dprintf(idx, "%susername: %s\n", ss, conf.username);
 */
       if (!what || !strcasecmp(what, "homedir"))    dprintf(idx, "%shomedir: %s\n", ss, conf.homedir);
-      if (!what || !strcasecmp(what, "binpath"))    dprintf(idx, "%sbinpath: %s\n", ss, conf.binpath);
-      if (!what || !strcasecmp(what, "binname"))    dprintf(idx, "%sbinname: %s\n", ss, conf.binname);
       if (!what || !strcasecmp(what, "datadir"))    dprintf(idx, "%sdatadir: %s\n", ss, conf.datadir);
       if (!what || !strcasecmp(what, "portmin"))    dprintf(idx, "%sportmin: %d\n", ss, conf.portmin);
       if (!what || !strcasecmp(what, "portmax"))    dprintf(idx, "%sportmax: %d\n", ss, conf.portmax);
       if (!what || !strcasecmp(what, "autocron"))   dprintf(idx, "%sautocron: %d\n", ss, conf.autocron);
-      if (!what || !strcasecmp(what, "autouname"))  dprintf(idx, "%sautouname: %d\n", ss, conf.autouname);
-      if (!what || !strcasecmp(what, "watcher"))    dprintf(idx, "%swatcher: %d\n", ss, conf.watcher);
     }
   }
 #endif /* !CYGWIN_HACKS */

+ 3 - 116
src/conf.c

@@ -50,17 +50,12 @@ tellconf()
   sdprintf(STR("tempdir: %s\n"), replace(tempdir, conf.homedir, "~"));
   sdprintf(STR("features: %d\n"), conf.features);
   sdprintf(STR("uid: %d\n"), conf.uid);
-  sdprintf(STR("uname: %s\n"), conf.uname);
   sdprintf(STR("homedir: %s\n"), conf.homedir);
   sdprintf(STR("username: %s\n"), conf.username);
-  sdprintf(STR("binpath: %s\n"), replace(conf.binpath, conf.homedir, "~"));
-  sdprintf(STR("binname: %s\n"), conf.binname);
   sdprintf(STR("datadir: %s\n"), replace(conf.datadir, conf.homedir, "~"));
   sdprintf(STR("portmin: %d\n"), conf.portmin);
   sdprintf(STR("portmax: %d\n"), conf.portmax);
   sdprintf(STR("autocron: %d\n"), conf.autocron);
-  sdprintf(STR("autouname: %d\n"), conf.autouname);
-  sdprintf(STR("watcher: %d\n"), conf.watcher);
   sdprintf(STR("bots:\n"));
   for (bot = conf.bots; bot && bot->nick; bot = bot->next) {
     i++;
@@ -316,7 +311,6 @@ confedit()
   free_conf();
 
   readconf((const char *) tmpconf.file, 0);               /* read cleartext conf tmp into &settings */
-  expand_tilde(&conf.binpath);
   expand_tilde(&conf.datadir);
   unlink(tmpconf.file);
   conf_to_bin(&conf, 0, -1);
@@ -348,33 +342,16 @@ init_conf()
   conf.bot = NULL;
 
   conf.localhub = NULL;
-  conf.watcher = 0;
 #ifdef CYGWIN_HACKS
   conf.autocron = 0;
 #else
   conf.autocron = 1;
 #endif /* !CYGWIN_HACKS */
-  conf.autouname = 0;
-#ifdef CYGWIN_HACKS
-  if (homedir())
-    conf.binpath = strdup(homedir());
-#else /* !CYGWIN_HACKS */
-  conf.binpath = strdup(dirname(binname));
-#endif /* CYGWIN_HACKS */
-  char *p = strrchr(binname, '/');
-
-  p++;
-
-  if (!strncmp(p, STR("wraith."), 7) && strchr(p, '-'))
-    conf.binname = strdup(STR("wraith"));
-  else
-    conf.binname = strdup(p);
 
   conf.features = 0;
   conf.portmin = 0;
   conf.portmax = 0;
   conf.uid = -1;
-  conf.uname = NULL;
   conf.username = NULL;
   conf.homedir = NULL;
   conf.datadir = strdup(STR("./..."));
@@ -566,18 +543,12 @@ free_conf()
   conf.bot = NULL;
   if (conf.localhub)
     free(conf.localhub);
-  if (conf.uname)
-    free(conf.uname);
   if (conf.username)
     free(conf.username);
   if (conf.datadir)
     free(conf.datadir);
   if (conf.homedir)
     free(conf.homedir);
-  if (conf.binname)
-   free(conf.binname);
-  if (conf.binpath)
-    free(conf.binpath);
   init_conf();
 }
 
@@ -607,7 +578,7 @@ void prep_homedir(bool error)
 int
 parseconf(bool error)
 {
-  if (error && conf.uid == -1 && !conf.uname)
+  if (error && conf.uid == -1 && !conf.homedir)
     werr(ERR_NOTINIT);
 
   if (!conf.username)
@@ -623,17 +594,6 @@ parseconf(bool error)
   } else if (!conf.uid)
     conf.uid = myuid;
 
-  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)
-      werr(ERR_WRONGUNAME);
-  } 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());
-  }
-  
 #endif /* !CYGWIN_HACKS */
   return 0;
 }
@@ -671,17 +631,7 @@ readconf(const char *fname, int bits)
     sdprintf(STR("CONF LINE: %s"), line.c_str());
 // !strchr("_`|}][{*/#-+!abcdefghijklmnopqrstuvwxyzABDEFGHIJKLMNOPWRSTUVWXYZ", line[0])) {
     /* - uid */
-    if (line[0] == '-') {
-      if (conf.uid == -1)
-        conf.uid = atoi(newsplit(line).c_str());
-
-      /* + uname */
-    } else if (line[0] == '+') {
-      if (!conf.uname)
-        conf.uname = strdup(newsplit(line).c_str());
-
-      /* ! is misc options */
-    } else if (line[0] == '!') {
+    if (line[0] == '!') {
       ++line;
       line.trim();
 
@@ -698,10 +648,6 @@ readconf(const char *fname, int bits)
         if (egg_isdigit(line[0]))
           conf.autocron = atoi(line.c_str());
 
-      } else if (option == STR("autouname")) {      /* auto update uname contents? */
-        if (egg_isdigit(line[0]))
-          conf.autouname = atoi(line.c_str());
-
       } else if (option == STR("username")) {       /* shell username */
         str_redup(&conf.username, line.c_str());
 
@@ -711,12 +657,6 @@ readconf(const char *fname, int bits)
       } else if (option == STR("datadir")) {        /* datadir */
         str_redup(&conf.datadir, line.c_str());
 
-      } else if (option == STR("binpath")) {        /* path that the binary should move to? */
-        str_redup(&conf.binpath, line.c_str());
-
-      } else if (option == STR("binname")) {        /* filename of the binary? */
-        str_redup(&conf.binname, line.c_str());
-
       } else if (option == STR("portmin")) {
         if (egg_isdigit(line[0]))
           conf.portmin = atoi(line.c_str());
@@ -729,13 +669,6 @@ readconf(const char *fname, int bits)
         if (str_isdigit(line.c_str()))
           conf.uid = atoi(line.c_str());
 
-      } else if (option == STR("uname")) {  /* new method uname */
-        str_redup(&conf.uname, line.c_str());
-
-      } else if (option == STR("watcher")) {
-        if (egg_isdigit(line[0]))
-          conf.watcher = atoi(line.c_str());
-
       } else {
         putlog(LOG_MISC, "*", STR("Unrecognized config option '%s'"), option.c_str());
 
@@ -793,8 +726,6 @@ writeconf(char *filename, int fd, int bits)
   char *p = NULL;
 
   comment("");
-  comment("# Lines beginning with # are what the preceeding line SHOULD be");
-  comment("# They are simply comments and are not parsed at all.\n");
 
 #define conf_com() do {							\
 	if (do_confedit == CONF_AUTO) {					\
@@ -811,23 +742,6 @@ writeconf(char *filename, int fd, int bits)
   } else
     *stream << buf.printf(STR("! uid %d\n"), conf.uid);
 
-  if (!conf.uname || (conf.uname && conf.autouname && strcmp(conf.uname, my_uname()))) {
-    autowrote = 1;
-    if (conf.uname)
-      comment("# autouname is ON");
-    else
-      comment("# Automatically updated empty uname");
-
-    *stream << buf.printf(STR("! uname %s\n"), my_uname());
-    if (conf.uname)
-      *stream << buf.printf(STR("#! uname %s\n"), conf.uname);
-  } else if (conf.uname && !conf.autouname && strcmp(conf.uname, my_uname())) {
-    conf_com();
-    *stream << buf.printf(STR("%s! uname %s\n"), do_confedit == CONF_AUTO ? "" : "#", my_uname());
-    *stream << buf.printf(STR("%s! uname %s\n"), do_confedit == CONF_STATIC ? "" : "#", conf.uname);
-  } else
-    *stream << buf.printf(STR("! uname %s\n"), conf.uname);
-
   comment("");
 
   if (conf.username && my_username() && strcmp(conf.username, my_username())) {
@@ -844,20 +758,6 @@ writeconf(char *filename, int fd, int bits)
   } else 
     *stream << buf.printf(STR("! homedir %s\n"), conf.homedir ? conf.homedir : homedir(0) ? homedir(0) : "");
 
-  comment("\n# binpath needs to be full path unless it begins with '~', which uses 'homedir', ie, '~/'");
-
-  if (homedir() && strstr(conf.binpath, homedir())) {
-    p = replace(conf.binpath, homedir(), "~");
-    *stream << buf.printf(STR("! binpath %s\n"), p);
-  } else if (conf.homedir && strstr(conf.binpath, conf.homedir)) { /* Could be an older homedir */
-    p = replace(conf.binpath, conf.homedir, "~");
-    *stream << buf.printf(STR("! binpath %s\n"), p);
-  } else
-    *stream << buf.printf(STR("! binpath %s\n"), conf.binpath);
-
-  comment("# binname is relative to binpath, if you change this, you'll need to manually remove the old one from crontab.");
-  *stream << buf.printf(STR("! binname %s\n"), conf.binname);
-
   comment("");
 
   if (conf.datadir && strcmp(conf.datadir, "./...")) {
@@ -891,13 +791,6 @@ writeconf(char *filename, int fd, int bits)
     comment("");
   }
 
-  if (conf.autouname) {
-    comment("# Automatically update 'uname' if it changes? (DANGEROUS)");
-    *stream << buf.printf(STR("! autouname %d\n"), conf.autouname);
-
-    comment("");
-  }
-
   comment("# '|' means OR, [] means the enclosed is optional");
   comment("# A '+' in front of HOST means the HOST is ipv6");
   comment("# A '/' in front of BOT will disable that bot.");
@@ -1041,22 +934,16 @@ bin_to_conf(bool error)
   conf.uid = atol(settings.uid);
   if (settings.username[0])
     str_redup(&conf.username, settings.username);
-  str_redup(&conf.uname, settings.uname); 
   str_redup(&conf.datadir, settings.datadir);
   if (settings.homedir[0])
     str_redup(&conf.homedir, settings.homedir);
-  str_redup(&conf.binpath, settings.binpath);
-  str_redup(&conf.binname, 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);
 
 
   prep_homedir(error);
   expand_tilde(&conf.datadir);
-  expand_tilde(&conf.binpath);
 
   /* PARSE/ADD BOTS */
   {
@@ -1096,7 +983,7 @@ bin_to_conf(bool error)
   if (!mkdir_p(conf.datadir) && error)
     werr(ERR_DATADIR);
 
-  str_redup(&conf.datadir, replace(datadir, conf.binpath, "."));
+  str_redup(&conf.datadir, replace(datadir, dirname(binname), "."));
 
   if (Tempfile::FindDir() == ERROR)
     werr(ERR_TMPSTAT);

+ 0 - 5
src/conf.h

@@ -32,16 +32,11 @@ typedef struct conf_b {
   conf_bot *bot;        /* single bot (me) */
   int features;		/* Pack features (take, mdop, beta... etc..) */
   int uid;
-  int autouname;        /* should we just auto update any changed in uname output? */
   int autocron;         /* should the bot auto crontab itself? */
-  int watcher;		/* spawn a watcher pid to block ptrace? */
   char *localhub;	/* my localhub */
-  char *uname;
   char *datadir;
   char *username;       /* shell username */
   char *homedir;        /* homedir */
-  char *binpath;        /* path to binary, ie: ~/ */
-  char *binname;        /* binary name, ie: .sshrc */
   port_t portmin;       /* for hubs, the reserved port range for incoming connections */
   port_t portmax;       /* for hubs, the reserved port range for incoming connections */
 } conf_t;

+ 4 - 9
src/main.c

@@ -346,7 +346,6 @@ static void dtx_arg(int& argc, char *argv[])
         exit(2);
       case '4':
         readconf(optarg, CONF_ENC);
-        expand_tilde(&conf.binpath);
         expand_tilde(&conf.datadir);
         parseconf(0);
         conf_to_bin(&conf, 0, 6);		/* this will exit() in write_settings() */
@@ -431,7 +430,7 @@ static void dtx_arg(int& argc, char *argv[])
 #ifdef DEBUG
 	printf(STR("pack: %d conf: %d settings_t: %d prefix: %d pad: %d needed padding: %d\n"), SIZE_PACK, SIZE_CONF, sizeof(settings_t), PREFIXLEN, SIZE_PAD, (16 - ((sizeof(settings_t) - sizeof(settings.padding)) % 16)) % 16);
 #endif
-        if (settings.uname[0]) {
+        if (settings.dynamic_initialized[0]) {
           ++sdebug;
           bin_to_conf();
         }
@@ -620,8 +619,8 @@ static void core_halfhourly()
 
 static void startup_checks(int hack) {
   /* for compatability with old conf files 
-   * only check/use conf file if it exists and settings.uname is empty.
-   * if settings.uname is NOT empty, just erase the conf file if it exists
+   * only check/use conf file if it exists and settings.homedir is empty.
+   * if settings.homedir is NOT empty, just erase the conf file if it exists
    * otherwise, assume we're working only with the struct */
 
 #ifdef CYGWIN_HACKS
@@ -634,7 +633,7 @@ static void startup_checks(int hack) {
 
 #ifndef CYGWIN_HACKS
   /* Only error out with missing homedir when we aren't editing the binary */
-  if (settings.uname[0])
+  if (settings.dynamic_initialized[0])
     bin_to_conf(do_confedit ? 0 : 1);		/* read our memory from settings[] into conf[] */
 
   if (do_confedit)
@@ -649,10 +648,6 @@ static void startup_checks(int hack) {
   if (!can_stat(binname))
    werr(ERR_BINSTAT);
 
-#ifndef CYGWIN_HACKS
-  move_bin(conf.binpath, conf.binname, 1);
-#endif /* !CYGWIN_HACKS */
-
   fill_conf_bot();
 //  if (((!conf.bot || !conf.bot->nick) || (!conf.bot->hub && conf.bot->localhub)) && !used_B) {
   if (!used_B) {

+ 1 - 1
src/misc_file.c

@@ -303,7 +303,7 @@ bool Tempfile::FindDir()
 
   /* If this is a hub, use, "./tmp/" */
   if (conf.bots && conf.bots->nick && conf.bots->hub) {
-    simple_snprintf(tempdir, DIRMAX, "%s/tmp/", conf.binpath);
+    simple_snprintf(tempdir, DIRMAX, "%s/tmp/", dirname(binname));
     if (check_tempdir(0)) {
       looking = 0;
       return OK;

+ 3 - 3
src/mod/update.mod/update.c

@@ -239,7 +239,7 @@ void finish_update_stream(int idx, bd::Stream& stream)
 
   char rand[7] = "";
   make_rand_str(rand, sizeof(rand) - 1, 0);
-  simple_snprintf(buf, sizeof(buf), "%s/.update-%s", conf.binpath, rand);
+  simple_snprintf(buf, sizeof(buf), "%s/.update-%s", dirname(binname), rand);
 
   stream.writeFile(buf);
   fixmod(buf);
@@ -295,9 +295,9 @@ static void start_sending_binary(int idx, bool streamable)
 
   simple_snprintf(update_file, sizeof update_file, "wraith.%s-%s", sysname, egg_version);
 
-  simple_snprintf(update_fpath, sizeof update_fpath, "%s/bins/%s", conf.binpath, update_file);
+  simple_snprintf(update_fpath, sizeof update_fpath, "%s/bins/%s", dirname(binname), update_file);
   if (!can_stat(update_fpath))
-    simple_snprintf(update_fpath, sizeof update_fpath, "%s/%s", conf.binpath, update_file);
+    simple_snprintf(update_fpath, sizeof update_fpath, "%s/%s", dirname(binname), update_file);
 
   if (!can_stat(update_fpath)) {
     putlog(LOG_MISC, "*", "Need to update \002%s\002 with %s but there was an error: %s", dcc[idx].nick, update_fpath,

+ 7 - 9
src/settings.h

@@ -8,6 +8,8 @@
 /* !!! THIS MUST BE CHANGED WHEN CHANGING THE PACK STRUCT OR ALGORITHMS !!! */
 #define SETTINGS_VER 2
 
+#define DYNAMIC_HEADER dynamic_initialized
+
 typedef struct settings_struct {
   char prefix[PREFIXLEN];
   /* -- STATIC -- */
@@ -23,21 +25,17 @@ typedef struct settings_struct {
   char dcc_prefix[17];
   char features[17];
   /* -- DYNAMIC -- */
+  char dynamic_initialized[17];
   char bots[1025];
   char uid[17];
-  char autouname[17];        /* should we just auto update any changed in uname output? */
   char autocron[17];         /* should the bot auto crontab itself? */
-  char watcher[17];          /* spawn a watcher pid to block ptrace? */
-  char uname[113];
   char username[49];       /* shell username */
   char datadir[1025];
   char homedir[1025];        /* homedir */
-  char binpath[1025];        /* path to binary, ie: ~/ */
-  char binname[113];        /* binary name, ie: .sshrc */
   char portmin[17];       /* for hubs, the reserved port range for incoming connections */
   char portmax[17];       /* for hubs, the reserved port range for incoming connections */
   /* -- PADDING -- */
-  char padding[9];        // (16 - (sizeof(settings_t) % 16)) % 16]
+  char padding[13];        // (16 - (sizeof(settings_t) % 16)) % 16]
 } settings_t;
 
 #define SALT1 {s1_1[0],s1_1[1],s1_5[0],s1_5[1],s1_8[0],s1_8[1],s1_4[0],s1_9[1],s1_2[0],s1_13[0],s1_6[0],s1_6[1],s1_7[0],s1_7[1],s1_3[0],s1_13[1],s1_16[1],s1_4[1],s1_15[0],s1_10[1],s1_14[0],s1_14[1],s1_12[0],s1_12[1],s1_2[1],s1_3[1],s1_11[0],s1_11[1],s1_10[0],s1_15[1],s1_16[0],s1_9[0],'\0'}
@@ -52,9 +50,9 @@ extern char s1_3[3],s1_2[3],s1_1[3],s2_7[3],s1_9[3],s1_13[3],s1_14[3],s2_2[3],s1
 sizeof(settings.owners) + sizeof(settings.hubs) + sizeof(settings.owneremail) + \
 sizeof(settings.salt1) + sizeof(settings.salt2) + sizeof(settings.dcc_prefix) + sizeof(settings.features)
 
-#define SIZE_CONF sizeof(settings.bots) + sizeof(settings.uid) + sizeof(settings.autouname) + \
-sizeof(settings.autocron) + sizeof(settings.watcher) + sizeof(settings.uname) + \
-sizeof(settings.username) + sizeof(settings.homedir) + sizeof(settings.binpath) + sizeof(settings.binname) + \
+#define SIZE_CONF sizeof(settings.dynamic_initialized) + sizeof(settings.bots) + sizeof(settings.uid) + \
+sizeof(settings.autocron) + \
+sizeof(settings.username) + sizeof(settings.homedir) + \
 sizeof(settings.portmin) + sizeof(settings.portmin) + sizeof(settings.datadir)
 
 #define SIZE_PAD sizeof(settings.padding)

+ 9 - 166
src/shell.c

@@ -677,86 +677,22 @@ int email(char *subject, char *msg, int who)
   return 0;
 }
 
-void baduname(char *confhas, char *myuname) {
-  char *tmpFile = NULL;
-  int tosend = 0, make = 0;
-  size_t siz = strlen(tempdir) + 3 + 1;
-
-  tmpFile = (char *) my_calloc(1, siz);
-
-  simple_snprintf(tmpFile, siz, STR("%s/.un"), conf.datadir);
-  if (is_file(tmpFile)) {
-    struct stat ss;
-    time_t diff;
-
-    stat(tmpFile, &ss);
-    diff = now - ss.st_mtime;
-    if (diff >= 86400) {
-      tosend++;          		/* only send once a day */
-      unlink(tmpFile);		/* remove file */
-      make++;			/* make a new one at thie time. */
-    }
-  } else {
-    make++;
-  }
-
-  if (make) {
-    FILE *fp = NULL;
-    if ((fp = fopen(tmpFile, "w"))) {
-      fprintf(fp, "\n");
-      fflush(fp);
-      fclose(fp);
-      tosend++;           /* only send if we could write the file. */
-    }
-  }
-
-  if (tosend) {
-    struct utsname un;
-    char msg[1024] = "", subject[31] = "";
-
-    uname(&un);
-    simple_snprintf(subject, sizeof subject, STR("CONF/UNAME() mismatch notice"));
-    simple_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\nLocalhub: %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"), 
-                                  conf.username ? conf.username : "unknown", 
-                                  binname,
-                                  conf.bots && conf.bots->nick ? conf.bots->nick : origbotname,
-                                  confhas, myuname, un.nodename);
-    email(subject, msg, EMAIL_OWNERS);
-  }
-  free(tmpFile);
-}
-
 char *homedir(bool useconf)
 {
   static char homedir_buf[PATH_MAX] = "";
 
   if (!homedir_buf[0]) {
-    char tmp[DIRMAX] = "";
-
     if (conf.homedir && useconf)
-      simple_snprintf(tmp, sizeof tmp, "%s", conf.homedir);
+      simple_snprintf(homedir_buf, sizeof homedir_buf, "%s", conf.homedir);
     else {
 #ifdef CYGWIN_HACKS
-      simple_snprintf(tmp, sizeof tmp, "%s", dirname(binname));
+      simple_snprintf(homedir_buf, sizeof homedir_buf, "%s", dirname(binname));
 #else /* !CYGWIN_HACKS */
-      struct passwd *pw = NULL;
- 
-      ContextNote(STR("getpwuid()"));
-      pw = getpwuid(myuid);
-      if (pw)
-        simple_snprintf(tmp, sizeof tmp, "%s", pw->pw_dir);
-      ContextNote(STR("getpwuid(): Success"));
+    char *home = getenv("HOME");
+    if (home && strlen(home))
+      strlcpy(homedir_buf, home, sizeof(homedir_buf));
 #endif /* CYGWIN_HACKS */
     }
-    ContextNote(STR("realpath()"));
-    if (tmp[0]) {
-      if (!realpath(tmp, homedir_buf)) { /* this will convert lame home dirs of /home/blah->/usr/home/blah */
-        homedir_buf[0] = 0;
-        return NULL;
-      }
-      homedir_buf[DIRMAX < PATH_MAX ? DIRMAX - 1 : PATH_MAX - 1] = 0;
-    }
-    ContextNote(STR("realpath(): Success"));
   }
   return homedir_buf[0] ? homedir_buf : NULL;
 }
@@ -769,13 +705,9 @@ char *my_username()
 #ifdef CYGWIN_HACKS
     simple_snprintf(username, sizeof username, "cygwin");
 #else /* !CYGWIN_HACKS */
-    struct passwd *pw = NULL;
-
-    ContextNote(STR("getpwuid()"));
-    pw = getpwuid(myuid);
-    ContextNote(STR("getpwuid(): Success"));
-    if (pw)
-      strlcpy(username, pw->pw_name, sizeof(username));
+    char *user = getenv("USER");
+    if (user && strlen(user))
+      strlcpy(username, user, sizeof(username));
 #endif /* CYGWIN_HACKS */
   }
   return username[0] ? username : NULL;
@@ -830,96 +762,6 @@ void expand_tilde(char **ptr)
   }
 }
 
-char *my_uname()
-{
-  static char os_uname[250] = "";
-
-  if (!os_uname[0]) {
-    char *unix_n = NULL, *vers_n = NULL;
-    struct utsname un;
-
-    if (uname(&un) < 0) {
-      unix_n = "*unkown*";
-      vers_n = "";
-    } else {
-      unix_n = un.nodename;
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
-      vers_n = un.release;
-#elif defined(__linux__)
-      vers_n = un.version;
-#else
-# error "Don't know how to handle uname for this system!"
-#endif
-    }
-    simple_snprintf(os_uname, sizeof os_uname, "%s %s", unix_n, vers_n);
-  }
-  return os_uname;
-}
-
-#ifndef CYGWIN_HACKS
-char *move_bin(const char *ipath, const char *file, bool run)
-{
-  char *path = strdup(ipath);
-
-  expand_tilde(&path);
-
-  /* move the binary to the correct place */
-  static char newbin[DIRMAX] = "";
-  char real[PATH_MAX] = "";
-
-  simple_snprintf(newbin, sizeof newbin, "%s%s%s", path, path[strlen(path) - 1] == '/' ? "" : "/", file);
-
-  ContextNote(STR("realpath()"));
-  if (!realpath(binname, real))            /* get the realpath of binname */
-    fatal(STR("Unable to determine binary path."), 0);
-  real[(DIRMAX < PATH_MAX ? DIRMAX : PATH_MAX) - 1] = 0;
-  ContextNote(STR("realpath(): Success"));
-  /* running from wrong dir, or wrong bin name.. lets try to fix that :) */
-  sdprintf(STR("binname: %s"), binname);
-  sdprintf(STR("newbin: %s"), newbin);
-  sdprintf(STR("real: %s"), real);
-  if (strcmp(binname, newbin) && strcmp(newbin, real)) {              /* if wrong path and new path != current */
-    bool ok = 1;
-
-    sdprintf(STR("wrong dir, is: %s :: %s"), binname, newbin);
-
-    unlink(newbin);
-    if (copyfile(binname, newbin))
-      ok = 0;
-
-    if (ok && !can_stat(newbin)) {
-       unlink(newbin);
-       ok = 0;
-    }
-
-    if (ok && fixmod(newbin)) {
-        unlink(newbin);
-        ok = 0;
-    }
-
-    if (ok) {
-      sdprintf(STR("Binary successfully moved to: %s"), newbin);
-      unlink(binname);
-      if (run) {
-        simple_snprintf(newbin, sizeof newbin, "%s%s%s", 
-                        path, path[strlen(path) - 1] == '/' ? "" : "/", shell_escape(file));
-        if (system(newbin) == -1) {
-          printf("Unable to automatically start new binary.\n");
-          exit(1);
-        }
-        sdprintf(STR("exiting to let new binary run..."));
-        exit(0);
-      }
-    } else {
-      if (run)
-        werr(ERR_WRONGBINDIR);
-      sdprintf(STR("Binary move failed to: %s"), newbin);
-      return binname;
-    }
-  }
-  return newbin;
-}
-
 void check_crontab()
 {
   int i = 0;
@@ -952,6 +794,7 @@ void crontab_del() {
   unlink(tmpFile);
 }
 
+#ifndef CYGWIN_HACKS
 int crontab_exists() {
   char buf[2048] = "", *out = NULL;
 

+ 0 - 5
src/shell.h

@@ -45,12 +45,7 @@ void check_mypid();
 void clear_tmp();
 char *homedir(bool = 1);
 char *my_username();
-char *my_uname();
-#ifndef CYGWIN_HACKS
-char *move_bin(const char *, const char *, bool);
-#endif /* !CYGWIN_HACKS */
 void expand_tilde(char **);
-void baduname(char *, char *);
 int email(char *, char *, int);
 int shell_exec(char *, char *, char **, char **);
 #ifndef CYGWIN_HACKS