Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / s_user.c
index f483a0ee7dd57ce696d9f431961295dd1ab24ca1..3af97a6d5e7fb30e34044e334a316e3d01fe5b86 100644 (file)
  *
  * $Id$
  */
+#include "config.h"
+
 #include "s_user.h"
 #include "IPcheck.h"
 #include "channel.h"
 #include "class.h"
 #include "client.h"
-#include "gline.h"
 #include "hash.h"
 #include "ircd.h"
 #include "ircd_alloc.h"
 #include "ircd_chattr.h"
 #include "ircd_features.h"
 #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"
@@ -52,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"
@@ -130,50 +132,6 @@ void user_count_memory(size_t* count_out, size_t* bytes_out)
   *bytes_out = userCount * sizeof(struct User);
 }
 
-/*
- * user_set_away - set user away state
- * returns 1 if client is away or changed away message, 0 if 
- * client is removing away status.
- * NOTE: this function may modify user and message, so they
- * must be mutable.
- */
-int user_set_away(struct User* user, char* message)
-{
-  char* away;
-  assert(0 != user);
-
-  away = user->away;
-
-  if (EmptyString(message)) {
-    /*
-     * Marking as not away
-     */
-    if (away) {
-      MyFree(away);
-      user->away = 0;
-    }
-  }
-  else {
-    /*
-     * Marking as away
-     */
-    unsigned int len = strlen(message);
-
-    if (len > TOPICLEN) {
-      message[TOPICLEN] = '\0';
-      len = TOPICLEN;
-    }
-    if (away)
-      away = (char*) MyRealloc(away, len + 1);
-    else
-      away = (char*) MyMalloc(len + 1);
-    assert(0 != away);
-
-    user->away = away;
-    strcpy(away, message);
-  }
-  return (user->away != 0);
-}
 
 /*
  * next_client
@@ -271,6 +229,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...)
@@ -361,7 +365,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];
@@ -406,8 +410,8 @@ int register_user(struct Client *cptr, struct Client *sptr,
         {
           last_too_many1 = CurrentTime;
           sendto_opmask_butone(0, SNO_TOOMANY, "Too many connections in "
-                               "class for %s.",
-                               get_client_name(sptr, HIDE_IP));
+                               "class %i for %s.", get_client_class(sptr),
+                               get_client_name(sptr, SHOW_IP));
         }
         ++ServerStats->is_ref;
         IPcheck_connect_fail(cli_ip(sptr));
@@ -420,7 +424,7 @@ int register_user(struct Client *cptr, struct Client *sptr,
           last_too_many2 = CurrentTime;
           sendto_opmask_butone(0, SNO_TOOMANY, "Too many connections from "
                                "same IP for %s.",
-                               get_client_name(sptr, HIDE_IP));
+                               get_client_name(sptr, SHOW_IP));
         }
         ++ServerStats->is_ref;
         return exit_client(cptr, sptr, &me,
@@ -547,14 +551,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))
@@ -571,12 +567,12 @@ 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);
+    ircd_snprintf(0, featurebuf, sizeof(featurebuf), FEATURES, FEATURESVALUES);
     send_reply(sptr, RPL_ISUPPORT, featurebuf);
     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);
@@ -618,24 +614,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))
@@ -676,8 +661,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
@@ -697,6 +680,7 @@ int set_nick_name(struct Client* cptr, struct Client* sptr,
         }
       }
     }
+    client_set_privs(new_client); /* set privs on user */
     /*
      * Set new nick name.
      */
