Kaynağa Gözat

* Use special header for marking dynamic settings are initialized or not

Bryan Drewery 16 yıl önce
ebeveyn
işleme
cb8a56b549
3 değiştirilmiş dosya ile 14 ekleme ve 8 silme
  1. 7 4
      src/binary.c
  2. 2 2
      src/main.c
  3. 5 2
      src/settings.h

+ 7 - 4
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,6 +474,7 @@ 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->autocron);
@@ -507,6 +508,7 @@ tellconfig(settings_t *incfg)
 //  dofield(incfg->salt1);
 //  dofield(incfg->salt2);
   // -- DYNAMIC --
+  dofield(incfg->dynamic_initialized);
   dofield(incfg->bots);
   dofield(incfg->uid);
   dofield(incfg->autocron);
@@ -650,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)
@@ -661,6 +663,7 @@ 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);
+  strlcpy(settings.dynamic_initialized, "1", sizeof(settings.dynamic_initialized));
   simple_snprintf(settings.autocron, sizeof(settings.autocron), "%d", in->autocron);
   simple_snprintf(settings.portmin, sizeof(settings.portmin), "%d", in->portmin);
   simple_snprintf(settings.portmax, sizeof(settings.portmax), "%d", in->portmax);

+ 2 - 2
src/main.c

@@ -433,7 +433,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.homedir[0]) {
+        if (settings.dynamic_initialized[0]) {
           ++sdebug;
           bin_to_conf();
         }
@@ -636,7 +636,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.homedir[0])
+  if (settings.dynamic_initialized[0])
     bin_to_conf(do_confedit ? 0 : 1);		/* read our memory from settings[] into conf[] */
 
   if (do_confedit)

+ 5 - 2
src/settings.h

@@ -7,6 +7,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 -- */
@@ -22,6 +24,7 @@ typedef struct settings_struct {
   char dcc_prefix[17];
   char features[17];
   /* -- DYNAMIC -- */
+  char dynamic_initialized[17];
   char bots[1025];
   char uid[17];
   char autocron[17];         /* should the bot auto crontab itself? */
@@ -31,7 +34,7 @@ typedef struct settings_struct {
   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[14];        // (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'}
@@ -46,7 +49,7 @@ 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) + \
+#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)