]> jfr.im git - solanum.git/blobdiff - modules/core/m_nick.c
ban: Fix build breakage.
[solanum.git] / modules / core / m_nick.c
index 7335399b4409e90ccc51f1bfe8369e1f8d73c528..b9ed03fca9d834e8dd9748bdd2391b842c0ad12c 100644 (file)
@@ -47,6 +47,7 @@
 #include "scache.h"
 #include "s_newconf.h"
 #include "monitor.h"
+#include "s_assert.h"
 
 /* Give all UID nicks the same TS. This ensures nick TS is always the same on
  * all servers for each nick-user pair, also if a user with a UID nick changes
@@ -94,7 +95,7 @@ static int change_remote_nick(struct Client *, struct Client *, time_t,
 static int clean_nick(const char *, int loc_client);
 static int clean_username(const char *);
 static int clean_host(const char *);
-static int clean_uid(const char *uid);
+static int clean_uid(const char *uid, const char *sid);
 
 static void set_initial_nick(struct Client *client_p, struct Client *source_p, char *nick);
 static void change_local_nick(struct Client *client_p, struct Client *source_p, char *nick, int);
@@ -108,7 +109,6 @@ static int perform_nickchange_collides(struct Client *, struct Client *,
                                       struct Client *, int, const char **, time_t, const char *);
 
 /* mr_nick()
- *       parv[0] = sender prefix
  *       parv[1] = nickname
  */
 static int
@@ -116,7 +116,6 @@ mr_nick(struct Client *client_p, struct Client *source_p, int parc, const char *
 {
        struct Client *target_p;
        char nick[NICKLEN];
-       char *s;
 
        if (strlen(client_p->id) == 3)
        {
@@ -124,22 +123,15 @@ mr_nick(struct Client *client_p, struct Client *source_p, int parc, const char *
                return 0;
        }
 
-       if(parc < 2 || EmptyString(parv[1]) || (parv[1][0] == '~'))
+       if(parc < 2 || EmptyString(parv[1]))
        {
                sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
                           me.name, EmptyString(source_p->name) ? "*" : source_p->name);
                return 0;
        }
 
-       /* due to the scandinavian origins, (~ being uppercase of ^) and ~
-        * being disallowed as a nick char, we need to chop the first ~
-        * instead of just erroring.
-        */
-       if((s = strchr(parv[1], '~')))
-               *s = '\0';
-
        /* copy the nick and terminate it */
-       rb_strlcpy(nick, parv[1], sizeof(nick));
+       rb_strlcpy(nick, parv[1], ConfigFileEntry.nicklen);
 
        /* check the nickname is ok */
        if(!clean_nick(nick, 1))
@@ -175,7 +167,6 @@ mr_nick(struct Client *client_p, struct Client *source_p, int parc, const char *
 }
 
 /* m_nick()
- *     parv[0] = sender prefix
  *     parv[1] = nickname
  */
 static int
@@ -183,27 +174,19 @@ m_nick(struct Client *client_p, struct Client *source_p, int parc, const char *p
 {
        struct Client *target_p;
        char nick[NICKLEN];
-       char *s;
 
-       if(parc < 2 || EmptyString(parv[1]) || (parv[1][0] == '~'))
+       if(parc < 2 || EmptyString(parv[1]))
        {
                sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), me.name, source_p->name);
                return 0;
        }
 
-       /* due to the scandinavian origins, (~ being uppercase of ^) and ~
-        * being disallowed as a nick char, we need to chop the first ~
-        * instead of just erroring.
-        */
-       if((s = strchr(parv[1], '~')))
-               *s = '\0';
-
        /* mark end of grace period, to prevent nickflooding */
        if(!IsFloodDone(source_p))
                flood_endgrace(source_p);
 
        /* terminate nick to NICKLEN, we dont want clean_nick() to error! */
-       rb_strlcpy(nick, parv[1], sizeof(nick));
+       rb_strlcpy(nick, parv[1], ConfigFileEntry.nicklen);
 
        /* check the nickname is ok */
        if(!clean_nick(nick, 1))
@@ -256,9 +239,8 @@ m_nick(struct Client *client_p, struct Client *source_p, int parc, const char *p
 }
 
 /* mc_nick()
- *      
+ *
  * server -> server nick change
- *    parv[0] = sender prefix
  *    parv[1] = nickname
  *    parv[2] = TS when nick change
  */
@@ -365,11 +347,11 @@ ms_uid(struct Client *client_p, struct Client *source_p, int parc, const char *p
                return 0;
        }
 
-       if(!clean_uid(parv[8]))
+       if(!clean_uid(parv[8], source_p->id))
        {
                rb_snprintf(squitreason, sizeof squitreason,
-                               "Invalid UID %s for nick %s on %s",
-                               parv[8], parv[1], source_p->name);
+                               "Invalid UID %s for nick %s on %s/%s",
+                               parv[8], parv[1], source_p->name, source_p->id);
                exit_client(client_p, client_p, client_p, squitreason);
                return 0;
        }
@@ -456,11 +438,11 @@ ms_euid(struct Client *client_p, struct Client *source_p, int parc, const char *
                return 0;
        }
 
-       if(!clean_uid(parv[8]))
+       if(!clean_uid(parv[8], source_p->id))
        {
                rb_snprintf(squitreason, sizeof squitreason,
-                               "Invalid UID %s for nick %s on %s",
-                               parv[8], parv[1], source_p->name);
+                               "Invalid UID %s for nick %s on %s/%s",
+                               parv[8], parv[1], source_p->name, source_p->id);
                exit_client(client_p, client_p, client_p, squitreason);
                return 0;
        }
