Author: Isomer <isomer@coders.net>
[ircu2.10.12-pk.git] / ircd / s_user.c
index 0a71c4a742b1370d67fed4851949b6b008a0f3ea..cf34ba2566876e014f04807576f1cc42bc1f0c72 100644 (file)
@@ -29,7 +29,6 @@
 #include "channel.h"
 #include "class.h"
 #include "client.h"
-#include "gline.h"
 #include "hash.h"
 #include "ircd.h"
 #include "ircd_alloc.h"
@@ -38,6 +37,7 @@
 #include "ircd_log.h"
 #include "ircd_policy.h"
 #include "ircd_reply.h"
+#include "ircd_snprintf.h"
 #include "ircd_string.h"
 #include "list.h"
 #include "match.h"
@@ -55,7 +55,6 @@
 #include "s_misc.h"
 #include "s_serv.h" /* max_client_count */
 #include "send.h"
-#include "sprintf_irc.h"
 #include "struct.h"
 #include "support.h"
 #include "supported.h"
@@ -192,6 +191,11 @@ int hunt_server_cmd(struct Client *from, const char *cmd, const char *tok,
   struct Client *acptr;
   char *to;
 
+  if (MustBeOper && !IsPrivileged(acptr))
+  {
+    send_reply(from, ERR_NOPRIVILEGES);
+    return HUNTED_NOSUCH;
+  }
   /* Assume it's me, if no server or an unregistered client */
   if (parc <= server || EmptyString((to = parv[server])) || IsUnknown(from))
     return (HUNTED_ISME);
@@ -230,6 +234,52 @@ int hunt_server_cmd(struct Client *from, const char *cmd, const char *tok,
   return (HUNTED_PASS);
 }
 
+int hunt_server_prio_cmd(struct Client *from, const char *cmd, const char *tok,
+                        struct Client *one, int MustBeOper,
+                        const char *pattern, int server, int parc,
+                        char *parv[])
+{
+  struct Client *acptr;
+  char *to;
+
+  /* Assume it's me, if no server or an unregistered client */
+  if (parc <= server || EmptyString((to = parv[server])) || IsUnknown(from))
+    return (HUNTED_ISME);
+
+  /* Make sure it's a server */
+  if (MyUser(from)) {
+    /* Make sure it's a server */
+    if (!strchr(to, '*')) {
+      if (0 == (acptr = FindClient(to)))
+        return HUNTED_NOSUCH;
+
+      if (cli_user(acptr))
+        acptr = cli_user(acptr)->server;
+    } else if (!(acptr = find_match_server(to))) {
+      send_reply(from, ERR_NOSUCHSERVER, to);
+      return (HUNTED_NOSUCH);
+    }
+  } else if (!(acptr = FindNServer(to)))
+    return (HUNTED_NOSUCH);        /* Server broke off in the meantime */
+
+  if (IsMe(acptr))
+    return (HUNTED_ISME);
+
+  if (MustBeOper && !IsPrivileged(from)) {
+    send_reply(from, ERR_NOPRIVILEGES);
+    return HUNTED_NOSUCH;
+  }
+
+  assert(!IsServer(from));
+
+  parv[server] = (char *) acptr; /* HACK! HACK! HACK! ARGH! */
+
+  sendcmdto_prio_one(from, cmd, tok, acptr, pattern, parv[1], parv[2], parv[3],
+                    parv[4], parv[5], parv[6], parv[7], parv[8]);
+
+  return (HUNTED_PASS);
+}
+
 /*
  * 'do_nick_name' ensures that the given parameter (nick) is really a proper
  * string for a nickname (note, the 'nick' may be modified in the process...)
@@ -320,7 +370,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, struct Gline *agline)
+                  const char *nick, char *username)
 {
   struct ConfItem* aconf;
   char*            parv[3];
@@ -338,7 +388,6 @@ int register_user(struct Client *cptr, struct Client *sptr,
   short            digitgroups = 0;
   struct User*     user = cli_user(sptr);
   char             ip_base64[8];
-  char             featurebuf[512];
 
   user->last = CurrentTime;
   parv[0] = cli_name(sptr);
@@ -506,14 +555,6 @@ int register_user(struct Client *cptr, struct Client *sptr,
   }
   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))
@@ -530,12 +571,11 @@ int register_user(struct Client *cptr, struct Client *sptr,
     send_reply(sptr, RPL_YOURHOST, cli_name(&me), version);
     send_reply(sptr, RPL_CREATED, creation);
     send_reply(sptr, RPL_MYINFO, cli_name(&me), version);
-    sprintf_irc(featurebuf,FEATURES,FEATURESVALUES);
-    send_reply(sptr, RPL_ISUPPORT, featurebuf);
+    send_supported(sptr);
     m_lusers(sptr, sptr, 1, parv);
     update_load();
     motd_signon(sptr);
-    nextping = CurrentTime;
+/*      nextping = CurrentTime; */
     if (cli_snomask(sptr) & SNO_NOISY)
       set_snomask(sptr, cli_snomask(sptr) & SNO_NOISY, SNO_ADD);
     IPcheck_connect_succeeded(sptr);
@@ -577,24 +617,13 @@ int register_user(struct Client *cptr, struct Client *sptr,
     }
   }
   tmpstr = umode_str(sptr);
