فهرست منبع

Merge branch 'fish-updates'

* fish-updates:
  * Populate FishKeys in cmd_setkey
  * Don't FiSH encrypt DCC CHAT responses
  * Support '+p ' prefix on messages to not use FiSH
  * Add cmd_setkey for setting/clearing FiSH keys
Bryan Drewery 15 سال پیش
والد
کامیت
5ebce3f56f
4فایلهای تغییر یافته به همراه50 افزوده شده و 2 حذف شده
  1. 9 0
      doc/help.txt
  2. 5 1
      src/chanprog.c
  3. 1 1
      src/mod/ctcp.mod/ctcp.c
  4. 35 0
      src/mod/server.mod/cmdsserv.c

+ 9 - 0
doc/help.txt

@@ -1194,6 +1194,8 @@ See also: botjump, servers, botserver
 :leaf:keyx
 ### $bkeyx$b <nick>
     Initiaite DH1080 key-exchange with nick for FiSH protocol.
+ 
+%{+m}See also: setkey%{-}
 :leaf:kick
 ###  $bkick$b [channel|*] <nickname> [reason]
    Will kick a user off your current console channel (or specified
@@ -1726,6 +1728,13 @@ See also: reload, backup
     '%dbotset wraith nick -'
  
 See also: botset
+:leaf:setkey
+### $bsetkey$b <nick|channel> [key]
+ 
+    Sets the FiSH key for the given target.
+    Use no key to clear the currently set key.
+ 
+See also: keyx
 ::sha1
 ###  $bsha1$b <string>
    Returns the SHA1 hash of the specified string.

+ 5 - 1
src/chanprog.c

@@ -968,11 +968,15 @@ void privmsg(bd::String target, bd::String msg, int idx) {
   struct chanset_t* chan = NULL;
   if (have_cprivmsg && !strchr(CHANMETA, target[0]))
     chan = find_common_opped_chan(target);
+  bool cleartextPrefix = (msg(0, 3) == "+p ");
 
   // Encrypt with FiSH?
-  if (!strchr(CHANMETA, target[0]) && FishKeys.contains(target) && FishKeys[target]->sharedKey.length()) {
+  if (!strchr(CHANMETA, target[0]) && !cleartextPrefix && FishKeys.contains(target) && FishKeys[target]->sharedKey.length()) {
     msg = "+OK " + egg_bf_encrypt(msg, FishKeys[target]->sharedKey);
   }
+  if (cleartextPrefix) {
+    msg += static_cast<size_t>(3);
+  }
   if (chan)
     dprintf(idx, "CPRIVMSG %s %s :%s\n", target.c_str(), chan->name, msg.c_str());
   else

+ 1 - 1
src/mod/ctcp.mod/ctcp.c

@@ -658,7 +658,7 @@ static int ctcp_CHAT(char *nick, char *uhost, struct userrec *u, char *object, c
        * CTCP replies are NOTICE's this has to be a PRIVMSG
        * -poptix 5/1/1997 */
       bd::String msg;
-      msg = bd::String::printf("\001DCC CHAT chat %lu %u\001", iptolong(getmyip()), dcc[ix].port);
+      msg = bd::String::printf("+p \001DCC CHAT chat %lu %u\001", iptolong(getmyip()), dcc[ix].port);
       privmsg(nick, msg, DP_SERVER);
     }
     return BIND_RET_BREAK;

+ 35 - 0
src/mod/server.mod/cmdsserv.c

@@ -138,6 +138,40 @@ static void cmd_keyx(int idx, char *par) {
   return;
 }
 
+static void cmd_setkey(int idx, char *par) {
+  putlog(LOG_CMDS, "*", "#%s# setkey %s", dcc[idx].nick, par);
+
+  if (!par[0]) {
+    dprintf(idx, "Usage: setkey <nick|channel> [key]\n");
+    return;
+  }
+
+  char *target = newsplit(&par);
+  char *key = newsplit(&par);
+  bool have_key = FishKeys.contains(target);
+  fish_data_t* fishData = NULL;
+
+  if (!key[0]) {
+    // Clear the key
+    if (have_key) {
+      fishData = FishKeys[target];
+      FishKeys.remove(target);
+      delete fishData;
+      dprintf(idx, "Key cleared for '%s'\n", target);
+    } else {
+      dprintf(idx, "No key found for '%s'\n", target);
+    }
+  } else {
+    // Set the key
+    fishData = new fish_data_t;
+    fishData->sharedKey = key;
+    fishData->timestamp = now;
+    FishKeys[target] = fishData;
+    dprintf(idx, "Set key for '%s' to: %s", target, key);
+  }
+  return;
+}
+
 static void cmd_clearqueue(int idx, char *par)
 {
   int msgs;
@@ -202,6 +236,7 @@ static cmd_t C_dcc_serv[] =
   {"jump",		"m",	(Function) cmd_jump,		NULL, LEAF},
   {"keyx",		"o",	(Function) cmd_keyx,		NULL, LEAF},
   {"servers",		"m",	(Function) cmd_servers,		NULL, LEAF},
+  {"setkey",		"m",	(Function) cmd_setkey,		NULL, LEAF},
   {"umode",		"m",	(Function) cmd_umode,		NULL, LEAF},
   {NULL,		NULL,	NULL,				NULL, 0}
 };