Просмотр исходного кода

* Remove conf.uname and conf.autouname

Bryan Drewery 16 лет назад
Родитель
Сommit
bf9674e1c1
8 измененных файлов с 9 добавлено и 161 удалено
  1. 1 8
      src/binary.c
  2. 0 4
      src/cmds.c
  3. 2 62
      src/conf.c
  4. 0 2
      src/conf.h
  5. 4 4
      src/main.c
  6. 2 4
      src/settings.h
  7. 0 75
      src/shell.c
  8. 0 2
      src/shell.h

+ 1 - 8
src/binary.c

@@ -32,7 +32,7 @@ settings_t settings = {
   /* -- STATIC -- */
   "", "", "", "", "", "", "", "", "", "",
   /* -- DYNAMIC -- */
-  "", "", "", "", "", "", "", "", "", "", "", "", "",
+  "", "", "", "", "", "", "", "", "", "", "",
   /* -- PADDING */
   ""
 };
@@ -476,10 +476,8 @@ static void edpack(settings_t *incfg, const char *in_hash, int what)
   /* -- DYNAMIC -- */
   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);
@@ -514,10 +512,8 @@ tellconfig(settings_t *incfg)
   // -- DYNAMIC --
   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);
@@ -673,15 +669,12 @@ void conf_to_bin(conf_t *in, bool move, int die)
   simple_snprintf(settings.uid, sizeof(settings.uid), "%d", in->uid);
   simple_snprintf(settings.watcher, sizeof(settings.watcher), "%d", in->watcher);
   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));

+ 0 - 4
src/cmds.c

@@ -1745,7 +1745,6 @@ 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);
@@ -1755,7 +1754,6 @@ static void cmd_conf(int idx, char *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--;
@@ -1768,7 +1766,6 @@ 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);
@@ -1778,7 +1775,6 @@ static void cmd_conf(int idx, char *par)
       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);
     }
   }

+ 2 - 62
src/conf.c

@@ -50,7 +50,6 @@ 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, "~"));
@@ -59,7 +58,6 @@ tellconf()
   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) {
@@ -354,7 +352,6 @@ init_conf()
 #else
   conf.autocron = 1;
 #endif /* !CYGWIN_HACKS */
-  conf.autouname = 0;
 #ifdef CYGWIN_HACKS
   if (homedir())
     conf.binpath = strdup(homedir());
@@ -374,7 +371,6 @@ init_conf()
   conf.portmin = 0;
   conf.portmax = 0;
   conf.uid = -1;
-  conf.uname = NULL;
   conf.username = NULL;
   conf.homedir = NULL;
   conf.datadir = strdup(STR("./..."));
@@ -566,8 +562,6 @@ 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)
@@ -607,7 +601,7 @@ void prep_homedir(bool error)
 int
 parseconf(bool error)
 {
-  if (error && conf.uid == -1 && !conf.uname)
+  if (error && conf.uid == -1 && !conf.datadir)
     werr(ERR_NOTINIT);
 
   if (!conf.username)
@@ -623,17 +617,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 +654,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 +671,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());
 
@@ -729,9 +698,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());
@@ -811,23 +777,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())) {
@@ -891,13 +840,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,7 +983,6 @@ 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);
@@ -1049,7 +990,6 @@ bin_to_conf(bool error)
   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);
 

+ 0 - 2
src/conf.h

@@ -32,11 +32,9 @@ 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 */

+ 4 - 4
src/main.c

@@ -434,7 +434,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.datadir[0]) {
           ++sdebug;
           bin_to_conf();
         }
@@ -623,8 +623,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.datadir is empty.
+   * if settings.datadir is NOT empty, just erase the conf file if it exists
    * otherwise, assume we're working only with the struct */
 
 #ifdef CYGWIN_HACKS
@@ -637,7 +637,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.datadir[0])
     bin_to_conf(do_confedit ? 0 : 1);		/* read our memory from settings[] into conf[] */
 
   if (do_confedit)

+ 2 - 4
src/settings.h

@@ -24,10 +24,8 @@ typedef struct settings_struct {
   /* -- DYNAMIC -- */
   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 */
@@ -51,8 +49,8 @@ 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) + \
+#define SIZE_CONF sizeof(settings.bots) + sizeof(settings.uid) + \
+sizeof(settings.autocron) + sizeof(settings.watcher) + \
 sizeof(settings.username) + sizeof(settings.homedir) + sizeof(settings.binpath) + sizeof(settings.binname) + \
 sizeof(settings.portmin) + sizeof(settings.portmin) + sizeof(settings.datadir)
 

+ 0 - 75
src/shell.c

@@ -677,55 +677,6 @@ 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] = "";
@@ -830,32 +781,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)
 {

+ 0 - 2
src/shell.h

@@ -45,12 +45,10 @@ 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