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

* Added compat functions to read in a config file if a new binary's struct size if
different than our current size, not finished.


svn: 1685

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

+ 2 - 2
src/binary.c

@@ -333,7 +333,7 @@ void write_settings(const char *fname, int die)
 
 
   MD5_Init(&ctx);
   MD5_Init(&ctx);
   if ((hash = bin_checksum(fname, WRITE_CHECKSUM, &ctx))) {
   if ((hash = bin_checksum(fname, WRITE_CHECKSUM, &ctx))) {
-    printf("* Wrote settings to %s.\n", fname);
+    printf("* Wrote settings to: %s.\n", fname);
     edpack(&settings, hash, PACK_DEC);
     edpack(&settings, hash, PACK_DEC);
   }
   }
 
 
@@ -379,5 +379,5 @@ void conf_to_bin(conf_t *in)
 
 
   newbin = move_bin(in->binpath, in->binname, 0);
   newbin = move_bin(in->binpath, in->binname, 0);
   /* tellconfig(&settings); */
   /* tellconfig(&settings); */
-  write_settings(newbin, 0);
+  write_settings(newbin, 1);
 }
 }

+ 1 - 1
src/cmds.c

@@ -1886,7 +1886,7 @@ static void cmd_conf(int idx, char *par)
 #endif /* LEAF */
 #endif /* LEAF */
 
 
   if (save) {
   if (save) {
-    write_settings(binname, 0);
+    write_settings(binname, -1);
 #ifdef LEAF
 #ifdef LEAF
     spawnbots();			/* parse conffile struct and spawn/kill as needed */
     spawnbots();			/* parse conffile struct and spawn/kill as needed */
 #endif /* LEAF */
 #endif /* LEAF */

+ 9 - 6
src/conf.c

@@ -24,7 +24,9 @@
 #include <sys/stat.h>
 #include <sys/stat.h>
 #include <signal.h>
 #include <signal.h>
 
 
+#ifdef CYGWIN_HACKS
 char cfile[DIRMAX] = "";
 char cfile[DIRMAX] = "";
+#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 */
 conf_t conffile;                /* just some config options only avail during loading */
 
 
@@ -234,7 +236,7 @@ confedit()
 
 
   if (!can_stat(tmpconf.file))
   if (!can_stat(tmpconf.file))
     fatal("Error reading new config file", 0);
     fatal("Error reading new config file", 0);
-  readconf(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);
   fix_tilde(&conffile.binpath);
   fix_tilde(&conffile.binpath);
   conf_to_bin(&conffile);       /* will exit */
   conf_to_bin(&conffile);       /* will exit */
@@ -455,9 +457,9 @@ void free_conf(void)
 }
 }
 
 
 int
 int
-parseconf()
+parseconf(bool error)
 {
 {
-  if (!conffile.bots->nick && !conffile.bots->next)     /* no bots ! */
+  if (error && !conffile.bots->nick && !conffile.bots->next)     /* no bots ! */
     werr(ERR_NOBOTS);
     werr(ERR_NOBOTS);
 
 
   if (conffile.username) {
   if (conffile.username) {
@@ -467,7 +469,7 @@ parseconf()
   }
   }
 
 
 #ifndef CYGWIN_HACKS
 #ifndef CYGWIN_HACKS
-  if (conffile.uid && conffile.uid != myuid) {
+  if (error && conffile.uid && conffile.uid != myuid) {
     sdprintf("wrong uid, conf: %d :: %d", conffile.uid, myuid);
     sdprintf("wrong uid, conf: %d :: %d", conffile.uid, myuid);
     werr(ERR_WRONGUID);
     werr(ERR_WRONGUID);
   } else if (!conffile.uid)
   } else if (!conffile.uid)
@@ -476,7 +478,8 @@ parseconf()
   if (conffile.uname && strcmp(conffile.uname, my_uname()) && !conffile.autouname) {
   if (conffile.uname && strcmp(conffile.uname, my_uname()) && !conffile.autouname) {
     baduname(conffile.uname, my_uname());       /* its not auto, and its not RIGHT, bail out. */
     baduname(conffile.uname, my_uname());       /* its not auto, and its not RIGHT, bail out. */
     sdprintf("wrong uname, conf: %s :: %s", conffile.uname, my_uname());
     sdprintf("wrong uname, conf: %s :: %s", conffile.uname, my_uname());
-    werr(ERR_WRONGUNAME);
+    if (error)
+      werr(ERR_WRONGUNAME);
   } else if (conffile.uname && conffile.autouname) {    /* if autouname, dont bother comparing, just set uname to output */
   } else if (conffile.uname && conffile.autouname) {    /* if autouname, dont bother comparing, just set uname to output */
     str_redup(&conffile.uname, my_uname());
     str_redup(&conffile.uname, my_uname());
   } else if (!conffile.uname) { /* if not set, then just set it, wont happen again next time... */
   } else if (!conffile.uname) { /* if not set, then just set it, wont happen again next time... */
@@ -496,7 +499,7 @@ parseconf()
 }
 }
 
 
 int
 int
-readconf(char *fname, int bits)
+readconf(const char *fname, int bits)
 {
 {
   FILE *f = NULL;
   FILE *f = NULL;
   int i = 0, enc = (bits & CONF_ENC) ? 1 : 0;
   int i = 0, enc = (bits & CONF_ENC) ? 1 : 0;

+ 4 - 2
src/conf.h

@@ -66,11 +66,13 @@ int conf_delbot(char *);
 pid_t checkpid(char *, conf_bot *);
 pid_t checkpid(char *, conf_bot *);
 void init_conf();
 void init_conf();
 void free_conf();
 void free_conf();
-int readconf(char *, int);
-int parseconf();
+int readconf(const char *, int);
+int parseconf(bool);
 int writeconf(char *, FILE *, int);
 int writeconf(char *, FILE *, int);
 void fillconf(conf_t *);
 void fillconf(conf_t *);
 void bin_to_conf(void);
 void bin_to_conf(void);
 
 
+#ifdef CYGWIN_HACKS
 extern char		cfile[DIRMAX];
 extern char		cfile[DIRMAX];
+#endif /* CYGWIN_HACKS */
 #endif /* !_CONF_H */
 #endif /* !_CONF_H */

+ 7 - 9
src/main.c

@@ -268,9 +268,9 @@ static void show_help()
 }
 }
 
 
 #ifdef LEAF
 #ifdef LEAF
-# define PARSE_FLAGS "023B:Cd:De:Eg:G:k:L:P:hnstu:U:v"
+# define PARSE_FLAGS "0234:B:Cd:De:Eg:G:k:L:P:hnstu:U:v"
 #else /* !LEAF */
 #else /* !LEAF */
-# define PARSE_FLAGS "023Cd:De:Eg:G:hnstu:U:v"
+# define PARSE_FLAGS "0234:Cd:De:Eg:G:hnstu:U:v"
 #endif /* HUB */
 #endif /* HUB */
 #define FLAGS_CHECKPASS "CdDeEgGhkntuUv"
 #define FLAGS_CHECKPASS "CdDeEgGhkntuUv"
 static void dtx_arg(int argc, char *argv[])
 static void dtx_arg(int argc, char *argv[])
@@ -293,6 +293,10 @@ static void dtx_arg(int argc, char *argv[])
       case '3':		/* return the size of our settings struct */
       case '3':		/* return the size of our settings struct */
         printf("%d %d\n", SETTINGS_VER, sizeof(settings_t));
         printf("%d %d\n", SETTINGS_VER, sizeof(settings_t));
         exit(0);
         exit(0);
+      case '4':
+        readconf(optarg, CONF_ENC);
+        parseconf(0);
+        conf_to_bin(&conffile);		/* this will exit() in write_settings() */
 #ifdef LEAF
 #ifdef LEAF
       case 'B':
       case 'B':
         localhub = 0;
         localhub = 0;
@@ -568,13 +572,6 @@ static void check_tempdir()
   }
   }
 }
 }
 
 
