]> jfr.im git - irc/quakenet/snircd-patchqueue.git/blobdiff - welcome.patch
welcome: check the length of the message and throw warning to user when too long
[irc/quakenet/snircd-patchqueue.git] / welcome.patch
index b3aac7b2b75352e8226f5684dcbee76428d4e6d1..d2931823e8fdec0561f568070815be1da0da5881 100644 (file)
@@ -771,7 +771,7 @@ diff -r a9b437e961ec ircd/s_user.c
 diff -r a9b437e961ec ircd/welcome.c
 --- /dev/null
 +++ b/ircd/welcome.c
-@@ -0,0 +1,585 @@
+@@ -0,0 +1,592 @@
 +/*
 + * IRC - Internet Relay Chat, ircd/welcome.c
 + * Copyright (C) 1990 Jarkko Oikarinen and
@@ -875,12 +875,11 @@ diff -r a9b437e961ec ircd/welcome.c
 +/** Log a welcome message.
 + * @param[in] sptr Originator of the welcome.
 + * @param[in] msg The message to show.
-+ * @param[in] who Who set this message.
 + * @param[in] flags Flags to set on welcome.
 + * @return Zero
 + */
 +int
-+welcome_log(struct Client *sptr, char *msg, char *who, unsigned int flags)
++welcome_log(struct Client *sptr, char *msg, unsigned int flags)
 +{
 +
 +  /* inform ops */
@@ -889,7 +888,7 @@ diff -r a9b437e961ec ircd/welcome.c
 +    get_client_name_and_opername(sptr) : cli_name((cli_user(sptr))->server), msg);
 +
 +  /* log it */
-+  log_write(LS_NETWORK, L_INFO, LOG_NOSNOTICE, "%#C (%s) %s", sptr, who, msg);
++  log_write(LS_NETWORK, L_INFO, LOG_NOSNOTICE, "%s %s", get_client_name_and_opername(sptr), msg);
 +
 +  /* welcome by remote user, inform oper of success */
 +  if ((flags & WELCOME_LOCAL) && IsUser(sptr) && !MyUser(sptr)) {
@@ -935,14 +934,14 @@ diff -r a9b437e961ec ircd/welcome.c
 +  welcome_make(namearray, text, who, timestamp);
 +
 +  /* create msg for log */
-+  ircd_snprintf(0, msg, 0, "%s%s%s WELCOME %d \"%s\" [%Tu]",
++  ircd_snprintf(0, msg, 0, "%s%s%s WELCOME %d \"%s\" %s [%Tu]",
 +    new ? "setting" : "changing",
 +    (flags & WELCOME_ANNOUNCE) ? " and announcing " : " ",
 +    (flags & WELCOME_LOCAL) ? "local" : "global",
-+    nameint, text, timestamp);
++    nameint, text, who, timestamp);
 +
 +  /* log it */
-+  welcome_log(sptr, msg, who, flags);
++  welcome_log(sptr, msg, flags);
 +
 +  /* propagate it */
 +  if (!(flags & WELCOME_LOCAL))
@@ -987,11 +986,11 @@ diff -r a9b437e961ec ircd/welcome.c
 +  welcome_make(namearray, "", who, timestamp);
 +
 +  /* create msg for log */
-+  ircd_snprintf(0, msg, 0, "unsetting %s WELCOME %d \"%s\" [%Tu]",
-+    (flags & WELCOME_LOCAL) ? "local" : "global", nameint, text, timestamp);
++  ircd_snprintf(0, msg, 0, "unsetting %s WELCOME %d \"%s\" %s [%Tu]",
++    (flags & WELCOME_LOCAL) ? "local" : "global", nameint, text, who, timestamp);
 +
 +  /* log it */
-+  welcome_log(sptr, msg, who, flags);
++  welcome_log(sptr, msg, flags);
 +
 +  /* propagate it, but not when inserting */
 +  if (!(flags & (WELCOME_LOCAL|WELCOME_INSERT)))
@@ -1072,7 +1071,7 @@ diff -r a9b437e961ec ircd/welcome.c
 +      (flags & WELCOME_LOCAL) ? "local" : "global", nameint, (empty - nameint > 1) ? "to" : "and" , empty);
 +
 +  /* log it */
