Prechádzať zdrojové kódy

Merge branch 'maint'

* maint:
  Make ./wraith -q and -Q clearly exit when already written.
  Fix pack settings.hash starting with \0 even though it's a valid hash.
Bryan Drewery 7 rokov pred
rodič
commit
794c227b65
6 zmenil súbory, kde vykonal 25 pridanie a 7 odobranie
  1. 3 1
      doc/UPDATES.md
  2. 3 1
      src/binary.cc
  3. 2 2
      src/main.cc
  4. 13 2
      src/settings.h
  5. 2 0
      src/shell.cc
  6. 2 1
      src/shell.h

+ 3 - 1
doc/UPDATES.md

@@ -14,7 +14,9 @@
   * Clear FiSH keys when a client quits.
   * Fix crash when clearing last botset entry for a bot.
   * Bots now share channel key to other bots even if not opped.
-  * Some small performance improvements
+  * Some small performance improvements.
+  * Fix rare issue with writing binary config.
+  * Make ./wraith -q and -Q clearly exit when already written.
 
 # 1.4.9
   * Fix various compile warnings and spam

+ 3 - 1
src/binary.cc

@@ -639,7 +639,7 @@ tellconfig(settings_t *incfg)
 void
 check_sum(const char *fname, const char *cfgfile, bool read_stdin)
 {
-   if (!settings.hash[0]) {
+   if (!settings_initialized()) {
 
     if (!cfgfile && !read_stdin)
       fatal(STR("Binary not initialized."), 0);
@@ -651,6 +651,8 @@ check_sum(const char *fname, const char *cfgfile, bool read_stdin)
       printf(STR("* Wrote settings to binary.\n")); 
     exit(0);
   } else {
+    if (cfgfile || read_stdin)
+      werr(ERR_ALREADYINIT);
     char *hash = bin_checksum(fname, GET_CHECKSUM);
 
 // tellconfig(&settings); 

+ 2 - 2
src/main.cc

@@ -743,11 +743,11 @@ int main(int argc, char **argv)
 //  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
   if (argc == 2 && !strcmp(argv[1], STR("-q"))) {
-    if (settings.hash[0]) exit(4);	/* initialized */
+    if (settings_initialized()) exit(4);	/* initialized */
     exit(5);				/* not initialized */
   }
   if (argc == 2 && !strcmp(argv[1], STR("-p"))) {
-    if (settings.hash[0]) exit(4);	/* initialized */
+    if (settings_initialized()) exit(4);	/* initialized */
     exit(5);				/* not initialized */
   }
 

+ 13 - 2
src/settings.h

@@ -1,6 +1,8 @@
 #ifndef _SETTINGS_H
 #define _SETTINGS_H
 
+#include <string.h>
+
 // If changing this, need to also change the usage in main.c which assumes all of it is \200
 #define SETTINGS_HEADER "\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200"
 #define PREFIXLEN sizeof(SETTINGS_HEADER)
@@ -10,7 +12,7 @@
 
 #define DYNAMIC_HEADER dynamic_initialized
 
-typedef struct settings_struct {
+struct settings_struct {
   char prefix[PREFIXLEN];
   /* -- STATIC -- */
 //  char hash[33];
@@ -37,7 +39,8 @@ typedef struct settings_struct {
   char portmax[17];       /* for hubs, the reserved port range for incoming connections */
   /* -- PADDING -- */
   char padding[6];        // (16 - (sizeof(settings_t) % 16)) % 16]
-} settings_t;
+} __attribute__((packed, aligned(16)));
+typedef struct settings_struct 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'}
 #define SALT2 {s2_5[0],s2_5[1],s2_2[0],s2_2[1],s2_8[1],s2_4[0],s2_7[1],s2_4[1],s2_1[0],s2_6[0],s2_1[1],s2_6[1],s2_3[0],s2_3[1],s2_8[0],s2_7[0],'\0'}
@@ -64,4 +67,12 @@ sizeof(settings.portmin) + sizeof(settings.portmin) + sizeof(settings.datadir)
 
 extern settings_t       settings;
 
+static inline bool
+__attribute__((pure))
+settings_initialized(void)
+{
+  static const char p[sizeof(settings.hash)] = "";
+  return memcmp(settings.hash, p, sizeof(settings.hash)) != 0;
+}
+
 #endif /* !_SETTINGS_H */

+ 2 - 0
src/shell.cc

@@ -740,6 +740,8 @@ const char *werr_tostr(int errnum)
     return STR("Too many bots defined. 5 max. Too many will lead to klines.\nSpread out into multiple accounts/shells/ip ranges.");
   case ERR_LIBS:
     return STR("Failed to load required libraries.\nEnsure that 32bit glibc, OpenSSL and libgcc are installed.\nhttps://github.com/wraith/wraith/wiki/Binary-Compatibiliy");
+  case ERR_ALREADYINIT:
+    return STR("Binary settings already written.");
   default:
     return STR("Unforseen error");
   }

+ 2 - 1
src/shell.h

@@ -24,7 +24,8 @@
 #define ERR_NOTINIT	22
 #define ERR_TOOMANYBOTS 23
 #define ERR_LIBS	24
-#define ERR_MAX         25
+#define ERR_ALREADYINIT 25
+#define ERR_MAX         26
 
 #define DETECT_LOGIN 	1
 #define DETECT_TRACE 	2