-void compat_read_conf(const char *fname)
-{
-  readconf(fname, CONF_ENC);
-  parseconf(0);
-  conf_to_bin(&conffile);	/* this will exit() in write_settings() */
-}
-
 /* FIXME: Remove after 1.2 (the hacks) */
 /* FIXME: Remove after 1.2 (the hacks) */
 static void startup_checks(int hack) {
 static void startup_checks(int hack) {
   /* for compatability with old conf files 
   /* for compatability with old conf files 
@@ -691,6 +688,7 @@ printf("out: %s\n", out);
   /* This allows -2/-0 to be used without an initialized binary */
   /* This allows -2/-0 to be used without an initialized binary */
 //  if (!(argc == 2 && (!strcmp(argv[1], "-2") || !strcmp(argv[1], "0")))) {
 //  if (!(argc == 2 && (!strcmp(argv[1], "-2") || !strcmp(argv[1], "0")))) {
 //  doesn't work correctly yet, if we don't go in here, our settings stay encrypted
 //  doesn't work correctly yet, if we don't go in here, our settings stay encrypted
+
     check_sum(binname, argc >= 3 && !strcmp(argv[1], "-p") ? argv[2] : NULL);
     check_sum(binname, argc >= 3 && !strcmp(argv[1], "-p") ? argv[2] : NULL);
 
 
     if (!checked_bin_buf)
     if (!checked_bin_buf)

+ 2 - 0
src/settings.h

@@ -2,6 +2,8 @@
 #define _SETTINGS_H
 #define _SETTINGS_H
 #define PREFIXLEN 16
 #define PREFIXLEN 16
 
 
+#define SETTINGS_VER 1
+
 typedef struct settings_struct {
 typedef struct settings_struct {
   char prefix[PREFIXLEN];
   char prefix[PREFIXLEN];
   /* -- STATIC -- */
   /* -- STATIC -- */

+ 3 - 2
src/shell.c

@@ -909,16 +909,17 @@ char *move_bin(const char *path, const char *file, bool run)
   char real[DIRMAX] = "";
   char real[DIRMAX] = "";
 
 
   egg_snprintf(newbin, sizeof newbin, "%s%s%s", path, path[strlen(path) - 1] == '/' ? "" : "/", file);
   egg_snprintf(newbin, sizeof newbin, "%s%s%s", path, path[strlen(path) - 1] == '/' ? "" : "/", file);
-  sdprintf("newbin: %s", newbin);
 
 
   ContextNote("realpath()");
   ContextNote("realpath()");
   realpath(binname, real);            /* get the realpath of binname */
   realpath(binname, real);            /* get the realpath of binname */
   ContextNote("realpath(): Success");
   ContextNote("realpath(): Success");
   /* running from wrong dir, or wrong bin name.. lets try to fix that :) */
   /* running from wrong dir, or wrong bin name.. lets try to fix that :) */
+  sdprintf("binname: %s", binname);
+  sdprintf("newbin: %s", newbin);
+  sdprintf("real: %s", real);
   if (strcmp(binname, newbin) && strcmp(newbin, real)) {              /* if wrong path and new path != current */
   if (strcmp(binname, newbin) && strcmp(newbin, real)) {              /* if wrong path and new path != current */
     bool ok = 1;
     bool ok = 1;
 
 
-    sdprintf("real: %s", real);
     sdprintf("wrong dir, is: %s :: %s", binname, newbin);
     sdprintf("wrong dir, is: %s :: %s", binname, newbin);
 
 
     unlink(newbin);
     unlink(newbin);