-+  welcome_log(sptr, msg, who, flags);
++  welcome_log(sptr, msg, flags);
 +
 +  /* set it */
 +  welcome_set(cptr, sptr, nameint, namearray, timestamp, who, text, flags);
@@ -1097,6 +1096,7 @@ diff -r a9b437e961ec ircd/welcome.c
 +{
 +  int nameint = atoi(name);                /* transform to int */
 +  int namearray = nameint - 1;             /* used to test the array element */
++  int max = WELCOME_MAX_ENTRIES;           /* max number of entries */
 +  static time_t rate;                      /* rate limit snomask message */
 +
 +  assert(NULL != cptr);
@@ -1119,24 +1119,35 @@ diff -r a9b437e961ec ircd/welcome.c
 +  }
 +
 +  /* check name */
-+  if (nameint < 1 || nameint > WELCOME_MAX_ENTRIES) {
++  if (!WelcomeIsValid(namearray)) {
 +    if (IsUser(sptr))
 +      sendcmdto_one(&me, CMD_NOTICE, sptr,
 +        "%C :WELCOME: Invalid message number %s - should between 1 and %d",
-+        sptr, name, WELCOME_MAX_ENTRIES);
++        sptr, name, max);
 +    else {
 +      protocol_violation(cptr, "WELCOME: Invalid message number %s from %C - should be between 1 and %d",
-+        name, sptr, WELCOME_MAX_ENTRIES);
-+      /* nameint greater than MAX, perhaps we are upgrading, but used extra slots too soon?
++        name, sptr, max);
++      /* nameint greater than max, perhaps we are upgrading, but used extra slots too soon?
 +       *   propagate it manually
 +       * TODO: cant do announce here?
 +       */
-+      if (nameint > WELCOME_MAX_ENTRIES && !(flags & WELCOME_LOCAL))
++      if (nameint > max && !(flags & WELCOME_LOCAL))
 +        welcome_propagate(cptr, sptr, nameint, timestamp, who, text, flags);
 +    }
 +    return 0;
 +  }
 +
++  /* source is user, and is myuser or welcome is local, check length of the message */
++  if ((IsUser(sptr)) && ((MyUser(sptr)) || (flags & WELCOME_LOCAL)) && (strlen(text) > WELCOMELEN)) {
++    sendcmdto_one(&me, CMD_NOTICE, sptr,
++      "%C :WELCOME: The message is too long with %d chars - max is %d chars",
++      sptr, strlen(text), WELCOMELEN);
++    ircd_strncpy(text, text, WELCOMELEN);
++    sendcmdto_one(&me, CMD_NOTICE, sptr,
++      "%C :WELCOME: Change or trunacte the message to: \"%s\"", sptr, text);
++    return 0;
++  }
++
 +  /* correct namearray for local offset */
 +  if (flags & WELCOME_LOCAL)
 +    namearray += WELCOME_MAX_ENTRIES;
@@ -1190,12 +1201,8 @@ diff -r a9b437e961ec ircd/welcome.c
 +  }
 +
 +  /* do not insert for last global/local entry and when not set yet */
-+  if (flags & WELCOME_INSERT) {
-+    if ((WelcomeArray[namearray].timestamp == 0) ||
-+         (!(flags & WELCOME_LOCAL) && nameint == WELCOME_MAX_ENTRIES) ||
-+         ((flags & WELCOME_LOCAL) && nameint == 2 * WELCOME_MAX_ENTRIES))
-+      flags &= ~WELCOME_INSERT;
-+  } 
++  if ((flags & WELCOME_INSERT) && ((WelcomeArray[namearray].timestamp == 0) || (nameint == max)))
++    flags &= ~WELCOME_INSERT;
 +
 +  /* TODO: rate limited for what? max 10 welcome messages..? */
 +  /* possible timestamp drift - warn ops */