Use +U instead of +u for user passwords (avoiding collisions with a
[ircu2.10.12-pk.git] / ircd / channel.c
index be0e3367156ff3bc05dcacf032606001731a8a2a..4306d36c0c6d239527e8ba815134db52cd3954fb 100644 (file)
@@ -174,12 +174,11 @@ static char *make_nick_user_host(char *namebuf, const char *nick,
  * Create a string of form "foo!bar@123.456.789.123" given foo, bar and the
  * IP-number as the parameters.  If NULL, they become "*".
  */
-#define NUI_BUFSIZE    (NICKLEN + USERLEN + 16 + 3)
+#define NUI_BUFSIZE    (NICKLEN + USERLEN + SOCKIPLEN + 4)
 static char *make_nick_user_ip(char *ipbuf, char *nick, char *name,
-                              struct in_addr ip)
+                              const struct irc_in_addr *ip)
 {
-  ircd_snprintf(0, ipbuf, NUI_BUFSIZE, "%s!%s@%s", nick, name,
-               ircd_ntoa((const char*) &ip));
+  ircd_snprintf(0, ipbuf, NUI_BUFSIZE, "%s!%s@%s", nick, name, ircd_ntoa(ip));
   return ipbuf;
 }
 
@@ -480,11 +479,11 @@ static int is_banned(struct Client *cptr, struct Channel *chptr,
     if ((tmp->flags & CHFL_BAN_IPMASK)) {
       if (!ip_s)
         ip_s = make_nick_user_ip(nu_ip, cli_name(cptr),
-                                (cli_user(cptr))->username, cli_ip(cptr));
+                                (cli_user(cptr))->username, &cli_ip(cptr));
       if (match(tmp->value.ban.banstr, ip_s) == 0)
         break;
     }
-    else if (match(tmp->value.ban.banstr, s) == 0)
+    if (match(tmp->value.ban.banstr, s) == 0)
       break;
     else if (sr && match(tmp->value.ban.banstr, sr) == 0)
       break;
@@ -799,7 +798,7 @@ void channel_modes(struct Client *cptr, char *mbuf, char *pbuf, int buflen,
     previous_parameter = 1;
   }
   if (*chptr->mode.upass) {
-    *mbuf++ = 'u';
+    *mbuf++ = 'U';
     if (previous_parameter)
       strcat(pbuf, " ");
     if (IsServer(cptr) || (member && IsChanOp(member) && OpLevel(member) == 0)) {
@@ -841,6 +840,7 @@ void send_channel_modes(struct Client *cptr, struct Channel *chptr)
   int                 opped_members_index = 0;
   struct Membership** opped_members = NULL;
   int                 last_oplevel = 0;
+  int                 feat_oplevels = (chptr->mode.mode & MODE_APASS) != 0;
 
   assert(0 != cptr);
   assert(0 != chptr); 
@@ -919,7 +919,7 @@ void send_channel_modes(struct Client *cptr, struct Channel *chptr)
           * Do we have a nick with a new mode ?
           * Or are we starting a new BURST line?
           */
-         if (new_mode)
+         if (new_mode || !feat_oplevels)
          {
            /*
             * This means we are at the _first_ member that has only
@@ -937,9 +937,11 @@ void send_channel_modes(struct Client *cptr, struct Channel *chptr)
              tbuf[loc++] = 'v';
            if (IsChanOp(member))       /* flag_cnt == 2 or 3 */
            {
-             /* append the absolute value of the oplevel */
-             loc += ircd_snprintf(0, tbuf + loc, sizeof(tbuf) - loc, "%u", member->oplevel);
-             last_oplevel = member->oplevel;
+              /* append the absolute value of the oplevel */
+              if (feat_oplevels)
+                loc += ircd_snprintf(0, tbuf + loc, sizeof(tbuf) - loc, "%u", last_oplevel = member->oplevel);
+              else
+                tbuf[loc++] = 'o';
            }
            tbuf[loc] = '\0';
            msgq_append(&me, mb, tbuf);
@@ -1522,9 +1524,9 @@ modebuf_flush_int(struct ModeBuf *mbuf, int all)
     MODE_WASDELJOINS,   'd',
 /*  MODE_KEY,          'k', */
 /*  MODE_BAN,          'b', */
-/*  MODE_LIMIT,                'l', */
+    MODE_LIMIT,                'l',
 /*  MODE_APASS,                'A', */
-/*  MODE_UPASS,                'u', */
+/*  MODE_UPASS,                'U', */
     0x0, 0x0
   };
   int i;
@@ -1613,7 +1615,7 @@ modebuf_flush_int(struct ModeBuf *mbuf, int all)
            mode_char = 'A';
            break;
          case MODE_UPASS:
-           mode_char = 'u';
+           mode_char = 'U';
            break;
          default:
            mode_char = 'b';
@@ -1736,7 +1738,7 @@ modebuf_flush_int(struct ModeBuf *mbuf, int all)
                addbuf_i ? "+" : "", addbuf, remstr, addstr);
 
     if (mbuf->mb_dest & MODEBUF_DEST_CHANNEL)
-      sendcmdto_channel_butserv_butone(app_source, CMD_MODE, mbuf->mb_channel, NULL,
+      sendcmdto_channel_butserv_butone(app_source, CMD_MODE, mbuf->mb_channel, NULL, 0,
                                "%H %s%s%s%s%s%s", mbuf->mb_channel,
                                rembuf_i ? "-" : "", rembuf,
                                addbuf_i ? "+" : "", addbuf, remstr, addstr);
@@ -1928,6 +1930,10 @@ modebuf_mode_uint(struct ModeBuf *mbuf, unsigned int mode, unsigned int uint)
   assert(0 != mbuf);
   assert(0 != (mode & (MODE_ADD | MODE_DEL)));
 
+  if (mode == (MODE_LIMIT | MODE_DEL)) {
+      mbuf->mb_rem |= mode;
+      return;
+  }
   MB_TYPE(mbuf, mbuf->mb_count) = mode;
   MB_UINT(mbuf, mbuf->mb_count) = uint;
 
@@ -2020,7 +2026,7 @@ modebuf_extract(struct ModeBuf *mbuf, char *buf)
     MODE_NOPRIVMSGS,   'n',
     MODE_KEY,          'k',
     MODE_APASS,                'A',
-    MODE_UPASS,                'u',
+    MODE_UPASS,                'U',
 /*  MODE_BAN,          'b', */
     MODE_LIMIT,                'l',
     MODE_REGONLY,      'r',
@@ -2069,7 +2075,7 @@ modebuf_extract(struct ModeBuf *mbuf, char *buf)
       build_string(buf, &bufpos, key, 0, ' ');
     else if (buf[i] == 'l')
       build_string(buf, &bufpos, limitbuf, 0, ' ');
-    else if (buf[i] == 'u')
+    else if (buf[i] == 'U')
       build_string(buf, &bufpos, upass, 0, ' ');
     else if (buf[i] == 'A')
       build_string(buf, &bufpos, apass, 0, ' ');
@@ -2319,8 +2325,8 @@ mode_parse_upass(struct ParseState *state, int *flag_p)
 
   if (state->parc <= 0) { /* warn if not enough args */
     if (MyUser(state->sptr))
-      need_more_params(state->sptr, state->dir == MODE_ADD ? "MODE +u" :
-                      "MODE -u");
+      need_more_params(state->sptr, state->dir == MODE_ADD ? "MODE +U" :
+                      "MODE -U");
     return;
   }
 
@@ -2334,6 +2340,13 @@ mode_parse_upass(struct ParseState *state, int *flag_p)
     return;
   }
 
+  /* If a non-service user is trying to force it, refuse. */
+  if (state->flags & MODE_PARSE_FORCE && !IsChannelService(state->sptr)) {
+    send_reply(state->sptr, ERR_NOTMANAGER, state->chptr->chname,
+               "Use /JOIN", state->chptr->chname, " <AdminPass>.");
+    return;
+  }
+
   /* If they are not the channel manager, they are not allowed to change it */
   if (MyUser(state->sptr) && !IsChannelManager(state->member)) {
     if (*state->chptr->mode.apass) {
@@ -2362,8 +2375,8 @@ mode_parse_upass(struct ParseState *state, int *flag_p)
 
   if (!*t_str) { /* warn if empty */
     if (MyUser(state->sptr))
-      need_more_params(state->sptr, state->dir == MODE_ADD ? "MODE +u" :
-                      "MODE -u");
+      need_more_params(state->sptr, state->dir == MODE_ADD ? "MODE +U" :
+                      "MODE -U");
     return;
   }
 
@@ -2434,6 +2447,13 @@ mode_parse_apass(struct ParseState *state, int *flag_p)
     return;
   }
 
+  /* If a non-service user is trying to force it, refuse. */
+  if (state->flags & MODE_PARSE_FORCE && !IsChannelService(state->sptr)) {
+    send_reply(state->sptr, ERR_NOTMANAGER, state->chptr->chname,
+               "Use /JOIN", state->chptr->chname, " <AdminPass>.");
+    return;
+  }
+
   /* Don't allow to change the Apass if the channel is older than 48 hours. */
   if (TStime() - state->chptr->creationtime >= 172800 && !IsAnOper(state->sptr)) {
     send_reply(state->sptr, ERR_CHANSECURED, state->chptr->chname);
@@ -2965,7 +2985,7 @@ mode_parse(struct ModeBuf *mbuf, struct Client *cptr, struct Client *sptr,
     MODE_NOPRIVMSGS,   'n',
     MODE_KEY,          'k',
     MODE_APASS,                'A',
-    MODE_UPASS,                'u',
+    MODE_UPASS,                'U',
     MODE_BAN,          'b',
     MODE_LIMIT,                'l',
     MODE_REGONLY,      'r',
@@ -3046,7 +3066,7 @@ mode_parse(struct ModeBuf *mbuf, struct Client *cptr, struct Client *sptr,
        mode_parse_apass(&state, flag_p);
        break;
 
-      case 'u': /* deal with user passes */
+      case 'U': /* deal with user passes */
         if (feature_bool(FEAT_OPLEVELS))
        mode_parse_upass(&state, flag_p);
        break;
@@ -3207,7 +3227,7 @@ joinbuf_join(struct JoinBuf *jbuf, struct Channel *chan, unsigned int flags)
 
     /* Send notification to channel */
     if (!(flags & (CHFL_ZOMBIE | CHFL_DELAYED)))
-      sendcmdto_channel_butserv_butone(jbuf->jb_source, CMD_PART, chan, NULL,
+      sendcmdto_channel_butserv_butone(jbuf->jb_source, CMD_PART, chan, NULL, 0,
                                (flags & CHFL_BANNED || !jbuf->jb_comment) ?
                                ":%H" : "%H :%s", chan, jbuf->jb_comment);
     else if (MyUser(jbuf->jb_source))
@@ -3238,11 +3258,11 @@ joinbuf_join(struct JoinBuf *jbuf, struct Channel *chan, unsigned int flags)
 
     if (!((chan->mode.mode & MODE_DELJOINS) && !(flags & CHFL_VOICED_OR_OPPED))) {
       /* Send the notification to the channel */
-      sendcmdto_channel_butserv_butone(jbuf->jb_source, CMD_JOIN, chan, NULL, "%H", chan);
+      sendcmdto_channel_butserv_butone(jbuf->jb_source, CMD_JOIN, chan, NULL, 0, "%H", chan);
 
       /* send an op, too, if needed */
       if (!MyUser(jbuf->jb_source) && jbuf->jb_type == JOINBUF_TYPE_CREATE)
-       sendcmdto_channel_butserv_butone(jbuf->jb_source, CMD_MODE, chan, NULL, "%H +o %C",
+       sendcmdto_channel_butserv_butone(jbuf->jb_source, CMD_MODE, chan, NULL, 0, "%H +o %C",
                                         chan, jbuf->jb_source);
     } else if (MyUser(jbuf->jb_source))
       sendcmdto_one(jbuf->jb_source, CMD_JOIN, jbuf->jb_source, ":%H", chan);
@@ -3328,7 +3348,7 @@ int IsInvited(struct Client* cptr, const void* chptr)
 
 void RevealDelayedJoin(struct Membership *member) {
   ClearDelayedJoin(member);
-  sendcmdto_channel_butserv_butone(member->user, CMD_JOIN, member->channel, member->user, ":%H",
+  sendcmdto_channel_butserv_butone(member->user, CMD_JOIN, member->channel, member->user, 0, ":%H",
                                    member->channel);
   CheckDelayedJoins(member->channel);
 }
@@ -3346,7 +3366,7 @@ void CheckDelayedJoins(struct Channel *chan) {
     if (!memb2) {
       /* clear +d */
       chan->mode.mode &= ~MODE_WASDELJOINS;
-      sendcmdto_channel_butserv_butone(&me, CMD_MODE, chan, NULL, 
+      sendcmdto_channel_butserv_butone(&me, CMD_MODE, chan, NULL, 0,
                                        "%H -d", chan);
     }
   }