@@ -717,19 +701,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]) {
     /*
@@ -822,7 +794,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;
     }
   }
@@ -1001,13 +973,13 @@ int whisper(struct Client* source, const char* nick, const char* channel,
 /*
  * added Sat Jul 25 07:30:42 EST 1992
  */
-void send_umode_out(struct Client *cptr, struct Client *sptr, int old)
+void send_umode_out(struct Client *cptr, struct Client *sptr, int old,
+                   int prop)
 {
   int i;
   struct Client *acptr;
 
-  send_umode(NULL, sptr, old,
-            SEND_UMODES & ~(HasPriv(sptr, PRIV_PROPAGATE) ? 0 : FLAGS_OPER));
+  send_umode(NULL, sptr, old, SEND_UMODES & ~(prop ? 0 : FLAGS_OPER));
 
   for (i = HighestFd; i >= 0; i--) {
     if ((acptr = LocalClientArray[i]) && IsServer(acptr) &&
@@ -1071,6 +1043,7 @@ int set_user_mode(struct Client *cptr, struct Client *sptr, int parc, char *parv
   unsigned int tmpmask = 0;
   int snomask_given = 0;
   char buf[BUFSIZE];
+  int prop = 0;
 
   what = MODE_ADD;
 
@@ -1143,9 +1116,9 @@ int set_user_mode(struct Client *cptr, struct Client *sptr, int parc, char *parv
           tmpmask = (what == MODE_ADD) ?
               (IsAnOper(sptr) ? SNO_OPERDEFAULT : SNO_DEFAULT) : 0;
         if (tmpmask)
-          cli_flags(sptr) |= FLAGS_SERVNOTICE;
+         SetServNotice(sptr);
         else
-          cli_flags(sptr) &= ~FLAGS_SERVNOTICE;
+         ClearServNotice(sptr);
         break;
       case 'w':
         if (what == MODE_ADD)
@@ -1225,33 +1198,47 @@ int set_user_mode(struct Client *cptr, struct Client *sptr, int parc, char *parv
     if (feature_bool(FEAT_WALLOPS_OPER_ONLY) && !IsAnOper(sptr) &&
        !(setflags & FLAGS_WALLOP))
       ClearWallops(sptr);
+#ifdef SERVNOTICE_OPER_ONLY
+    if (MyConnect(sptr) && !IsAnOper(sptr) && !(setflags & FLAGS_SERVNOTICE)) {
+      ClearServNotice(sptr);
+      set_snomask(sptr, 0, SNO_SET);
+    }
+#endif
+#ifdef DEBUG_OPER_ONLY
+    if (!IsAnOper(sptr) && !(setflags & FLAGS_DEBUG))
+      ClearDebug(sptr);
+#endif
   }
   if (MyConnect(sptr)) {
     if ((setflags & (FLAGS_OPER | FLAGS_LOCOP)) && !IsAnOper(sptr))
       det_confs_butmask(sptr, CONF_CLIENT & ~CONF_OPS);
 
-    if (tmpmask != cli_snomask(sptr))
-      set_snomask(sptr, tmpmask, SNO_SET);
-    if (cli_snomask(sptr) && snomask_given)
-      send_reply(sptr, RPL_SNOMASK, cli_snomask(sptr), cli_snomask(sptr));
+    if (SendServNotice(sptr)) {
+      if (tmpmask != cli_snomask(sptr))
+       set_snomask(sptr, tmpmask, SNO_SET);
+      if (cli_snomask(sptr) && snomask_given)
+       send_reply(sptr, RPL_SNOMASK, cli_snomask(sptr), cli_snomask(sptr));
+    }
   }
   /*
    * Compare new flags with old flags and send string which
    * will cause servers to update correctly.
    */
-  if ((setflags & FLAGS_OPER) && !IsOper(sptr)) {
-    --UserStats.opers;
-    client_set_privs(sptr);
-  }
-  if (!(setflags & FLAGS_OPER) && IsOper(sptr)) {
+  if (!(setflags & FLAGS_OPER) && IsOper(sptr)) { /* user now oper */
     ++UserStats.opers;
-    client_set_privs(sptr);
+    client_set_privs(sptr); /* may set propagate privilege */
+  }
+  if (HasPriv(sptr, PRIV_PROPAGATE)) /* remember propagate privilege setting */
+    prop = 1;
+  if ((setflags & FLAGS_OPER) && !IsOper(sptr)) { /* user no longer oper */
+    --UserStats.opers;
+    client_set_privs(sptr); /* will clear propagate privilege */
   }
   if ((setflags & FLAGS_INVISIBLE) && !IsInvisible(sptr))
     --UserStats.inv_clients;
   if (!(setflags & FLAGS_INVISIBLE) && IsInvisible(sptr))
     ++UserStats.inv_clients;
-  send_umode_out(cptr, sptr, setflags);
+  send_umode_out(cptr, sptr, setflags, prop);
 
   return 0;
 }
@@ -1461,9 +1448,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)) ||
@@ -1528,7 +1516,8 @@ int add_silence(struct Client* sptr, const char* mask)
     if (MyUser(sptr))
     {
       len += strlen(lp->value.cp);
-      if ((len > MAXSILELENGTH) || (++cnt >= MAXSILES))
+      if ((len > (feature_int(FEAT_AVBANLEN) * feature_int(FEAT_MAXSILES))) ||
+         (++cnt >= feature_int(FEAT_MAXSILES)))
       {
         send_reply(sptr, ERR_SILELISTFULL, mask);
         return -1;