Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / m_server.c
index 69f24a83ba9c51606759169e4ce9d4b6140349b3..56ce072ce5c85b06ce6b032595c3b40a63c97d5c 100644 (file)
@@ -79,6 +79,8 @@
  *            note:   it is guaranteed that parv[0]..parv[parc-1] are all
  *                    non-NULL pointers.
  */
+#include "config.h"
+
 #if 0
 /*
  * No need to include handlers.h here the signatures must match
@@ -91,6 +93,7 @@
 #include "hash.h"
 #include "ircd.h"
 #include "ircd_log.h"
+#include "ircd_features.h"
 #include "ircd_reply.h"
 #include "ircd_string.h"
 #include "jupe.h"
  *  If cptr is P10:
  *    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[7] = +hs (h == hub, s == service)
  */
 int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 {
@@ -177,6 +180,18 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   if (!IsServer(cptr))          /* Don't allow silently connecting a server */
     *parv[5] = 'J';
 
+  if (*parv[7] == '+') {
+    for (ch = parv[7] + 1; *ch; ch++)
+      switch (*ch) {
+      case 'h':
+       SetHub(cptr);
+       break;
+      case 's':
+       SetService(cptr);
+       break;
+      }
+  }
+
   prot = atoi(parv[5] + 1);
   if (prot > atoi(MAJOR_PROTOCOL))
     prot = atoi(MAJOR_PROTOCOL);
@@ -189,8 +204,8 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   hop = atoi(parv[2]);
   start_timestamp = atoi(parv[3]);
   timestamp = atoi(parv[4]);
-  Debug((DEBUG_INFO, "Got SERVER %s with timestamp [%s] age " TIME_T_FMT " ("
-        TIME_T_FMT ")", host, parv[4], start_timestamp, cli_serv(&me)->timestamp));
+  Debug((DEBUG_INFO, "Got SERVER %s with timestamp [%s] age %Tu (%Tu)",
+        host, parv[4], start_timestamp, cli_serv(&me)->timestamp));
 
   if ((timestamp < OLDEST_TS || (hop == 1 && start_timestamp < OLDEST_TS)))
   {
@@ -324,16 +339,7 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
       return exit_client_msg(cptr, cptr, &me,
           "Access denied. No conf line for server %s", cli_name(cptr));
     }
-#ifdef CRYPT_LINK_PASSWORD
-    /* passwd may be NULL. Head it off at the pass... */
-    if (*(cli_passwd(cptr))) {
-      encr = ircd_crypt(cli_passwd(cptr), aconf->passed);
-    }
-    else
-      encr = "";
-#else
     encr = cli_passwd(cptr);
-#endif /* CRYPT_LINK_PASSWORD */
 
     if (*aconf->passwd && !!strcmp(aconf->passwd, encr)) {
       ++ServerStats->is_ref;
@@ -345,14 +351,14 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 
     memset(cli_passwd(cptr), 0, sizeof(cli_passwd(cptr)));
 
-#ifndef HUB
-    for (i = 0; i <= HighestFd; i++)
-      if (LocalClientArray[i] && IsServer(LocalClientArray[i])) {
-        active_lh_line = 3;
-        LHcptr = 0;
-        break;
-      }
-#endif
+    if (!feature_bool(FEAT_HUB)) {
+      for (i = 0; i <= HighestFd; i++)
+       if (LocalClientArray[i] && IsServer(LocalClientArray[i])) {
+         active_lh_line = 3;
+         LHcptr = 0;
+         break;
+       }
+    }
   }
 
   /*
@@ -686,9 +692,10 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
         continue;
       if (0 == match(cli_name(&me), cli_name(acptr)))
         continue;
-      sendcmdto_one(sptr, CMD_SERVER, bcptr, "%s %d 0 %s %s %s%s 0 :%s",
-                   cli_name(acptr), hop + 1, parv[4], parv[5], NumServCap(acptr),
-                   cli_info(acptr));
+      sendcmdto_one(sptr, CMD_SERVER, bcptr, "%s %d 0 %s %s %s%s +%s%s :%s",
+                   cli_name(acptr), hop + 1, parv[4], parv[5],
+                   NumServCap(acptr), IsHub(acptr) ? "h" : "",
+                   IsService(acptr) ? "s" : "", cli_info(acptr));
     }
     return 0;
   }
@@ -702,65 +709,59 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     SetServerYXX(cptr, cptr, parv[6]);
     if (start_timestamp > OLDEST_TS)
     {
-#ifndef RELIABLE_CLOCK
-#ifdef TESTNET
-      sendto_opmask_butone(0, SNO_OLDSNO, "Debug: my start time: %Tu ; "
-                          "others start time: %Tu", cli_serv(&me)->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 < cli_serv(&me)->timestamp)
-      {
-        sendto_opmask_butone(0, SNO_OLDSNO, "got earlier start time: "
-                            "%Tu < %Tu", start_timestamp, cli_serv(&me)->timestamp);
-        cli_serv(&me)->timestamp = start_timestamp;
-        TSoffset += timestamp - recv_time;
-        sendto_opmask_butone(0, SNO_OLDSNO, "clock adjusted by adding %d",
-                            (int)(timestamp - recv_time));
-      }
-      else if ((start_timestamp > cli_serv(&me)->timestamp) && IsUnknown(cptr))
-        cli_serv(cptr)->timestamp = TStime();
-
-      else if (timestamp != recv_time)
-      {
-        /*
-         * Equal start times, we have a collision.  Let the connected-to server
-         * decide. This assumes leafs issue more than half of the connection
-         * attempts.
-         */
-        if (IsUnknown(cptr))
-          cli_serv(cptr)->timestamp = TStime();
-        else if (IsHandshake(cptr))
-        {
-          sendto_opmask_butone(0, SNO_OLDSNO, "clock adjusted by adding %d",
+      Debug((DEBUG_DEBUG, "My start time: %Tu; other's start time: %Tu",
+            cli_serv(&me)->timestamp, start_timestamp));
+      Debug((DEBUG_DEBUG, "Receive time: %Tu; received timestamp: %Tu; "
+            "difference %ld", recv_time, timestamp, timestamp - recv_time));
+      if (feature_bool(FEAT_RELIABLE_CLOCK)) {
+       if (start_timestamp < cli_serv(&me)->timestamp)
+         cli_serv(&me)->timestamp = start_timestamp;
+       if (IsUnknown(cptr))
+         cli_serv(cptr)->timestamp = TStime();
+      } else {
+       if (start_timestamp < cli_serv(&me)->timestamp) {
+         sendto_opmask_butone(0, SNO_OLDSNO, "got earlier start time: "
+                              "%Tu < %Tu", start_timestamp,
+                              cli_serv(&me)->timestamp);
+         cli_serv(&me)->timestamp = start_timestamp;
+         TSoffset += timestamp - recv_time;
+         sendto_opmask_butone(0, SNO_OLDSNO, "clock adjusted by adding %d",
                               (int)(timestamp - recv_time));
-          TSoffset += timestamp - recv_time;
-        }
+       } else if ((start_timestamp > cli_serv(&me)->timestamp) &&
+                IsUnknown(cptr))
+         cli_serv(cptr)->timestamp = TStime();
+
+       else if (timestamp != recv_time) {
+         /*
+          * Equal start times, we have a collision.  Let the connected-to
+          * server decide. This assumes leafs issue more than half of the
+          * connection attempts.
+          */
+         if (IsUnknown(cptr))
+           cli_serv(cptr)->timestamp = TStime();
+         else if (IsHandshake(cptr)) {
+           sendto_opmask_butone(0, SNO_OLDSNO, "clock adjusted by adding %d",
+                                (int)(timestamp - recv_time));
+           TSoffset += timestamp - recv_time;
+         }
+       }
       }
-#else /* RELIABLE CLOCK IS TRUE, we _always_ use our own clock */
-      if (start_timestamp < cli_serv(&me)->timestamp)
-        cli_serv(&me)->timestamp = start_timestamp;
-      if (IsUnknown(cptr))
-        cli_serv(cptr)->timestamp = TStime();
-#endif
     }
 
-    ret = server_estab(cptr, aconf, ajupe);
+    ret = server_estab(cptr, aconf);
   }
   else
     ret = 0;
