Przeglądaj źródła

* Added code to check if an update binary is initialized or not

svn: 1755
Bryan Drewery 21 lat temu
rodzic
commit
e24e9c25b0
2 zmienionych plików z 28 dodań i 4 usunięć
  1. 21 1
      src/binary.c
  2. 7 3
      src/main.c

+ 21 - 1
src/binary.c

@@ -352,12 +352,32 @@ check_sum(const char *fname, const char *cfgfile)
   }
 }
 
+static bool check_bin_initialized(const char *fname)
+{
+  int i = 0;
+  size_t len = strlen(fname) + 3 + 1;
+  char *path = (char *) calloc(1, len);
+
+  egg_snprintf(path, len, "%s -p", fname);
+
+  i = system(path);
+  free(path);
+  if (i != -1 && WEXITSTATUS(i) == 4)
+    return 1;
+
+  return 0;
+}
+
 void write_settings(const char *fname, int die)
 {
   MD5_CTX ctx;
   char *hash = NULL;
-
   MD5_Init(&ctx);
+
+
+  /* see if the binary is already initialized or not */
+  bool initialized = check_bin_initialized(fname);
+
   if ((hash = bin_checksum(fname, WRITE_CHECKSUM, &ctx))) {
     printf("* Wrote settings to: %s.\n", fname);
     if (die == -1)			/* only bother decrypting if we aren't about to exit */

+ 7 - 3
src/main.c

@@ -694,11 +694,15 @@ printf("out: %s\n", out);
   /* This allows -2/-0 to be used without an initialized binary */
 //  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], "-p")) {
+    if (settings.uname[0]) exit(4);
+    exit(5);
+  }
 
-    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)
-      exit(1);
+  if (!checked_bin_buf)
+    exit(1);
 //  }
   /* Now settings struct is filled */