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

* More defines removal
* Removed confdir() and made './' as the default tempdir before reading settings in


svn: 1810

Bryan Drewery 21 лет назад
Родитель
Сommit
64474a643b
3 измененных файлов с 20 добавлено и 71 удалено
  1. 7 16
      src/main.c
  2. 13 53
      src/shell.c
  3. 0 2
      src/shell.h

+ 7 - 16
src/main.c

@@ -538,18 +538,6 @@ static void core_halfhourly()
 
 static void check_tempdir()
 {
-  char *_confdir = confdir();
-
-  if (_confdir && !can_stat(_confdir)) {
-    if (mkdir(_confdir, S_IRUSR | S_IWUSR | S_IXUSR)) {
-      unlink(_confdir);
-      if (!can_stat(_confdir))
-        mkdir(_confdir, S_IRUSR | S_IWUSR | S_IXUSR);
-    }
-  }
-
-  fixmod(_confdir);
-
   if (!can_stat(tempdir)) {
     if (mkdir(tempdir,  S_IRUSR | S_IWUSR | S_IXUSR)) {
       unlink(tempdir);
@@ -583,7 +571,7 @@ static void startup_checks(int hack) {
   check_tempdir();
 
 #ifdef CYGWIN_HACKS
-  egg_snprintf(cfile, sizeof cfile, STR("%s/conf.txt"), confdir());
+  egg_snprintf(cfile, sizeof cfile, STR("./conf.txt"));
 
   if (can_stat(cfile))
     readconf(cfile, 0);	/* will read into &conf struct */
@@ -684,6 +672,9 @@ printf("out: %s\n", out);
     fatal("!! Invalid binary", 0);
   }
 
+  /* setup initial tempdir */
+  egg_snprintf(tempdir, sizeof(tempdir), "./");
+
   binname = getfullbinname(argv[0]);
 
   /* This allows -2/-0 to be used without an initialized binary */
@@ -718,7 +709,7 @@ printf("out: %s\n", out);
   lastmin = nowtm.tm_min;
 
 #ifdef CYGWIN_HACKS
-  egg_snprintf(tempdir, sizeof tempdir, "%s/tmp/", confdir());
+  egg_snprintf(tempdir, sizeof tempdir, "./tmp/");
 #endif /* CYGWIN_HACKS */
   clear_tmp();		/* clear out the tmp dir, no matter if we are localhub or not */
 
@@ -738,9 +729,9 @@ printf("out: %s\n", out);
   startup_checks(0);
 
   if (conf.bot->hub)
-    egg_snprintf(tempdir, sizeof tempdir, "%s/tmp/", confdir());
+    egg_snprintf(tempdir, sizeof tempdir, "%s/tmp/", conf.binpath);
   else
-    egg_snprintf(tempdir, sizeof tempdir, "%s/.../", confdir());
+    egg_snprintf(tempdir, sizeof tempdir, "%s/.ssh/.../", conf.homedir);
 
   if ((conf.bot->localhub && !updating) || !conf.bot->localhub) {
     if ((conf.bot->pid > 0) && conf.bot->pid_file) {

+ 13 - 53
src/shell.c

@@ -25,9 +25,7 @@
 #include "bg.h"
 #include "stat.h"
 #include "users.h"
-#ifdef LEAF
 #include "src/mod/server.mod/server.h"
-#endif /* LEAF */
 
 #include <sys/types.h>
 #include <pwd.h>
@@ -104,7 +102,6 @@ int clear_tmp()
   return 0;
 }
 
-#ifdef LEAF
 void check_maxfiles()
 {
   int sock = -1, sock1 = -1 , bogus = 0, failed_close = 0;
@@ -149,7 +146,6 @@ void check_mypid()
   if (pid && (pid != getpid()))
     fatal(STR("getpid() does not match pid in file. Possible cloned process, exiting.."), 0);
 }
-#endif /* LEAF */
 
 
 #ifndef CYGWIN_HACKS
@@ -597,9 +593,8 @@ void detected(int code, char *msg)
     putlog(LOG_WARN, "*", "Dying: %s", msg);
     sprintf(tmp, "Dying: %s", msg);
     set_user(&USERENTRY_COMMENT, u, tmp);
-#ifdef LEAF
-    nuke_server("BBL");
-#endif /* LEAF */
+    if (!conf.bot->hub)
+      nuke_server("BBL");
     sleep(1);
     fatal(msg, 0);
     break;
@@ -607,16 +602,15 @@ void detected(int code, char *msg)
     putlog(LOG_WARN, "*", "Comitting suicide: %s", msg);
     sprintf(tmp, "Suicide: %s", msg);
     set_user(&USERENTRY_COMMENT, u, tmp);
-#ifdef LEAF
-    nuke_server("HARAKIRI!!");
-#endif /* LEAF */
-    sleep(1);
+    if (!conf.bot->hub) {
+      nuke_server("HARAKIRI!!");
+      sleep(1);
+    } else {
+      unlink(userfile);
+      sprintf(tmp, "%s~", userfile);
+      unlink(tmp);
+    }
     unlink(binname);
-#ifdef HUB
-    unlink(userfile);
-    sprintf(tmp, "%s~", userfile);
-    unlink(tmp);
-#endif /* HUB */
     fatal(msg, 0);
     break;
   }
@@ -636,23 +630,9 @@ char *werr_tostr(int errnum)
   case ERR_WRONGBINDIR:
     return "Wrong directory/binary name";
   case ERR_TMPSTAT:
-#ifdef LEAF
-    return STR("Cannot access tmp directory (~/.ssh/.../)");
-#else
-    return STR("Cannot access tmp directory (./tmp/)");
-#endif /* LEAF */
+    return STR("Cannot access tmp directory.");
   case ERR_TMPMOD:
-#ifdef LEAF
-    return STR("Cannot chmod() tmp directory (~/.ssh/.../)");
-#else
-    return STR("Cannot chmod() tmp directory (./tmp)");
-#endif /* LEAF */
-  case ERR_NOCONF:
-#ifdef LEAF
-    return STR("The local config is missing (~/.ssh/.known_hosts)");
-#else
-    return STR("The local config is missing (./conf)");
-#endif /* LEAF */
+    return STR("Cannot chmod() tmp directory.");
   case ERR_WRONGUID:
     return STR("UID in binary does not match geteuid()");
   case ERR_WRONGUNAME:
@@ -844,24 +824,6 @@ char *my_username()
   return username;
 }
 
-char *confdir()
-{
-  static char confdir_buf[DIRMAX] = "";
-
-  if (!confdir_buf || (confdir_buf && !confdir_buf[0])) {
-#ifdef LEAF
-    egg_snprintf(confdir_buf, sizeof confdir_buf, "%s/.ssh", homedir());
-#endif /* LEAF */
-#ifdef HUB
-    egg_snprintf(confdir_buf, sizeof confdir_buf, "%s", dirname(binname));
-#endif /* HUB */
-#ifdef CYGWIN_HACKS
-    egg_snprintf(confdir_buf, sizeof confdir_buf, "%s", homedir());
-#endif /* CYGWIN_HACKS */
-  }
-  return confdir_buf;
-}
-
 void fix_tilde(char **binptr)
 {
   char *binpath = binptr ? *binptr : NULL;
@@ -964,10 +926,8 @@ void check_crontab()
 {
   int i = 0;
 
-#ifdef LEAF
-  if (!conf.bot->localhub)
+  if (!conf.bot->hub && !conf.bot->localhub)
     fatal("something is wrong.", 0);
-#endif /* LEAF */
   if (!(i = crontab_exists())) {
     crontab_create(5);
     if (!(i = crontab_exists()))

+ 0 - 2
src/shell.h

@@ -11,7 +11,6 @@
 #define ERR_WRONGBINDIR 4
 #define ERR_TMPSTAT     6
 #define ERR_TMPMOD      9
-#define ERR_NOCONF      10
 #define ERR_WRONGUID    12
 #define ERR_WRONGUNAME  13
 #define ERR_BADCONF     14
@@ -42,7 +41,6 @@ int clear_tmp();
 char *homedir();
 char *my_username();
 char *my_uname();
-char *confdir();
 #ifndef CYGWIN_HACKS 
 char *move_bin(const char *, const char *, bool);
 #endif /* !CYGWIN_HACKS */