]> jfr.im git - solanum.git/blobdiff - modules/m_signon.c
strcpy: mass-migrate to strlcpy where appropriate
[solanum.git] / modules / m_signon.c
index d57d953a9ef0e3800aefa10ec5d9b7030db3653e..6aeecc4714a10918897768bb6e808a732307632b 100644 (file)
@@ -25,8 +25,6 @@
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
- *
- * $Id: m_signon.c 1192 2006-04-21 16:21:02Z jilles $
  */
 
 #include "stdinc.h"
@@ -34,8 +32,7 @@
 #include "send.h"
 #include "channel.h"
 #include "client.h"
-#include "common.h"
-#include "config.h"
+#include "defaults.h"
 #include "ircd.h"
 #include "numeric.h"
 #include "s_conf.h"
 #include "match.h"
 #include "s_user.h"
 
-static int me_svslogin(struct Client *, struct Client *, int, const char **);
-static int ms_signon(struct Client *, struct Client *, int, const char **);
+static const char signon_desc[] = "Provides account login/logout support for services";
+
+static void me_svslogin(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void ms_signon(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
 
 static void send_signon(struct Client *, struct Client *, const char *, const char *, const char *, unsigned int, const char *);
 
 struct Message svslogin_msgtab = {
-       "SVSLOGIN", 0, 0, 0, MFLG_SLOW,
+       "SVSLOGIN", 0, 0, 0, 0,
        {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_svslogin, 6}, mg_ignore}
 };
 struct Message signon_msgtab = {
-       "SIGNON", 0, 0, 0, MFLG_SLOW,
+       "SIGNON", 0, 0, 0, 0,
        {mg_ignore, mg_ignore, {ms_signon, 6}, mg_ignore, mg_ignore, mg_ignore}
 };
 
-mapi_clist_av1 signon_clist[] = { 
+mapi_clist_av1 signon_clist[] = {
        &svslogin_msgtab, &signon_msgtab, NULL
 };
 
-DECLARE_MODULE_AV1(signon, NULL, NULL, signon_clist, NULL, NULL, "$Revision: 1192 $");
+DECLARE_MODULE_AV2(signon, NULL, NULL, signon_clist, NULL, NULL, NULL, NULL, signon_desc);
 
 #define NICK_VALID     1
 #define USER_VALID     2
 #define HOST_VALID     4
 
-static int
-clean_nick(const char *nick)
-{
-       int len = 0;
-
-       if(*nick == '-')
-               return 0;
-
-       /* This is used to check logins, which are often
-        * numeric. Don't check for leading digits, if
-        * services wants to set someone's nick to something
-        * starting with a number, let it try.
-        * --gxti
-        */
-
-       for (; *nick; nick++)
-       {
-               len++;
-               if(!IsNickChar(*nick))
-                       return 0;
-       }
-
-       /* nicklen is +1 */
-       if(len >= NICKLEN)
-               return 0;
-
-       return 1;
-}
-
-static int
+static bool
 clean_username(const char *username)
 {
        int len = 0;
@@ -114,16 +84,16 @@ clean_username(const char *username)
                len++;
 
                if(!IsUserChar(*username))
-                       return 0;
+                       return false;
        }
 
        if(len > USERLEN)
-               return 0;
+               return false;
 
-       return 1;
+       return true;
 }
 
-static int
+static bool
 clean_host(const char *host)
 {
        int len = 0;
@@ -133,17 +103,17 @@ clean_host(const char *host)
                len++;
 
                if(!IsHostChar(*host))
-                       return 0;
+                       return false;
        }
 
        if(len > HOSTLEN)
-               return 0;
+               return false;
 
-       return 1;
+       return true;
 }
 
