Author: Isomer
[ircu2.10.12-pk.git] / ircd / s_user.c
index cb6fd5af0efaf3449b757161d8ff09879ca7f3d2..cf85fb8898f44689fd0fbcad5b9d5f2fde4e3ef2 100644 (file)
@@ -407,7 +407,7 @@ static char *clean_user_id(char *dest, char *source, int tilde)
  *    nick from local user or kill him/her...
  */
 int register_user(struct Client *cptr, struct Client *sptr,
-                  const char *nick, char *username)
+                  const char *nick, char *username, struct Gline *agline)
 {
   struct ConfItem* aconf;
   char*            parv[3];
@@ -426,7 +426,6 @@ int register_user(struct Client *cptr, struct Client *sptr,
   struct User*     user = sptr->user;
   char             ip_base64[8];
   char             featurebuf[512];
-  struct Gline*    gline;
 
   user->last = CurrentTime;
   parv[0] = sptr->name;
@@ -457,7 +456,6 @@ int register_user(struct Client *cptr, struct Client *sptr,
                               get_client_name(sptr, HIDE_IP));
         }
         ++ServerStats->is_ref;
-        ip_registry_connect_fail(sptr->ip.s_addr);
         return exit_client(cptr, sptr, &me,
                           "Sorry, your connection class is full - try "
                           "again later or try another server");
@@ -476,7 +474,6 @@ int register_user(struct Client *cptr, struct Client *sptr,
         /* Can this ever happen? */
       case ACR_BAD_SOCKET:
         ++ServerStats->is_ref;
-        ip_registry_connect_fail(sptr->ip.s_addr);
         return exit_client(cptr, sptr, &me, "Unknown error -- Try again");
     }
     ircd_strncpy(user->host, sptr->sockhost, HOSTLEN);
@@ -492,13 +489,9 @@ int register_user(struct Client *cptr, struct Client *sptr,
 
     if (!EmptyString(aconf->passwd)
         && !(IsDigit(*aconf->passwd) && !aconf->passwd[1])
-#ifdef USEONE
-        && strcmp("ONE", aconf->passwd)
-#endif
         && strcmp(sptr->passwd, aconf->passwd))
     {
       ServerStats->is_ref++;
-      ip_registry_connect_fail(sptr->ip.s_addr);
       send_reply(sptr, ERR_PASSWDMISMATCH);
       return exit_client(cptr, sptr, &me, "Bad Password");
     }
@@ -508,7 +501,6 @@ int register_user(struct Client *cptr, struct Client *sptr,
      */
     if (find_kill(sptr)) {
       ServerStats->is_ref++;
-      ip_registry_connect_fail(sptr->ip.s_addr);
       return exit_client(cptr, sptr, &me, "K-lined");
     }
     /*
@@ -594,11 +586,17 @@ int register_user(struct Client *cptr, struct Client *sptr,
   else {
     ircd_strncpy(user->username, username, USERLEN);
     Count_newremoteclient(UserStats, user->server);
-    if ((gline = gline_lookup(sptr)) && GlineIsActive(gline))
-      gline_resend(cptr, gline);
   }
   SetUser(sptr);
 
+  /* a gline wasn't passed in, so find a matching global one that isn't
+   * a Uworld-set one, and propagate it if there is such an animal.
+   */
+  if (!agline &&
+      (agline = gline_lookup(sptr, GLINE_GLOBAL | GLINE_LASTMOD)) &&
+      !IsBurstOrBurstAck(cptr))
+    gline_resend(cptr, agline);
+  
   if (IsInvisible(sptr))
     ++UserStats.inv_clients;
   if (IsOper(sptr))
@@ -627,7 +625,6 @@ int register_user(struct Client *cptr, struct Client *sptr,
     nextping = CurrentTime;
     if (sptr->snomask & SNO_NOISY)
       set_snomask(sptr, sptr->snomask & SNO_NOISY, SNO_ADD);
-    ip_registry_connect_succeeded(sptr);
   }
   else
     /* if (IsServer(cptr)) */
@@ -656,22 +653,27 @@ int register_user(struct Client *cptr, struct Client *sptr,
       if (IsBurst(acptr) || Protocol(acptr) < 10)
         break;
     }
-    if (!ip_registry_check_remote(sptr, (acptr != &me)))
-      /*
-       * We ran out of bits to count this
-       */
-      return exit_client(cptr, sptr, &me, "More than 255 connections from this address");
   }
-
   tmpstr = umode_str(sptr);
-  sendcmdto_serv_butone(user->server, CMD_NICK, cptr, *tmpstr ?
-                       "%s %d %d %s %s +%s %s %s%s :%s" :
-                       "%s %d %d %s %s %s%s %s%s :%s",
-                       nick, sptr->hopcount + 1, sptr->lastnick,
-                       user->username, user->host, tmpstr,
-                       inttobase64(ip_base64, ntohl(sptr->ip.s_addr), 6),
-                       NumNick(sptr), sptr->info);
-
+  if (agline)
+    sendcmdto_serv_butone(user->server, CMD_NICK, cptr,
+                         "%s %d %Tu %s %s %s%s%s%%%Tu:%s@%s %s %s%s :%s",
+                         nick, sptr->hopcount + 1, sptr->lastnick,
+                         user->username, user->host,
+                         *tmpstr ? "+" : "", tmpstr, *tmpstr ? " " : "",
+                         GlineLastMod(agline), GlineUser(agline),
+                         GlineHost(agline),
+                         inttobase64(ip_base64, ntohl(sptr->ip.s_addr), 6),
+                         NumNick(sptr), sptr->info);
+  else
+    sendcmdto_serv_butone(user->server, CMD_NICK, cptr,
+                         "%s %d %Tu %s %s %s%s%s%s %s%s :%s",
+                         nick, sptr->hopcount + 1, sptr->lastnick,
+                         user->username, user->host,
+                         *tmpstr ? "+" : "", tmpstr, *tmpstr ? " " : "",
+                         inttobase64(ip_base64, ntohl(sptr->ip.s_addr), 6),
+                         NumNick(sptr), sptr->info);
+  
   /* Send umode to client */
   if (MyUser(sptr))
   {
@@ -725,6 +727,8 @@ int set_nick_name(struct Client* cptr, struct Client* sptr,
   if (IsServer(sptr)) {
     int   i;
     const char* p;
+    char *t;
+    struct Gline *agline = 0;
 
     /*
      * A server introducing a new client, change source
@@ -763,7 +767,26 @@ int set_nick_name(struct Client* cptr, struct Client* sptr,
     ircd_strncpy(new_client->username, parv[4], USERLEN);
     ircd_strncpy(new_client->user->host, parv[5], HOSTLEN);
     ircd_strncpy(new_client->info, parv[parc - 1], REALLEN);
-    return register_user(cptr, new_client, new_client->name, parv[4]);
+
+    /* Deal with GLINE parameters... */
+    if (*parv[parc - 4] == '%' && (t = strchr(parv[parc - 4] + 1, ':'))) {
+      time_t lastmod;
+
+      *(t++) = '\0';
+      lastmod = atoi(parv[parc - 4] + 1);
+
+      if (lastmod &&
+         (agline = gline_find(t, GLINE_EXACT | GLINE_GLOBAL | GLINE_LASTMOD))
+         && GlineLastMod(agline) > lastmod && !IsBurstOrBurstAck(cptr))
+       gline_resend(cptr, agline);
+    }
+    if (!ip_registry_remote_connect(new_client)) {
+       sendcmdto_one(&me, CMD_KILL, new_client, "%C :%s (Too many connections from your host -- Ghost)",
+                     new_client,me.name);
+       return exit_client(cptr,new_client,&me,"Too many connections from your host -- throttled");
+    }
+    sendto_ops("Registering new remote client");
+    return register_user(cptr, new_client, new_client->name, parv[4], agline);
   }
   else if (sptr->name[0]) {
     /*
@@ -856,7 +879,7 @@ int set_nick_name(struct Client* cptr, struct Client* sptr,
        * for it - must test this and exit m_nick too !
        */
       sptr->lastnick = TStime();        /* Always local client */
-      if (register_user(cptr, sptr, nick, sptr->user->username) == CPTR_KILLED)
+      if (register_user(cptr, sptr, nick, sptr->user->username, 0) == CPTR_KILLED)
         return CPTR_KILLED;
     }
   }