Author: Isomer <isomer@coders.net>
[ircu2.10.12-pk.git] / ircd / m_server.c
index baaaf582629b12d664e97ed728389d152bf40907..b0af144cbd227808ed90f75bb60822e8d5603415 100644 (file)
 #include "handlers.h"
 #endif /* 0 */
 #include "client.h"
-#include "crule.h"
 #include "hash.h"
 #include "ircd.h"
 #include "ircd_log.h"
 #include "ircd_reply.h"
 #include "ircd_string.h"
+#include "jupe.h"
 #include "list.h"
 #include "match.h"
 #include "msg.h"
@@ -137,8 +137,8 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   struct Client*   bcptr;
   struct Client*   LHcptr = 0;
   struct ConfItem* aconf = 0;
-  struct ConfItem* cconf;
   struct ConfItem* lhconf = 0;
+  struct Jupe*     ajupe = 0;
   int              hop;
   int              ret;
   int              active_lh_line = 0;
@@ -148,12 +148,6 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   time_t           recv_time;
   time_t           ghost = 0;
 
-  if (IsUser(cptr))
-  {
-    sendto_one(cptr, err_str(ERR_ALREADYREGISTRED), me.name, parv[0]);
-    return 0;
-  }
-
   if (IsUserPort(cptr))
     return exit_client_msg(cptr, cptr, &me, 
                            "Cannot connect a server to a user port");
@@ -166,8 +160,13 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     return need_more_params(sptr, "SERVER");
     return exit_client(cptr, cptr, &me, "Need more parameters");
   }
-  ircd_log(L_NOTICE, "SERVER: %s %s[%s]", parv[1], cptr->sockhost, cptr->sock_ip);
   host = parv[1];
+
+  if ((ajupe = jupe_find(host)) && JupeIsActive(ajupe))
+    return exit_client_msg(cptr, sptr, &me, "Juped: %s", JupeReason(ajupe));
+
+  ircd_log(L_NOTICE, "SERVER: %s %s[%s]", parv[1], cptr->sockhost, cptr->sock_ip);
+
   /*
    * Detect protocol
    */
@@ -200,8 +199,8 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   ircd_strncpy(info, parv[parc - 1], REALLEN);
   info[REALLEN] = '\0';
   if (prot < atoi(MINOR_PROTOCOL)) {
-    sendto_ops("Got incompatible protocol version (%s) from %s",
-               parv[5], cptr->name);
+    sendto_opmask_butone(0, SNO_OLDSNO, "Got incompatible protocol version "
+                        "(%s) from %s", parv[5], cptr->name);
     return exit_new_server(cptr, sptr, host, timestamp,
                            "Incompatible protocol: %s", parv[5]);
   }
@@ -221,7 +220,8 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
       break;
   }
   if (*ch || !strchr(host, '.')) {
-    sendto_ops("Bogus server name (%s) from %s", host, cptr->name);
+    sendto_opmask_butone(0, SNO_OLDSNO, "Bogus server name (%s) from %s",
+                        host, cptr->name);
     return exit_client_msg(cptr, cptr, &me, "Bogus server name (%s)", host);
   }
 
@@ -299,18 +299,16 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     cptr->hopcount = hop;
 
     /* check connection rules */