-#ifdef RELIABLE_CLOCK
-  if (abs(cli_serv(cptr)->timestamp - recv_time) > 30)
-  {
+
+  if (feature_bool(FEAT_RELIABLE_CLOCK) &&
+      abs(cli_serv(cptr)->timestamp - recv_time) > 30) {
     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(), cli_name(&me));
+    sendcmdto_prio_one(&me, CMD_SETTIME, cptr, "%Tu :%s", TStime(),
+                      cli_name(&me));
   }
-#endif
 
   return ret;
 }
@@ -778,9 +779,7 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
  *  If cptr is P10:
  *    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
+ *    parv[7] = +hs (h == hub, s == service)
  */
 int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 {
@@ -793,7 +792,6 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   struct Client*   LHcptr = 0;
   struct ConfItem* aconf = 0;
   struct ConfItem* lhconf = 0;
-  struct Jupe*     ajupe = 0;
   int              hop;
   int              ret;
   int              active_lh_line = 0;
@@ -802,7 +800,6 @@ 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;
-  time_t           lastmod = 0;
 
   if (IsUserPort(cptr))
     return exit_client_msg(cptr, cptr, &me,
@@ -826,6 +823,18 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   if (!IsServer(cptr))          /* Don't allow silently connecting a server */
     *parv[5] = 'J';
 
+  if (*parv[7] == '+') {
+    for (ch = parv[7] + 1; *ch; ch++)
+      switch (*ch) {
+      case 'h':
+       SetHub(cptr);
+       break;
+      case 's':
+       SetService(cptr);
+       break;
+      }
+  }
+
   prot = atoi(parv[5] + 1);
   if (prot > atoi(MAJOR_PROTOCOL))
     prot = atoi(MAJOR_PROTOCOL);
@@ -838,8 +847,8 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   hop = atoi(parv[2]);
   start_timestamp = atoi(parv[3]);
   timestamp = atoi(parv[4]);
-  Debug((DEBUG_INFO, "Got SERVER %s with timestamp [%s] age " TIME_T_FMT " ("
-      TIME_T_FMT ")", host, parv[4], start_timestamp, cli_serv(&me)->timestamp));
+  Debug((DEBUG_INFO, "Got SERVER %s with timestamp [%s] age %Tu (%Tu)",
+        host, parv[4], start_timestamp, cli_serv(&me)->timestamp));
   if ((timestamp < OLDEST_TS || (hop == 1 && start_timestamp < OLDEST_TS)))
   {
     return exit_client_msg(cptr, sptr, &me,
@@ -853,16 +862,6 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     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
@@ -979,17 +978,7 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
       return exit_client_msg(cptr, cptr, &me,
                              "Access denied. No conf line for server %s", cli_name(cptr));
     }
-#ifdef CRYPT_LINK_PASSWORD
-    /* passwd may be NULL. Head it off at the pass... */
-    if (*(cli_passwd(cptr)))
-    {
-      encr = ircd_crypt(cli_passwd(cptr), cli_passwd(aconf));
-    }
-    else
-      encr = "";
-#else
     encr = cli_passwd(cptr);
-#endif /* CRYPT_LINK_PASSWORD */
 
     if (*(aconf->passwd) && !!strcmp(aconf->passwd, encr)) {
       ++ServerStats->is_ref;
@@ -1000,14 +989,14 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     }
     memset(cli_passwd(cptr), 0, sizeof(cli_passwd(cptr)));
 
-#ifndef HUB
-    for (i = 0; i <= HighestFd; i++)
-      if (LocalClientArray[i] && IsServer(LocalClientArray[i])) {
-        active_lh_line = 3;
-        LHcptr = 0;
-        break;
-      }
-#endif
+    if (!feature_bool(FEAT_HUB)) {
+      for (i = 0; i <= HighestFd; i++)
+       if (LocalClientArray[i] && IsServer(LocalClientArray[i])) {
+         active_lh_line = 3;
+         LHcptr = 0;
+         break;
+       }
+    }
   }
 
   /*
@@ -1337,9 +1326,10 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
         continue;
       if (0 == match(cli_name(&me), cli_name(acptr)))
         continue;
-      sendcmdto_one(sptr, CMD_SERVER, bcptr, "%s %d 0 %s %s %s%s 0 :%s",
-                   cli_name(acptr), hop + 1, parv[4], parv[5], NumServCap(acptr),
-                   cli_info(acptr));
+      sendcmdto_one(sptr, CMD_SERVER, bcptr, "%s %d 0 %s %s %s%s +%s%s :%s",
+                   cli_name(acptr), hop + 1, parv[4], parv[5],
+                   NumServCap(acptr), IsHub(acptr) ? "h" : "",
+                   IsService(acptr) ? "s" : "", cli_info(acptr));
     }
     return 0;
   }
@@ -1353,64 +1343,58 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     SetServerYXX(cptr, cptr, parv[6]);
     if (start_timestamp > OLDEST_TS)
     {
-#ifndef RELIABLE_CLOCK
-#ifdef TESTNET
-      sendto_opmask_butone(0, SNO_OLDSNO, "Debug: my start time: %Tu ; "
-                          "others start time: %Tu", cli_serv(&me)->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 < cli_serv(&me)->timestamp)
-      {
-        sendto_opmask_butone(0, SNO_OLDSNO, "got earlier start time: "
-                            "%Tu < %Tu", start_timestamp, cli_serv(&me)->timestamp);
-        cli_serv(&me)->timestamp = start_timestamp;
-        TSoffset += timestamp - recv_time;
-        sendto_opmask_butone(0, SNO_OLDSNO, "clock adjusted by adding %d",
-                            (int)(timestamp - recv_time));
-      }
-      else if ((start_timestamp > cli_serv(&me)->timestamp) && IsUnknown(cptr))
-        cli_serv(cptr)->timestamp = TStime();
-
-      else if (timestamp != recv_time)
-      {
-        /*
-         * Equal start times, we have a collision.  Let the connected-to server
-         * decide. This assumes leafs issue more than half of the connection
-         * attempts.
-         */
-        if (IsUnknown(cptr))
-          cli_serv(cptr)->timestamp = TStime();
-        else if (IsHandshake(cptr))
-        {
-          sendto_opmask_butone(0, SNO_OLDSNO, "clock adjusted by adding %d",
+      Debug((DEBUG_DEBUG, "My start time: %Tu; other's start time: %Tu",
+            cli_serv(&me)->timestamp, start_timestamp));
+      Debug((DEBUG_DEBUG, "Receive time: %Tu; received timestamp: %Tu; "
+            "difference %ld", recv_time, timestamp, timestamp - recv_time));
+      if (feature_bool(FEAT_RELIABLE_CLOCK)) {
+       if (start_timestamp < cli_serv(&me)->timestamp)
+         cli_serv(&me)->timestamp = start_timestamp;
+       if (IsUnknown(cptr))
+         cli_serv(cptr)->timestamp = TStime();
+      } else {
+       if (start_timestamp < cli_serv(&me)->timestamp) {
+         sendto_opmask_butone(0, SNO_OLDSNO, "got earlier start time: "
+                              "%Tu < %Tu", start_timestamp,
+                              cli_serv(&me)->timestamp);
+         cli_serv(&me)->timestamp = start_timestamp;
+         TSoffset += timestamp - recv_time;
+         sendto_opmask_butone(0, SNO_OLDSNO, "clock adjusted by adding %d",
                               (int)(timestamp - recv_time));
-          TSoffset += timestamp - recv_time;
-        }
+       } else if ((start_timestamp > cli_serv(&me)->timestamp) &&
+                  IsUnknown(cptr))
+         cli_serv(cptr)->timestamp = TStime();
+
+       else if (timestamp != recv_time) {
+         /*
+          * Equal start times, we have a collision.  Let the connected-to
+          * server decide. This assumes leafs issue more than half of the
+          * connection attempts.
+          */
+         if (IsUnknown(cptr))
+           cli_serv(cptr)->timestamp = TStime();
+         else if (IsHandshake(cptr)) {
+           sendto_opmask_butone(0, SNO_OLDSNO, "clock adjusted by adding %d",
+                                (int)(timestamp - recv_time));
+           TSoffset += timestamp - recv_time;
+         }
+       }
       }
-#else /* RELIABLE CLOCK IS TRUE, we _always_ use our own clock */
-      if (start_timestamp < cli_serv(&me)->timestamp)
-        cli_serv(&me)->timestamp = start_timestamp;
-      if (IsUnknown(cptr))
-        cli_serv(cptr)->timestamp = TStime();
-#endif
     }
 
-    ret = server_estab(cptr, aconf, ajupe);
+    ret = server_estab(cptr, aconf);
   }
   else
     ret = 0;
-#ifdef RELIABLE_CLOCK
-  if (abs(cli_serv(cptr)->timestamp - recv_time) > 30)
-  {
+
+  if (feature_bool(FEAT_RELIABLE_CLOCK) &&
+      abs(cli_serv(cptr)->timestamp - recv_time) > 30) {
     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(), cli_name(&me));
+    sendcmdto_prio_one(&me, CMD_SETTIME, cptr, "%Tu :%s", TStime(),
+                      cli_name(&me));
   }
-#endif
 
   return ret;
 }