Browse Source

* Fix 'HQ' user getting wiped in -t mode resulting in a crash. (fixes #298)

The user is no longer booted after the user transfer. Instead, if it did
not exist on the remote side, it is re-added. This resolves the segfault
from not having a user entry.

This may seem to be a security risk, however, adding user 'HQ' with minimal
flags will mitigate this a little because then the linking bot will still
have its flags wiped, but retain a user. This is of course assuming the binary
has not been tampered with.
Bryan Drewery 17 years ago
parent
commit
2e30b94f8d
5 changed files with 27 additions and 16 deletions
  1. 1 0
      doc/UPDATES
  2. 17 0
      src/chanprog.c
  3. 1 0
      src/chanprog.h
  4. 2 14
      src/main.c
  5. 6 2
      src/users.c

+ 1 - 0
doc/UPDATES

@@ -29,6 +29,7 @@
 * Fix cmd_slowjoin not counting bots correctly. (fixes #431)
 * Added telnet 'tcl expect' script in scripts/telnet.exp. Can be used for easier hub management over telnet from shell.
 * Fix 'cmd_rehash' problems on hubs.
+* Fix 'HQ' user getting wiped in -t mode resulting in a crash. (fixes #298)
 
 1.2.15.1
 * Fix leaf bots not updating behind other hubs (fixes #419)

+ 17 - 0
src/chanprog.c

@@ -656,6 +656,23 @@ void reload()
   hook_read_userfile();
 }
 
+void setup_HQ(int n) {
+    dcc[n].addr = iptolong(getmyip());
+    dcc[n].sock = STDOUT;
+    dcc[n].timeval = now;
+    dcc[n].u.chat->con_flags = conmask | LOG_ALL;
+    dcc[n].u.chat->strip_flags = STRIP_ALL;
+    dcc[n].status = STAT_ECHO;
+    strlcpy(dcc[n].nick, STR("HQ"), NICKLEN);
+    strlcpy(dcc[n].host, STR("llama@console"), UHOSTLEN);
+    dcc[n].user = get_user_by_handle(userlist, dcc[n].nick);
+    /* Make sure there's an innocuous HQ user if needed */
+    if (!dcc[n].user) {
+      userlist = adduser(userlist, dcc[n].nick, "none", "-", USER_ADMIN | USER_OWNER | USER_MASTER | USER_VOICE | USER_OP | USER_PARTY | USER_CHUBA | USER_HUBA, 0);
+      dcc[n].user = get_user_by_handle(userlist, dcc[n].nick);
+    }
+}
+
 /* Oddly enough, written by proton (Emech's coder)
  */
 int isowner(char *name)

+ 1 - 0
src/chanprog.h

@@ -30,6 +30,7 @@ char *samechans(const char *, const char *);
 void add_myself_to_userlist();
 bool is_hub(const char*);
 void load_internal_users();
+void setup_HQ(int);
 
 extern struct chanset_t		*chanset;
 extern char			admin[], origbotnick[NICKLEN + 1], origbotname[NICKLEN + 1], jupenick[NICKLEN], botname[NICKLEN + 1];

+ 2 - 14
src/main.c

@@ -903,20 +903,8 @@ printf("out: %s\n", out);
   if (!backgrd && term_z) {
     int n = new_dcc(&DCC_CHAT, sizeof(struct chat_info));
 
-    dcc[n].addr = iptolong(getmyip());
-    dcc[n].sock = STDOUT;
-    dcc[n].timeval = now;
-    dcc[n].u.chat->con_flags = conmask | LOG_ALL;
-    dcc[n].u.chat->strip_flags = STRIP_ALL;
-    dcc[n].status = STAT_ECHO;
-    strlcpy(dcc[n].nick, STR("HQ"), NICKLEN);
-    strlcpy(dcc[n].host, STR("llama@console"), UHOSTLEN);
-    dcc[n].user = get_user_by_handle(userlist, dcc[n].nick);
-    /* Make sure there's an innocuous HQ user if needed */
-    if (!dcc[n].user) {
-      userlist = adduser(userlist, dcc[n].nick, "none", "-", USER_ADMIN | USER_OWNER | USER_MASTER | USER_VOICE | USER_OP | USER_PARTY | USER_CHUBA | USER_HUBA, 0);
-      dcc[n].user = get_user_by_handle(userlist, dcc[n].nick);
-    }
+    setup_HQ(n);
+
     setsock(STDOUT, 0);          /* Entry in net table */
     dprintf(n, STR("\n### ENTERING DCC CHAT SIMULATION ###\n\n"));
     dcc_chatter(n);

+ 6 - 2
src/users.c

@@ -1217,8 +1217,12 @@ void check_stale_dcc_users()
     if (dcc[i].user == NULL) { /* Removed user */
       if (dcc[i].type == &DCC_BOT || dcc[i].type == &DCC_FORK_BOT || dcc[i].type == &DCC_BOT_NEW)
         botunlink(i, dcc[i].nick, "No longer a valid bot.");
-      else if (dcc[i].type == &DCC_CHAT)
-        do_boot(i, "internal", "No longer a valid user.");
+      else if (dcc[i].type == &DCC_CHAT) {
+        if (!backgrd && term_z && !strcmp(dcc[i].nick, "HQ"))
+          setup_HQ(i);
+        else
+          do_boot(i, "internal", "No longer a valid user.");
+      }
     }
   }
 }