-    for (cconf = GlobalConfList; cconf; cconf = cconf->next) {
-      if ((cconf->status == CONF_CRULEALL) && (match(cconf->host, host) == 0)) {
-        if (crule_eval(cconf->passwd)) {
-          ServerStats->is_ref++;
-          sendto_ops("Refused connection from %s.", cptr->name);
-          return exit_client(cptr, cptr, &me, "Disallowed by connection rule");
-        }
-      }
+    if (0 != conf_eval_crule(host, CRULE_ALL)) {
+      ServerStats->is_ref++;
+      sendto_opmask_butone(0, SNO_OLDSNO, "Refused connection from %s.", cptr->name);
+      return exit_client(cptr, cptr, &me, "Disallowed by connection rule");
     }
+
     if (conf_check_server(cptr)) {
       ++ServerStats->is_ref;
-      sendto_ops("Received unauthorized connection from %s.", cptr->name);
+      sendto_opmask_butone(0, SNO_OLDSNO, "Received unauthorized connection "
+                          "from %s.", cptr->name);
       return exit_client(cptr, cptr, &me, "No C:line");
     }
 
@@ -321,15 +319,17 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     if (!(aconf = find_conf_byname(cptr->confs, host, CONF_SERVER))) {
       ++ServerStats->is_ref;
 #ifndef GODMODE
-      sendto_ops("Access denied. No conf line for server %s", cptr->name);
+      sendto_opmask_butone(0, SNO_OLDSNO, "Access denied. No conf line for "
+                          "server %s", cptr->name);
       return exit_client_msg(cptr, cptr, &me,
           "Access denied. No conf line for server %s", cptr->name);
 #else /* GODMODE */
-      sendto_ops("General C: line active: No line for server %s", cptr->name);
+      sendto_opmask_butone(0, SNO_OLDSNO, "General C: line active: No line "
+                          "for server %s", cptr->name);
       aconf = find_conf_byname(cptr->confs, "general.undernet.org", CONF_SERVER);
       if (!aconf) {
-        sendto_ops("Neither C lines for server %s nor "
-            "\"general.undernet.org\"", cptr->name);
+        sendto_opmask_butone(0, SNO_OLDSNO, "Neither C lines for server %s "
+                            "nor \"general.undernet.org\"", cptr->name);
         return exit_client_msg(cptr, cptr, &me, "No C lines for server %s", cptr->name);
       }
 #endif /* GODMODE */
@@ -337,12 +337,7 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 #ifdef CRYPT_LINK_PASSWORD
     /* passwd may be NULL. Head it off at the pass... */
     if (*cptr->passwd) {
-      char salt[3];
-
-      salt[0] = aconf->passwd[0];
-      salt[1] = aconf->passwd[1];
-      salt[2] = '\0';
-      encr = ircd_crypt(cptr->passwd, salt);
+      encr = ircd_crypt(cptr->passwd, aconf->passed);
     }
     else
       encr = "";
@@ -352,7 +347,8 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 #ifndef GODMODE
     if (*aconf->passwd && !!strcmp(aconf->passwd, encr)) {
       ++ServerStats->is_ref;
-      sendto_ops("Access denied (passwd mismatch) %s", cptr->name);
+      sendto_opmask_butone(0, SNO_OLDSNO, "Access denied (passwd mismatch) %s",
+                          cptr->name);
       return exit_client_msg(cptr, cptr, &me,
           "No Access (passwd mismatch) %s", cptr->name);
     }
@@ -393,14 +389,14 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
      *  If my ircd.conf sucks, I can try to connect to myself:
      */
     if (acptr == &me)
-      return exit_client_msg(cptr, cptr, &me, "nick collision with me (%s)", host);
+      return exit_client_msg(cptr, cptr, &me, "nick collision with me (%s), check server number in M:?", host);
     /*
      * Detect wrong numeric.
      */
     if (0 != ircd_strcmp(acptr->name, host)) {
-      sendto_serv_butone(cptr,
-          ":%s WALLOPS :SERVER Numeric Collision: %s != %s",
-          me.name, acptr->name, host);
+      sendcmdto_serv_butone(&me, CMD_WALLOPS, cptr,
+                           ":SERVER Numeric Collision: %s != %s",
+                           acptr->name, host);
       return exit_client_msg(cptr, cptr, &me,
           "NUMERIC collision between %s and %s."
           " Is your server numeric correct ?", host, acptr->name);
@@ -437,8 +433,9 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     {
       if (!IsServer(sptr))
         return exit_client(cptr, sptr, &me, acptr->info);
-      sendto_one(cptr, ":%s WALLOPS :Received :%s SERVER %s from %s !?!",
-          me.name, parv[0], parv[1], cptr->name);
+      sendcmdto_serv_butone(&me, CMD_WALLOPS, cptr,
+                           ":Received :%s SERVER %s from %s !?!", parv[0],
+                           parv[1], cptr->name);
       return exit_new_server(cptr, sptr, host, timestamp, "%s", acptr->info);
     }
     /*
@@ -620,7 +617,8 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   {
     if (LHcptr == 0) {
       return exit_new_server(cptr, sptr, host, timestamp,
-          (active_lh_line == 2) ?  "Non-Hub link %s <- %s(%s)" : "Leaf-only link %s <- %s(%s)",
+          (active_lh_line == 2) ?  "Non-Hub link %s <- %s(%s), check H:" : 
+                                   "Leaf-only link %s <- %s(%s), check L:",
           cptr->name, host, 
           lhconf ? (lhconf->name ? lhconf->name : "*") : "!");
     }
@@ -630,7 +628,8 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
       if (active_lh_line < 3)
       {
         if (exit_client_msg(cptr, LHcptr, &me,
-            (active_lh_line == 2) ?  "Non-Hub link %s <- %s(%s)" : "Leaf-only link %s <- %s(%s)",
+            (active_lh_line == 2) ?  "Non-Hub link %s <- %s(%s), check H:" : 
+                                     "Leaf-only link %s <- %s(%s), check L:",
             cptr->name, host,
             lhconf ? (lhconf->name ? lhconf->name : "*") : "!") == CPTR_KILLED)
           return CPTR_KILLED;
@@ -638,7 +637,7 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
       else
       {
         ServerStats->is_ref++;
-        if (exit_client(cptr, LHcptr, &me, "I'm a leaf") == CPTR_KILLED)
+        if (exit_client(cptr, LHcptr, &me, "I'm a leaf, define HUB") == CPTR_KILLED)
           return CPTR_KILLED;
       }
       /*
@@ -679,13 +678,16 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     if (*parv[5] == 'J')
     {
       SetBurst(acptr);
-      sendto_op_mask(SNO_NETWORK, "Net junction: %s %s",
+      sendto_opmask_butone(0, SNO_NETWORK, "Net junction: %s %s",
           sptr->name, acptr->name);
       SetJunction(acptr);
     }
     /*
      * Old sendto_serv_but_one() call removed because we now need to send
      * different names to different servers (domain name matching).
+     *
+     * Personally, I think this is bogus; it's a feature we don't use here.
+     * -Kev
      */
     for (i = 0; i <= HighestFd; i++)
     {
@@ -694,9 +696,9 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
         continue;
       if (0 == match(me.name, acptr->name))
         continue;
-        sendto_one(bcptr, "%s " TOK_SERVER " %s %d 0 %s %s %s%s 0 :%s",
-            NumServ(sptr), acptr->name, hop + 1, parv[4], parv[5],
-            NumServCap(acptr), acptr->info);
+      sendcmdto_one(sptr, CMD_SERVER, bcptr, "%s %d 0 %s %s %s%s 0 :%s",
+                   acptr->name, hop + 1, parv[4], parv[5], NumServCap(acptr),
+                   acptr->info);
     }
     return 0;
   }
@@ -712,19 +714,21 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     {
 #ifndef RELIABLE_CLOCK
 #ifdef TESTNET
-      sendto_ops("Debug: my start time: " TIME_T_FMT " ; others start time: "
-          TIME_T_FMT, me.serv->timestamp, start_timestamp);
-      sendto_ops("Debug: receive time: " TIME_T_FMT " ; received timestamp: "
-          TIME_T_FMT " ; difference %ld",
-          recv_time, timestamp, timestamp - recv_time);
+      sendto_opmask_butone(0, SNO_OLDSNO, "Debug: my start time: %Tu ; "
+                          "others start time: %Tu", me.serv->timestamp,
+                          start_timestamp);
+      sendto_opmask_butone(0, SNO_OLDSNO, "Debug: receive time: %Tu ; "
+                          "received timestamp: %Tu ; difference %ld",
+                          recv_time, timestamp, timestamp - recv_time);
 #endif
       if (start_timestamp < me.serv->timestamp)
       {
-        sendto_ops("got earlier start time: " TIME_T_FMT " < " TIME_T_FMT,
-            start_timestamp, me.serv->timestamp);
+        sendto_opmask_butone(0, SNO_OLDSNO, "got earlier start time: "
+                            "%Tu < %Tu", start_timestamp, me.serv->timestamp);
         me.serv->timestamp = start_timestamp;
         TSoffset += timestamp - recv_time;
-        sendto_ops("clock adjusted by adding %d", (int)(timestamp - recv_time));
+        sendto_opmask_butone(0, SNO_OLDSNO, "clock adjusted by adding %d",
+                            (int)(timestamp - recv_time));
       }
       else if ((start_timestamp > me.serv->timestamp) && IsUnknown(cptr))
         cptr->serv->timestamp = TStime();
@@ -740,8 +744,8 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
           cptr->serv->timestamp = TStime();
         else if (IsHandshake(cptr))
         {
-          sendto_ops("clock adjusted by adding %d",
-              (int)(timestamp - recv_time));
+          sendto_opmask_butone(0, SNO_OLDSNO, "clock adjusted by adding %d",
+                              (int)(timestamp - recv_time));
           TSoffset += timestamp - recv_time;
         }
       }
@@ -753,18 +757,18 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 #endif
     }
 
-    ret = server_estab(cptr, aconf);
+    ret = server_estab(cptr, aconf, ajupe);
   }
   else
     ret = 0;
 #ifdef RELIABLE_CLOCK
   if (abs(cptr->serv->timestamp - recv_time) > 30)
   {
-    sendto_ops("Connected to a net with a timestamp-clock"
-        " difference of " STIME_T_FMT " seconds! Used SETTIME to correct"
-        " this.", timestamp - recv_time);
-    sendto_one(cptr, ":%s SETTIME " TIME_T_FMT " :%s",
-        me.name, TStime(), me.name);
+    sendto_opmask_butone(0, SNO_OLDSNO, "Connected to a net with a "
+                        "timestamp-clock difference of %Td seconds! "
+                        "Used SETTIME to correct this.",
+                        timestamp - recv_time);
+    sendcmdto_one(&me, CMD_SETTIME, cptr, "%Tu :%s", TStime(), me.name);
   }
 #endif
 
