Răsfoiți Sursa

* Updated -c/-C so both will display the correct values but:
-C will comment the wrong values
-c will comment the correct values if the old is wrong


svn: 2071

Bryan Drewery 21 ani în urmă
părinte
comite
82d36e759d
3 a modificat fișierele cu 34 adăugiri și 20 ștergeri
  1. 2 1
      doc/UPDATES
  2. 27 19
      src/conf.c
  3. 5 0
      src/main.h

+ 2 - 1
doc/UPDATES

@@ -78,7 +78,8 @@ Lines prefixxed with '-' were disabled before release and are not finishsed, or
 * Combined kick reasons for +k and .kickban
 * Some changes to ./binary -C:
   -Default binpath is now the directory the binary is first ran in
-  -Running the bot with -C will automatically update uid/uname/homedir/username **(use -c to avoid this)**
+  -Running the bot with -C will automatically update uid/uname/homedir/username
+  -Added cmd line param '-c' to avoid auto updating uid/uname/homedir/username
   * Things done after the config is saved:
    -New bots are spawned and added (if linked)
    -Changed (NEW) ip/host for bots are added to the botnet (if linked)

+ 27 - 19
src/conf.c

@@ -699,9 +699,10 @@ writeconf(char *filename, FILE * stream, int bits)
   else if (!(bits & CONF_ENC))
     my_write = fprintf;
 
-#define comment(text)			\
+#define comment(text)	do {		\
 	if (bits & CONF_COMMENT)	\
-	  my_write(f, "%s\n", text);
+	  my_write(f, "%s\n", text);	\
+} while(0)
 
   if (stream) {
     f = stream;
@@ -713,36 +714,43 @@ writeconf(char *filename, FILE * stream, int bits)
   comment("# Lines beginning with # are what the preceeding line SHOULD be");
   comment("# They are simply comments and are not parsed at all.\n");
 
-  if ((do_confedit != 2) && (bits & CONF_COMMENT) && conf.uid != (signed) myuid) {
-    comment("#* Automatically updated with -C *#");
-    my_write(f, "! uid %d\n", myuid);
-    my_write(f, "#! uid %d\n", conf.uid);
+#define conf_com() do {							\
+	if (do_confedit == CONF_AUTO)					\
+	  comment("# Automatically updated with -C");			\
+	else								\
+	  comment("#The correct line follows. (Not auto due to -c)");	\
+} while(0)
+
+  if ((bits & CONF_COMMENT) && conf.uid != (signed) myuid) {
+    conf_com();
+    my_write(f, "%s! uid %d\n", do_confedit == CONF_AUTO ? "" : "#", myuid);
+    my_write(f, "%s! uid %d\n", do_confedit == CONF_STATIC ? "" : "#", conf.uid);
   } else
     my_write(f, "! uid %d\n", conf.uid);
 
   if (!conf.uname || (conf.uname && conf.autouname && strcmp(conf.uname, my_uname()))) {
-    comment("\n#* Automiatically updated - autouname is ON *#");
+    conf_com();
     my_write(f, "! uname %s\n", my_uname());
-  } else if ((do_confedit != 2) && conf.uname && !conf.autouname && strcmp(conf.uname, my_uname())) {
-    comment("\n#* Automatically updated with -C *#");
-    my_write(f, "! uname %s\n", my_uname());
-    my_write(f, "#! uname %s\n", conf.uname);
+  } else if (conf.uname && !conf.autouname && strcmp(conf.uname, my_uname())) {
+    conf_com();
+    my_write(f, "%s! uname %s\n", do_confedit == CONF_AUTO ? "" : "#", my_uname());
+    my_write(f, "%s! uname %s\n", do_confedit == CONF_STATIC ? "" : "#", conf.uname);
   } else
     my_write(f, "! uname %s\n", conf.uname);
 
   comment("");
 
-  if ((do_confedit != 2) && conf.username && strcmp(conf.username, my_username())) {
-    comment("#* Automatically updated with -C *#");
-    my_write(f, "! username %s\n", my_username());
-    my_write(f, "#! username %s\n", conf.username);
+  if (conf.username && strcmp(conf.username, my_username())) {
+    conf_com();
+    my_write(f, "%s! username %s\n", do_confedit == CONF_AUTO ? "" : "#", my_username());
+    my_write(f, "%s! username %s\n", do_confedit == CONF_STATIC ? "" : "#", conf.username);
   } else
     my_write(f, "! username %s\n", conf.username ? conf.username : my_username());
 
-  if ((do_confedit != 2) && conf.homedir && strcmp(conf.homedir, homedir(0))) {
-    comment("\n#* Automatically updated with -C *#");
-    my_write(f, "! homedir %s\n", homedir(0));
-    my_write(f, "#! homedir %s\n", conf.homedir);
+  if (conf.homedir && strcmp(conf.homedir, homedir(0))) {
+    conf_com();
+    my_write(f, "%s! homedir %s\n", do_confedit == CONF_AUTO ? "" : "#", homedir(0));
+    my_write(f, "%s! homedir %s\n", do_confedit == CONF_STATIC ? "" : "#", conf.homedir);
   } else 
     my_write(f, "! homedir %s\n", conf.homedir ? conf.homedir : homedir(0));
 

+ 5 - 0
src/main.h

@@ -8,6 +8,11 @@ enum {
   UPDATE_EXIT
 };
 
+enum {
+  CONF_AUTO = 1,
+  CONF_STATIC
+};
+
 extern int		role, default_flags, default_uflags, do_confedit,
 			updating;
 extern bool		use_stderr, backgrd, used_B, term_z, loading, have_take;