@@ -547,7 +529,7 @@ ms_save(struct Client *client_p, struct Client *source_p, int parc, const char *
  *
  * input       - nickname to check
  * output      - 0 if erroneous, else 1
- * side effects - 
+ * side effects -
  */
 static int
 clean_nick(const char *nick, int loc_client)
@@ -569,7 +551,7 @@ clean_nick(const char *nick, int loc_client)
        }
 
        /* nicklen is +1 */
-       if(len >= NICKLEN)
+       if(len >= NICKLEN && len >= ConfigFileEntry.nicklen)
                return 0;
 
        return 1;
@@ -626,10 +608,13 @@ clean_host(const char *host)
 }
 
 static int
-clean_uid(const char *uid)
+clean_uid(const char *uid, const char *sid)
 {
        int len = 1;
 
+       if(strncmp(uid, sid, strlen(sid)))
+               return 0;
+
        if(!IsDigit(*uid++))
                return 0;
 
@@ -731,7 +716,7 @@ change_local_nick(struct Client *client_p, struct Client *source_p,
                             source_p->name, nick, source_p->username, source_p->host);
 
        /* send the nick change to the users channels */
-       sendto_common_channels_local(source_p, ":%s!%s@%s NICK :%s",
+       sendto_common_channels_local(source_p, NOCAPS, ":%s!%s@%s NICK :%s",
                                     source_p->name, source_p->username, source_p->host, nick);
 
        /* send the nick change to servers.. */
@@ -755,7 +740,7 @@ change_local_nick(struct Client *client_p, struct Client *source_p,
                monitor_signon(source_p);
 
        /* Make sure everyone that has this client on its accept list
-        * loses that reference. 
+        * loses that reference.
         */
        /* we used to call del_all_accepts() here, but theres no real reason
         * to clear a clients own list of accepted clients.  So just remove
@@ -792,7 +777,7 @@ change_remote_nick(struct Client *client_p, struct Client *source_p,
                monitor_signoff(source_p);
        }
 
-       sendto_common_channels_local(source_p, ":%s!%s@%s NICK :%s",
+       sendto_common_channels_local(source_p, NOCAPS, ":%s!%s@%s NICK :%s",
                                     source_p->name, source_p->username, source_p->host, nick);
 
        if(source_p->user)
@@ -1025,8 +1010,8 @@ perform_nickchange_collides(struct Client *source_p, struct Client *client_p,
                        {
                                ServerStats.is_kill++;
 
-                               sendto_one_numeric(target_p, ERR_NICKCOLLISION,
-                                               form_str(ERR_NICKCOLLISION), target_p->name);
+                               sendto_one_numeric(source_p, ERR_NICKCOLLISION,
+                                               form_str(ERR_NICKCOLLISION), source_p->name);
 
                                /* kill the client issuing the nickchange */
                                kill_client_serv_butone(client_p, source_p,