@@ -785,6 +789,8 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
  *    parv[6] = "YMM", where 'Y' is the server numeric and "MM" is the
  *              numeric nick mask of this server.
  *    parv[7] = 0 (not used yet, mandatory unsigned int after u2.10.06)
+ *    parv[8] = %<lastmod> - optional parameter only present if there's an
+ *             outstanding JUPE; specifies the JUPE's lastmod field
  */
 int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 {
@@ -796,8 +802,8 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   struct Client*   bcptr;
   struct Client*   LHcptr = 0;
   struct ConfItem* aconf = 0;
-  struct ConfItem* cconf;
   struct ConfItem* lhconf = 0;
+  struct Jupe*     ajupe = 0;
   int              hop;
   int              ret;
   int              active_lh_line = 0;
@@ -806,12 +812,7 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   time_t           timestamp = 0;
   time_t           recv_time;
   time_t           ghost = 0;
-
-  if (IsUser(cptr))
-  {
-    sendto_one(cptr, err_str(ERR_ALREADYREGISTRED), me.name, parv[0]);
-    return 0;
-  }
+  time_t           lastmod = 0;
 
   if (IsUserPort(cptr))
     return exit_client_msg(cptr, cptr, &me,
@@ -825,6 +826,7 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     return exit_client(cptr, cptr, &me, "Need more parameters");
   }
   host = parv[1];
+
   /*
    * Detect protocol
    */
@@ -856,11 +858,21 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   ircd_strncpy(info, parv[parc - 1], REALLEN);
   info[REALLEN] = '\0';
   if (prot < atoi(MINOR_PROTOCOL)) {
-    sendto_ops("Got incompatible protocol version (%s) from %s",
-               parv[5], cptr->name);
+    sendto_opmask_butone(0, SNO_OLDSNO, "Got incompatible protocol version "
+                        "(%s) from %s", parv[5], cptr->name);
     return exit_new_server(cptr, sptr, host, timestamp,
                            "Incompatible protocol: %s", parv[5]);
   }
+  if (parc > 9 && *parv[8] == '%')
+    lastmod = atoi(parv[8] + 1);
+  /* If there's a jupe that matches, and it's a global jupe, and the
+   * introducer didn't indicate it knew of the jupe or has an older
+   * version of the jupe, and the connection isn't in a BURST, resynch
+   * the jupe.
+   */
+  if ((ajupe = jupe_find(host)) && !JupeIsLocal(ajupe) &&
+      JupeLastMod(ajupe) > lastmod && !IsBurstOrBurstAck(cptr))
+    jupe_resend(cptr, ajupe);
   /*
    * Check for "FRENCH " infection ;-) (actually this should
    * be replaced with routine to check the hostname syntax in
@@ -875,7 +887,8 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     if (*ch <= ' ' || *ch > '~')
       break;
   if (*ch || !strchr(host, '.')) {
-    sendto_ops("Bogus server name (%s) from %s", host, cptr->name);
+    sendto_opmask_butone(0, SNO_OLDSNO, "Bogus server name (%s) from %s",
+                        host, cptr->name);
     return exit_client_msg(cptr, cptr, &me, "Bogus server name (%s)", host);
   }
 
@@ -953,19 +966,15 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     cptr->hopcount = hop;
 
     /* check connection rules */
-    for (cconf = GlobalConfList; cconf; cconf = cconf->next) {
-      if ((cconf->status == CONF_CRULEALL) && (match(cconf->host, host) == 0)) {
-        if (crule_eval(cconf->passwd))
-        {
-          ServerStats->is_ref++;
-          sendto_ops("Refused connection from %s.", cptr->name);
-          return exit_client(cptr, cptr, &me, "Disallowed by connection rule");
-        }
-      }
+    if (0 != conf_eval_crule(host, CRULE_ALL)) {
+      ServerStats->is_ref++;
+      sendto_opmask_butone(0, SNO_OLDSNO, "Refused connection from %s.", cptr->name);
+      return exit_client(cptr, cptr, &me, "Disallowed by connection rule");
     }
     if (conf_check_server(cptr)) {
       ++ServerStats->is_ref;
-      sendto_ops("Received unauthorized connection from %s.", cptr->name);
+      sendto_opmask_butone(0, SNO_OLDSNO, "Received unauthorized connection "
+                          "from %s.", cptr->name);
       return exit_client(cptr, cptr, &me, "No C conf lines");
     }
 
@@ -976,16 +985,18 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     if (!(aconf = find_conf_byname(cptr->confs, host, CONF_SERVER))) {
       ++ServerStats->is_ref;
 #ifndef GODMODE
-      sendto_ops("Access denied. No conf line for server %s", cptr->name);
+      sendto_opmask_butone(0, SNO_OLDSNO, "Access denied. No conf line for "
+                          "server %s", cptr->name);
       return exit_client_msg(cptr, cptr, &me,
                              "Access denied. No conf line for server %s", cptr->name);
 #else /* GODMODE */
-      sendto_ops("General C line active: No line for server %s", cptr->name);
+      sendto_opmask_butone(0, SNO_OLDSNO, "General C line active: No line "
+                          "for server %s", cptr->name);
       aconf =
           find_conf_byname(cptr->confs, "general.undernet.org", CONF_SERVER);
       if (!aconf) {
-        sendto_ops("Neither C lines for server %s nor "
-            "\"general.undernet.org\"", cptr->name);
+        sendto_opmask_butone(0, SNO_OLDSNO, "Neither C lines for server %s "
+                            "nor \"general.undernet.org\"", cptr->name);
         return exit_client_msg(cptr, cptr, &me,
             "No C lines for server %s", cptr->name);
       }
@@ -995,12 +1006,7 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     /* passwd may be NULL. Head it off at the pass... */
     if (*cptr->passwd)
     {
-      char salt[3];
-
-      salt[0] = aconf->passwd[0];
-      salt[1] = aconf->passwd[1];
-      salt[2] = '\0';
-      encr = ircd_crypt(cptr->passwd, salt);
+      encr = ircd_crypt(cptr->passwd, aconf->passwd);
     }
     else
       encr = "";
@@ -1010,7 +1016,8 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 #ifndef GODMODE
     if (*aconf->passwd && !!strcmp(aconf->passwd, encr)) {
       ++ServerStats->is_ref;
-      sendto_ops("Access denied (passwd mismatch) %s", cptr->name);
+      sendto_opmask_butone(0, SNO_OLDSNO, "Access denied (passwd mismatch) %s",
+                          cptr->name);
       return exit_client_msg(cptr, cptr, &me,
                              "No Access (passwd mismatch) %s", cptr->name);
     }
@@ -1052,15 +1059,15 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
      */
     if (acptr == &me)
       return exit_client_msg(cptr, cptr, &me,
-          "nick collision with me (%s)", host);
+          "nick collision with me, check server number in M:? (%s)", host);
     /*
      * Detect wrong numeric.
      */
     if (0 != ircd_strcmp(acptr->name, host))
     {
-      sendto_serv_butone(cptr,
-          ":%s WALLOPS :SERVER Numeric Collision: %s != %s",
-          me.name, acptr->name, host);
+      sendcmdto_serv_butone(&me, CMD_WALLOPS, cptr,
+                           ":SERVER Numeric Collision: %s != %s", acptr->name,
+                           host);
       return exit_client_msg(cptr, cptr, &me,
           "NUMERIC collision between %s and %s."
           " Is your server numeric correct ?", host, acptr->name);
@@ -1097,8 +1104,8 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     {
       if (!IsServer(sptr))
         return exit_client(cptr, sptr, &me, acptr->info);
-      sendto_one(cptr, ":%s WALLOPS :Received :%s SERVER %s from %s !?!",
-          me.name, parv[0], parv[1], cptr->name);
+      sendcmdto_one(&me, CMD_WALLOPS, cptr, ":Received :%s SERVER %s "
+                   "from %s !?!", parv[0], parv[1], cptr->name);
       return exit_new_server(cptr, sptr, host, timestamp, "%s", acptr->info);
     }
     /*
@@ -1339,8 +1346,8 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     if (*parv[5] == 'J')
     {
       SetBurst(acptr);
-      sendto_op_mask(SNO_NETWORK, "Net junction: %s %s",
-          sptr->name, acptr->name);
+      sendto_opmask_butone(0, SNO_NETWORK, "Net junction: %s %s",
+                          sptr->name, acptr->name);
       SetJunction(acptr);
     }
     /*
@@ -1354,9 +1361,9 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
         continue;
       if (0 == match(me.name, acptr->name))
         continue;
-        sendto_one(bcptr, "%s " TOK_SERVER " %s %d 0 %s %s %s%s 0 :%s",
-            NumServ(sptr), acptr->name, hop + 1, parv[4], parv[5],
-            NumServCap(acptr), acptr->info);
+      sendcmdto_one(sptr, CMD_SERVER, bcptr, "%s %d 0 %s %s %s%s 0 :%s",
+                   acptr->name, hop + 1, parv[4], parv[5], NumServCap(acptr),
+                   acptr->info);
     }
     return 0;
   }
@@ -1372,19 +1379,21 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     {
 #ifndef RELIABLE_CLOCK
 #ifdef TESTNET
-      sendto_ops("Debug: my start time: " TIME_T_FMT " ; others start time: "
-          TIME_T_FMT, me.serv->timestamp, start_timestamp);
-      sendto_ops("Debug: receive time: " TIME_T_FMT " ; received timestamp: "
-          TIME_T_FMT " ; difference %ld",
-          recv_time, timestamp, timestamp - recv_time);
+      sendto_opmask_butone(0, SNO_OLDSNO, "Debug: my start time: %Tu ; "
+                          "others start time: %Tu", me.serv->timestamp,
+                          start_timestamp);
+      sendto_opmask_butone(0, SNO_OLDSNO, "Debug: receive time: %Tu ; "
+                          "received timestamp: %Tu ; difference %ld",
+                          recv_time, timestamp, timestamp - recv_time);
 #endif
       if (start_timestamp < me.serv->timestamp)
       {
-        sendto_ops("got earlier start time: " TIME_T_FMT " < " TIME_T_FMT,
-            start_timestamp, me.serv->timestamp);
+        sendto_opmask_butone(0, SNO_OLDSNO, "got earlier start time: "
+                            "%Tu < %Tu", start_timestamp, me.serv->timestamp);
         me.serv->timestamp = start_timestamp;
         TSoffset += timestamp - recv_time;
-        sendto_ops("clock adjusted by adding %d", (int)(timestamp - recv_time));
+        sendto_opmask_butone(0, SNO_OLDSNO, "clock adjusted by adding %d",
+                            (int)(timestamp - recv_time));
       }
       else if ((start_timestamp > me.serv->timestamp) && IsUnknown(cptr))
         cptr->serv->timestamp = TStime();
@@ -1400,8 +1409,8 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
           cptr->serv->timestamp = TStime();
         else if (IsHandshake(cptr))
         {
-          sendto_ops("clock adjusted by adding %d",
-              (int)(timestamp - recv_time));
+          sendto_opmask_butone(0, SNO_OLDSNO, "clock adjusted by adding %d",
+                              (int)(timestamp - recv_time));
           TSoffset += timestamp - recv_time;
         }
       }
@@ -1413,18 +1422,17 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 #endif
     }
 
-    ret = server_estab(cptr, aconf);
+    ret = server_estab(cptr, aconf, ajupe);
   }
   else
     ret = 0;
 #ifdef RELIABLE_CLOCK
   if (abs(cptr->serv->timestamp - recv_time) > 30)
   {
-    sendto_ops("Connected to a net with a timestamp-clock"
-        " difference of " STIME_T_FMT " seconds! Used SETTIME to correct"
-        " this.", timestamp - recv_time);
-    sendto_one(cptr, ":%s SETTIME " TIME_T_FMT " :%s",
-        me.name, TStime(), me.name);
+    sendto_opmask_butone(0, SNO_OLDSNO, "Connected to a net with a "
+                        "timestamp-clock difference of %Td seconds! Used "
+                        "SETTIME to correct this.", timestamp - recv_time);
+    sendcmdto_one(&me, CMD_SETTIME, cptr, "%Tu :%s", TStime(), me.name);
   }
 #endif
 
@@ -1458,8 +1466,8 @@ int m_server(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
   struct Client*   bcptr;
   struct Client*   LHcptr = 0;
   struct ConfItem* aconf = 0;
-  struct ConfItem* cconf;
   struct ConfItem* lhconf = 0;
+  struct Jupe*     ajupe = 0;
   int              hop;
   int              ret;
   int              active_lh_line = 0;
@@ -1471,7 +1479,7 @@ int m_server(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
 
   if (IsUser(cptr))
   {
-    sendto_one(cptr, err_str(ERR_ALREADYREGISTRED), me.name, parv[0]);
+    sendto_one(cptr, err_str(ERR_ALREADYREGISTRED), me.name, parv[0]); /* XXX DEAD */
     return 0;
   }
 
@@ -1519,7 +1527,7 @@ int m_server(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
   ircd_strncpy(info, parv[parc - 1], REALLEN);
   info[REALLEN] = '\0';
   if (prot < atoi(MINOR_PROTOCOL)) {
-    sendto_ops("Got incompatible protocol version (%s) from %s",
+    sendto_ops("Got incompatible protocol version (%s) from %s", /* XXX DEAD */
                parv[5], cptr->name);
     return exit_new_server(cptr, sptr, host, timestamp,
         "Incompatible protocol: %s", parv[5]);
@@ -1539,7 +1547,7 @@ int m_server(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
       break;
   if (*ch || !strchr(host, '.'))
   {
-    sendto_ops("Bogus server name (%s) from %s", host, cptr->name);
+    sendto_ops("Bogus server name (%s) from %s", host, cptr->name); /* XXX DEAD */
     return exit_client_msg(cptr, cptr, &me, "Bogus server name (%s)", host);
   }
 
@@ -1617,19 +1625,14 @@ int m_server(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
     cptr->hopcount = hop;
 
     /* check connection rules */
-    for (cconf = GlobalConfList; cconf; cconf = cconf->next) {
-      if ((cconf->status == CONF_CRULEALL) && (match(cconf->host, host) == 0)) {
-        if (crule_eval(cconf->passwd))
-        {
-          ServerStats->is_ref++;
-          sendto_ops("Refused connection from %s.", cptr->name);
-          return exit_client(cptr, cptr, &me, "Disallowed by connection rule");
-        }
-      }
+    if (0 != conf_eval_crule(host, CRULE_ALL)) {
+      ServerStats->is_ref++;
+      sendto_ops("Refused connection from %s.", cptr->name); /* XXX DEAD */
+      return exit_client(cptr, cptr, &me, "Disallowed by connection rule");
     }
     if (conf_check_server(cptr)) {
       ++ServerStats->is_ref;
-      sendto_ops("Received unauthorized connection from %s.", cptr->name);
+      sendto_ops("Received unauthorized connection from %s.", cptr->name); /* XXX DEAD */
       return exit_client(cptr, cptr, &me, "No C/N conf lines");
     }
 
@@ -1640,15 +1643,15 @@ int m_server(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
     if (!(aconf = find_conf_byname(cptr->confs, host, CONF_SERVER))) {
       ++ServerStats->is_ref;
 #ifndef GODMODE
-      sendto_ops("Access denied. No conf line for server %s", cptr->name);
+      sendto_ops("Access denied. No conf line for server %s", cptr->name); /* XXX DEAD */
       return exit_client_msg(cptr, cptr, &me,
           "Access denied. No conf line for server %s", cptr->name);
 #else /* GODMODE */
-      sendto_ops("General C/N: line active: No line for server %s", cptr->name);
+      sendto_ops("General C/N: line active: No line for server %s", cptr->name); /* XXX DEAD */
       aconf =
           find_conf_byname(cptr->confs, "general.undernet.org", CONF_SERVER);
       if (!aconf) {
-        sendto_ops("Neither C/N lines for server %s nor "
+        sendto_ops("Neither C/N lines for server %s nor " /* XXX DEAD */
             "\"general.undernet.org\"", cptr->name);
         return exit_client_msg(cptr, cptr, &me,
             "No C/N lines for server %s", cptr->name);
@@ -1659,12 +1662,7 @@ int m_server(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
     /* passwd may be NULL. Head it off at the pass... */
     if (*cptr->passwd)
     {
-      char salt[3];
-
-      salt[0] = aconf->passwd[0];
-      salt[1] = aconf->passwd[1];
-      salt[2] = '\0';
-      encr = ircd_crypt(cptr->passwd, salt);
+      encr = ircd_crypt(cptr->passwd, aconf->passwd);
     }
     else
       encr = "";
@@ -1674,7 +1672,7 @@ int m_server(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
 #ifndef GODMODE
     if (*aconf->passwd && !!strcmp(aconf->passwd, encr)) {
       ++ServerStats->is_ref;
-      sendto_ops("Access denied (passwd mismatch) %s", cptr->name);
+      sendto_ops("Access denied (passwd mismatch) %s", cptr->name); /* XXX DEAD */
       return exit_client_msg(cptr, cptr, &me,
           "No Access (passwd mismatch) %s", cptr->name);
     }
@@ -1716,13 +1714,13 @@ int m_server(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
      */
     if (acptr == &me)
       return exit_client_msg(cptr, cptr, &me,
-          "nick collision with me (%s)", host);
+          "nick collision with me, check server number in M:? (%s)", host);
     /*
      * Detect wrong numeric.
      */
     if (0 != ircd_strcmp(acptr->name, host))
     {
-      sendto_serv_butone(cptr,
+      sendto_serv_butone(cptr, /* XXX DEAD */
           ":%s WALLOPS :SERVER Numeric Collision: %s != %s",
           me.name, acptr->name, host);
       return exit_client_msg(cptr, cptr, &me,
@@ -1761,7 +1759,7 @@ int m_server(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
     {
       if (!IsServer(sptr))
         return exit_client(cptr, sptr, &me, acptr->info);
-      sendto_one(cptr, ":%s WALLOPS :Received :%s SERVER %s from %s !?!",
+      sendto_one(cptr, ":%s WALLOPS :Received :%s SERVER %s from %s !?!", /* XXX DEAD */
           me.name, parv[0], parv[1], cptr->name);
       return exit_new_server(cptr, sptr, host, timestamp, "%s", acptr->info);
     }
@@ -2003,7 +2001,7 @@ int m_server(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
     if (*parv[5] == 'J')
     {
       SetBurst(acptr);
-      sendto_op_mask(SNO_NETWORK, "Net junction: %s %s",
+      sendto_op_mask(SNO_NETWORK, "Net junction: %s %s", /* XXX DEAD */
           sptr->name, acptr->name);
       SetJunction(acptr);
     }
@@ -2018,7 +2016,7 @@ int m_server(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
         continue;
       if (0 == match(me.name, acptr->name))
         continue;
-        sendto_one(bcptr, "%s " TOK_SERVER " %s %d 0 %s %s %s%s 0 :%s",
+        sendto_one(bcptr, "%s " TOK_SERVER " %s %d 0 %s %s %s%s 0 :%s", /* XXX DEAD */
             NumServ(sptr), acptr->name, hop + 1, parv[4], parv[5],
             NumServCap(acptr), acptr->info);
     }
@@ -2036,19 +2034,19 @@ int m_server(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
     {
 #ifndef RELIABLE_CLOCK
 #ifdef TESTNET
-      sendto_ops("Debug: my start time: " TIME_T_FMT " ; others start time: "
+      sendto_ops("Debug: my start time: " TIME_T_FMT " ; others start time: " /* XXX DEAD */
           TIME_T_FMT, me.serv->timestamp, start_timestamp);
-      sendto_ops("Debug: receive time: " TIME_T_FMT " ; received timestamp: "
+      sendto_ops("Debug: receive time: " TIME_T_FMT " ; received timestamp: " /* XXX DEAD */
           TIME_T_FMT " ; difference %ld",
           recv_time, timestamp, timestamp - recv_time);
 #endif
       if (start_timestamp < me.serv->timestamp)
       {
-        sendto_ops("got earlier start time: " TIME_T_FMT " < " TIME_T_FMT,
+        sendto_ops("got earlier start time: " TIME_T_FMT " < " TIME_T_FMT, /* XXX DEAD */
             start_timestamp, me.serv->timestamp);
         me.serv->timestamp = start_timestamp;
         TSoffset += timestamp - recv_time;
-        sendto_ops("clock adjusted by adding %d", (int)(timestamp - recv_time));
+        sendto_ops("clock adjusted by adding %d", (int)(timestamp - recv_time)); /* XXX DEAD */
       }
       else if ((start_timestamp > me.serv->timestamp) && IsUnknown(cptr))
         cptr->serv->timestamp = TStime();
@@ -2064,7 +2062,7 @@ int m_server(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
           cptr->serv->timestamp = TStime();
         else if (IsHandshake(cptr))
         {
-          sendto_ops("clock adjusted by adding %d",
+          sendto_ops("clock adjusted by adding %d", /* XXX DEAD */
               (int)(timestamp - recv_time));
           TSoffset += timestamp - recv_time;
         }
@@ -2077,17 +2075,17 @@ int m_server(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
 #endif
     }
 
-    ret = server_estab(cptr, aconf);
+    ret = server_estab(cptr, aconf); /* XXX DEAD */
   }
   else
     ret = 0;
 #ifdef RELIABLE_CLOCK
   if (abs(cptr->serv->timestamp - recv_time) > 30)
   {
-    sendto_ops("Connected to a net with a timestamp-clock"
+    sendto_ops("Connected to a net with a timestamp-clock" /* XXX DEAD */
         " difference of " STIME_T_FMT " seconds! Used SETTIME to correct"
         " this.", timestamp - recv_time);
-    sendto_one(cptr, ":%s SETTIME " TIME_T_FMT " :%s",
+    sendto_one(cptr, ":%s SETTIME " TIME_T_FMT " :%s", /* XXX DEAD */
         me.name, TStime(), me.name);
   }
 #endif