-  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, cli_hopcount(sptr) + 1, cli_lastnick(sptr),
-                          user->username, user->host,
-                          *tmpstr ? "+" : "", tmpstr, *tmpstr ? " " : "",
-                          GlineLastMod(agline), GlineUser(agline),
-                          GlineHost(agline),
-                          inttobase64(ip_base64, ntohl(cli_ip(sptr).s_addr), 6),
-                          NumNick(sptr), cli_info(sptr));
-  else
-    sendcmdto_serv_butone(user->server, CMD_NICK, cptr,
-                          "%s %d %Tu %s %s %s%s%s%s %s%s :%s",
-                          nick, cli_hopcount(sptr) + 1, cli_lastnick(sptr),
-                          user->username, user->host,
-                          *tmpstr ? "+" : "", tmpstr, *tmpstr ? " " : "",
-                          inttobase64(ip_base64, ntohl(cli_ip(sptr).s_addr), 6),
-                          NumNick(sptr), cli_info(sptr));
+  sendcmdto_serv_butone(user->server, CMD_NICK, cptr,
+                       "%s %d %Tu %s %s %s%s%s%s %s%s :%s",
+                       nick, cli_hopcount(sptr) + 1, cli_lastnick(sptr),
+                       user->username, user->host,
+                       *tmpstr ? "+" : "", tmpstr, *tmpstr ? " " : "",
+                       inttobase64(ip_base64, ntohl(cli_ip(sptr).s_addr), 6),
+                       NumNick(sptr), cli_info(sptr));
   
   /* Send umode to client */
   if (MyUser(sptr))
@@ -635,8 +664,6 @@ 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
@@ -677,19 +704,7 @@ int set_nick_name(struct Client* cptr, struct Client* sptr,
     ircd_strncpy(cli_user(new_client)->host, parv[5], HOSTLEN);
     ircd_strncpy(cli_info(new_client), parv[parc - 1], REALLEN);
 
-    /* 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);
-    }
-    return register_user(cptr, new_client, cli_name(new_client), parv[4], agline);
+    return register_user(cptr, new_client, cli_name(new_client), parv[4]);
   }
   else if ((cli_name(sptr))[0]) {
     /*
@@ -782,7 +797,7 @@ int set_nick_name(struct Client* cptr, struct Client* sptr,
        * for it - must test this and exit m_nick too !
        */
       cli_lastnick(sptr) = TStime();        /* Always local client */
-      if (register_user(cptr, sptr, nick, cli_user(sptr)->username, 0) == CPTR_KILLED)
+      if (register_user(cptr, sptr, nick, cli_user(sptr)->username) == CPTR_KILLED)
         return CPTR_KILLED;
     }
   }
@@ -1206,7 +1221,8 @@ int set_user_mode(struct Client *cptr, struct Client *sptr, int parc, char *parv
        set_snomask(sptr, tmpmask, SNO_SET);
       if (cli_snomask(sptr) && snomask_given)
        send_reply(sptr, RPL_SNOMASK, cli_snomask(sptr), cli_snomask(sptr));
-    }
+    } else
+      set_snomask(sptr, 0, SNO_SET);
   }
   /*
    * Compare new flags with old flags and send string which
@@ -1436,9 +1452,10 @@ int is_silenced(struct Client *sptr, struct Client *acptr)
 
   if (!cli_user(acptr) || !(lp = cli_user(acptr)->silence) || !(user = cli_user(sptr)))
     return 0;
-  sprintf_irc(sender, "%s!%s@%s", cli_name(sptr), user->username, user->host);
-  sprintf_irc(senderip, "%s!%s@%s", cli_name(sptr), user->username,
-              ircd_ntoa((const char*) &(cli_ip(sptr))));
+  ircd_snprintf(0, sender, sizeof(sender), "%s!%s@%s", cli_name(sptr),
+               user->username, user->host);
+  ircd_snprintf(0, senderip, sizeof(senderip), "%s!%s@%s", cli_name(sptr),
+               user->username, ircd_ntoa((const char*) &(cli_ip(sptr))));
   for (; lp; lp = lp->next)
   {
     if ((!(lp->flags & CHFL_SILENCE_IPMASK) && !match(lp->value.cp, sender)) ||
@@ -1527,3 +1544,15 @@ int add_silence(struct Client* sptr, const char* mask)
   return 0;
 }
 
+int
+send_supported(struct Client *cptr)
+{
+  char featurebuf[512];
+
+  ircd_snprintf(0, featurebuf, sizeof(featurebuf), FEATURES1, FEATURESVALUES1);
+  send_reply(cptr, RPL_ISUPPORT, featurebuf);
+  ircd_snprintf(0, featurebuf, sizeof(featurebuf), FEATURES2, FEATURESVALUES2);
+  send_reply(cptr, RPL_ISUPPORT, featurebuf);
+
+  return 0; /* convenience return, if it's ever needed */
+}