Преглед на файлове

* Running the bot with -C will automatically update uid/uname/homedir/username **(use -c to avoid this)**

svn: 2069
Bryan Drewery преди 21 години
родител
ревизия
ab9fb47f5b
променени са 6 файла, в които са добавени 50 реда и са изтрити 40 реда
  1. 7 5
      doc/UPDATES
  2. 24 16
      src/conf.c
  3. 9 5
      src/main.c
  4. 1 1
      src/main.h
  5. 8 12
      src/shell.c
  6. 1 1
      src/shell.h

+ 7 - 5
doc/UPDATES

@@ -34,7 +34,6 @@ Lines prefixxed with '-' were disabled before release and are not finishsed, or
 * cmd_botconfig now supports wildcards for the bot parameter
 * Eliminated a duplicate struct (conffile)
 * Removed chanset cookie-time-slack
-* Default binpath is now the directory the binary is in when doing -C.
 * Fixed a memory leak in dns
 * Fixed DNS staying on nameservers that fail to give replies
 * Removed channel flag '+|-manop' as it was redundant with chanint 'manop'
@@ -77,10 +76,13 @@ Lines prefixxed with '-' were disabled before release and are not finishsed, or
 * Fixed unsetting a global ban when the same ban is local to a chan causes the bots to unban it. (#24)
 * +O now implies +o
 * Combined kick reasons for +k and .kickban
-* Some automatic things done after editing the binary with -C are:
-  -New bots are spawned and added (if linked)
-  -Changed (NEW) ip/host for bots are added to the botnet (if linked)
-  -Removed bots are killed and removed from the userlist (if linked)
+* 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)**
+  * 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)
+   -Removed bots are killed and removed from the userlist (if linked)
 * Fixed dccauth not correctly working according to it's [bot]config setting (#30)
 * Added match option for cmd_botcmd: '&' will match on all localhubs (first bot in config) (#28)
 * Added some debug logging when a telnet connection is ignored.

+ 24 - 16
src/conf.c

@@ -713,30 +713,38 @@ 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");
 
-  my_write(f, "! uid %d\n", conf.uid);
-
-  if ((bits & CONF_COMMENT) && conf.uid != (signed) myuid)
-    my_write(f, "#! uid %d\n\n", myuid);
+  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);
+  } else
+    my_write(f, "! uid %d\n", conf.uid);
 
   if (!conf.uname || (conf.uname && conf.autouname && strcmp(conf.uname, my_uname()))) {
-    comment("# Automatic");
+    comment("\n#* Automiatically updated - autouname is ON *#");
     my_write(f, "! uname %s\n", my_uname());
-  } else if (conf.uname && !conf.autouname && strcmp(conf.uname, my_uname())) {
-    my_write(f, "! uname %s\n", conf.uname);
-    comment("# autouname is OFF");
-    my_write(f, "#! uname %s\n\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
     my_write(f, "! uname %s\n", conf.uname);
 
   comment("");
 
-  my_write(f, "! username %s\n", conf.username ? conf.username : my_username());
-  if (conf.username && strcmp(conf.username, my_username()))
-    my_write(f, "#! username %s\n", my_username());
-
-  my_write(f, "! homedir %s\n", conf.homedir ? conf.homedir : homedir());
-  if (conf.homedir && strcmp(conf.homedir, homedir()))
-    my_write(f, "#! homedir %s\n", homedir());
+  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);
+  } 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);
+  } else 
+    my_write(f, "! homedir %s\n", conf.homedir ? conf.homedir : homedir(0));
 
   comment("\n# binpath needs to be full path unless it begins with '~', which uses 'homedir', ie, '~/'");
 

+ 9 - 5
src/main.c

@@ -93,7 +93,7 @@ char	quit_msg[1024];		/* quit message */
 time_t	now;			/* duh, now :) */
 
 #define fork_interval atoi( CFG_FORKINTERVAL.ldata ? CFG_FORKINTERVAL.ldata : CFG_FORKINTERVAL.gdata ? CFG_FORKINTERVAL.gdata : "0")