-static int
-me_svslogin(struct Client *client_p, struct Client *source_p,
+static void
+me_svslogin(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
        int parc, const char *parv[])
 {
        struct Client *target_p, *exist_p;
@@ -152,15 +122,19 @@ me_svslogin(struct Client *client_p, struct Client *source_p,
        int valid = 0;
 
        if(!(source_p->flags & FLAGS_SERVICE))
-               return 0;
+       {
+               sendto_realops_snomask(SNO_GENERAL, L_ALL,
+                       "Non-service server %s attempting to execute services-only command SVSLOGIN", source_p->name);
+               return;
+       }
 
        if((target_p = find_client(parv[1])) == NULL)
-               return 0;
+               return;
 
        if(!MyClient(target_p) && !IsUnknown(target_p))
-               return 0;
+               return;
 
-       if(clean_nick(parv[2]))
+       if(clean_nick(parv[2], 0))
        {
                rb_strlcpy(nick, parv[2], NICKLEN + 1);
                valid |= NICK_VALID;
@@ -199,8 +173,8 @@ me_svslogin(struct Client *client_p, struct Client *source_p,
                rb_strlcpy(login, parv[5], NICKLEN + 1);
 
        /* Login (mostly) follows nick rules. */
-       if(*login && !clean_nick(login))
-               return 0;
+       if(*login && !clean_nick(login, 0))
+               return;
 
        if((exist_p = find_person(nick)) && target_p != exist_p)
        {
@@ -213,11 +187,16 @@ me_svslogin(struct Client *client_p, struct Client *source_p,
                exist_p->flags |= FLAGS_KILLED;
                kill_client_serv_butone(NULL, exist_p, "%s (Nickname regained by services)",
                                        me.name);
+               sendto_realops_snomask(SNO_SKILL, L_ALL,
+                               "Nick collision due to SVSLOGIN on %s",
+                               nick);
 
                snprintf(buf, sizeof(buf), "Killed (%s (Nickname regained by services))",
                        me.name);
                exit_client(NULL, exist_p, &me, buf);
-       }else if((exist_p = find_client(nick)) && IsUnknown(exist_p) && exist_p != target_p) {
+       }
+       else if((exist_p = find_client(nick)) && IsUnknown(exist_p) && exist_p != target_p)
+       {
                exit_client(NULL, exist_p, &me, "Overridden");
        }
 
@@ -242,13 +221,13 @@ me_svslogin(struct Client *client_p, struct Client *source_p,
                struct User *user_p = make_user(target_p);
 
                if(valid & NICK_VALID)
-                       strcpy(target_p->preClient->spoofnick, nick);
+                       rb_strlcpy(target_p->preClient->spoofnick, nick, sizeof(target_p->preClient->spoofnick));
 
                if(valid & USER_VALID)
-                       strcpy(target_p->preClient->spoofuser, user);
+                       rb_strlcpy(target_p->preClient->spoofuser, user, sizeof(target_p->preClient->spoofuser));
 
                if(valid & HOST_VALID)
-                       strcpy(target_p->preClient->spoofhost, host);
+                       rb_strlcpy(target_p->preClient->spoofhost, host, sizeof(target_p->preClient->spoofhost));
 
                rb_strlcpy(user_p->suser, login, NICKLEN + 1);
        }
@@ -258,22 +237,20 @@ me_svslogin(struct Client *client_p, struct Client *source_p,
 
                send_signon(NULL, target_p, nick, user, host, rb_current_time(), login);
 
-               rb_snprintf(note, NICKLEN + 10, "Nick: %s", target_p->name);
+               snprintf(note, NICKLEN + 10, "Nick: %s", target_p->name);
                rb_note(target_p->localClient->F, note);
        }
-
-       return 0;
 }
 
-static int
-ms_signon(struct Client *client_p, struct Client *source_p,
+static void
+ms_signon(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
        int parc, const char *parv[])
 {
        struct Client *target_p;
        int newts, sameuser;
        char login[NICKLEN+1];
 
-       if(!clean_nick(parv[1]))
+       if(!clean_nick(parv[1], 0))
        {
                ServerStats.is_kill++;
                sendto_realops_snomask(SNO_DEBUG, L_ALL,
@@ -288,7 +265,7 @@ ms_signon(struct Client *client_p, struct Client *source_p,
                                me.name);
                source_p->flags |= FLAGS_KILLED;
                exit_client(NULL, source_p, &me, "Bad nickname from SIGNON");
-               return 0;
+               return;
        }
 
        if(!clean_username(parv[2]) || !clean_host(parv[3]))
@@ -306,7 +283,7 @@ ms_signon(struct Client *client_p, struct Client *source_p,
                                me.name);
                source_p->flags |= FLAGS_KILLED;
                exit_client(NULL, source_p, &me, "Bad user@host from SIGNON");
-               return 0;
+               return;
        }
 
        newts = atol(parv[4]);
@@ -315,11 +292,13 @@ ms_signon(struct Client *client_p, struct Client *source_p,
                login[0] = '\0';
        else if(*parv[5] != '*')
        {
-               if (clean_nick(parv[5]))
+               if (clean_nick(parv[5], 0))
                        rb_strlcpy(login, parv[5], NICKLEN + 1);
                else
-                       return 0;
+                       return;
        }
+       else
+               login[0] = '\0';
 
        target_p = find_named_client(parv[1]);
        if(target_p != NULL && target_p != source_p)
@@ -336,28 +315,28 @@ ms_signon(struct Client *client_p, struct Client *source_p,
                                                     "Nick change collision from SIGNON from %s to %s(%s <- %s)(both killed)",
                                                     source_p->name, target_p->name, target_p->from->name,
                                                     client_p->name);
-               
+
                                ServerStats.is_kill++;
                                sendto_one_numeric(target_p, ERR_NICKCOLLISION,
                                                   form_str(ERR_NICKCOLLISION), target_p->name);
-               
+
                                kill_client_serv_butone(NULL, source_p, "%s (Nick change collision)", me.name);
-               
+
                                ServerStats.is_kill++;
-               
+
                                kill_client_serv_butone(NULL, target_p, "%s (Nick change collision)", me.name);
-               
+
                                target_p->flags |= FLAGS_KILLED;
                                exit_client(NULL, target_p, &me, "Nick collision(new)");
                                source_p->flags |= FLAGS_KILLED;
                                exit_client(client_p, source_p, &me, "Nick collision(old)");
-                               return 0;
+                               return;
                        }
                        else
                        {
                                sameuser = !irccmp(target_p->username, source_p->username) &&
                                        !irccmp(target_p->host, source_p->host);
-               
+
                                if((sameuser && newts < target_p->tsinfo) ||
                                   (!sameuser && newts > target_p->tsinfo))
                                {
@@ -371,23 +350,23 @@ ms_signon(struct Client *client_p, struct Client *source_p,
                                                                     "Nick change collision from SIGNON from %s to %s(%s <- %s)(newer killed)",
                                                                     source_p->name, target_p->name,
                                                                     target_p->from->name, client_p->name);
-               
+
                                        ServerStats.is_kill++;
-               
+
                                        sendto_one_numeric(target_p, ERR_NICKCOLLISION,
                                                           form_str(ERR_NICKCOLLISION), target_p->name);
-               
+
                                        /* kill the client issuing the nickchange */
                                        kill_client_serv_butone(client_p, source_p,
                                                                "%s (Nick change collision)", me.name);
-               
+
                                        source_p->flags |= FLAGS_KILLED;
-               
+
                                        if(sameuser)
                                                exit_client(client_p, source_p, &me, "Nick collision(old)");
                                        else
                                                exit_client(client_p, source_p, &me, "Nick collision(new)");
-                                       return 0;
+                                       return;
                                }
                                else
                                {
@@ -401,26 +380,25 @@ ms_signon(struct Client *client_p, struct Client *source_p,
                                                                     "Nick collision from SIGNON on %s(%s <- %s)(newer killed)",
                                                                     target_p->name, target_p->from->name,
                                                                     client_p->name);
-               
+
                                        sendto_one_numeric(target_p, ERR_NICKCOLLISION,
                                                           form_str(ERR_NICKCOLLISION), target_p->name);
-               
+
                                        /* kill the client who existed before hand */
-                                       kill_client_serv_butone(client_p, target_p, 
+                                       kill_client_serv_butone(client_p, target_p,
                                                        "%s (Nick collision)", me.name);
-               
+
                                        ServerStats.is_kill++;
-               
+
                                        target_p->flags |= FLAGS_KILLED;
                                        (void) exit_client(client_p, target_p, &me, "Nick collision");
                                }
                        }
-               
+
                }
        }
 
        send_signon(client_p, source_p, parv[1], parv[2], parv[3], newts, login);
-       return 0;
 }
 
 static void
@@ -432,8 +410,7 @@ send_signon(struct Client *client_p, struct Client *target_p,
                        use_id(target_p), nick, user, host,
                        (long) target_p->tsinfo, *login ? login : "0");
 
-       strcpy(target_p->user->suser, login);
+       rb_strlcpy(target_p->user->suser, login, sizeof(target_p->user->suser));
 
        change_nick_user_host(target_p, nick, user, host, newts, "Signing %s (%s)", *login ?  "in" : "out", nick);
 }
-