-static bool do_confedit = 0;		/* show conf menu if -C */
+int do_confedit = 0;		/* show conf menu if -C */
 static char do_killbot[21] = "";
 static int kill_sig;
 static char *update_bin = NULL;
@@ -272,8 +272,8 @@ static void show_help()
 }
 
 // leaf: BkLP
-#define PARSE_FLAGS STR("0234:aB:c:Cd:De:Ek:L:P:hnr:stu:U:v")
-#define FLAGS_CHECKPASS STR("CdDeEhknrtuUv")
+#define PARSE_FLAGS STR("0234:aB:cCd:De:EH:k:L:P:hnr:stu:U:v")
+#define FLAGS_CHECKPASS STR("cCdDeEhknrtuUv")
 static void dtx_arg(int argc, char *argv[])
 {
   int i = 0;
@@ -304,12 +304,15 @@ static void dtx_arg(int argc, char *argv[])
         used_B = 1;
         strlcpy(origbotname, optarg, NICKLEN + 1);
         break;
-      case 'c':
+      case 'H':
         printf("SHA1 (%s): %s\n", optarg, SHA1(optarg));
         printf("MD5  (%s): %s\n", optarg, MD5(optarg));
 //        do_crypt_console();
         exit(0);
         break;
+      case 'c':
+        do_confedit = 2;
+        break;
       case 'C':
         do_confedit = 1;
         break;
@@ -565,7 +568,8 @@ static void startup_checks(int hack) {
     confedit();		/* this will exit() */
 #endif /* !CYGWIN_HACKS */
 
-  parseconf(1);
+  if (!updating)
+    parseconf(1);
 
   if (!can_stat(binname))
    werr(ERR_BINSTAT);

+ 1 - 1
src/main.h

@@ -8,7 +8,7 @@ enum {
   UPDATE_EXIT
 };
 
-extern int		role, default_flags, default_uflags,
+extern int		role, default_flags, default_uflags, do_confedit,
 			updating;
 extern bool		use_stderr, backgrd, used_B, term_z, loading, have_take;
 extern char		tempdir[], *binname, owner[], version[], ver[], quit_msg[];

+ 8 - 12
src/shell.c

@@ -788,14 +788,14 @@ void baduname(char *confhas, char *myuname) {
   free(tmpFile);
 }
 
-char *homedir()
+char *homedir(bool useconf)
 {
   static char homedir_buf[DIRMAX] = "";
 
   if (!homedir_buf || (homedir_buf && !homedir_buf[0])) {
     char tmp[DIRMAX] = "";
 
-    if (conf.homedir)
+    if (conf.homedir && useconf)
       simple_snprintf(tmp, sizeof tmp, "%s", conf.homedir);
     else {
 #ifdef CYGWIN_HACKS
@@ -821,20 +821,16 @@ char *my_username()
   static char username[DIRMAX] = "";
 
   if (!username || (username && !username[0])) {
-    if (conf.username)
-      simple_snprintf(username, sizeof username, "%s", conf.username);
-    else {
 #ifdef CYGWIN_HACKS
-      simple_snprintf(username, sizeof username, "cygwin");
+    simple_snprintf(username, sizeof username, "cygwin");
 #else /* !CYGWIN_HACKS */
-      struct passwd *pw = NULL;
+    struct passwd *pw = NULL;
 
-      ContextNote("getpwuid()");
-      pw = getpwuid(myuid);
-      ContextNote("getpwuid(): Success");
-      simple_snprintf(username, sizeof username, "%s", pw->pw_name);
+    ContextNote("getpwuid()");
+    pw = getpwuid(myuid);
+    ContextNote("getpwuid(): Success");
+    simple_snprintf(username, sizeof username, "%s", pw->pw_name);
 #endif /* CYGWIN_HACKS */
-    }
   }
   return username;
 }

+ 1 - 1
src/shell.h

@@ -39,7 +39,7 @@
 void check_maxfiles();
 void check_mypid();
 int clear_tmp();
-char *homedir();
+char *homedir(bool = 1);
 char *my_username();
 char *my_uname();
 #ifndef CYGWIN_HACKS